[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:
EngineX CI
2026-07-30 09:35:51 +00:00
parent b4d01f481e
commit 56fd68e7dd
8871 changed files with 1454674 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
/**
* @file
* @brief Ensure an error is detected when a task uses a logical data from a
* different context
*/
#include <cuda/experimental/stf.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
template <typename Ctx, size_t n>
void run(double (&X)[n])
{
Ctx ctx1;
auto lX = ctx1.logical_data(X);
// We are now using lX in the wrong context
should_abort = true;
Ctx ctx2;
ctx2.task(lX.rw())->*[&](cudaStream_t /*unused*/, auto /*unused*/) {};
assert(0 && "This should not be reached");
}
int main()
{
/* Setup an handler to catch the SIGABRT signal during the programming error */
#if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
#else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
#endif // !_CCCL_COMPILER(MSVC)
const int n = 12;
double X[n];
for (int ind = 0; ind < n; ind++)
{
X[ind] = 1.0 * ind;
}
// We can't run both stream and graph tests because either will abort the program. So choose one at random.
srand(static_cast<unsigned>(time(nullptr)));
if (rand() % 2 == 0)
{
run<stream_ctx>(X);
}
else
{
run<graph_ctx>(X);
}
assert(0 && "This should not be reached");
return EXIT_FAILURE;
}

View File

@@ -0,0 +1,101 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
/**
* @file
* @brief Ensure an error is detected dynamically if we access a data instance
* with the wrong interface type
*/
#include <cuda/experimental/__stf/graph/graph_ctx.cuh>
#include <cuda/experimental/__stf/stream/stream_ctx.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
template <typename Ctx, size_t n>
void run(double (&X)[n])
{
Ctx ctx;
// This creates an untyped logical data that is implicitly a vector of size
// n. Had the code used `auto` instead of `logical_data_untyped`, errors
// would have been rejected statically. We want to disable static checking
// for the purposes of this test.
logical_data_untyped handle_X = ctx.logical_data(X);
// Here we create a dynamically-typed task, again to go around static typechecking.
auto t = ctx.task();
t.add_deps(handle_X.rw());
t->*[&](auto&) {
should_abort = true;
// We have a programming error here with a vector of `double` accessad as a vector of `float`.
handle_X.instance<slice<float>>(t);
should_abort = false;
};
assert(0 && "This should not be reached");
}
int main()
{
/* Setup an handler to catch the SIGABRT signal during the programming error */
#if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
#else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
#endif // !_CCCL_COMPILER(MSVC)
const int n = 12;
double X[n];
for (int ind = 0; ind < n; ind++)
{
X[ind] = 1.0 * ind;
}
// We can't run both stream and graph tests because either will abort the program. So choose one at random.
srand(static_cast<unsigned>(time(nullptr)));
if (rand() % 2 == 0)
{
run<stream_ctx>(X);
}
else
{
run<graph_ctx>(X);
}
assert(0 && "This should not be reached");
return EXIT_FAILURE;
}

View File

@@ -0,0 +1,80 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
/**
* @file
* @brief Ensure an error is detected if we can finalize more than once
*/
#include <cuda/experimental/stf.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
int main()
{
// This test only works when assert() is enabled in
#ifndef NDEBUG
/* Setup an handler to catch the SIGABRT signal during the programming error */
# if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
# else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
# endif // !_CCCL_COMPILER(MSVC)
context ctx;
const int n = 12;
double X[n];
for (int ind = 0; ind < n; ind++)
{
X[ind] = 1.0 * ind;
}
// This creates a handle that is implicitly a vector of size n
auto lX = ctx.logical_data(X);
ctx.task(lX.rw())->*[](cudaStream_t, auto) { /* no-op */ };
ctx.finalize();
should_abort = true;
// We cannot call sync twice
ctx.finalize();
assert(0 && "This should not be reached");
return EXIT_FAILURE;
#endif
}

View File

@@ -0,0 +1,77 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
/**
* @file
*
* @brief Ensure temporary data are destroyed
*
*/
#include <cuda/experimental/__stf/graph/graph_ctx.cuh>
#include <cuda/experimental/__stf/stream/stream_ctx.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
int main()
{
/* Setup an handler to catch the SIGABRT signal during the programming error */
#if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
#else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
#endif // !_CCCL_COMPILER(MSVC)
stream_ctx ctx;
const int N = 16;
int X[N];
for (int i = 0; i < N; i++)
{
X[i] = i;
}
auto lX = ctx.logical_data(X);
lX.freeze(access_mode::rw, data_place::current_device());
// This should cause an error because lX is frozen while the context is finalized
should_abort = true;
ctx.finalize();
assert(0 && "This should not be reached");
return EXIT_FAILURE;
}

View File

@@ -0,0 +1,78 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
/**
* @file
* @brief Ensure that an error is detected if we end a task twice
*/
#include <cuda/experimental/__stf/stream/stream_ctx.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
int main()
{
// This test only works when assert() is enabled in
#ifndef NDEBUG
/* Setup an handler to catch the SIGABRT signal during the programming error */
# if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
# else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
# endif // !_CCCL_COMPILER(MSVC)
stream_ctx ctx;
const int n = 12;
double X[n];
for (int ind = 0; ind < n; ind++)
{
X[ind] = 1.0 * ind;
}
// This creates a handle that is implicitly a vector of size n
auto lX = ctx.logical_data(X);
auto t = ctx.task(lX.rw());
t.start();
t.end();
should_abort = true;
t.end();
assert(0 && "This should not be reached");
return EXIT_FAILURE;
#endif
}

View File

@@ -0,0 +1,75 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
/**
* @file
* @brief Ensure that an error is detected if we start a task twice
*/
#include <cuda/experimental/__stf/stream/stream_ctx.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
int main()
{
/* Setup an handler to catch the SIGABRT signal during the programming error */
#if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
#else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
#endif // !_CCCL_COMPILER(MSVC)
stream_ctx ctx;
const int n = 12;
double X[n];
for (int ind = 0; ind < n; ind++)
{
X[ind] = 1.0 * ind;
}
// This creates a handle that is implicitly a vector of size n
auto lX = ctx.logical_data(X);
auto t = ctx.task(lX.rw());
t.start();
should_abort = true;
t.start();
t.end();
assert(0 && "This should not be reached");
return EXIT_FAILURE;
}

View File

@@ -0,0 +1,70 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
/**
* @file
* @brief Ensure an error is detected when trying to declare a logical data
* with a managed memory data place while the data is not in managed
* memory
*/
#include <cuda/experimental/__stf/graph/graph_ctx.cuh>
#include <cuda/experimental/__stf/stream/stream_ctx.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
int main()
{
/* Setup an handler to catch the SIGABRT signal during the programming error */
#ifndef NDEBUG
# if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
# else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
# endif // !_CCCL_COMPILER(MSVC)
stream_ctx ctx;
logical_data<slice<int>> lX;
should_abort = true;
int X[128];
lX = ctx.logical_data(X, data_place::managed());
assert(0 && "This should not be reached");
return EXIT_FAILURE;
#endif
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
/**
* @file
* @brief Ensure that out of bound accesses on slices are detected with the
* CUDASTF_BOUNDSCHECK option set
*/
/*
* We are forcing this option by defining this value to be set.
*/
#ifndef NDEBUG
# ifndef CUDASTF_BOUNDSCHECK
# define CUDASTF_BOUNDSCHECK
# endif // CUDASTF_BOUNDSCHECK
#endif // NDEBUG
#include <cuda/experimental/stf.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
int main()
{
/* Setup an handler to catch the SIGABRT signal during the programming error */
#ifndef NDEBUG
# if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
# else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
# endif // !_CCCL_COMPILER(MSVC)
context ctx;
int X[128];
logical_data<slice<int>> lX;
lX = ctx.logical_data(X);
should_abort = true;
// The last access will be out of bounds
ctx.parallel_for(lX.shape(), lX.rw())->*[] __device__(size_t i, auto X) {
X(i + 1) = 42;
};
ctx.finalize();
assert(0 && "This should not be reached");
return EXIT_FAILURE;
#endif
}

View File

@@ -0,0 +1,75 @@
//===----------------------------------------------------------------------===//
//
// 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-2025 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
/**
* @file
*
* @brief Ensure fence() in a nested stackable context triggers an abort
*/
#include <cuda/experimental/stf.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
int main()
{
#if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
#else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
#endif // !_CCCL_COMPILER(MSVC)
stackable_ctx sctx;
auto lA = sctx.logical_data(shape_of<slice<int>>(64));
sctx.parallel_for(lA.shape(), lA.write())->*[] __device__(size_t i, auto a) {
a(i) = static_cast<int>(i);
};
{
auto scope = sctx.graph_scope();
sctx.parallel_for(lA.shape(), lA.rw())->*[] __device__(size_t i, auto a) {
a(i) *= 2;
};
should_abort = true;
sctx.fence(); // fence() in nested context must abort
}
_CCCL_ASSERT(false, "This should not be reached");
return EXIT_FAILURE;
}

View File

@@ -0,0 +1,82 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
/**
* @file
*
* @brief Ensure we detect erroneous access on non exportable stackable logical
* data after the context was popped
*
*/
#include <cuda/experimental/stf.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
int main()
{
/* Setup an handler to catch the SIGABRT signal during the programming error */
#if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
#else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
#endif // !_CCCL_COMPILER(MSVC)
stackable_ctx sctx;
sctx.push();
auto lB = sctx.logical_data_no_export(shape_of<slice<int>>(1024));
lB.set_symbol("B");
sctx.parallel_for(lB.shape(), lB.write())->*[] __device__(size_t i, auto b) {
b(i) = 42;
};
sctx.pop();
// We are going to try to access B while it was not exportable, and that the
// context where it was created has been popped: this should raise an error.
should_abort = true;
sctx.host_launch(lB.read())->*[](auto b) {
for (size_t i = 0; i < b.size(); i++)
{
EXPECT(b(i) == 42);
}
};
_CCCL_ASSERT(false, "This should not be reached");
return EXIT_FAILURE;
}

View File

@@ -0,0 +1,92 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
/**
* @file
*
* @brief Test that ensures we catch programming errors with inconsistent access modes in nested contexts
*
* This test verifies that attempting to escalate from read-only to read-write access mode
* in nested stackable contexts is properly caught and produces a clear error message.
*
*/
#include <cuda/experimental/stf.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
int main()
{
/* Setup an handler to catch the SIGABRT signal during the programming error */
#if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
#else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
#endif // !_CCCL_COMPILER(MSVC)
stackable_ctx sctx;
size_t sz = 1024;
::std::vector<int> data(sz);
// Initialize data
for (size_t i = 0; i < sz; i++)
{
data[i] = static_cast<int>(i);
}
// Create logical data
auto ldata = sctx.logical_data(make_slice(data.data(), sz));
// First scope: push with READ access mode
{
stackable_ctx::graph_scope_guard scope1{sctx};
ldata.push(access_mode::read);
// We are going to try to escalate from read to rw access mode in nested context:
// this should raise an error.
should_abort = true;
// NESTED second scope: attempt to push with RW access mode
// This should be caught as an invalid access mode escalation
{
stackable_ctx::graph_scope_guard scope2{sctx};
ldata.push(access_mode::rw); // This should trigger abort()!
}
}
_CCCL_ASSERT(false, "This should not be reached");
return EXIT_FAILURE;
}

View File

@@ -0,0 +1,75 @@
//===----------------------------------------------------------------------===//
//
// 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-2025 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
/**
* @file
*
* @brief Ensure wait() in a nested stackable context triggers an abort
*/
#include <cuda/experimental/stf.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
int main()
{
#if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
#else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
#endif // !_CCCL_COMPILER(MSVC)
stackable_ctx sctx;
auto lval = sctx.logical_data(shape_of<scalar_view<int>>());
sctx.parallel_for(box(1), lval.write())->*[] __device__(size_t, auto val) {
*val = 42;
};
{
auto scope = sctx.graph_scope();
sctx.parallel_for(box(1), lval.rw())->*[] __device__(size_t, auto val) {
*val += 1;
};
should_abort = true;
sctx.wait(lval); // wait() in nested context must abort
}
_CCCL_ASSERT(false, "This should not be reached");
return EXIT_FAILURE;
}

View File

@@ -0,0 +1,72 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
/**
* @file
* @brief Ensure an error is detected if we use an uninitialized logical data in a task
*/
#include <cuda/experimental/__stf/graph/graph_ctx.cuh>
#include <cuda/experimental/__stf/stream/stream_ctx.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
int main()
{
/* Setup an handler to catch the SIGABRT signal during the programming error */
#ifndef NDEBUG
# if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
# else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
# endif // !_CCCL_COMPILER(MSVC)
stream_ctx ctx;
logical_data<slice<int>> lX;
logical_data<slice<int>> lY;
int X[128];
lX = ctx.logical_data(X);
should_abort = true;
// We did not initialize lY, so this task should not be able to use it.
ctx.task(lX.rw(), lY.rw())->*[](cudaStream_t, auto, auto) {};
assert(0 && "This should not be reached");
return EXIT_FAILURE;
#endif
}

View File

@@ -0,0 +1,72 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
/**
* @file
* @brief Ensure an error is raised if we try to ask for an unreasonnable
* amount of resources in a thread hierarchy spec
*/
#include <cuda/experimental/stf.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
int main()
{
/* Setup an handler to catch the SIGABRT signal during the programming error */
#ifndef NDEBUG
# if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
# else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
# endif // !_CCCL_COMPILER(MSVC)
context ctx;
int X[128];
auto lX = ctx.logical_data(X);
should_abort = true;
// We are asking an unreasonnable amount of threads per block
auto spec = con(con<128000>());
ctx.launch(spec, lX.rw())->*[] __device__(auto th, auto X) {
X[th.rank()] = th.rank();
};
assert(0 && "This should not be reached");
return EXIT_FAILURE;
#endif
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
/**
* @file
*
* @brief Ensure temporary data are destroyed
*
*/
#include <cuda/experimental/__stf/graph/graph_ctx.cuh>
#include <cuda/experimental/__stf/stream/stream_ctx.cuh>
#include <csignal>
using namespace cuda::experimental::stf;
bool should_abort = false;
void cleanupRoutine(int /*unused*/)
{
if (should_abort)
{
exit(EXIT_SUCCESS);
}
else
{
fprintf(stderr, "Unexpected SIGABRT !\n");
exit(EXIT_FAILURE);
}
}
int main()
{
/* Setup an handler to catch the SIGABRT signal during the programming error */
#if _CCCL_COMPILER(MSVC)
signal(SIGABRT, &cleanupRoutine);
#else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC)
struct sigaction sigabrt_action{};
memset(&sigabrt_action, 0, sizeof(sigabrt_action));
sigabrt_action.sa_handler = &cleanupRoutine;
if (sigaction(SIGABRT, &sigabrt_action, nullptr) != 0)
{
perror("sigaction SIGABRT");
exit(EXIT_FAILURE);
}
#endif // !_CCCL_COMPILER(MSVC)
stream_ctx ctx;
const int N = 16;
int X[N];
for (int i = 0; i < N; i++)
{
X[i] = i;
}
auto lX = ctx.logical_data(X);
lX.freeze(access_mode::rw, data_place::current_device());
// This is an illegal access because we cannot make a write access on a frozen data
should_abort = true;
ctx.task(lX.rw())->*[](cudaStream_t, auto) {};
ctx.finalize();
assert(0 && "This should not be reached");
return EXIT_FAILURE;
}