[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:
86
cccl_upstream/thrust/testing/cuda/stream_wrapper.cu
Normal file
86
cccl_upstream/thrust/testing/cuda/stream_wrapper.cu
Normal file
@@ -0,0 +1,86 @@
|
||||
#include <thrust/execution_policy.h>
|
||||
#include <thrust/reduce.h>
|
||||
|
||||
#include <cuda/stream>
|
||||
|
||||
#include <unittest/unittest.h>
|
||||
|
||||
// Simple non-owning stream wrapper that allows implicit conversion to cudaStream_t.
|
||||
struct stream_wrapper
|
||||
{
|
||||
stream_wrapper(cudaStream_t s)
|
||||
: stream(s)
|
||||
{}
|
||||
|
||||
operator cudaStream_t() const
|
||||
{
|
||||
return stream;
|
||||
}
|
||||
|
||||
cudaStream_t stream;
|
||||
};
|
||||
|
||||
// Simple non-owning stream wrapper that allows implicit conversion to cudaStream_t and cuda::stream_ref.
|
||||
struct stream_wrapper_ref
|
||||
{
|
||||
stream_wrapper_ref(cudaStream_t s)
|
||||
: stream(s)
|
||||
{}
|
||||
|
||||
operator cudaStream_t() const
|
||||
{
|
||||
return stream;
|
||||
}
|
||||
operator cuda::stream_ref() const
|
||||
{
|
||||
return cuda::stream_ref(stream);
|
||||
}
|
||||
|
||||
cudaStream_t stream;
|
||||
};
|
||||
|
||||
template <typename Wrapper, typename ExecutionPolicy>
|
||||
void TestOnStream(ExecutionPolicy policy)
|
||||
{
|
||||
using Vector = thrust::device_vector<int>;
|
||||
|
||||
Vector v(3);
|
||||
v[0] = 1;
|
||||
v[1] = -2;
|
||||
v[2] = 3;
|
||||
|
||||
cudaStream_t s;
|
||||
cudaStreamCreate(&s);
|
||||
|
||||
Wrapper wrapper(s);
|
||||
|
||||
auto streampolicy = policy.on(wrapper);
|
||||
|
||||
ASSERT_EQUAL(thrust::reduce(streampolicy, v.begin(), v.end()), 2);
|
||||
|
||||
cudaStreamDestroy(s);
|
||||
}
|
||||
|
||||
void TestCudartStreamSync()
|
||||
{
|
||||
TestOnStream<stream_wrapper>(thrust::cuda::par);
|
||||
}
|
||||
DECLARE_UNITTEST(TestCudartStreamSync);
|
||||
|
||||
void TestCudartStreamNoSync()
|
||||
{
|
||||
TestOnStream<stream_wrapper>(thrust::cuda::par_nosync);
|
||||
}
|
||||
DECLARE_UNITTEST(TestCudartStreamNoSync);
|
||||
|
||||
void TestCudaStreamRefSync()
|
||||
{
|
||||
TestOnStream<stream_wrapper_ref>(thrust::cuda::par);
|
||||
}
|
||||
DECLARE_UNITTEST(TestCudaStreamRefSync);
|
||||
|
||||
void TestCudaStreamRefNoSync()
|
||||
{
|
||||
TestOnStream<stream_wrapper_ref>(thrust::cuda::par_nosync);
|
||||
}
|
||||
DECLARE_UNITTEST(TestCudaStreamRefNoSync);
|
||||
Reference in New Issue
Block a user