OmniSciDB  c07336695a
JoinHashTableGpuUtils.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 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 
17 #ifndef QUERYENGINE_JOINHASHTABLE_GPUUTILS_H
18 #define QUERYENGINE_JOINHASHTABLE_GPUUTILS_H
19 
21 #include "GpuMemUtils.h"
22 
23 template <class T>
24 T* transfer_pod_vector_to_gpu(const std::vector<T>& vec, ThrustAllocator& allocator) {
25  static_assert(std::is_pod<T>::value,
26  "Transferring a vector to GPU only works for POD elements");
27  const auto vec_bytes = vec.size() * sizeof(T);
28  auto gpu_vec = allocator.allocateScopedBuffer(vec_bytes);
29  copy_to_gpu(allocator.getDataMgr(),
30  reinterpret_cast<CUdeviceptr>(gpu_vec),
31  &vec[0],
32  vec_bytes,
33  allocator.getDeviceId());
34  return reinterpret_cast<T*>(gpu_vec);
35 }
36 
37 template <class T>
38 T* transfer_object_to_gpu(const T& object, ThrustAllocator& allocator) {
39  static_assert(std::is_standard_layout<T>::value,
40  "Transferring an object to GPU only works for standard layout elements");
41  const auto bytes = sizeof(T);
42  auto gpu_ptr = allocator.allocateScopedBuffer(bytes);
43  copy_to_gpu(allocator.getDataMgr(),
44  reinterpret_cast<CUdeviceptr>(gpu_ptr),
45  &object,
46  bytes,
47  allocator.getDeviceId());
48  return reinterpret_cast<T*>(gpu_ptr);
49 }
50 
51 #endif // QUERYENGINE_JOINHASHTABLE_GPUUTILS_H
Data_Namespace::DataMgr * getDataMgr() const
unsigned long long CUdeviceptr
Definition: nocuda.h:27
T * transfer_pod_vector_to_gpu(const std::vector< T > &vec, ThrustAllocator &allocator)
int8_t * allocateScopedBuffer(std::ptrdiff_t num_bytes)
T * transfer_object_to_gpu(const T &object, ThrustAllocator &allocator)
void copy_to_gpu(Data_Namespace::DataMgr *data_mgr, CUdeviceptr dst, const void *src, const size_t num_bytes, const int device_id)
Definition: GpuMemUtils.cpp:31
int getDeviceId() const