| 例子 | doxygen文檔(todo) |
|---|
cuCollections ( cuco )是一個開源的,僅GPU加速的同時數據結構的庫。
類似於推力和幼崽提供類似STL的GPU加速算法和原語的方式, cuCollections提供了類似STL的並發數據結構。 cuCollections不是std::unordered_map等STL數據結構的一對一的替換。取而代之的是,它提供了適合與GPU有效使用的功能相似的數據結構。
cuCollections仍處於繁重的發展狀態。用戶應該期望破裂的變化和重構是普遍的。
11/01/2024將術語window簡化為bucket
01/08/2024棄用了experimental名稱空間
01/02/2024將傳統static_map移至cuco::legacy名稱空間
cuCollections僅是標頭,可以通過下載標題並將其放入源樹來手動合併到您的項目中。
cuCollections cuCollections旨在使在另一個CMAKE項目中易於包含。 CMakeLists.txt導出一個可以將1鏈接到設置目標的cuco目標,包括目錄,依賴項和編譯在項目中使用cuCollections所需的標誌。
我們建議使用CMAKE軟件包管理器(CPM)將cuCollections獲取到您的項目中。使用CPM,獲得cuCollections很容易:
cmake_minimum_required ( VERSION 3.23.1 FATAL_ERROR)
include ( path /to/CPM.cmake)
CPMAddPackage(
NAME cuco
GITHUB_REPOSITORY NVIDIA/cuCollections
GIT_TAG dev
OPTIONS
"BUILD_TESTS OFF"
"BUILD_BENCHMARKS OFF"
"BUILD_EXAMPLES OFF"
)
target_link_libraries (my_library cuco)這將負責從GitHub下載cuCollections ,並在Cmake可以找到的位置中提供標頭。鏈接到cuco目標將提供my_library目標使用的cuco所需的一切。
1: cuCollections僅是標頭,因此沒有二進制組件可以“鏈接”。鏈接術語來自CMAKE的target_link_libraries即使是僅用於僅標頭庫目標的,它仍然使用。
nvcc 11.5+cuCollections取決於以下庫:
用戶不需要採取任何措施來滿足這些依賴性。 cuCollections的CMake腳本配置為首先搜索這些庫的系統,如果找不到這些庫,則可以自動從Github獲取它們。
由於cuCollections僅是標頭,因此沒有什麼可構建的。
建立測試,基準和示例:
cd $CUCO_ROOT
mkdir -p build
cd build
cmake .. # configure
make # build
ctest --test-dir tests # run tests二進製文件將內置為:
build/tests/build/benchmarks/build/examples/另外,您可以使用位於ci/build.sh構建腳本。沒有參數的腳本將觸發一個完整的構建,該構建將位於build/local 。
cd $CUCO_ROOT
ci/build.sh # configure and build
ctest --test-dir build/local/tests # run tests有關所有可用選項的綜合列表以及描述和示例,您可以使用選項ci/build.sh -h 。
默認情況下, cuCollections使用pre-commit.ci和mirrors-clang-format使用拉動請求中的C ++/CUDA文件自動格式化。用戶應Allow edits by maintainers ,以使自動形成工作。
可選地,您可能希望設置一個pre-commit掛鉤,以自動運行git commit時自動運行clang-format 。這可以通過通過conda或pip安裝pre-commit來完成:
conda install -c conda-forge pre_commitpip install pre-commit然後運行:
pre-commit install從cuCollections存儲庫的根部。現在,每次提交更改時,都將運行代碼格式。
您也可能希望手動格式化代碼:
pre-commit run clang-format --all-filesmirrors-clang-format保證了正確版本的clang-format ,並避免版本不匹配。用戶不應直接在命令行上使用clang-format來格式化代碼。
Doxygen用於從源代碼中的C ++/CUDA註釋中生成HTML頁面。
以下示例涵蓋了用於記錄cuCollections中C ++/CUDA代碼的大多數Doxygen塊註釋和標籤樣式。
/* *
* @file source_file.cpp
* @brief Description of source file contents
*
* Longer description of the source file contents.
*/
/* *
* @brief Short, one sentence description of the class.
*
* Longer, more detailed description of the class.
*
* A detailed description must start after a blank line.
*
* @tparam T Short description of each template parameter
* @tparam U Short description of each template parameter
*/
template < typename T, typename U>
class example_class {
void get_my_int (); // /< Simple members can be documented like this
void set_my_int ( int value ); // /< Try to use descriptive member names
/* *
* @brief Short, one sentence description of the member function.
*
* A more detailed description of what this function does and what
* its logic does.
*
* @param[in] first This parameter is an input parameter to the function
* @param[in,out] second This parameter is used both as an input and output
* @param[out] third This parameter is an output of the function
*
* @return The result of the complex function
*/
T complicated_function ( int first, double * second, float * third)
{
// Do not use doxygen-style block comments
// for code logic documentation.
}
private:
int my_int; // /< An example private member variable
};cuCollections還將doxygen用作文檔襯裡。要在本地檢查Doxygen樣式,請運行
./ci/pre-commit/doxygen.sh我們計劃將許多GPU加速的並發數據結構添加到cuCollections 。截至目前,這兩個旗艦是哈希表的變體。
static_set cuco::static_set是一個固定尺寸的容器,它以無特定順序存儲唯一的元素。有關更多詳細信息,請參見static_set.cuh中的doxygen文檔。
static_map cuco::static_map是使用線性探測的打開地址的固定尺寸哈希表。有關更多詳細信息,請參見static_map.cuh中的doxygen文檔。
static_multimap cuco::static_multimap是一個固定大小的哈希表,支持存儲等效鍵。默認情況下,它使用Double哈希,並支持切換到線性探測。有關更多詳細信息,請參見static_multimap.cuh中的doxygen文檔。
static_multiset cuco::static_multiset是一個固定大小的容器,支持存儲等效鍵。默認情況下,它使用Double哈希,並支持切換到線性探測。有關更多詳細信息,請參見static_multiset.cuh中的doxygen文檔。
dynamic_map cuco::dynamic_map將多個cuco::static_map s鏈接在一起,以提供可以在插入鍵值對時生長的哈希表。目前,它僅提供主機構成API。有關更多詳細信息,請參見dynamic_map.cuh中的doxygen文檔。
hyperloglog cuco::hyperloglog實現了已建立的超置型++算法,以近似多種/流中不同項目的計數。
bloom_filter cuco::bloom_filter實現了一個阻塞的綻放過濾器,以進行大約設置的會員資格查詢。