Debian Codegraph @

packages/stokhos/src/kokkos/Cuda/Stokhos_Cuda_WarpShuffle.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #ifndef STOKHOS_CUDA_WARP_SHUFFLE_HPP
11 #define STOKHOS_CUDA_WARP_SHUFFLE_HPP
12
13 #include "Kokkos_Core.hpp"
14
15 #ifdef __CUDA_ARCH__
16 # if (__CUDA_ARCH__ >= 300)
17 # define HAVE_CUDA_SHUFFLE 1
18 # else
19 # define HAVE_CUDA_SHUFFLE 0
20 # endif
21 #else
22 # define HAVE_CUDA_SHUFFLE 0
23 #endif
24
25 namespace Stokhos {
26
27 template<typename Scalar>
28 KOKKOS_INLINE_FUNCTION
29 Scalar shfl_down(const Scalar &val, const int& delta, const int& width){
30 return Kokkos::shfl_down(val, delta, width);
31 }
32
33 template<typename Scalar>
34 KOKKOS_INLINE_FUNCTION
35 Scalar shfl_up(const Scalar &val, const int& delta, const int& width){
36 return Kokkos::shfl_up(val, delta, width);
37 }
38
39 template<typename Scalar>
40 KOKKOS_INLINE_FUNCTION
41 Scalar shfl_down(const Scalar &val, const int& delta, const int& width,
42 const int& mask){
43 #ifdef __CUDA_ARCH__
44 return __shfl_down_sync(mask, val, delta, width);
45 #else
46 (void) delta;
47 (void) width;
48 (void) mask;
49 return val;
50 #endif
51 }
52
53 template<typename Scalar>
54 KOKKOS_INLINE_FUNCTION
55 Scalar shfl_up(const Scalar &val, const int& delta, const int& width,
56 const int& mask){
57 #ifdef __CUDA_ARCH__
58 return __shfl_up_sync(mask, val, delta, width);
59 #else
60 (void) delta;
61 (void) width;
62 (void) mask;
63 return val;
64 #endif
65 }
66
67 KOKKOS_INLINE_FUNCTION
68 void sync_warp(const int& mask) {
69 #ifdef __CUDA_ARCH__
70 __syncwarp(mask);
71 #endif
72 }
73
74 } // namespace Stokhos
75
76 #endif /* #ifndef STOKHOS_CUDA_WARP_SHUFFLE_HPP */