CUB 為 CUDA 程式設計模型的每一層提供最先進的、可重複使用的軟體元件:
CUB 包含在 NVIDIA HPC SDK 和 CUDA 工具包中。
我們推薦 CUB 專案網站以獲取更多資訊和範例。
# include < cub/cub.cuh >
// Block-sorting CUDA kernel
__global__ void BlockSortKernel ( int *d_in, int *d_out)
{
using namespace cub ;
// Specialize BlockRadixSort, BlockLoad, and BlockStore for 128 threads
// owning 16 integer items each
typedef BlockRadixSort< int , 128 , 16 > BlockRadixSort;
typedef BlockLoad< int , 128 , 16 , BLOCK_LOAD_TRANSPOSE> BlockLoad;
typedef BlockStore< int , 128 , 16 , BLOCK_STORE_TRANSPOSE> BlockStore;
// Allocate shared memory
__shared__ union {
typename BlockRadixSort::TempStorage sort;
typename BlockLoad::TempStorage load;
typename BlockStore::TempStorage store;
} temp_storage;
int block_offset = blockIdx. x * ( 128 * 16 ); // OffsetT for this block's ment
// Obtain a segment of 2048 consecutive keys that are blocked across threads
int thread_keys[ 16 ];
BlockLoad (temp_storage. load ). Load (d_in + block_offset, thread_keys);
__syncthreads ();
// Collectively sort the keys
BlockRadixSort (temp_storage. sort ). Sort (thread_keys);
__syncthreads ();
// Store the sorted segment
BlockStore (temp_storage. store ). Store (d_out + block_offset, thread_keys);
}
每個執行緒區塊使用cub::BlockRadixSort
對其自己的輸入段進行集體排序。該類別根據要排序的資料類型、每個區塊的執行緒數、每個執行緒的鍵數以及隱式的目標編譯體系結構進行專門化。
cub::BlockLoad
和cub::BlockStore
類別同樣是專門化的。此外,為了提供對設備內存的合併訪問,這些原語被配置為使用條帶訪問模式(其中連續線程同時訪問連續項)來訪問內存,然後將鍵轉置為跨線程的元素的阻塞排列。
一旦專門化,這些類別就會公開不透明的TempStorage
成員類型。線程塊使用這些儲存類型來靜態分配線程塊所需的共享記憶體的聯合。 (或者,這些儲存類型可以別名為全域記憶體分配)。
使用下列編譯器的指定版本定期測試 CUB。不支援的版本可能會發出棄用警告,可以透過在編譯期間定義 CUB_IGNORE_DEPRECATED_COMPILER 來消除警告。
除了 GitHub 之外,CUB 還隨 NVIDIA HPC SDK 和 CUDA 工具包一起分發。
有關特定版本的詳細信息,請參閱變更日誌。
CUB發布 | 包含在 |
---|---|
2.0.1 | CUDA工具包12.0 |
2.0.0 | 待定 |
1.17.2 | 待定 |
1.17.1 | 待定 |
1.17.0 | 待定 |
1.16.0 | 待定 |
1.15.0 | NVIDIA HPC SDK 22.1 和 CUDA 工具包 11.6 |
1.14.0 | NVIDIA HPC SDK 21.9 |
1.13.1 | CUDA 工具包 11.5 |
1.13.0 | NVIDIA HPC SDK 21.7 |
1.12.1 | CUDA 工具包 11.4 |
1.12.0 | NVIDIA HPC SDK 21.3 |
1.11.0 | CUDA 工具包 11.3 |
1.10.0 | NVIDIA HPC SDK 20.9 和 CUDA 工具包 11.2 |
1.9.10-1 | NVIDIA HPC SDK 20.7 和 CUDA 工具包 11.1 |
1.9.10 | NVIDIA HPC SDK 20.5 |
1.9.9 | CUDA工具包11.0 |
1.9.8-1 | NVIDIA HPC SDK 20.3 |
1.9.8 | CUDA 工具包 11.0 搶先體驗 |
1.9.8 | CUDA 11.0 搶先體驗 |
1.8.0 | |
1.7.5 | 推力1.9.2 |
1.7.4 | 推力1.9.1-2 |
1.7.3 | |
1.7.2 | |
1.7.1 | |
1.7.0 | 推力1.9.0-5 |
1.6.4 | |
1.6.3 | |
1.6.2(之前為 1.5.5) | |
1.6.1(之前為 1.5.4) | |
1.6.0(之前的 1.5.3) | |
1.5.2 | |
1.5.1 | |
1.5.0 | |
1.4.1 | |
1.4.0 | |
1.3.2 | |
1.3.1 | |
1.3.0 | |
1.2.3 | |
1.2.2 | |
1.2.0 | |
1.1.1 | |
1.0.2 | |
1.0.1 | |
0.9.4 | |
0.9.2 | |
0.9.1 | |
0.9.0 |
CUB 和推力相互依賴。建議複製 Thrust 並將 CUB 建構為 Thrust 的組件。
CUB 使用 CMake 建置系統來建置單元測試、範例和標頭測試。要作為開發人員建構 CUB,應遵循以下秘訣:
# Clone Thrust and CUB from Github. CUB is located in Thrust's
# `dependencies/cub` submodule.
git clone --recursive https://github.com/NVIDIA/thrust.git
cd thrust
# Create build directory:
mkdir build
cd build
# Configure -- use one of the following:
cmake -DTHRUST_INCLUDE_CUB_CMAKE=ON .. # Command line interface.
ccmake -DTHRUST_INCLUDE_CUB_CMAKE=ON .. # ncurses GUI (Linux only)
cmake-gui # Graphical UI, set source/build directories and options in the app
# Build:
cmake --build . -j < num jobs > # invokes make (or ninja, etc)
# Run tests and examples:
ctest
預設情況下,以 C++14 標準為目標,但這可以在 CMake 中變更。有關配置 CUB 建置和建立拉取請求的更多信息,請參閱 CONTRIBUTING.md。
CUB 可在「New BSD」開源許可證下使用:
Copyright (c) 2010-2011, Duane Merrill. All rights reserved.
Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the NVIDIA CORPORATION nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.