feat(cuda): make the GPU architecture configurable, native by default
nvcc ran with -arch=sm_89 for every build, which is code for that one architecture and its PTX, whatever GPU the program was for. Jorijn asked for the architecture to be configurable, and native when nothing sets it, as the CPU's is. cfg.cudaArch is nvcc's -arch now, and it defaults to "native": nvcc compiles for the GPUs it sees, and where it sees none it warns and uses its own default architecture. Like -march=native it is for a program that runs where it is built, since it carries no PTX, and `crafter-build bundle` warns of a bundle whose CUDA code, in the program or a library it is built on, is compiled for native, as it warns of -march=native. ApplyStandardArgs sets it from --cuda-arch= and CRAFTER_BUILD_CUDA_ARCH as it sets march from --march= and CRAFTER_BUILD_MARCH; AddTest and AddMarchVariants give their tests the parent's, as they give them its sysroot and debug flag; and ForceHostTooling gives host tooling the host's, as it gives it the host's march, since project.so runs it on the machine that loads it. A .cu is compiled again only when it is newer than its object, so the architecture keys VariantId, and so does the nvcc that compiles it, by what it is rather than where: Toolchain::nvccStamp, its canonical path, size and time, read without a process, changes when CUDA_PATH names another toolkit and when an update replaces the one at the same path, as a package does at /opt/cuda. native is keyed as well, by Toolchain::cudaNativeKey: the NVIDIA display devices sysfs lists, by PCI address and device ID, and CUDA_VISIBLE_DEVICES and CUDA_DEVICE_ORDER, which choose and number them, each empty value apart from an unset one, read without a process. It is crafter-build's reading of the machine, not nvcc's. The word alone would keep an object compiled for a GPU the machine no longer has, after a GPU change or on another machine that shares the checkout, and that object carries no PTX for the GPU it has now, where sm_89's carried its PTX. Only a configuration with CUDA sources is keyed, so every other one keeps the directory it had, but for one built with --cuda-arch=, which was a project argument, hashed as one, and is crafter-build's own now.
This commit is contained in:
parent
2fd45133a0
commit
967dd12b06
10 changed files with 262 additions and 15 deletions
|
|
@ -128,6 +128,42 @@ int main() {
|
|||
b.march = "x86-64-v3";
|
||||
Check(a.VariantId() != b.VariantId(), "march change perturbs VariantId");
|
||||
}
|
||||
{
|
||||
// The GPU architecture decides what a .cu compiles into, and it need
|
||||
// not touch the files whose times decide whether a .cu is compiled
|
||||
// again, so it keys the directory of a configuration with CUDA
|
||||
// sources, and only of one.
|
||||
Configuration a = MakeBase();
|
||||
a.cuda = { "/tmp/variant-id-test/kernel" };
|
||||
Configuration b = MakeBase();
|
||||
b.cuda = a.cuda;
|
||||
b.cudaArch = "sm_89";
|
||||
Check(a.VariantId() != b.VariantId(), "cudaArch change perturbs the VariantId of a configuration with CUDA sources");
|
||||
Configuration c = MakeBase();
|
||||
Configuration d = MakeBase();
|
||||
d.cudaArch = "sm_89";
|
||||
Check(c.VariantId() == d.VariantId(), "without CUDA sources, cudaArch leaves VariantId alone");
|
||||
// So does the nvcc that compiles them, by what it is: CUDA_PATH can
|
||||
// name another toolkit, and an update can replace one at its path,
|
||||
// and the old one's objects must not pass for the new one's.
|
||||
const Toolchain one = GetToolchain();
|
||||
Toolchain other = one;
|
||||
other.nvccStamp = "/opt/other-cuda/bin/nvcc|1|1";
|
||||
Toolchain updated = other;
|
||||
updated.nvccStamp = "/opt/other-cuda/bin/nvcc|2|2";
|
||||
Check(a.VariantId(one) != a.VariantId(other), "another nvcc perturbs the VariantId of a configuration with CUDA sources");
|
||||
Check(a.VariantId(other) != a.VariantId(updated), "so does an nvcc updated at the same path");
|
||||
Check(c.VariantId(one) == c.VariantId(other), "without CUDA sources, the nvcc leaves VariantId alone");
|
||||
// native is what nvcc finds on the machine, so the GPUs it finds key
|
||||
// it as well, and only it.
|
||||
Toolchain first = one;
|
||||
first.cudaNativeKey = "0x2684|";
|
||||
Toolchain swapped = one;
|
||||
swapped.cudaNativeKey = "0x2b85|";
|
||||
Check(a.VariantId(first) != a.VariantId(swapped), "another GPU perturbs the VariantId of a configuration with CUDA sources for native");
|
||||
Check(b.VariantId(first) == b.VariantId(swapped), "but not for a named architecture");
|
||||
Check(c.VariantId(first) == c.VariantId(swapped), "nor without CUDA sources");
|
||||
}
|
||||
{
|
||||
// A project flag the framework can't interpret still decides what gets
|
||||
// compiled and bundled, so it has to key into VariantId. Otherwise both
|
||||
|
|
|
|||
Loading…
Reference in a new issue