/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.4.1/hipcub/include/hipcub/backend/rocprim/block/block_load.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.4.1/hipcub/include/hipcub/backend/rocprim/block/block_load.hpp Source File#

hipCUB: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.4.1/hipcub/include/hipcub/backend/rocprim/block/block_load.hpp Source File
block_load.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_LOAD_HPP_
31 #define HIPCUB_ROCPRIM_BLOCK_BLOCK_LOAD_HPP_
32 
33 #include <type_traits>
34 
35 #include "../../../config.hpp"
36 
37 #include <rocprim/block/block_load.hpp>
38 
39 #include "block_load_func.hpp"
40 
41 BEGIN_HIPCUB_NAMESPACE
42 
43 namespace detail
44 {
45  inline constexpr
46  typename std::underlying_type<::rocprim::block_load_method>::type
47  to_BlockLoadAlgorithm_enum(::rocprim::block_load_method v)
48  {
49  using utype = std::underlying_type<::rocprim::block_load_method>::type;
50  return static_cast<utype>(v);
51  }
52 }
53 
54 enum BlockLoadAlgorithm
55 {
56  BLOCK_LOAD_DIRECT
57  = detail::to_BlockLoadAlgorithm_enum(::rocprim::block_load_method::block_load_direct),
58  BLOCK_LOAD_STRIPED
59  = detail::to_BlockLoadAlgorithm_enum(::rocprim::block_load_method::block_load_striped),
60  BLOCK_LOAD_VECTORIZE
61  = detail::to_BlockLoadAlgorithm_enum(::rocprim::block_load_method::block_load_vectorize),
62  BLOCK_LOAD_TRANSPOSE
63  = detail::to_BlockLoadAlgorithm_enum(::rocprim::block_load_method::block_load_transpose),
64  BLOCK_LOAD_WARP_TRANSPOSE
65  = detail::to_BlockLoadAlgorithm_enum(::rocprim::block_load_method::block_load_warp_transpose),
66  BLOCK_LOAD_WARP_TRANSPOSE_TIMESLICED
67  = detail::to_BlockLoadAlgorithm_enum(::rocprim::block_load_method::block_load_warp_transpose)
68 };
69 
70 template<
71  typename T,
72  int BLOCK_DIM_X,
73  int ITEMS_PER_THREAD,
74  BlockLoadAlgorithm ALGORITHM = BLOCK_LOAD_DIRECT,
75  int BLOCK_DIM_Y = 1,
76  int BLOCK_DIM_Z = 1,
77  int ARCH = HIPCUB_ARCH /* ignored */
78 >
79 class BlockLoad
80  : private ::rocprim::block_load<
81  T,
82  BLOCK_DIM_X,
83  ITEMS_PER_THREAD,
84  static_cast<::rocprim::block_load_method>(ALGORITHM),
85  BLOCK_DIM_Y,
86  BLOCK_DIM_Z
87  >
88 {
89  static_assert(
90  BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z > 0,
91  "BLOCK_DIM_X * BLOCK_DIM_Y * BLOCK_DIM_Z must be greater than 0"
92  );
93 
94  using base_type =
95  typename ::rocprim::block_load<
96  T,
97  BLOCK_DIM_X,
98  ITEMS_PER_THREAD,
99  static_cast<::rocprim::block_load_method>(ALGORITHM),
100  BLOCK_DIM_Y,
101  BLOCK_DIM_Z
102  >;
103 
104  // Reference to temporary storage (usually shared memory)
105  typename base_type::storage_type& temp_storage_;
106 
107 public:
108  using TempStorage = typename base_type::storage_type;
109 
110  HIPCUB_DEVICE inline
111  BlockLoad() : temp_storage_(private_storage())
112  {
113  }
114 
115  HIPCUB_DEVICE inline
116  BlockLoad(TempStorage& temp_storage) : temp_storage_(temp_storage)
117  {
118  }
119 
120  template<class InputIteratorT>
121  HIPCUB_DEVICE inline
122  void Load(InputIteratorT block_iter,
123  T (&items)[ITEMS_PER_THREAD])
124  {
125  base_type::load(block_iter, items, temp_storage_);
126  }
127 
128  template<class InputIteratorT>
129  HIPCUB_DEVICE inline
130  void Load(InputIteratorT block_iter,
131  T (&items)[ITEMS_PER_THREAD],
132  int valid_items)
133  {
134  base_type::load(block_iter, items, valid_items, temp_storage_);
135  }
136 
137  template<
138  class InputIteratorT,
139  class Default
140  >
141  HIPCUB_DEVICE inline
142  void Load(InputIteratorT block_iter,
143  T (&items)[ITEMS_PER_THREAD],
144  int valid_items,
145  Default oob_default)
146  {
147  base_type::load(block_iter, items, valid_items, oob_default, temp_storage_);
148  }
149 
150 private:
151  HIPCUB_DEVICE inline
152  TempStorage& private_storage()
153  {
154  HIPCUB_SHARED_MEMORY TempStorage private_storage;
155  return private_storage;
156  }
157 };
158 
159 END_HIPCUB_NAMESPACE
160 
161 #endif // HIPCUB_ROCPRIM_BLOCK_BLOCK_LOAD_HPP_
Definition: block_load.hpp:88