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