[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:
37
cccl_upstream/thrust/examples/max_abs_diff.cu
Normal file
37
cccl_upstream/thrust/examples/max_abs_diff.cu
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <thrust/device_vector.h>
|
||||
#include <thrust/functional.h>
|
||||
#include <thrust/inner_product.h>
|
||||
|
||||
#include <cuda/functional>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// this example computes the maximum absolute difference
|
||||
// between the elements of two vectors
|
||||
|
||||
template <typename T>
|
||||
struct abs_diff
|
||||
{
|
||||
__host__ __device__ T operator()(const T& a, const T& b)
|
||||
{
|
||||
return fabsf(b - a);
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
thrust::device_vector<float> d_a = {1.0, 2.0, 3.0, 4.0};
|
||||
thrust::device_vector<float> d_b = {2.0, 4.0, 3.0, 0.0};
|
||||
|
||||
// initial value of the reduction
|
||||
float init = 0;
|
||||
|
||||
// binary operations
|
||||
cuda::maximum<float> binary_op1{};
|
||||
abs_diff<float> binary_op2;
|
||||
|
||||
float max_abs_diff = thrust::inner_product(d_a.begin(), d_a.end(), d_b.begin(), init, binary_op1, binary_op2);
|
||||
|
||||
std::cout << "maximum absolute difference: " << max_abs_diff << '\n';
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user