diff --git a/tests/CudaCompile/fixture/kernel.cu b/tests/CudaCompile/fixture/kernel.cu index 8faa343..a1b299f 100644 --- a/tests/CudaCompile/fixture/kernel.cu +++ b/tests/CudaCompile/fixture/kernel.cu @@ -1,12 +1,13 @@ // SPDX-License-Identifier: LGPL-3.0-only // SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® +#include "kernel.h" #include #include __global__ void Double(float* values, std::int32_t count) { const std::int32_t i = static_cast(blockIdx.x * blockDim.x + threadIdx.x); - if (i < count) values[i] = 2.0f * static_cast(i); + if (i < count) values[i] = Factor * static_cast(i); } extern "C" std::int32_t LaunchDouble(std::int32_t count, float* values) { diff --git a/tests/CudaCompile/fixture/kernel.h b/tests/CudaCompile/fixture/kernel.h new file mode 100644 index 0000000..1ce22df --- /dev/null +++ b/tests/CudaCompile/fixture/kernel.h @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® + +#pragma once + +// What kernel.cu multiplies every index by: a header of the .cu's own, which +// the test makes newer than the object built from it. +constexpr float Factor = 2.0f; diff --git a/tests/CudaCompile/main.cpp b/tests/CudaCompile/main.cpp index 01b9acc..bfc6374 100644 --- a/tests/CudaCompile/main.cpp +++ b/tests/CudaCompile/main.cpp @@ -18,9 +18,11 @@ using namespace Crafter; // executable from a C++ unit and a .cu: with the default architecture, which // is native, then with another one, which compiles the unchanged .cu again in // a directory of its own, then once more with nothing changed, which compiles -// nothing. Where nvcc is looked for is ToolchainResolve's to check; this is -// the build that uses it. Skips without a CUDA toolkit, which CI does not -// have. +// nothing, and once its header is newer than its object, which compiles it +// again: nvcc's depfile is the record of what the .cu includes, and before +// nvcc wrote one, a changed header left the old object in place. Where nvcc +// is looked for is ToolchainResolve's to check; this is the build that uses +// it. Skips without a CUDA toolkit, which CI does not have. namespace { std::int32_t Failures = 0; @@ -124,6 +126,12 @@ int main() { const auto [again, againBinary] = build("sm_86"); Check(again.empty() && Lines(log).size() == 2, std::format("an unchanged build compiles nothing (ran: {})", Joined(Lines(log)))); + fs::last_write_time(project / "kernel.h", fs::file_time_type::clock::now()); + const auto [touched, touchedBinary] = build("sm_86"); + Check(touched.empty(), std::format("the build after the header changed succeeds: {}", touched)); + runs = Lines(log); + Check(runs.size() == 3 && runs.back().contains("-arch=sm_86"), std::format("a changed header compiles the .cu again (ran: {})", Joined(runs))); + fs::remove_all(scratch, ec); return Failures == 0 ? 0 : 1; }