OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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:
46  const int device_id,
47  CUstream cuda_stream);
48 
49  ~CudaAllocator() override;
50 
52  Data_Namespace::DataMgr* data_mgr,
53  const size_t num_bytes,
54  const int device_id);
55 
56  static void freeGpuAbstractBuffer(Data_Namespace::DataMgr* data_mgr,
58 
59  int8_t* alloc(const size_t num_bytes) override;
60 
61  void free(Data_Namespace::AbstractBuffer* ab) const override;
62 
63  void copyToDevice(void* device_dst,
64  const void* host_src,
65  const size_t num_bytes) const override;
66 
67  void copyFromDevice(void* host_dst,
68  const void* device_src,
69  const size_t num_bytes) const override;
70 
71  void zeroDeviceMem(int8_t* device_ptr, const size_t num_bytes) const override;
72 
73  void setDeviceMem(int8_t* device_ptr,
74  unsigned char uc,
75  const size_t num_bytes) const override;
76 
77  private:
78  std::vector<Data_Namespace::AbstractBuffer*> owned_buffers_;
79 
83 };
void * CUstream
Definition: nocuda.h:23
void zeroDeviceMem(int8_t *device_ptr, const size_t num_bytes) const override
CudaAllocator(Data_Namespace::DataMgr *data_mgr, const int device_id, CUstream cuda_stream)
Data_Namespace::DataMgr * data_mgr_
Definition: CudaAllocator.h:80
An AbstractBuffer is a unit of data management for a data manager.
void free(Data_Namespace::AbstractBuffer *ab) const override
void copyToDevice(void *device_dst, const void *host_src, const size_t num_bytes) const override
int8_t * alloc(const size_t num_bytes) override
std::vector< Data_Namespace::AbstractBuffer * > owned_buffers_
Definition: CudaAllocator.h:78
static void freeGpuAbstractBuffer(Data_Namespace::DataMgr *data_mgr, Data_Namespace::AbstractBuffer *ab)
void setDeviceMem(int8_t *device_ptr, unsigned char uc, const size_t num_bytes) const override
Abstract class for managing device memory allocations.
~CudaAllocator() override
static Data_Namespace::AbstractBuffer * allocGpuAbstractBuffer(Data_Namespace::DataMgr *data_mgr, const size_t num_bytes, const int device_id)
CUstream cuda_stream_
Definition: CudaAllocator.h:82
void copyFromDevice(void *host_dst, const void *device_src, const size_t num_bytes) const override