OmniSciDB  dfae7c3b14
CudaAllocator.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 
23 #pragma once
24 
25 #include <cstdint>
26 #include <cstdlib>
27 
28 #ifdef HAVE_CUDA
29 #include <cuda.h>
30 #else
31 #include <Shared/nocuda.h>
32 #endif
33 
35 
36 namespace Data_Namespace {
37 class AbstractBuffer;
38 class DataMgr;
39 } // namespace Data_Namespace
40 
41 class RenderAllocator;
42 
44  public:
45  CudaAllocator(Data_Namespace::DataMgr* data_mgr, const int device_id);
46 
47  ~CudaAllocator() override;
48 
49  static Data_Namespace::AbstractBuffer* allocGpuAbstractBuffer(
50  Data_Namespace::DataMgr* data_mgr,
51  const size_t num_bytes,
52  const int device_id);
53 
54  static void freeGpuAbstractBuffer(Data_Namespace::DataMgr* data_mgr,
56 
57  int8_t* alloc(const size_t num_bytes) override;
58 
59  void free(Data_Namespace::AbstractBuffer* ab) const override;
60 
61  void copyToDevice(int8_t* device_dst,
62  const int8_t* host_src,
63  const size_t num_bytes) const override;
64 
65  void copyFromDevice(int8_t* host_dst,
66  const int8_t* device_src,
67  const size_t num_bytes) const override;
68 
69  void zeroDeviceMem(int8_t* device_ptr, const size_t num_bytes) const override;
70 
71  void setDeviceMem(int8_t* device_ptr,
72  unsigned char uc,
73  const size_t num_bytes) const override;
74 
75  private:
76  std::vector<Data_Namespace::AbstractBuffer*> owned_buffers_;
77 
80 };
Data_Namespace::DataMgr * data_mgr_
Definition: CudaAllocator.h:78
An AbstractBuffer is a unit of data management for a data manager.
std::vector< Data_Namespace::AbstractBuffer * > owned_buffers_
Definition: CudaAllocator.h:76
Abstract class for managing device memory allocations.