OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GpuCudaBuffer.cpp
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 
18 
19 #include <cassert>
20 
21 #include "CudaMgr/CudaMgr.h"
22 #include "Logger/Logger.h"
23 
24 namespace Buffer_Namespace {
25 
27  BufferList::iterator seg_it,
28  const int device_id,
30  const size_t page_size,
31  const size_t num_bytes)
32  : Buffer(bm, seg_it, device_id, page_size, num_bytes), cuda_mgr_(cuda_mgr) {}
33 
34 void GpuCudaBuffer::readData(int8_t* const dst,
35  const size_t num_bytes,
36  const size_t offset,
37  const MemoryLevel dst_buffer_type,
38  const int dst_device_id) {
39  if (dst_buffer_type == CPU_LEVEL) {
41  dst, mem_ + offset, num_bytes); // need to replace 0 with gpu num
42  } else if (dst_buffer_type == GPU_LEVEL) {
44  dst, mem_ + offset, num_bytes, dst_device_id, device_id_);
45 
46  } else {
47  LOG(FATAL) << "Unsupported buffer type";
48  }
49 }
50 
51 void GpuCudaBuffer::writeData(int8_t* const src,
52  const size_t num_bytes,
53  const size_t offset,
54  const MemoryLevel src_buffer_type,
55  const int src_device_id) {
56  if (src_buffer_type == CPU_LEVEL) {
57  // std::cout << "Writing to GPU from source CPU" << std::endl;
58 
60  mem_ + offset, src, num_bytes, device_id_); // need to replace 0 with gpu num
61 
62  } else if (src_buffer_type == GPU_LEVEL) {
63  // std::cout << "Writing to GPU from source GPU" << std::endl;
64  CHECK_GE(src_device_id, 0);
66  mem_ + offset, src, num_bytes, device_id_, src_device_id);
67  } else {
68  LOG(FATAL) << "Unsupported buffer type";
69  }
70 }
71 
72 } // namespace Buffer_Namespace
void copyHostToDevice(int8_t *device_ptr, const int8_t *host_ptr, const size_t num_bytes, const int device_num, CUstream cuda_stream=0)
Definition: CudaMgr.cpp:127
#define LOG(tag)
Definition: Logger.h:285
#define CHECK_GE(x, y)
Definition: Logger.h:306
Note(s): Forbid Copying Idiom 4.1.
Definition: BufferMgr.h:96
void readData(int8_t *const dst, const size_t num_bytes, const size_t offset=0, const MemoryLevel dst_buffer_type=CPU_LEVEL, const int dst_devic_id=-1) override
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, CUstream cuda_stream=0)
Definition: CudaMgr.cpp:164
void copyDeviceToHost(int8_t *host_ptr, const int8_t *device_ptr, const size_t num_bytes, CUstream cuda_stream=0)
Definition: CudaMgr.cpp:143
void writeData(int8_t *const src, const size_t num_bytes, const size_t offset=0, const MemoryLevel src_buffer_type=CPU_LEVEL, const int src_device_id=-1) override
CudaMgr_Namespace::CudaMgr * cuda_mgr_
Definition: GpuCudaBuffer.h:48
GpuCudaBuffer(BufferMgr *bm, BufferList::iterator seg_it, const int device_id, CudaMgr_Namespace::CudaMgr *cuda_mgr, const size_t page_size=512, const size_t num_bytes=0)
Note(s): Forbid Copying Idiom 4.1.
Definition: Buffer.h:42