OmniSciDB  a987f07e93
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DeviceAllocator.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 "Logger/Logger.h"
25 
26 #ifdef HAVE_CUDA
27 #include <cuda.h>
28 #else
29 #include <Shared/nocuda.h>
30 #endif
31 
32 namespace Data_Namespace {
33 class AbstractBuffer;
34 class DataMgr;
35 } // namespace Data_Namespace
36 
37 class Allocator {
38  public:
39  Allocator() {}
40  virtual ~Allocator() {}
41 
42  virtual int8_t* alloc(const size_t num_bytes) = 0;
43 };
44 
45 class DeviceAllocator : public Allocator {
46  public:
47  virtual void free(Data_Namespace::AbstractBuffer* ab) const = 0;
48 
49  virtual void copyToDevice(void* device_dst,
50  const void* host_src,
51  const size_t num_bytes) const = 0;
52 
53  virtual void copyFromDevice(void* host_dst,
54  const void* device_src,
55  const size_t num_bytes) const = 0;
56 
57  virtual void zeroDeviceMem(int8_t* device_ptr, const size_t num_bytes) const = 0;
58 
59  virtual void setDeviceMem(int8_t* device_ptr,
60  unsigned char uc,
61  const size_t num_bytes) const = 0;
62 };
virtual int8_t * alloc(const size_t num_bytes)=0
virtual void free(Data_Namespace::AbstractBuffer *ab) const =0
virtual void copyToDevice(void *device_dst, const void *host_src, const size_t num_bytes) const =0
virtual void zeroDeviceMem(int8_t *device_ptr, const size_t num_bytes) const =0
An AbstractBuffer is a unit of data management for a data manager.
virtual void copyFromDevice(void *host_dst, const void *device_src, const size_t num_bytes) const =0
virtual void setDeviceMem(int8_t *device_ptr, unsigned char uc, const size_t num_bytes) const =0
virtual ~Allocator()