OmniSciDB  04ee39c94c
GpuCudaBuffer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 
17 #include "GpuCudaBuffer.h"
18 #include "../../../CudaMgr/CudaMgr.h"
19 #include "Shared/Logger.h"
20 
21 #include <cassert>
22 
23 namespace Buffer_Namespace {
24 
26  BufferList::iterator segIt,
27  const int deviceId,
29  const size_t pageSize,
30  const size_t numBytes)
31  : Buffer(bm, segIt, deviceId, pageSize, numBytes), cudaMgr_(cudaMgr) {}
32 
33 void GpuCudaBuffer::readData(int8_t* const dst,
34  const size_t numBytes,
35  const size_t offset,
36  const MemoryLevel dstBufferType,
37  const int dstDeviceId) {
38  if (dstBufferType == CPU_LEVEL) {
40  dst, mem_ + offset, numBytes, deviceId_); // need to replace 0 with gpu num
41  } else if (dstBufferType == GPU_LEVEL) {
42  //@todo fill this in
43  // CudaUtils::copyGpuToGpu(dst, mem_ + offset, numBytes, 1, dst->getDeviceId());
44  //@todo, populate device id
45  // CudaUtils::copyGpuToGpu(dst, mem_ + offset, numBytes, 1, 0);
46  cudaMgr_->copyDeviceToDevice(dst, mem_ + offset, numBytes, dstDeviceId, deviceId_);
47 
48  } else {
49  LOG(FATAL) << "Unsupported buffer type";
50  }
51 }
52 
53 void GpuCudaBuffer::writeData(int8_t* const src,
54  const size_t numBytes,
55  const size_t offset,
56  const MemoryLevel srcBufferType,
57  const int srcDeviceId) {
58  if (srcBufferType == CPU_LEVEL) {
59  // std::cout << "Writing to GPU from source CPU" << std::endl;
60 
62  mem_ + offset, src, numBytes, deviceId_); // need to replace 0 with gpu num
63 
64  } else if (srcBufferType == GPU_LEVEL) {
65  // std::cout << "Writing to GPU from source GPU" << std::endl;
66  assert(srcDeviceId >= 0);
67  cudaMgr_->copyDeviceToDevice(mem_ + offset, src, numBytes, deviceId_, srcDeviceId);
68  // CudaUtils::copyGpuToGpu(mem_ + offset, src, numBytes, 1, deviceId_);
69  //@todo fill this in
70  } else {
71  LOG(FATAL) << "Unsupported buffer type";
72  }
73 }
74 
75 } // namespace Buffer_Namespace
void writeData(int8_t *const src, const size_t numBytes, const size_t offset=0, const MemoryLevel srcBufferType=CPU_LEVEL, const int srcDeviceId=-1) override
void copyDeviceToHost(int8_t *host_ptr, const int8_t *device_ptr, const size_t num_bytes, const int device_num)
Definition: CudaMgr.cpp:80
#define LOG(tag)
Definition: Logger.h:182
int64_t * src
void copyDeviceToDevice(int8_t *dest_ptr, int8_t *src_ptr, const size_t num_bytes, const int dest_device_num, const int src_device_num)
Definition: CudaMgr.cpp:89
Note(s): Forbid Copying Idiom 4.1.
Definition: BufferMgr.h:96
void copyHostToDevice(int8_t *device_ptr, const int8_t *host_ptr, const size_t num_bytes, const int device_num)
Definition: CudaMgr.cpp:71
void readData(int8_t *const dst, const size_t numBytes, const size_t offset=0, const MemoryLevel dstBufferType=CPU_LEVEL, const int dstDeviceId=-1) override
GpuCudaBuffer(BufferMgr *bm, BufferList::iterator segIt, const int deviceId, CudaMgr_Namespace::CudaMgr *cudaMgr, const size_t pageSize=512, const size_t numBytes=0)
CudaMgr_Namespace::CudaMgr * cudaMgr_
Definition: GpuCudaBuffer.h:50
Note(s): Forbid Copying Idiom 4.1.
Definition: Buffer.h:45