This commit is contained in:
parent
c0e4067639
commit
19b059a88c
11 changed files with 286 additions and 1 deletions
16
tests/Cuda/inner/kernel.cu
Normal file
16
tests/Cuda/inner/kernel.cu
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// A staged-but-unlaunched kernel forces nvcc to emit a real fatbin and
|
||||
// the cudart-registration glue, which is what makes this a meaningful
|
||||
// CUDA-pipeline test. The host entry the C++ side actually calls returns
|
||||
// the same constant via plain CPU code so the test passes on hosts that
|
||||
// have the SDK but no NVIDIA driver/GPU.
|
||||
__device__ int compute_on_device() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
__global__ void kernel(int* out) {
|
||||
*out = compute_on_device();
|
||||
}
|
||||
|
||||
extern "C" int kernel_compute() {
|
||||
return 42;
|
||||
}
|
||||
8
tests/Cuda/inner/main.cpp
Normal file
8
tests/Cuda/inner/main.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import std;
|
||||
|
||||
extern "C" int kernel_compute();
|
||||
|
||||
int main() {
|
||||
std::println("answer={}", kernel_compute());
|
||||
return 0;
|
||||
}
|
||||
29
tests/Cuda/inner/project.cpp
Normal file
29
tests/Cuda/inner/project.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import std;
|
||||
import Crafter.Build;
|
||||
namespace fs = std::filesystem;
|
||||
using namespace Crafter;
|
||||
|
||||
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view>) {
|
||||
Configuration cfg;
|
||||
cfg.path = "./";
|
||||
cfg.name = "cuda-test";
|
||||
cfg.outputName = "cuda-test";
|
||||
cfg.target = "x86_64-pc-linux-gnu";
|
||||
cfg.type = ConfigurationType::Executable;
|
||||
|
||||
std::array<fs::path, 0> ifaces = {};
|
||||
std::array<fs::path, 1> impls = { "main" };
|
||||
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||||
|
||||
cfg.cuda.push_back("kernel");
|
||||
|
||||
// The outer test driver discovers the SDK location and exports it; nvcc
|
||||
// emits __cudaRegisterFatBinary references into every .cu object even
|
||||
// when no kernel is launched, so libcudart has to be on the link line.
|
||||
if (const char* libDir = std::getenv("CRAFTER_CUDA_LIBDIR")) {
|
||||
cfg.linkFlags.push_back(std::format("-L{}", libDir));
|
||||
cfg.linkFlags.push_back("-lcudart");
|
||||
}
|
||||
|
||||
return cfg;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue