[INFRA] Import NVIDIA/CCCL upstream as optimization reference library
CCCL (CUDA C++ Core Libraries) provides: - CUB: device/block/warp-level GPU primitives (reduce, scan, sort, topk) - Thrust: high-level parallel algorithms (transform_reduce, sort, scan) - libcudacxx: CUDA C++ standard library (atomics, barriers, memory) - cudax: experimental features (memory resources, allocators) - Tuning policies: per-SM hardware-specific algorithm parameters Competition optimization vectors mapped to CCCL: - Output TPS (83% weight): warp_reduce, block_reduce, device_topk - Input TPS (14% weight): device_scan, block_load, prefetch - Cache TPS (3% weight): prefix caching strategy patterns - Memory (0.9 util): pooled/cached/buddy allocators Source: https://github.com/NVIDIA/cccl (shallow clone, HEAD only) License: Apache-2.0
This commit is contained in:
34
cccl_upstream/thrust/examples/counting_iterator.cu
Normal file
34
cccl_upstream/thrust/examples/counting_iterator.cu
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <thrust/copy.h>
|
||||
#include <thrust/device_vector.h>
|
||||
#include <thrust/functional.h>
|
||||
#include <thrust/iterator/counting_iterator.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
|
||||
int main()
|
||||
{
|
||||
// this example computes indices for all the nonzero values in a sequence
|
||||
|
||||
// sequence of zero and nonzero values
|
||||
thrust::device_vector<int> stencil{0, 1, 1, 0, 0, 1, 0, 1};
|
||||
|
||||
// storage for the nonzero indices
|
||||
thrust::device_vector<int> indices(8);
|
||||
|
||||
// counting iterators define a sequence [0, 8)
|
||||
thrust::counting_iterator<int> first(0);
|
||||
thrust::counting_iterator<int> last = first + 8;
|
||||
|
||||
// compute indices of nonzero elements
|
||||
using IndexIterator = thrust::device_vector<int>::iterator;
|
||||
|
||||
IndexIterator indices_end = thrust::copy_if(first, last, stencil.begin(), indices.begin(), cuda::std::identity{});
|
||||
// indices now contains [1,2,5,7]
|
||||
|
||||
// print result
|
||||
std::cout << "found " << cuda::std::distance(indices.begin(), indices_end) << " nonzero values at indices:\n";
|
||||
thrust::copy(indices.begin(), indices_end, std::ostream_iterator<int>(std::cout, "\n"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user