OmniSciDB  c07336695a
CpuBuffer.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 "CpuBuffer.h"
18 #include <cassert>
19 #include <cstring>
20 #include "../../../CudaMgr/CudaMgr.h"
21 #include "Shared/Logger.h"
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 CpuBuffer::readData(int8_t* const dst,
34  const size_t numBytes,
35  const size_t offset,
36  const MemoryLevel dstMemoryLevel,
37  const int dstDeviceId) {
38  if (dstMemoryLevel == CPU_LEVEL) {
39  memcpy(dst, mem_ + offset, numBytes);
40  } else if (dstMemoryLevel == GPU_LEVEL) {
41  //@todo: use actual device id in next call
42  assert(dstDeviceId >= 0);
44  dst, mem_ + offset, numBytes, dstDeviceId); // need to replace 0 with gpu num
45  } else {
46  LOG(FATAL) << "Unsupported buffer type";
47  }
48 }
49 
50 void CpuBuffer::writeData(int8_t* const src,
51  const size_t numBytes,
52  const size_t offset,
53  const MemoryLevel srcMemoryLevel,
54  const int srcDeviceId) {
55  if (srcMemoryLevel == CPU_LEVEL) {
56  // std::cout << "Writing to CPU from source CPU" << std::endl;
57  memcpy(mem_ + offset, src, numBytes);
58  } else if (srcMemoryLevel == GPU_LEVEL) {
59  // std::cout << "Writing to CPU from source GPU" << std::endl;
60  //@todo: use actual device id in next call
61  assert(srcDeviceId >= 0);
63  mem_ + offset, src, numBytes, srcDeviceId); // need to replace 0 with gpu num
64  } else {
65  LOG(FATAL) << "Unsupported buffer type";
66  }
67 }
68 
69 } // namespace Buffer_Namespace
CudaMgr_Namespace::CudaMgr * cudaMgr_
Definition: CpuBuffer.h:49
CpuBuffer(BufferMgr *bm, BufferList::iterator segIt, const int deviceId, CudaMgr_Namespace::CudaMgr *cudaMgr, const size_t pageSize=512, const size_t numBytes=0)
Definition: CpuBuffer.cpp:25
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
Note(s): Forbid Copying Idiom 4.1.
Definition: BufferMgr.h:96
void writeData(int8_t *const src, const size_t numBytes, const size_t offset=0, const MemoryLevel srcMemoryLevel=CPU_LEVEL, const int srcDeviceId=-1) override
Definition: CpuBuffer.cpp:50
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 dstMemoryLevel=CPU_LEVEL, const int dstDeviceId=-1) override
Definition: CpuBuffer.cpp:33
Note(s): Forbid Copying Idiom 4.1.
Definition: Buffer.h:45