ThrustUtils.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_THRUST_UTILS_HPP
12 #define CUBBYFLOW_THRUST_UTILS_HPP
13 
14 #ifdef CUBBYFLOW_USE_CUDA
15 
16 #include <Core/CUDA/CUDAArray.hpp>
17 
18 #include <cuda_runtime.h>
19 
20 #include <thrust/device_ptr.h>
21 
22 #include <algorithm>
23 #include <cstdint>
24 
25 namespace CubbyFlow
26 {
27 template <typename T, size_t N, typename D>
28 thrust::device_ptr<T> thrustBegin(CUDAArrayBase<T, N, D>& arr)
29 {
30  return thrust::device_ptr<T>(arr.data());
31 }
32 
33 template <typename T, size_t N, typename D>
34 thrust::device_ptr<const T> thrustCBegin(const CUDAArrayBase<T, N, D>& arr)
35 {
36  return thrust::device_ptr<const T>(arr.data());
37 }
38 
39 template <typename T, size_t N, typename D>
40 thrust::device_ptr<T> thrustEnd(CUDAArrayBase<T, N, D>& arr)
41 {
42  return thrust::device_ptr<T>(arr.data() + arr.Length());
43 }
44 
45 template <typename T, size_t N, typename D>
46 thrust::device_ptr<const T> thrustCEnd(const CUDAArrayBase<T, N, D>& arr)
47 {
48  return thrust::device_ptr<const T>(arr.data() + arr.Length());
49 }
50 } // namespace CubbyFlow
51 
52 #endif
53 
54 #endif
Definition: pybind11Utils.hpp:20