Loading...
Searching...
No Matches
CUDAAlgorithms.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_CUDA_ALGORITHMS_HPP
12#define CUBBYFLOW_CUDA_ALGORITHMS_HPP
13
14#ifdef CUBBYFLOW_USE_CUDA
15
17
18#include <stdio.h>
19
20namespace CubbyFlow
21{
22#ifdef __CUDACC__
23
24template <typename T>
25__global__ void CUDAFillKernel(T* dst, size_t n, T val)
26{
27 size_t i = blockIdx.x * blockDim.x + threadIdx.x;
28
29 if (i < n)
30 {
31 dst[i] = val;
32 }
33}
34
35template <typename T>
36void CUDAFill(T* dst, size_t n, const T& val)
37{
38 if (n == 0)
39 {
40 return;
41 }
42
43 unsigned int numBlocks, numThreads;
44 CUDAComputeGridSize((unsigned int)n, 256, numBlocks, numThreads);
46
47 CUBBYFLOW_CUDA_CHECK_LAST_ERROR("Failed executing CUDAFillKernel");
48}
49
50#endif
51
52template <typename T>
53__host__ __device__ inline void CUDASwap(T& a, T& b)
54{
55 T tmp = a;
56 a = b;
57 b = tmp;
58}
59
60// TODO: Rename it to something else to indicate this is a memory copy.
61// TODO: Also, having CUDA prefix may collide with CUDA API.
62template <typename T>
63void CUDACopy(const T* src, size_t n, T* dst,
65{
67}
68
69template <typename T>
70void CUDACopyDeviceToDevice(const T* src, size_t n, T* dst)
71{
73}
74
75template <typename T>
76void CUDACopyHostToDevice(const T* src, size_t n, T* dst)
77{
79}
80
81template <typename T>
82void CUDACopyDeviceToHost(const T* src, size_t n, T* dst)
83{
85}
86} // namespace CubbyFlow
87
88#endif
89
90#endif
Definition pybind11Utils.hpp:21
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738