Files
project_6/cccl_upstream/thrust/testing/cuda/tabulate.cu
EngineX CI 56fd68e7dd [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
2026-07-30 09:35:51 +00:00

96 lines
2.2 KiB
Plaintext

#include <thrust/execution_policy.h>
#include <thrust/functional.h>
#include <thrust/tabulate.h>
#include <unittest/unittest.h>
#ifdef THRUST_TEST_DEVICE_SIDE
template <typename ExecutionPolicy, typename Iterator, typename Function>
__global__ void tabulate_kernel(ExecutionPolicy exec, Iterator first, Iterator last, Function f)
{
thrust::tabulate(exec, first, last, f);
}
template <typename ExecutionPolicy>
void TestTabulateDevice(ExecutionPolicy exec)
{
using Vector = thrust::device_vector<int>;
using namespace thrust::placeholders;
using T = typename Vector::value_type;
Vector v(5);
tabulate_kernel<<<1, 1>>>(exec, v.begin(), v.end(), ::cuda::std::identity{});
{
cudaError_t const err = cudaDeviceSynchronize();
ASSERT_EQUAL(cudaSuccess, err);
}
Vector ref{0, 1, 2, 3, 4};
ASSERT_EQUAL(v, ref);
tabulate_kernel<<<1, 1>>>(exec, v.begin(), v.end(), -_1);
{
cudaError_t const err = cudaDeviceSynchronize();
ASSERT_EQUAL(cudaSuccess, err);
}
ref = {0, -1, -2, -3, -4};
ASSERT_EQUAL(v, ref);
tabulate_kernel<<<1, 1>>>(exec, v.begin(), v.end(), _1 * _1 * _1);
{
cudaError_t const err = cudaDeviceSynchronize();
ASSERT_EQUAL(cudaSuccess, err);
}
ref = {0, 1, 8, 27, 64};
ASSERT_EQUAL(v, ref);
}
void TestTabulateDeviceSeq()
{
TestTabulateDevice(thrust::seq);
}
DECLARE_UNITTEST(TestTabulateDeviceSeq);
void TestTabulateDeviceDevice()
{
TestTabulateDevice(thrust::device);
}
DECLARE_UNITTEST(TestTabulateDeviceDevice);
#endif
void TestTabulateCudaStreams()
{
using namespace thrust::placeholders;
using Vector = thrust::device_vector<int>;
using T = Vector::value_type;
Vector v(5);
cudaStream_t s;
cudaStreamCreate(&s);
thrust::tabulate(thrust::cuda::par.on(s), v.begin(), v.end(), ::cuda::std::identity{});
cudaStreamSynchronize(s);
Vector ref{0, 1, 2, 3, 4};
ASSERT_EQUAL(v, ref);
thrust::tabulate(thrust::cuda::par.on(s), v.begin(), v.end(), -_1);
cudaStreamSynchronize(s);
ref = {0, -1, -2, -3, -4};
ASSERT_EQUAL(v, ref);
thrust::tabulate(thrust::cuda::par.on(s), v.begin(), v.end(), _1 * _1 * _1);
cudaStreamSynchronize(s);
ref = {0, 1, 8, 27, 64};
ASSERT_EQUAL(v, ref);
cudaStreamSynchronize(s);
}
DECLARE_UNITTEST(TestTabulateCudaStreams);