fix(cuda): rebuild a .cu when a header it includes changes
A .cu was compiled again only when it was newer than its object, so one whose header changed kept the object built from the old header. The C and C++ paths ask the compiler for a depfile and check every prerequisite in it; nvcc was left out because its -MD and -MF had never been run here. They work with CUDA 13.4 as they do with clang: the depfile lists the .cu and every header it read, the toolkit's and the system's included. nvcc puts a space before the rule's colon, which NewestPrerequisite reads as a target token like any other. An object from before has no depfile and is compiled once more.
This commit is contained in:
parent
ad021ee652
commit
c2338d1122
1 changed files with 9 additions and 7 deletions
|
|
@ -1142,12 +1142,14 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
files += std::format(" {}_source.o ", (buildDir / cFile.filename()).string());
|
files += std::format(" {}_source.o ", (buildDir / cFile.filename()).string());
|
||||||
const std::string objPath = std::format("{}_source.o", (buildDir / cFile.filename()).string());
|
const std::string objPath = std::format("{}_source.o", (buildDir / cFile.filename()).string());
|
||||||
const std::string srcPath = std::format("{}.cu", cFile.string());
|
const std::string srcPath = std::format("{}.cu", cFile.string());
|
||||||
// Still .cu-mtime only: the header tracking the C and C++ paths get
|
// nvcc writes the depfile clang writes for a C source (-MD -MF): the
|
||||||
// comes from asking the compiler for a depfile, and nvcc's -MD/-MF are
|
// .cu and every header it read, the toolkit's and the system's among
|
||||||
// untested here (no CUDA toolkit in CI), so a .cu that only sees a
|
// them, as a Make rule NewestPrerequisite reads as it reads clang's,
|
||||||
// changed header does not rebuild yet. cfg.cudaArch needs no check:
|
// although nvcc puts a space before the colon. Without it, a .cu
|
||||||
// it is part of VariantId, so another one builds in another directory.
|
// whose header changed kept its old object. cfg.cudaArch needs no
|
||||||
if (!fs::exists(objPath) || (fs::exists(srcPath) && fs::last_write_time(srcPath) > fs::last_write_time(objPath))) {
|
// check: it is part of VariantId, so another one builds in another
|
||||||
|
// directory.
|
||||||
|
if (!fs::exists(objPath) || (fs::exists(srcPath) && fs::last_write_time(srcPath) > fs::last_write_time(objPath)) || NewestPrerequisite(std::format("{}.d", objPath)) > fs::last_write_time(objPath)) {
|
||||||
const Toolchain& toolchain = GetToolchain();
|
const Toolchain& toolchain = GetToolchain();
|
||||||
if (toolchain.nvcc.empty()) {
|
if (toolchain.nvcc.empty()) {
|
||||||
bool expected = false;
|
bool expected = false;
|
||||||
|
|
@ -1160,7 +1162,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
||||||
Progress::Task task(std::format("Compiling {}.cu", cFile.filename().string()));
|
Progress::Task task(std::format("Compiling {}.cu", cFile.filename().string()));
|
||||||
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
||||||
|
|
||||||
std::string result = RunBuildCommand(std::format("{} {} -c -o {} -O3 -arch={}", ShellQuote(toolchain.nvcc.string()), ShellQuote(srcPath), ShellQuote(objPath), ShellQuote(config.cudaArch)));
|
std::string result = RunBuildCommand(std::format("{} {} -c -MD -MF {} -o {} -O3 -arch={}", ShellQuote(toolchain.nvcc.string()), ShellQuote(srcPath), ShellQuote(std::format("{}.d", objPath)), ShellQuote(objPath), ShellQuote(config.cudaArch)));
|
||||||
if (result.empty()) return;
|
if (result.empty()) return;
|
||||||
|
|
||||||
bool expected = false;
|
bool expected = false;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue