[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:
20
cccl_upstream/thrust/testing/omp/CMakeLists.txt
Normal file
20
cccl_upstream/thrust/testing/omp/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
file(
|
||||
GLOB test_srcs
|
||||
RELATIVE "${CMAKE_CURRENT_LIST_DIR}"
|
||||
CONFIGURE_DEPENDS
|
||||
*.cu
|
||||
*.cpp
|
||||
)
|
||||
|
||||
foreach (thrust_target IN LISTS THRUST_TARGETS)
|
||||
thrust_get_target_property(config_device ${thrust_target} DEVICE)
|
||||
if (NOT config_device STREQUAL "OMP")
|
||||
continue()
|
||||
endif()
|
||||
|
||||
foreach (test_src IN LISTS test_srcs)
|
||||
get_filename_component(test_name "${test_src}" NAME_WLE)
|
||||
string(PREPEND test_name "omp.")
|
||||
thrust_add_test(test_target ${test_name} "${test_src}" ${thrust_target})
|
||||
endforeach()
|
||||
endforeach()
|
||||
75
cccl_upstream/thrust/testing/omp/nvcc_independence.cpp
Normal file
75
cccl_upstream/thrust/testing/omp/nvcc_independence.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include <thrust/device_ptr.h>
|
||||
#include <thrust/reduce.h>
|
||||
#include <thrust/scan.h>
|
||||
#include <thrust/sort.h>
|
||||
#include <thrust/system_error.h>
|
||||
#include <thrust/transform.h>
|
||||
|
||||
#include <unittest/unittest.h>
|
||||
|
||||
void TestNvccIndependenceTransform()
|
||||
{
|
||||
using T = int;
|
||||
const int n = 10;
|
||||
|
||||
thrust::host_vector<T> h_input = unittest::random_integers<T>(n);
|
||||
thrust::device_vector<T> d_input = h_input;
|
||||
|
||||
thrust::host_vector<T> h_output(n);
|
||||
thrust::device_vector<T> d_output(n);
|
||||
|
||||
thrust::transform(h_input.begin(), h_input.end(), h_output.begin(), ::cuda::std::negate<T>());
|
||||
thrust::transform(d_input.begin(), d_input.end(), d_output.begin(), ::cuda::std::negate<T>());
|
||||
|
||||
ASSERT_EQUAL(h_output, d_output);
|
||||
}
|
||||
DECLARE_UNITTEST(TestNvccIndependenceTransform);
|
||||
|
||||
void TestNvccIndependenceReduce()
|
||||
{
|
||||
using T = int;
|
||||
const int n = 10;
|
||||
|
||||
thrust::host_vector<T> h_data = unittest::random_integers<T>(n);
|
||||
thrust::device_vector<T> d_data = h_data;
|
||||
|
||||
T init = 13;
|
||||
|
||||
T h_result = thrust::reduce(h_data.begin(), h_data.end(), init);
|
||||
T d_result = thrust::reduce(d_data.begin(), d_data.end(), init);
|
||||
|
||||
ASSERT_ALMOST_EQUAL(h_result, d_result);
|
||||
}
|
||||
DECLARE_UNITTEST(TestNvccIndependenceReduce);
|
||||
|
||||
void TestNvccIndependenceExclusiveScan()
|
||||
{
|
||||
using T = int;
|
||||
const int n = 10;
|
||||
|
||||
thrust::host_vector<T> h_input = unittest::random_integers<T>(n);
|
||||
thrust::device_vector<T> d_input = h_input;
|
||||
|
||||
thrust::host_vector<T> h_output(n);
|
||||
thrust::device_vector<T> d_output(n);
|
||||
|
||||
thrust::inclusive_scan(h_input.begin(), h_input.end(), h_output.begin());
|
||||
thrust::inclusive_scan(d_input.begin(), d_input.end(), d_output.begin());
|
||||
ASSERT_EQUAL(d_output, h_output);
|
||||
}
|
||||
DECLARE_UNITTEST(TestNvccIndependenceExclusiveScan);
|
||||
|
||||
void TestNvccIndependenceSort()
|
||||
{
|
||||
using T = int;
|
||||
const int n = 10;
|
||||
|
||||
thrust::host_vector<T> h_data = unittest::random_integers<T>(n);
|
||||
thrust::device_vector<T> d_data = h_data;
|
||||
|
||||
thrust::sort(h_data.begin(), h_data.end(), ::cuda::std::less<T>());
|
||||
thrust::sort(d_data.begin(), d_data.end(), ::cuda::std::less<T>());
|
||||
|
||||
ASSERT_EQUAL(h_data, d_data);
|
||||
}
|
||||
DECLARE_UNITTEST(TestNvccIndependenceSort);
|
||||
93
cccl_upstream/thrust/testing/omp/reduce_intervals.cu
Normal file
93
cccl_upstream/thrust/testing/omp/reduce_intervals.cu
Normal file
@@ -0,0 +1,93 @@
|
||||
#include <thrust/functional.h>
|
||||
#include <thrust/system/detail/internal/decompose.h>
|
||||
#include <thrust/system/omp/detail/reduce_intervals.h>
|
||||
|
||||
#include <unittest/unittest.h>
|
||||
|
||||
// CPP reference implementation
|
||||
template <typename InputIterator, typename OutputIterator, typename BinaryFunction, typename Decomposition>
|
||||
void reduce_intervals(InputIterator input, OutputIterator output, BinaryFunction binary_op, Decomposition decomp)
|
||||
{
|
||||
using OutputType = thrust::detail::it_value_t<OutputIterator>;
|
||||
using index_type = typename Decomposition::index_type;
|
||||
|
||||
// wrap binary_op
|
||||
thrust::detail::wrapped_function<BinaryFunction, OutputType> wrapped_binary_op{binary_op};
|
||||
|
||||
for (index_type i = 0; i < decomp.size(); ++i, ++output)
|
||||
{
|
||||
InputIterator begin = input + decomp[i].begin();
|
||||
InputIterator end = input + decomp[i].end();
|
||||
|
||||
if (begin != end)
|
||||
{
|
||||
OutputType sum = *begin;
|
||||
|
||||
++begin;
|
||||
|
||||
while (begin != end)
|
||||
{
|
||||
sum = wrapped_binary_op(sum, *begin);
|
||||
++begin;
|
||||
}
|
||||
|
||||
*output = sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TestOmpReduceIntervalsSimple()
|
||||
{
|
||||
using T = int;
|
||||
using Vector = thrust::device_vector<T>;
|
||||
|
||||
using thrust::system::detail::internal::uniform_decomposition;
|
||||
using thrust::system::omp::detail::reduce_intervals;
|
||||
|
||||
Vector input(10, 1);
|
||||
|
||||
thrust::omp::tag omp_tag;
|
||||
|
||||
{
|
||||
uniform_decomposition<int> decomp(10, 10, 1);
|
||||
Vector output(decomp.size());
|
||||
reduce_intervals(omp_tag, input.begin(), output.begin(), ::cuda::std::plus<T>(), decomp);
|
||||
|
||||
ASSERT_EQUAL(output[0], 10);
|
||||
}
|
||||
|
||||
{
|
||||
uniform_decomposition<int> decomp(10, 6, 2);
|
||||
Vector output(decomp.size());
|
||||
reduce_intervals(omp_tag, input.begin(), output.begin(), ::cuda::std::plus<T>(), decomp);
|
||||
|
||||
ASSERT_EQUAL(output[0], 6);
|
||||
ASSERT_EQUAL(output[1], 4);
|
||||
}
|
||||
}
|
||||
DECLARE_UNITTEST(TestOmpReduceIntervalsSimple);
|
||||
|
||||
template <typename T>
|
||||
struct TestOmpReduceIntervals
|
||||
{
|
||||
void operator()(const size_t n)
|
||||
{
|
||||
using thrust::system::detail::internal::uniform_decomposition;
|
||||
using thrust::system::omp::detail::reduce_intervals;
|
||||
|
||||
thrust::host_vector<T> h_input = unittest::random_integers<T>(n);
|
||||
thrust::device_vector<T> d_input = h_input;
|
||||
|
||||
uniform_decomposition<size_t> decomp(n, 7, 100);
|
||||
|
||||
thrust::host_vector<T> h_output(decomp.size());
|
||||
thrust::device_vector<T> d_output(decomp.size());
|
||||
|
||||
::reduce_intervals(h_input.begin(), h_output.begin(), ::cuda::std::plus<T>(), decomp);
|
||||
thrust::system::omp::tag omp_tag;
|
||||
reduce_intervals(omp_tag, d_input.begin(), d_output.begin(), ::cuda::std::plus<T>(), decomp);
|
||||
|
||||
ASSERT_EQUAL(h_output, d_output);
|
||||
}
|
||||
};
|
||||
VariableUnitTest<TestOmpReduceIntervals, IntegralTypes> TestOmpReduceIntervalsInstance;
|
||||
Reference in New Issue
Block a user