[CCCL] 瘦身 + 补全: 移除 cudax/python/libcudacxx-tests 冗余文件, 新增 c2h 测试助手 + cmake 构建系统 + 8 个 CUDA thrust examples
变更摘要:
- 删除: cudax/ (783 files, 7.2M) — 实验性组件,竞赛不需要
- 删除: python/ (226 files, 2.0M) — Python 绑定,竞赛不需要
- 删除: libcudacxx/{test,benchmarks,codegen,cmake,share} (4432 files, 31M)
保留: libcudacxx/include/ (1463 headers, cuda::std 编译依赖)
- 新增: c2h/ (27 files) — CUB Catch2 测试辅助头文件,编译 243 个测试必需
- 新增: cmake/ (29 files) — CCCL 原生 CMake 构建系统
- 新增: thrust/examples/cuda/ (7 files) + cpp_integration/ (1 file)
async_reduce, custom_temporary_allocation, explicit_cuda_stream,
global_device_vector, range_view, unwrap_pointer, wrap_pointer, device
结果: cccl_upstream 从 74M→35M (瘦身 53%), 核心内容 100% 保留:
27/27 tuning headers, 78 benchmarks, 243 tests,
60 thrust examples, 18 CUB examples, 全部编译头文件
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDASTF in CUDA C++ Core Libraries,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/stf.cuh>
|
||||
|
||||
using namespace cuda::experimental::stf;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
stream_ctx ctx;
|
||||
const size_t N = 16;
|
||||
double X[N], Y[N];
|
||||
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
X[i] = 1.0;
|
||||
Y[i] = 2.0;
|
||||
}
|
||||
|
||||
auto lX = ctx.logical_data(X);
|
||||
auto lY = ctx.logical_data(Y);
|
||||
|
||||
#ifdef NDEBUG
|
||||
size_t iter_cnt = 10000000;
|
||||
#else
|
||||
size_t iter_cnt = 10000;
|
||||
fprintf(stderr, "Warning: Running with small problem size in debug mode, should use DEBUG=0.\n");
|
||||
#endif
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
iter_cnt = atol(argv[1]);
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::time_point start, stop;
|
||||
start = std::chrono::steady_clock::now();
|
||||
for (size_t iter = 0; iter < iter_cnt; iter++)
|
||||
{
|
||||
ctx.task(lX.read(), lY.rw())->*[&](cudaStream_t, auto, auto) {};
|
||||
ctx.task(lY.read(), lX.rw())->*[&](cudaStream_t, auto, auto) {};
|
||||
}
|
||||
stop = std::chrono::steady_clock::now();
|
||||
ctx.finalize();
|
||||
|
||||
std::chrono::duration<double> duration = stop - start;
|
||||
fprintf(stderr, "Elapsed: %.2lf us per task\n", duration.count() * 1000000.0 / (2 * iter_cnt));
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDASTF in CUDA C++ Core Libraries,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/stf.cuh>
|
||||
|
||||
using namespace cuda::experimental::stf;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
stream_ctx ctx;
|
||||
const size_t N = 16;
|
||||
#ifdef NDEBUG
|
||||
int iter_cnt = 1000000;
|
||||
#else
|
||||
int iter_cnt = 10000;
|
||||
fprintf(stderr, "Warning: Running with small problem size in debug mode, should use DEBUG=0.\n");
|
||||
#endif
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
iter_cnt = atoi(argv[1]);
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::time_point start, stop;
|
||||
start = std::chrono::steady_clock::now();
|
||||
for (int iter = 0; iter < iter_cnt; iter++)
|
||||
{
|
||||
auto lX = ctx.logical_data(shape_of<slice<double>>(N));
|
||||
auto lY = ctx.logical_data(shape_of<slice<double>>(N));
|
||||
ctx.task(lX.write())->*[](cudaStream_t, auto) {};
|
||||
ctx.task(lY.write())->*[](cudaStream_t, auto) {};
|
||||
ctx.task(lX.read(), lY.rw())->*[](cudaStream_t, auto, auto) {};
|
||||
}
|
||||
stop = std::chrono::steady_clock::now();
|
||||
ctx.finalize();
|
||||
|
||||
std::chrono::duration<double> duration = stop - start;
|
||||
fprintf(stderr, "Elapsed: %.2lf us per task\n", duration.count() * 1000000.0 / (3 * iter_cnt));
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDASTF in CUDA C++ Core Libraries,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/stf.cuh>
|
||||
|
||||
using namespace cuda::experimental::stf;
|
||||
|
||||
__global__ void swap_kernel(slice<double> dst, slice<double> src)
|
||||
{
|
||||
size_t tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
size_t nthreads = blockDim.x * gridDim.x;
|
||||
size_t n = dst.size();
|
||||
|
||||
for (size_t i = tid; i < n; i += nthreads)
|
||||
{
|
||||
double tmp = dst(i);
|
||||
dst(i) = src(i);
|
||||
src(i) = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
stream_ctx ctx;
|
||||
const size_t N = 16;
|
||||
double X[N], Y[N];
|
||||
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
X[i] = 1.0;
|
||||
Y[i] = 2.0;
|
||||
}
|
||||
|
||||
auto lX = ctx.logical_data(X);
|
||||
auto lY = ctx.logical_data(Y);
|
||||
|
||||
#ifdef NDEBUG
|
||||
size_t iter_cnt = 10000000;
|
||||
#else
|
||||
size_t iter_cnt = 10000;
|
||||
fprintf(stderr, "Warning: Running with small problem size in debug mode, should use DEBUG=0.\n");
|
||||
#endif
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
iter_cnt = atol(argv[1]);
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::time_point start, stop;
|
||||
start = std::chrono::steady_clock::now();
|
||||
for (size_t iter = 0; iter < iter_cnt; iter++)
|
||||
{
|
||||
ctx.task(lX.rw(), lY.rw())->*[&](cudaStream_t s, auto dX, auto dY) {
|
||||
swap_kernel<<<4, 16, 0, s>>>(dY, dX);
|
||||
};
|
||||
ctx.task(lY.rw(), lX.rw())->*[&](cudaStream_t s, auto dY, auto dX) {
|
||||
swap_kernel<<<4, 16, 0, s>>>(dX, dY);
|
||||
};
|
||||
}
|
||||
stop = std::chrono::steady_clock::now();
|
||||
ctx.finalize();
|
||||
|
||||
std::chrono::duration<double> duration = stop - start;
|
||||
fprintf(stderr, "Elapsed: %.2lf us per task pair\n", duration.count() * 1000000.0 / (iter_cnt));
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDASTF in CUDA C++ Core Libraries,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/stf.cuh>
|
||||
|
||||
using namespace cuda::experimental::stf;
|
||||
|
||||
__global__ void swap(slice<double> dst, const slice<double> src)
|
||||
{
|
||||
size_t tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
size_t nthreads = blockDim.x * gridDim.x;
|
||||
size_t n = dst.size();
|
||||
|
||||
for (size_t i = tid; i < n; i += nthreads)
|
||||
{
|
||||
double tmp = dst(i);
|
||||
dst(i) = src(i);
|
||||
src(i) = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
stream_ctx ctx;
|
||||
const size_t N = 16;
|
||||
double X[N], Y[N];
|
||||
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
X[i] = 1.0;
|
||||
Y[i] = 2.0;
|
||||
}
|
||||
|
||||
auto lX = ctx.logical_data(X);
|
||||
auto lY = ctx.logical_data(Y);
|
||||
|
||||
#ifdef NDEBUG
|
||||
size_t iter_cnt = 10000000;
|
||||
#else
|
||||
size_t iter_cnt = 10000;
|
||||
fprintf(stderr, "Warning: Running with small problem size in debug mode, should use DEBUG=0.\n");
|
||||
#endif
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
iter_cnt = atol(argv[1]);
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::time_point start, stop;
|
||||
start = std::chrono::steady_clock::now();
|
||||
for (size_t iter = 0; iter < iter_cnt; iter++)
|
||||
{
|
||||
ctx.task(lY.rw(), lY.rw())->*[&](cudaStream_t s, auto dX, auto dY) {
|
||||
::swap<<<4, 16, 0, s>>>(dY, dX);
|
||||
::swap<<<4, 16, 0, s>>>(dX, dY);
|
||||
};
|
||||
}
|
||||
stop = std::chrono::steady_clock::now();
|
||||
ctx.finalize();
|
||||
|
||||
std::chrono::duration<double> duration = stop - start;
|
||||
fprintf(stderr, "Elapsed: %.2lf us per task\n", duration.count() * 1000000.0 / (iter_cnt));
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDASTF in CUDA C++ Core Libraries,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/stf.cuh>
|
||||
|
||||
using namespace cuda::experimental::stf;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
stream_ctx ctx;
|
||||
const size_t N = 16;
|
||||
double X[N], Y[N];
|
||||
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
X[i] = 1.0;
|
||||
Y[i] = 2.0;
|
||||
}
|
||||
|
||||
auto lX = ctx.logical_data(X);
|
||||
auto lY = ctx.logical_data(Y);
|
||||
|
||||
#ifdef NDEBUG
|
||||
int iter_cnt = 1000000;
|
||||
#else
|
||||
int iter_cnt = 10000;
|
||||
fprintf(stderr, "Warning: Running with small problem size in debug mode, should use DEBUG=0.\n");
|
||||
#endif
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
iter_cnt = atoi(argv[1]);
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::time_point start, stop;
|
||||
start = std::chrono::steady_clock::now();
|
||||
for (int iter = 0; iter < iter_cnt; iter++)
|
||||
{
|
||||
ctx.launch(lX.read(), lY.rw())->*[] _CCCL_DEVICE(auto th, auto X, auto Y) {
|
||||
for (size_t i = th.rank(); i < X.size(); i += th.size())
|
||||
{
|
||||
Y(i) = 2.0 * X(i);
|
||||
}
|
||||
};
|
||||
|
||||
ctx.launch(lX.rw(), lY.read())->*[] _CCCL_DEVICE(auto th, auto X, auto Y) {
|
||||
for (size_t i = th.rank(); i < X.size(); i += th.size())
|
||||
{
|
||||
X(i) = 0.5 * Y(i);
|
||||
}
|
||||
};
|
||||
}
|
||||
stop = std::chrono::steady_clock::now();
|
||||
ctx.finalize();
|
||||
|
||||
std::chrono::duration<double> duration = stop - start;
|
||||
fprintf(stderr, "Elapsed: %.2lf us per task\n", duration.count() * 1000000.0 / (2 * iter_cnt));
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDASTF in CUDA C++ Core Libraries,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/__places/partitions/blocked_partition.cuh>
|
||||
#include <cuda/experimental/__places/partitions/cyclic_shape.cuh>
|
||||
#include <cuda/experimental/__stf/stream/stream_ctx.cuh>
|
||||
#include <cuda/experimental/stf.cuh>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#define MAX_ITER 200
|
||||
|
||||
using namespace cuda::experimental::stf;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
stream_ctx ctx;
|
||||
|
||||
int N0 = 128;
|
||||
if (argc > 2)
|
||||
{
|
||||
N0 = atoi(argv[2]);
|
||||
}
|
||||
|
||||
// fprintf(stderr, "Using %d...\n", N0);
|
||||
|
||||
size_t N = size_t(N0) * 1024 * 1024;
|
||||
|
||||
#if 0
|
||||
auto number_devices = 1;
|
||||
auto all_devs = exec_place::repeat<blocked_partition>(exec_place::device(0), number_devices);
|
||||
#else
|
||||
auto all_devs = exec_place::all_devices();
|
||||
#endif
|
||||
|
||||
data_place cdp;
|
||||
// if (argc > 2) {
|
||||
// switch (atoi(argv[2])) {
|
||||
// case 0: cdp = data_place::composite(blocked_partition(), all_devs); break;
|
||||
// case 1: cdp = data_place::managed(); break;
|
||||
// case 2: cdp = data_place::device(0); break;
|
||||
// case 3: cdp = data_place::host(); break;
|
||||
// default: abort();
|
||||
// }
|
||||
// } else {
|
||||
cdp = data_place::composite(blocked_partition(), all_devs);
|
||||
// }
|
||||
|
||||
fprintf(stderr, "data place: %s\n", cdp.to_string().c_str());
|
||||
|
||||
// data_place cdp = data_place::device(0);
|
||||
// data_place cdp = data_place::managed();
|
||||
|
||||
auto data_logical = ctx.logical_data<int>(N);
|
||||
// initialize centroids
|
||||
ctx.parallel_for(blocked_partition(), all_devs, data_logical.shape(), data_logical.write(cdp))
|
||||
->*[=] _CCCL_DEVICE(size_t ind, auto data) {
|
||||
data(ind) = 0;
|
||||
};
|
||||
int cur_iter = 1;
|
||||
|
||||
const char* const method = argc >= 2 ? argv[1] : "launch-partition";
|
||||
|
||||
cudaEvent_t start, stop;
|
||||
cuda_safe_call(cudaEventCreate(&start));
|
||||
cuda_safe_call(cudaEventCreate(&stop));
|
||||
cuda_safe_call(cudaEventRecord(start, ctx.fence()));
|
||||
|
||||
if (strcmp(method, "launch-partition") == 0)
|
||||
{
|
||||
for (cur_iter = 1; cur_iter < MAX_ITER; ++cur_iter)
|
||||
{
|
||||
ctx.launch(all_devs, data_logical.write(cdp)).set_symbol("launch assignment")
|
||||
->*[=] _CCCL_DEVICE(auto&& t, auto&& data) {
|
||||
for (auto ind : t.apply_partition(shape(data)))
|
||||
{
|
||||
data(ind) = 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
else if (strcmp(method, "launch") == 0)
|
||||
{
|
||||
for (cur_iter = 1; cur_iter < MAX_ITER; ++cur_iter)
|
||||
{
|
||||
ctx.launch(all_devs, data_logical.rw(cdp))->*[=] _CCCL_DEVICE(auto t, auto data) {};
|
||||
}
|
||||
}
|
||||
else if (strcmp(method, "parallel") == 0)
|
||||
{
|
||||
for (cur_iter = 1; cur_iter < MAX_ITER; ++cur_iter)
|
||||
{
|
||||
ctx.parallel_for(blocked_partition(), all_devs, data_logical.shape(), data_logical.rw(cdp))
|
||||
->*[=] _CCCL_DEVICE(size_t ind, auto data) {};
|
||||
}
|
||||
}
|
||||
else if (strcmp(method, "parallel-indexed") == 0)
|
||||
{
|
||||
for (cur_iter = 1; cur_iter < MAX_ITER; ++cur_iter)
|
||||
{
|
||||
ctx.parallel_for(blocked_partition(), all_devs, data_logical.shape(), data_logical.rw(cdp))
|
||||
.set_symbol("parallel for assignment")
|
||||
->*[=] _CCCL_DEVICE(size_t ind, auto data) {
|
||||
data(ind) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Must choose one of launch-partition, parallel-indexed, launch, parallel\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
cuda_safe_call(cudaEventRecord(stop, ctx.fence()));
|
||||
|
||||
ctx.finalize();
|
||||
|
||||
float elapsed_ms;
|
||||
cuda_safe_call(cudaEventElapsedTime(&elapsed_ms, start, stop));
|
||||
|
||||
cuda_safe_call(cudaEventDestroy(start));
|
||||
cuda_safe_call(cudaEventDestroy(stop));
|
||||
|
||||
printf("Method: %s, elapsed: %f ms\n", argv[1], elapsed_ms);
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDASTF in CUDA C++ Core Libraries,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/stf.cuh>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
using namespace std::chrono;
|
||||
using namespace cuda::experimental::stf;
|
||||
|
||||
/* wall-clock time */
|
||||
double gettime()
|
||||
{
|
||||
auto now = system_clock::now().time_since_epoch();
|
||||
return duration_cast<duration<double>>(now).count();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
stream_ctx ctx;
|
||||
const size_t N = 16;
|
||||
double X[N], Y[N];
|
||||
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
X[i] = 1.0;
|
||||
Y[i] = 2.0;
|
||||
}
|
||||
|
||||
auto lX = ctx.logical_data(X);
|
||||
auto lY = ctx.logical_data(Y);
|
||||
|
||||
size_t nloops = 10;
|
||||
size_t inner_nloops = 1000;
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
nloops = atol(argv[1]);
|
||||
}
|
||||
|
||||
if (argc > 2)
|
||||
{
|
||||
inner_nloops = atol(argv[2]);
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < nloops; j++)
|
||||
{
|
||||
std::chrono::steady_clock::time_point start, stop;
|
||||
start = std::chrono::steady_clock::now();
|
||||
|
||||
for (size_t i = 0; i < inner_nloops; i++)
|
||||
{
|
||||
ctx.task(lX.read(), lY.rw())->*[](cudaStream_t, auto, auto) {};
|
||||
}
|
||||
|
||||
stop = std::chrono::steady_clock::now();
|
||||
std::chrono::duration<double> duration = stop - start;
|
||||
|
||||
fprintf(stderr, "Elapsed: %.2lf us per task\n", duration.count() * 1000000.0 / (inner_nloops));
|
||||
}
|
||||
|
||||
ctx.finalize();
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDASTF in CUDA C++ Core Libraries,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/stf.cuh>
|
||||
|
||||
using namespace cuda::experimental::stf;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
stream_ctx ctx;
|
||||
const size_t N = 16;
|
||||
double X[N], Y[N];
|
||||
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
X[i] = 1.0;
|
||||
Y[i] = 2.0;
|
||||
}
|
||||
|
||||
auto lX = ctx.logical_data(X);
|
||||
auto lY = ctx.logical_data(Y);
|
||||
|
||||
#ifdef NDEBUG
|
||||
int iter_cnt = 1000000;
|
||||
#else
|
||||
int iter_cnt = 10000;
|
||||
fprintf(stderr, "Warning: Running with small problem size in debug mode, should use DEBUG=0.\n");
|
||||
#endif
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
iter_cnt = atoi(argv[1]);
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::time_point start, stop;
|
||||
start = std::chrono::steady_clock::now();
|
||||
for (int iter = 0; iter < iter_cnt; iter++)
|
||||
{
|
||||
ctx.parallel_for(lX.shape(), lX.read(), lY.rw())->*[] _CCCL_DEVICE(size_t i, auto X, auto Y) {
|
||||
Y(i) = 2.0 * X(i);
|
||||
};
|
||||
|
||||
ctx.parallel_for(lX.shape(), lY.rw(), lY.read())->*[] _CCCL_DEVICE(size_t i, auto X, auto Y) {
|
||||
X(i) = 0.5 * Y(i);
|
||||
};
|
||||
}
|
||||
stop = std::chrono::steady_clock::now();
|
||||
ctx.finalize();
|
||||
|
||||
std::chrono::duration<double> duration = stop - start;
|
||||
fprintf(stderr, "Elapsed: %.2lf us per task\n", duration.count() * 1000000.0 / (2 * iter_cnt));
|
||||
}
|
||||
@@ -1,319 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDASTF in CUDA C++ Core Libraries,
|
||||
// under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
// SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cuda/experimental/__stf/internal/dot.cuh>
|
||||
#include <cuda/experimental/stf.cuh>
|
||||
|
||||
#include <cstdlib> // For rand() and srand()
|
||||
#include <numeric> // accumulate
|
||||
|
||||
using namespace cuda::experimental::stf;
|
||||
|
||||
enum test_id
|
||||
{
|
||||
TRIVIAL = 0,
|
||||
STENCIL = 1,
|
||||
FFT = 2,
|
||||
SWEEP = 3,
|
||||
TREE = 4,
|
||||
RANDOM = 5,
|
||||
};
|
||||
|
||||
std::string test_name(test_id id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case TRIVIAL:
|
||||
return "TRIVIAL";
|
||||
case STENCIL:
|
||||
return "STENCIL";
|
||||
case FFT:
|
||||
return "FFT";
|
||||
case SWEEP:
|
||||
return "SWEEP";
|
||||
case TREE:
|
||||
return "TREE";
|
||||
case RANDOM:
|
||||
return "RANDOM";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
int log2Int(int n)
|
||||
{
|
||||
int result = 0;
|
||||
while (n >>= 1)
|
||||
{ // Divide n by 2 until n becomes 0
|
||||
++result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#if _CCCL_COMPILER(MSVC)
|
||||
_CCCL_DIAG_PUSH
|
||||
_CCCL_DIAG_SUPPRESS_MSVC(4702) // unreachable code
|
||||
#endif // _CCCL_COMPILER(MSVC)
|
||||
bool skip_task(test_id id, int t, int i, int /*W*/)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case TRIVIAL:
|
||||
case STENCIL:
|
||||
case FFT:
|
||||
case RANDOM:
|
||||
return false;
|
||||
case SWEEP:
|
||||
// return (i <= t) && (t - i < W);
|
||||
return (i <= t);
|
||||
case TREE: {
|
||||
if (t == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int stride = 1 << (t);
|
||||
return (i % stride != 0);
|
||||
}
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
// should not be reached
|
||||
abort();
|
||||
return true;
|
||||
}
|
||||
#if _CCCL_COMPILER(MSVC)
|
||||
_CCCL_DIAG_POP
|
||||
#endif // _CCCL_COMPILER(MSVC)
|
||||
|
||||
std::vector<int> input_deps(test_id id, int t, int i, int W)
|
||||
{
|
||||
std::vector<int> res;
|
||||
|
||||
// no input deps for the first step
|
||||
if (t == 0)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case TRIVIAL:
|
||||
// D(t,i) = NIL
|
||||
break;
|
||||
case STENCIL:
|
||||
// D(t, i) = {i, i-1, i+1}
|
||||
res.push_back(i);
|
||||
if (i > 0)
|
||||
{
|
||||
res.push_back(i - 1);
|
||||
}
|
||||
if (i < W - 1)
|
||||
{
|
||||
res.push_back(i + 1);
|
||||
}
|
||||
break;
|
||||
case FFT:
|
||||
// D(t,i) = {i, i - 2^t, i+2^t}
|
||||
res.push_back(i);
|
||||
{
|
||||
if (t < 32)
|
||||
{
|
||||
int two_t1 = 1 << (t - 1);
|
||||
if (i - two_t1 >= 0)
|
||||
{
|
||||
res.push_back(i - two_t1);
|
||||
}
|
||||
if (i + two_t1 < W)
|
||||
{
|
||||
res.push_back(i + two_t1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case SWEEP:
|
||||
// D(t,i) = (i, i-1)
|
||||
res.push_back(i);
|
||||
if (i > 0)
|
||||
{
|
||||
res.push_back(i - 1);
|
||||
}
|
||||
break;
|
||||
case TREE:
|
||||
// D(t,i) = (t <= log2(W)) {i - 2^(-t)W(i mod 2^(-t+1)W)} else {i, i + 2^(t-1)*W^-1}
|
||||
{
|
||||
int stride = 1 << (t - 1);
|
||||
res.push_back(i);
|
||||
if (i + stride < W)
|
||||
{
|
||||
res.push_back(i + stride);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RANDOM:
|
||||
// Differs from TaskBench ( D(t,i) = {i | 0 <= i < W && random() < 0.5))
|
||||
// TaskBench topology assumes there can be arbitrarily large numbers of deps
|
||||
// for (int j = 0; j < W; j++) {
|
||||
// double r = static_cast<double>(rand()) / RAND_MAX;
|
||||
// if (r < 0.5)
|
||||
// res.push_back(j);
|
||||
// }
|
||||
for (int k = 0; k < 2; k++)
|
||||
{
|
||||
res.push_back(rand() % W);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void bench(context& ctx, test_id id, size_t width, size_t nsteps, size_t repeat_cnt)
|
||||
{
|
||||
std::chrono::steady_clock::time_point start, stop;
|
||||
|
||||
const size_t b = nsteps;
|
||||
|
||||
std::vector<logical_data<slice<int>>> data(width * b);
|
||||
const size_t data_size = 128;
|
||||
|
||||
/*
|
||||
* Note : CUDASTF_DOT_REMOVE_DATA_DEPS=1 CUDASTF_DOT_NO_FENCE=1 ACUDASTF_DOT_DISPLAY_STAGES=1
|
||||
* CUDASTF_DOT_FILE=pif.dot build/nvcc/tests/stress/task_bench 8 6 1 3; dot -Tpdf pif.dot -o pif.pdf
|
||||
*/
|
||||
ctx.get_dot()->set_tracing(false);
|
||||
|
||||
for (size_t t = 0; t < b; t++)
|
||||
{
|
||||
for (size_t i = 0; i < width; i++)
|
||||
{
|
||||
auto d = ctx.logical_data<int>(data_size);
|
||||
ctx.task(d.write())->*[](cudaStream_t, auto) {};
|
||||
data[t * width + i] = d;
|
||||
}
|
||||
}
|
||||
ctx.get_dot()->set_tracing(true);
|
||||
|
||||
cuda_safe_call(cudaStreamSynchronize(ctx.fence()));
|
||||
ctx.change_stage(); // for better DOT rendering
|
||||
|
||||
std::vector<double> tv;
|
||||
const int niter = 10;
|
||||
size_t task_cnt;
|
||||
size_t deps_cnt;
|
||||
|
||||
for (size_t iter = 0; iter < niter; iter++)
|
||||
{
|
||||
task_cnt = 0;
|
||||
deps_cnt = 0;
|
||||
start = std::chrono::steady_clock::now();
|
||||
|
||||
for (size_t k = 0; k < repeat_cnt; k++)
|
||||
{
|
||||
for (size_t t = 0; t < nsteps; t++)
|
||||
{
|
||||
for (size_t i = 0; i < width; i++)
|
||||
{
|
||||
if (!skip_task(id, t, i, width))
|
||||
{
|
||||
auto tsk = ctx.task();
|
||||
tsk.add_deps(data[(t % b) * width + i].rw());
|
||||
|
||||
auto deps = input_deps(id, t, i, width);
|
||||
for (int d : deps)
|
||||
{
|
||||
tsk.add_deps(data[((t - 1 + b) % b) * width + d].read());
|
||||
deps_cnt++;
|
||||
}
|
||||
|
||||
tsk.set_symbol(std::to_string(t) + "," + std::to_string(i));
|
||||
tsk->*[](cudaStream_t) {};
|
||||
task_cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cuda_safe_call(cudaStreamSynchronize(ctx.fence()));
|
||||
ctx.change_stage(); // for better DOT rendering
|
||||
stop = std::chrono::steady_clock::now();
|
||||
|
||||
std::chrono::duration<double> duration = stop - start;
|
||||
tv.push_back(duration.count() * 1000000.0 / (task_cnt));
|
||||
}
|
||||
|
||||
// Compute the mean (average)
|
||||
double sum = ::std::accumulate(tv.begin(), tv.end(), 0.0);
|
||||
double mean = sum / tv.size();
|
||||
|
||||
// Compute the standard deviation
|
||||
double sq_sum = ::std::accumulate(tv.begin(), tv.end(), 0.0, [mean](double acc, double val) {
|
||||
return acc + std::pow(val - mean, 2);
|
||||
});
|
||||
double variance = sq_sum / tv.size();
|
||||
double standardDeviation = ::std::sqrt(variance);
|
||||
|
||||
fprintf(stderr,
|
||||
"[%s] Elapsed: %.3lf+-%.4lf us per task (%zu tasks, %zu deps, %lf deps/task (avg)\n",
|
||||
test_name(id).c_str(),
|
||||
mean,
|
||||
standardDeviation,
|
||||
task_cnt,
|
||||
deps_cnt,
|
||||
(1.0 * deps_cnt) / task_cnt);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
context ctx;
|
||||
|
||||
size_t width = 8;
|
||||
if (argc > 1)
|
||||
{
|
||||
width = atol(argv[1]);
|
||||
}
|
||||
|
||||
size_t nsteps = width;
|
||||
if (argc > 2)
|
||||
{
|
||||
nsteps = atol(argv[2]);
|
||||
}
|
||||
|
||||
size_t repeat_cnt = 10;
|
||||
if (argc > 3)
|
||||
{
|
||||
repeat_cnt = atol(argv[3]);
|
||||
}
|
||||
|
||||
int id = -1; // all
|
||||
if (argc > 4)
|
||||
{
|
||||
id = atoi(argv[4]);
|
||||
}
|
||||
|
||||
if (id == -1)
|
||||
{
|
||||
bench(ctx, TRIVIAL, width, nsteps, repeat_cnt);
|
||||
bench(ctx, STENCIL, width, nsteps, repeat_cnt);
|
||||
bench(ctx, FFT, width, nsteps, repeat_cnt);
|
||||
bench(ctx, SWEEP, width, nsteps, repeat_cnt);
|
||||
bench(ctx, TREE, width, nsteps, repeat_cnt);
|
||||
bench(ctx, RANDOM, width, nsteps, repeat_cnt);
|
||||
}
|
||||
else
|
||||
{
|
||||
bench(ctx, test_id(id), width, nsteps, repeat_cnt);
|
||||
}
|
||||
|
||||
ctx.finalize();
|
||||
}
|
||||
Reference in New Issue
Block a user