OmniSciDB  c0231cc57d
 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 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 
22 #pragma once
23 
24 #include <cstdint>
25 #include <cstdlib>
26 
27 #ifdef HAVE_CUDA
28 #include <cuda.h>
29 #else
30 #include <Shared/nocuda.h>
31 #endif
32 
34 
35 namespace Data_Namespace {
36 class AbstractBuffer;
37 class DataMgr;
38 } // namespace Data_Namespace
39 
40 class RenderAllocator;
41 
43  public:
45  const int device_id,
46  CUstream cuda_stream);
47 
48  ~CudaAllocator() override;
49 
51  Data_Namespace::DataMgr* data_mgr,
52  const size_t num_bytes,
53  const int device_id);
54 
55  static void freeGpuAbstractBuffer(Data_Namespace::DataMgr* data_mgr,
57 
58  int8_t* alloc(const size_t num_bytes) override;
59 
60  void free(Data_Namespace::AbstractBuffer* ab) const override;
61 
62  void copyToDevice(void* device_dst,
63  const void* host_src,
64  const size_t num_bytes) const override;
65 
66  void copyFromDevice(void* host_dst,
67  const void* device_src,
68  const size_t num_bytes) const override;
69 
70  void zeroDeviceMem(int8_t* device_ptr, const size_t num_bytes) const override;
71 
72  void setDeviceMem(int8_t* device_ptr,
73  unsigned char uc,
74  const size_t num_bytes) const override;
75 
76  private:
77  std::vector<Data_Namespace::AbstractBuffer*> owned_buffers_;
78 
82 };
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:79
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:77
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:81
void copyFromDevice(void *host_dst, const void *device_src, const size_t num_bytes) const override