OmniSciDB  72c90bc290
 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 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 /*
18  * @file ThrustAllocator.h
19  * @brief Allocate GPU memory using GpuBuffers via DataMgr. Unlike the CudaAllocator,
20  * these buffers are destroyed and memory is released when the parent object goes out of
21  * scope.
22  *
23  */
24 
25 #pragma once
26 
27 #include <cstddef>
28 #include <cstdint>
29 #include <unordered_map>
30 #include <vector>
31 
32 namespace Data_Namespace {
33 class DataMgr;
34 class AbstractBuffer;
35 }; // namespace Data_Namespace
36 
38  public:
39  using value_type = int8_t;
41  : data_mgr_(mgr), device_id_(id) {}
43 
44  int8_t* allocate(std::ptrdiff_t num_bytes);
45  void deallocate(int8_t* ptr, size_t num_bytes);
46 
47  int8_t* allocateScopedBuffer(std::ptrdiff_t num_bytes);
48 
50 
51  int getDeviceId() const { return device_id_; }
52 
53  private:
55  const int device_id_;
56  using PtrMapperType = std::unordered_map<int8_t*, Data_Namespace::AbstractBuffer*>;
58  std::vector<Data_Namespace::AbstractBuffer*> scoped_buffers_;
59  std::vector<int8_t*> default_alloc_scoped_buffers_; // for unit tests only
60  size_t num_allocations_{0};
61 };
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)