[CCCL] Add missing CCCL components: c2h, nvbench_helper, cmake, cudax, AGENTS.md
Added 863 files from NVIDIA/cccl sparse checkout: - c2h/ (27 files): Catch2 test helpers — generators, validators, runner - nvbench_helper/ (10 files): Benchmark harness utilities - cmake/ (29 files): CMake presets and build helpers - cudax/ (794 files): Experimental CUDA extensions - AGENTS.md: NVIDIA's official AI agent instructions for CCCL - CMakePresets.json: Standardized build configurations - cccl-version.json: Version tracking Also added CCCL_ASSET_MAP.md mapping all 4295 CCCL files to competition value and PRD items. cccl_upstream now covers 100% of competition-critical assets: - 27 tuning headers (SM80/90/100 benchmark data) - 32 dispatch headers (algorithm implementations) - 60 Thrust examples (correctness verification) - 217 CUB Catch2 tests (regression matrix) - 153 CUB benchmarks (parameter space search) - 18 CUB examples (API verification) - 27 test helpers + benchmark harness - 794 cudax experimental extensions
This commit is contained in:
80
cccl_upstream/cudax/examples/stf/sqrt_newton_stackable.cu
Normal file
80
cccl_upstream/cudax/examples/stf/sqrt_newton_stackable.cu
Normal 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-2025 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @brief Compute square roots via Newton's method using while_graph_scope
|
||||
*
|
||||
* This is a minimal example of an iterative solver with convergence
|
||||
* checking in a stackable context. Each iteration applies the
|
||||
* Babylonian step x <- (x + S/x) / 2 and reduces the maximum
|
||||
* absolute change across all elements. The while loop exits once
|
||||
* the change drops below a tolerance.
|
||||
*/
|
||||
|
||||
#include <cuda/experimental/stf.cuh>
|
||||
|
||||
using namespace cuda::experimental::stf;
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _CCCL_CTK_BELOW(12, 4)
|
||||
fprintf(stderr, "Waiving example: while_graph_scope requires CUDA 12.4+.\n");
|
||||
return 0;
|
||||
#else
|
||||
stackable_ctx ctx;
|
||||
|
||||
constexpr size_t N = 1024;
|
||||
constexpr double tol = 1e-12;
|
||||
|
||||
::std::vector<double> host_S(N);
|
||||
::std::vector<double> host_X(N);
|
||||
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
host_S[i] = 1.0 + static_cast<double>(i);
|
||||
host_X[i] = host_S[i]; // initial guess x0 = S
|
||||
}
|
||||
|
||||
auto lS = ctx.logical_data(make_slice(host_S.data(), N)).set_symbol("S");
|
||||
lS.set_read_only();
|
||||
|
||||
auto lX = ctx.logical_data(make_slice(host_X.data(), N)).set_symbol("X");
|
||||
auto lmax_err = ctx.logical_data(shape_of<scalar_view<double>>()).set_symbol("max_err");
|
||||
|
||||
{
|
||||
auto while_guard = ctx.while_graph_scope();
|
||||
|
||||
// Babylonian step: x = (x + S/x) / 2, reduce max |change|
|
||||
ctx.parallel_for(box(N), lX.rw(), lS.read(), lmax_err.reduce(reducer::maxval<double>{}))
|
||||
->*[] __device__(size_t i, auto x, auto s, auto& max_err) {
|
||||
double x_old = x(i);
|
||||
double x_new = 0.5 * (x_old + s(i) / x_old);
|
||||
x(i) = x_new;
|
||||
max_err = fabs(x_new - x_old);
|
||||
};
|
||||
|
||||
while_guard.update_cond(lmax_err.read())->*[tol] __device__(auto max_err) {
|
||||
return (*max_err > tol);
|
||||
};
|
||||
}
|
||||
|
||||
ctx.finalize();
|
||||
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
double expected = sqrt(1.0 + static_cast<double>(i));
|
||||
EXPECT(fabs(host_X[i] - expected) < 1e-8);
|
||||
}
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user