[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:
@@ -0,0 +1,66 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of CUDA Experimental 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) 2026 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#include <hostjit/config.hpp>
|
||||
#include <hostjit/jit_compiler.hpp>
|
||||
|
||||
static const char* k_source = R"(
|
||||
#include <cuda_runtime.h>
|
||||
#include <cuda/std/version>
|
||||
|
||||
__global__ void device_kernel(int* ptr)
|
||||
{
|
||||
*ptr = 42;
|
||||
}
|
||||
|
||||
extern "C" _CCCL_VISIBILITY_EXPORT void host_entry(int* ptr)
|
||||
{
|
||||
device_kernel<<<1, 1>>>(ptr);
|
||||
}
|
||||
)";
|
||||
|
||||
int main()
|
||||
{
|
||||
// Detect Clang/CUDA configuration from the build environment
|
||||
auto config = hostjit::detectDefaultConfig();
|
||||
|
||||
hostjit::JITCompiler compiler(config);
|
||||
if (!compiler.compile(k_source))
|
||||
{
|
||||
std::fprintf(stderr, "HostJIT compilation failed:\n%s\n", compiler.getLastError().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto host_fn = compiler.getFunction<void (*)(int*)>("host_entry");
|
||||
if (!host_fn)
|
||||
{
|
||||
std::fprintf(stderr, "Symbol 'host_entry' not found\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int* d_ptr = nullptr;
|
||||
cudaMalloc(&d_ptr, sizeof(int));
|
||||
|
||||
host_fn(d_ptr);
|
||||
cudaDeviceSynchronize();
|
||||
|
||||
int result = 0;
|
||||
cudaMemcpy(&result, d_ptr, sizeof(int), cudaMemcpyDeviceToHost);
|
||||
cudaFree(d_ptr);
|
||||
|
||||
assert(result == 42 && "device kernel did not write expected value");
|
||||
std::printf("freestanding compiler test passed (result=%d)\n", result);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user