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

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

hipCUB: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.7.0/hipcub/include/hipcub/backend/rocprim/block/block_raking_layout.hpp Source File
block_raking_layout.hpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2011, Duane Merrill. All rights reserved.
3  * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  ******************************************************************************/
28 
35 #ifndef HIPCUB_ROCPRIM_BLOCK_BLOCK_RAKING_LAYOUT_HPP_
36 #define HIPCUB_ROCPRIM_BLOCK_BLOCK_RAKING_LAYOUT_HPP_
37 
38 #include <type_traits>
39 
40 #include "../../../config.hpp"
41 
42 #include <rocprim/config.hpp>
43 #include <rocprim/detail/various.hpp>
44 
45 BEGIN_HIPCUB_NAMESPACE
46 
62 template<typename T, int BLOCK_THREADS, int ARCH = HIPCUB_ARCH /* ignored */
63  >
65 {
66  //---------------------------------------------------------------------
67  // Constants and type definitions
68  //---------------------------------------------------------------------
69 
70  enum
71  {
73  SHARED_ELEMENTS = BLOCK_THREADS,
74 
76  MAX_RAKING_THREADS = ::rocprim::detail::get_min_warp_size(
77  static_cast<unsigned int>(BLOCK_THREADS), HIPCUB_DEVICE_WARP_THREADS),
78 
80  SEGMENT_LENGTH = (SHARED_ELEMENTS + MAX_RAKING_THREADS - 1) / MAX_RAKING_THREADS,
81 
83  RAKING_THREADS = (SHARED_ELEMENTS + SEGMENT_LENGTH - 1) / SEGMENT_LENGTH,
84 
86  USE_SEGMENT_PADDING = ((SEGMENT_LENGTH & 1) == 0) && (SEGMENT_LENGTH > 2),
87 
89  GRID_ELEMENTS = RAKING_THREADS * (SEGMENT_LENGTH + USE_SEGMENT_PADDING),
90 
92  UNGUARDED = (SHARED_ELEMENTS % RAKING_THREADS == 0),
93  };
94 
95 #ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document
99  struct __align__(16) _TempStorage
100  {
101  T buff[BlockRakingLayout::GRID_ELEMENTS];
102  };
103 
104 #endif
105 
107  struct TempStorage : Uninitialized<_TempStorage> {};
108 
112  static HIPCUB_DEVICE inline T* PlacementPtr(
113  TempStorage &temp_storage,
114  unsigned int linear_tid)
115  {
116  // Offset for partial
117  unsigned int offset = linear_tid;
118 
119  // Add in one padding element for every segment
120  if (USE_SEGMENT_PADDING > 0)
121  {
122  offset += offset / SEGMENT_LENGTH;
123  }
124 
125  // Incorporating a block of padding partials every shared memory segment
126  return temp_storage.Alias().buff + offset;
127  }
128 
132  static HIPCUB_DEVICE inline T* RakingPtr(
133  TempStorage &temp_storage,
134  unsigned int linear_tid)
135  {
136  return temp_storage.Alias().buff + (linear_tid * (SEGMENT_LENGTH + USE_SEGMENT_PADDING));
137  }
138 };
139 
140 END_HIPCUB_NAMESPACE
141 
142 #endif // HIPCUB_ROCPRIM_BLOCK_BLOCK_RAKING_LAYOUT_HPP_
Alias wrapper allowing storage to be unioned.
Definition: block_raking_layout.hpp:107
BlockRakingLayout provides a conflict-free shared memory layout abstraction for 1D raking across thre...
Definition: block_raking_layout.hpp:65
static __device__ T * RakingPtr(TempStorage &temp_storage, unsigned int linear_tid)
Returns the location for the calling thread to begin sequential raking.
Definition: block_raking_layout.hpp:132
static __device__ T * PlacementPtr(TempStorage &temp_storage, unsigned int linear_tid)
Returns the location for the calling thread to place data into the grid.
Definition: block_raking_layout.hpp:112
A storage-backing wrapper that allows types with non-trivial constructors to be aliased in unions.
Definition: util_type.hpp:363
__host__ __device__ __forceinline__ T & Alias()
Alias.
Definition: util_type.hpp:375