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
89 lines
2.1 KiB
Plaintext
89 lines
2.1 KiB
Plaintext
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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 Experiment with local context nesting
|
|
*
|
|
*/
|
|
|
|
#include <cuda/experimental/stf.cuh>
|
|
|
|
using namespace cuda::experimental::stf;
|
|
|
|
int main()
|
|
{
|
|
stackable_ctx sctx;
|
|
|
|
int array[1024];
|
|
for (size_t i = 0; i < 1024; i++)
|
|
{
|
|
array[i] = 1 + i * i;
|
|
}
|
|
|
|
auto lC = sctx.logical_data(array);
|
|
|
|
auto lA = sctx.logical_data(lC.shape());
|
|
lA.set_symbol("A");
|
|
|
|
auto lA2 = sctx.logical_data(shape_of<slice<int>>(1024));
|
|
lA2.set_symbol("A2");
|
|
|
|
sctx.parallel_for(lA.shape(), lA.write())->*[] __device__(size_t i, auto a) {
|
|
a(i) = 42 + 2 * i;
|
|
};
|
|
|
|
/* Create nested graph */
|
|
{
|
|
stackable_ctx::graph_scope_guard scope{sctx};
|
|
|
|
auto lB = sctx.logical_data(shape_of<slice<int>>(512));
|
|
lB.set_symbol("B");
|
|
|
|
sctx.parallel_for(lB.shape(), lB.write())->*[] __device__(size_t i, auto b) {
|
|
b(i) = 17 - 3 * i;
|
|
};
|
|
|
|
sctx.parallel_for(lA2.shape(), lA2.write())->*[] __device__(size_t i, auto a2) {
|
|
a2(i) = 5 * i + 4;
|
|
};
|
|
|
|
sctx.parallel_for(lB.shape(), lA.read(), lB.rw())->*[] __device__(size_t i, auto a, auto b) {
|
|
b(i) += a(i);
|
|
};
|
|
|
|
sctx.parallel_for(lB.shape(), lB.read(), lC.rw())->*[] __device__(size_t i, auto b, auto c) {
|
|
c(i) += b(i);
|
|
};
|
|
}
|
|
|
|
sctx.host_launch(lA2.read())->*[](auto a2) {
|
|
for (size_t i = 0; i < a2.size(); i++)
|
|
{
|
|
EXPECT(a2(i) == 5 * i + 4);
|
|
}
|
|
};
|
|
|
|
// Do the same check in another graph
|
|
{
|
|
stackable_ctx::graph_scope_guard scope{sctx};
|
|
lA2.push(access_mode::read);
|
|
sctx.host_launch(lA2.read())->*[](auto a2) {
|
|
for (size_t i = 0; i < a2.size(); i++)
|
|
{
|
|
EXPECT(a2(i) == 5 * i + 4);
|
|
}
|
|
};
|
|
}
|
|
|
|
sctx.finalize();
|
|
}
|