OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ThrustAllocator.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 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 /*
18  * @file ThrustAllocator.h
19  * @author Minggang Yu <miyu@mapd.com>
20  * @brief Allocate GPU memory using GpuBuffers via DataMgr. Unlike the CudaAllocator,
21  * these buffers are destroyed and memory is released when the parent object goes out of
22  * scope.
23  *
24  */
25 
26 #pragma once
27 
28 #include <cstddef>
29 #include <cstdint>
30 #include <unordered_map>
31 #include <vector>
32 
33 namespace Data_Namespace {
34 class DataMgr;
35 class AbstractBuffer;
36 }; // namespace Data_Namespace
37 
39  public:
40  using value_type = int8_t;
42  : data_mgr_(mgr), device_id_(id) {}
44 
45  int8_t* allocate(std::ptrdiff_t num_bytes);
46  void deallocate(int8_t* ptr, size_t num_bytes);
47 
48  int8_t* allocateScopedBuffer(std::ptrdiff_t num_bytes);
49 
51 
52  int getDeviceId() const { return device_id_; }
53 
54  private:
56  const int device_id_;
57  using PtrMapperType = std::unordered_map<int8_t*, Data_Namespace::AbstractBuffer*>;
59  std::vector<Data_Namespace::AbstractBuffer*> scoped_buffers_;
60  std::vector<int8_t*> default_alloc_scoped_buffers_; // for unit tests only
61  size_t num_allocations_{0};
62 };
int getDeviceId() const
std::unordered_map< int8_t *, Data_Namespace::AbstractBuffer * > PtrMapperType
int8_t * allocate(std::ptrdiff_t num_bytes)
std::vector< Data_Namespace::AbstractBuffer * > scoped_buffers_
void deallocate(int8_t *ptr, size_t num_bytes)
Data_Namespace::DataMgr * getDataMgr() const
std::vector< int8_t * > default_alloc_scoped_buffers_
Data_Namespace::DataMgr * data_mgr_
const int device_id_
PtrMapperType raw_to_ab_ptr_
int8_t * allocateScopedBuffer(std::ptrdiff_t num_bytes)
ThrustAllocator(Data_Namespace::DataMgr *mgr, const int id)