OmniSciDB  2e3a973ef4
ForeignStorageBuffer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, 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 additional_num_bytes) {
32  if (size_ + additional_num_bytes > reserved_byte_count_) {
33  auto old_buffer = std::move(buffer_);
34  reserved_byte_count_ += additional_num_bytes;
35  buffer_ = std::make_unique<int8_t[]>(reserved_byte_count_);
36  if (old_buffer) {
37  memcpy(buffer_.get(), old_buffer.get(), size_);
38  }
39  }
40 }
41 
42 void ForeignStorageBuffer::append(int8_t* source,
43  const size_t num_bytes,
44  const MemoryLevel source_buffer_type,
45  const int device_id) {
46  if (size_ + num_bytes > reserved_byte_count_) {
47  reserve(num_bytes);
48  }
49  memcpy(buffer_.get() + size_, source, num_bytes);
50  size_ += num_bytes;
51 }
52 
54  return buffer_.get();
55 }
56 
58  return reserved_byte_count_;
59 }
60 
62  return CPU_LEVEL;
63 }
64 
65 void ForeignStorageBuffer::write(int8_t* source,
66  const size_t num_bytes,
67  const size_t offset,
68  const MemoryLevel source_buffer_type,
69  const int source_device_id) {
70  UNREACHABLE();
71 }
72 
74  UNREACHABLE();
75  return 0; // Added to avoid "no return statement" compiler warning
76 }
77 
79  UNREACHABLE();
80  return 0; // Added to avoid "no return statement" compiler warning
81 }
82 } // namespace foreign_storage
#define UNREACHABLE()
Definition: Logger.h:241
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