OmniSciDB  340b00dbf6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
22 
23 template <class T>
24 T* transfer_vector_of_flat_objects_to_gpu(const std::vector<T>& vec,
25  CudaAllocator& allocator) {
26  static_assert(std::is_trivially_copyable<T>::value && std::is_standard_layout<T>::value,
27  "Transferring a vector to GPU only works for flat object elements");
28  const auto vec_bytes = vec.size() * sizeof(T);
29  auto gpu_vec = allocator.alloc(vec_bytes);
30  allocator.copyToDevice(gpu_vec, reinterpret_cast<const int8_t*>(vec.data()), vec_bytes);
31  return reinterpret_cast<T*>(gpu_vec);
32 }
33 
34 template <class T>
35 T* transfer_flat_object_to_gpu(const T& object, CudaAllocator& allocator) {
36  static_assert(std::is_standard_layout<T>::value,
37  "Transferring an object to GPU only works for standard layout elements");
38  const auto bytes = sizeof(T);
39  auto gpu_ptr = allocator.alloc(bytes);
40  allocator.copyToDevice(gpu_ptr, reinterpret_cast<const int8_t*>(&object), bytes);
41  return reinterpret_cast<T*>(gpu_ptr);
42 }
43 
44 #endif // QUERYENGINE_JOINHASHTABLE_GPUUTILS_H
void copyToDevice(int8_t *device_dst, const int8_t *host_src, const size_t num_bytes) const override
T * transfer_flat_object_to_gpu(const T &object, CudaAllocator &allocator)
int8_t * alloc(const size_t num_bytes) override
T * transfer_vector_of_flat_objects_to_gpu(const std::vector< T > &vec, CudaAllocator &allocator)
Allocate GPU memory using GpuBuffers via DataMgr.