~ubuntu-branches/debian/sid/lammps/sid

« back to all changes in this revision

Viewing changes to lib/kokkos/TPL/cub/block/block_raking_layout.cuh

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2015-04-29 23:44:49 UTC
  • mfrom: (5.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20150429234449-mbhy9utku6hp6oq8
Tags: 0~20150313.gitfa668e1-1
Upload into unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 * Copyright (c) 2011, Duane Merrill.  All rights reserved.
 
3
 * Copyright (c) 2011-2013, 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
 
 
29
/**
 
30
 * \file
 
31
 * cub::BlockRakingLayout provides a conflict-free shared memory layout abstraction for warp-raking across thread block data.
 
32
 */
 
33
 
 
34
 
 
35
#pragma once
 
36
 
 
37
#include "../util_macro.cuh"
 
38
#include "../util_arch.cuh"
 
39
#include "../util_namespace.cuh"
 
40
 
 
41
/// Optional outer namespace(s)
 
42
CUB_NS_PREFIX
 
43
 
 
44
/// CUB namespace
 
45
namespace cub {
 
46
 
 
47
/**
 
48
 * \brief BlockRakingLayout provides a conflict-free shared memory layout abstraction for raking across thread block data.    ![](raking.png)
 
49
 * \ingroup BlockModule
 
50
 *
 
51
 * \par Overview
 
52
 * This type facilitates a shared memory usage pattern where a block of CUDA
 
53
 * threads places elements into shared memory and then reduces the active
 
54
 * parallelism to one "raking" warp of threads for serially aggregating consecutive
 
55
 * sequences of shared items.  Padding is inserted to eliminate bank conflicts
 
56
 * (for most data types).
 
57
 *
 
58
 * \tparam T                    The data type to be exchanged.
 
59
 * \tparam BLOCK_THREADS        The thread block size in threads.
 
60
 * \tparam BLOCK_STRIPS         When strip-mining, the number of threadblock-strips per tile
 
61
 */
 
62
template <
 
63
    typename    T,
 
64
    int         BLOCK_THREADS,
 
65
    int         BLOCK_STRIPS = 1>
 
66
struct BlockRakingLayout
 
67
{
 
68
    //---------------------------------------------------------------------
 
69
    // Constants and typedefs
 
70
    //---------------------------------------------------------------------
 
71
 
 
72
    enum
 
73
    {
 
74
        /// The total number of elements that need to be cooperatively reduced
 
75
        SHARED_ELEMENTS =
 
76
            BLOCK_THREADS * BLOCK_STRIPS,
 
77
 
 
78
        /// Maximum number of warp-synchronous raking threads
 
79
        MAX_RAKING_THREADS =
 
80
            CUB_MIN(BLOCK_THREADS, PtxArchProps::WARP_THREADS),
 
81
 
 
82
        /// Number of raking elements per warp-synchronous raking thread (rounded up)
 
83
        SEGMENT_LENGTH =
 
84
            (SHARED_ELEMENTS + MAX_RAKING_THREADS - 1) / MAX_RAKING_THREADS,
 
85
 
 
86
        /// Never use a raking thread that will have no valid data (e.g., when BLOCK_THREADS is 62 and SEGMENT_LENGTH is 2, we should only use 31 raking threads)
 
87
        RAKING_THREADS =
 
88
            (SHARED_ELEMENTS + SEGMENT_LENGTH - 1) / SEGMENT_LENGTH,
 
89
 
 
90
        /// Pad each segment length with one element if it evenly divides the number of banks
 
91
        SEGMENT_PADDING =
 
92
            (PtxArchProps::SMEM_BANKS % SEGMENT_LENGTH == 0) ? 1 : 0,
 
93
 
 
94
        /// Total number of elements in the raking grid
 
95
        GRID_ELEMENTS =
 
96
            RAKING_THREADS * (SEGMENT_LENGTH + SEGMENT_PADDING),
 
97
 
 
98
        /// Whether or not we need bounds checking during raking (the number of reduction elements is not a multiple of the warp size)
 
99
        UNGUARDED =
 
100
            (SHARED_ELEMENTS % RAKING_THREADS == 0),
 
101
    };
 
102
 
 
103
 
 
104
    /**
 
105
     * \brief Shared memory storage type
 
106
     */
 
107
    typedef T TempStorage[BlockRakingLayout::GRID_ELEMENTS];
 
108
 
 
109
 
 
110
    /**
 
111
     * \brief Returns the location for the calling thread to place data into the grid
 
112
     */
 
113
    static __device__ __forceinline__ T* PlacementPtr(
 
114
        TempStorage &temp_storage,
 
115
        int linear_tid,
 
116
        int block_strip = 0)
 
117
    {
 
118
        // Offset for partial
 
119
        unsigned int offset = (block_strip * BLOCK_THREADS) + linear_tid;
 
120
 
 
121
        // Add in one padding element for every segment
 
122
        if (SEGMENT_PADDING > 0)
 
123
        {
 
124
            offset += offset / SEGMENT_LENGTH;
 
125
        }
 
126
 
 
127
        // Incorporating a block of padding partials every shared memory segment
 
128
        return temp_storage + offset;
 
129
    }
 
130
 
 
131
 
 
132
    /**
 
133
     * \brief Returns the location for the calling thread to begin sequential raking
 
134
     */
 
135
    static __device__ __forceinline__ T* RakingPtr(
 
136
        TempStorage &temp_storage,
 
137
        int linear_tid)
 
138
    {
 
139
        return temp_storage + (linear_tid * (SEGMENT_LENGTH + SEGMENT_PADDING));
 
140
    }
 
141
};
 
142
 
 
143
}               // CUB namespace
 
144
CUB_NS_POSTFIX  // Optional outer namespace(s)
 
145