OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ForeignStorageBuffer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "ForeignStorageBuffer.h"
18 
19 namespace foreign_storage {
21  : AbstractBuffer(0), buffer_(nullptr), reserved_byte_count_(0) {}
22 
23 void ForeignStorageBuffer::read(int8_t* const destination,
24  const size_t num_bytes,
25  const size_t offset,
26  const MemoryLevel destination_buffer_type,
27  const int destination_device_id) {
28  memcpy(destination, buffer_.get() + offset, num_bytes);
29 }
30 
31 void ForeignStorageBuffer::reserve(size_t total_num_bytes) {
32  if (total_num_bytes > reserved_byte_count_) {
33  auto old_buffer = std::move(buffer_);
35  while (total_num_bytes > reserved_byte_count_) {
37  }
38  buffer_ = std::make_unique<int8_t[]>(reserved_byte_count_);
39  if (old_buffer) {
40  memcpy(buffer_.get(), old_buffer.get(), size_);
41  }
42  }
43 }
44 
45 void ForeignStorageBuffer::append(int8_t* source,
46  const size_t num_bytes,
47  const MemoryLevel source_buffer_type,
48  const int device_id) {
49  if (size_ + num_bytes > reserved_byte_count_) {
50  reserve(size_ + num_bytes);
51  }
52  memcpy(buffer_.get() + size_, source, num_bytes);
53  size_ += num_bytes;
54 }
55 
57  return buffer_.get();
58 }
59 
61  return reserved_byte_count_;
62 }
63 
65  return CPU_LEVEL;
66 }
67 
68 void ForeignStorageBuffer::write(int8_t* source,
69  const size_t num_bytes,
70  const size_t offset,
71  const MemoryLevel source_buffer_type,
72  const int source_device_id) {
73  UNREACHABLE();
74 }
75 
77  UNREACHABLE();
78  return 0; // Added to avoid "no return statement" compiler warning
79 }
80 
82  UNREACHABLE();
83  return 0; // Added to avoid "no return statement" compiler warning
84 }
85 } // namespace foreign_storage
#define UNREACHABLE()
Definition: Logger.h:338
void append(int8_t *source, const size_t num_bytes, const MemoryLevel source_buffer_type=CPU_LEVEL, const int device_id=-1) override
void reserve(size_t additional_num_bytes) override
void read(int8_t *const destination, const size_t num_bytes, const size_t offset=0, const MemoryLevel destination_buffer_type=CPU_LEVEL, const int destination_device_id=-1) override
An AbstractBuffer is a unit of data management for a data manager.
void write(int8_t *source, const size_t num_bytes, const size_t offset=0, const MemoryLevel source_buffer_type=CPU_LEVEL, const int source_device_id=-1) override