/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.0.2/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.0.2/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.0.2/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 <
63  typename T,
64  int BLOCK_THREADS,
65  int ARCH = HIPCUB_ARCH /* ignored */
66 >
68 {
69  //---------------------------------------------------------------------
70  // Constants and type definitions
71  //---------------------------------------------------------------------
72 
73  enum
74  {
76  SHARED_ELEMENTS = BLOCK_THREADS,
77 
79  MAX_RAKING_THREADS = ::rocprim::detail::get_min_warp_size(BLOCK_THREADS, HIPCUB_DEVICE_WARP_THREADS),
80 
82  SEGMENT_LENGTH = (SHARED_ELEMENTS + MAX_RAKING_THREADS - 1) / MAX_RAKING_THREADS,
83 
85  RAKING_THREADS = (SHARED_ELEMENTS + SEGMENT_LENGTH - 1) / SEGMENT_LENGTH,
86 
88  USE_SEGMENT_PADDING = ((SEGMENT_LENGTH & 1) == 0) && (SEGMENT_LENGTH > 2),
89 
91  GRID_ELEMENTS = RAKING_THREADS * (SEGMENT_LENGTH + USE_SEGMENT_PADDING),
92 
94  UNGUARDED = (SHARED_ELEMENTS % RAKING_THREADS == 0),
95  };
96 
97 
98 #ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document
102  struct __align__(16) _TempStorage
103  {
104  T buff[BlockRakingLayout::GRID_ELEMENTS];
105  };
106 
107 #endif
108 
110  struct TempStorage : Uninitialized<_TempStorage> {};
111 
115  static HIPCUB_DEVICE inline T* PlacementPtr(
116  TempStorage &temp_storage,
117  unsigned int linear_tid)
118  {
119  // Offset for partial
120  unsigned int offset = linear_tid;
121 
122  // Add in one padding element for every segment
123  if (USE_SEGMENT_PADDING > 0)
124  {
125  offset += offset / SEGMENT_LENGTH;
126  }
127 
128  // Incorporating a block of padding partials every shared memory segment
129  return temp_storage.Alias().buff + offset;
130  }
131 
135  static HIPCUB_DEVICE inline T* RakingPtr(
136  TempStorage &temp_storage,
137  unsigned int linear_tid)
138  {
139  return temp_storage.Alias().buff + (linear_tid * (SEGMENT_LENGTH + USE_SEGMENT_PADDING));
140  }
141 };
142 
143 END_HIPCUB_NAMESPACE
144 
145 #endif // HIPCUB_ROCPRIM_BLOCK_BLOCK_RAKING_LAYOUT_HPP_
A storage-backing wrapper that allows types with non-trivial constructors to be aliased in unions.
Definition: util_type.hpp:359
__host__ __device__ __forceinline__ T & Alias()
Alias.
Definition: util_type.hpp:372
Alias wrapper allowing storage to be unioned.
Definition: block_raking_layout.hpp:110
BlockRakingLayout provides a conflict-free shared memory layout abstraction for 1D raking across thre...
Definition: block_raking_layout.hpp:68
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:135
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:115