OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 "DeviceAllocator.h"
26 
27 #ifdef HAVE_CUDA
28 #include <cuda.h>
29 #else
30 #include <Shared/nocuda.h>
31 #endif
32 
33 #include <cstdint>
34 #include <cstdlib>
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 int8_t* alloc(Data_Namespace::DataMgr* data_mgr,
50  const size_t num_bytes,
51  const int device_id);
52 
54  Data_Namespace::DataMgr* data_mgr,
55  const size_t num_bytes,
56  const int device_id);
57 
58  static void freeGpuAbstractBuffer(Data_Namespace::DataMgr* data_mgr,
60 
61  int8_t* alloc(const size_t num_bytes) override;
62 
63  void free(Data_Namespace::AbstractBuffer* ab) const override;
64 
65  void copyToDevice(int8_t* device_dst,
66  const int8_t* host_src,
67  const size_t num_bytes) const override;
68 
69  void copyFromDevice(int8_t* host_dst,
70  const int8_t* device_src,
71  const size_t num_bytes) const override;
72 
73  void zeroDeviceMem(int8_t* device_ptr, const size_t num_bytes) const override;
74 
75  void setDeviceMem(int8_t* device_ptr,
76  unsigned char uc,
77  const size_t num_bytes) const override;
78 
79  private:
82 };
void copyFromDevice(int8_t *host_dst, const int8_t *device_src, const size_t num_bytes) const override
CudaAllocator(Data_Namespace::DataMgr *data_mgr, const int device_id)
void copyToDevice(int8_t *device_dst, const int8_t *host_src, const size_t num_bytes) const override
void zeroDeviceMem(int8_t *device_ptr, const size_t num_bytes) const override
Data_Namespace::DataMgr * data_mgr_
Definition: CudaAllocator.h:80
static int8_t * alloc(Data_Namespace::DataMgr *data_mgr, const size_t num_bytes, const int device_id)
An AbstractBuffer is a unit of data management for a data manager.
void free(Data_Namespace::AbstractBuffer *ab) const override
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
Definition: CudaAllocator.h:47
static Data_Namespace::AbstractBuffer * allocGpuAbstractBuffer(Data_Namespace::DataMgr *data_mgr, const size_t num_bytes, const int device_id)