hipCUB
block_shuffle.hpp
1 /******************************************************************************
2  * Copyright (c) 2010-2011, Duane Merrill. All rights reserved.
3  * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved.
4  * Modifications Copyright (c) 2017-2020, Advanced Micro Devices, Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the NVIDIA CORPORATION nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  ******************************************************************************/
29 
30 #ifndef HIPCUB_ROCPRIM_BLOCK_BLOCK_SHUFFLE_HPP_
31 #define HIPCUB_ROCPRIM_BLOCK_BLOCK_SHUFFLE_HPP_
32 
33 #include <type_traits>
34 
35 #include "../../../config.hpp"
36 
37 #include "../thread/thread_operators.hpp"
38 
39 #include <rocprim/block/block_shuffle.hpp>
40 
41 BEGIN_HIPCUB_NAMESPACE
42 
43 
44 
45 template <
46  typename T,
47  int BLOCK_DIM_X,
48  int BLOCK_DIM_Y = 1,
49  int BLOCK_DIM_Z = 1,
50  int ARCH = HIPCUB_ARCH>
51 class BlockShuffle : public ::rocprim::block_shuffle<
52  T,
53  BLOCK_DIM_X,
54  BLOCK_DIM_Y,
55  BLOCK_DIM_Z>
56 {
57  static_assert(
58  BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z > 0,
59  "BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z must be greater than 0"
60  );
61 
62  using base_type =
63  typename ::rocprim::block_shuffle<
64  T,
65  BLOCK_DIM_X,
66  BLOCK_DIM_Y,
67  BLOCK_DIM_Z
68  >;
69 
70  // Reference to temporary storage (usually shared memory)
71  typename base_type::storage_type& temp_storage_;
72 
73 public:
74  using TempStorage = typename base_type::storage_type;
75 
76  HIPCUB_DEVICE inline
77  BlockShuffle() : temp_storage_(private_storage())
78  {}
79 
80 
81  HIPCUB_DEVICE inline
82  BlockShuffle(TempStorage &temp_storage)
83  : temp_storage_(temp_storage)
84  {}
85 
89  HIPCUB_DEVICE inline void Offset(
90  T input,
91  T& output,
92  int distance = 1)
93  {
94  base_type::offset(input,output,distance);
95  }
96 
100  HIPCUB_DEVICE inline void Rotate(
101  T input,
102  T& output,
103  unsigned int distance = 1)
104  {
105  base_type::rotate(input,output,distance);
106  }
110  template <int ITEMS_PER_THREAD>
111  HIPCUB_DEVICE inline void Up(
112  T (&input)[ITEMS_PER_THREAD],
113  T (&prev)[ITEMS_PER_THREAD])
114  {
115  base_type::up(input,prev);
116  }
117 
118 
122  template <int ITEMS_PER_THREAD>
123  HIPCUB_DEVICE inline void Up(
124  T (&input)[ITEMS_PER_THREAD],
125  T (&prev)[ITEMS_PER_THREAD],
126  T &block_suffix)
127  {
128  base_type::up(input,prev,block_suffix);
129  }
130 
134  template <int ITEMS_PER_THREAD>
135  HIPCUB_DEVICE inline void Down(
136  T (&input)[ITEMS_PER_THREAD],
137  T (&next)[ITEMS_PER_THREAD])
138  {
139  base_type::down(input,next);
140  }
141 
145  template <int ITEMS_PER_THREAD>
146  HIPCUB_DEVICE inline void Down(
147  T (&input)[ITEMS_PER_THREAD],
148  T (&next)[ITEMS_PER_THREAD],
149  T &block_prefix)
150  {
151  base_type::down(input,next,block_prefix);
152  }
153 
154 private:
155  HIPCUB_DEVICE inline
156  TempStorage& private_storage()
157  {
158  HIPCUB_SHARED_MEMORY TempStorage private_storage;
159  return private_storage;
160  }
161 };
162 
163 END_HIPCUB_NAMESPACE
164 
165 #endif // HIPCUB_ROCPRIM_BLOCK_BLOCK_SHUFFLE_HPP_
HIPCUB_DEVICE void Rotate(T input, T &output, unsigned int distance=1)
Each threadi obtains the input provided by threadi+distance.
Definition: block_shuffle.hpp:100
HIPCUB_DEVICE void Up(T(&input)[ITEMS_PER_THREAD], T(&prev)[ITEMS_PER_THREAD])
The thread block rotates its blocked arrangement of input items, shifting it up by one item...
Definition: block_shuffle.hpp:111
Definition: test_hipcub_block_load_store.kernels.hpp:167
HIPCUB_DEVICE BlockShuffle(TempStorage &temp_storage)
Definition: block_shuffle.hpp:82
Definition: block_shuffle.hpp:51
HIPCUB_DEVICE void Down(T(&input)[ITEMS_PER_THREAD], T(&next)[ITEMS_PER_THREAD], T &block_prefix)
The thread block rotates its blocked arrangement of input items, shifting it down by one item...
Definition: block_shuffle.hpp:146
HIPCUB_DEVICE void Down(T(&input)[ITEMS_PER_THREAD], T(&next)[ITEMS_PER_THREAD])
The thread block rotates its blocked arrangement of input items, shifting it down by one item...
Definition: block_shuffle.hpp:135
HIPCUB_DEVICE void Up(T(&input)[ITEMS_PER_THREAD], T(&prev)[ITEMS_PER_THREAD], T &block_suffix)
The thread block rotates its blocked arrangement of input items, shifting it up by one item...
Definition: block_shuffle.hpp:123
HIPCUB_DEVICE void Offset(T input, T &output, int distance=1)
Each threadi obtains the input provided by threadi+distance.
Definition: block_shuffle.hpp:89