python3Packages.torch.gpuChecks: add rocm

This commit is contained in:
Someone Serge
2024-06-26 00:35:45 +00:00
parent efd64b5f0b
commit 39f33456e4
3 changed files with 51 additions and 22 deletions
@@ -648,7 +648,7 @@ buildPythonPackage rec {
blasProvider = blas.provider;
# To help debug when a package is broken due to CUDA support
inherit brokenConditions;
gpuChecks.cudaAvailable = callPackage ./test-cuda.nix { torch = torchWithCuda; };
gpuChecks = callPackage ./gpu-checks.nix { };
};
meta = {
@@ -0,0 +1,50 @@
{
lib,
callPackage,
torchWithCuda,
torchWithRocm,
}:
let
accelAvailable =
{
feature,
versionAttr,
torch,
runCommandNoCC,
writers,
}:
let
name = "${torch.name}-${feature}-check";
unwrapped = writers.writePython3Bin "${name}-unwrapped" {libraries = [torch];} ''
import torch
message = f"{torch.cuda.is_available()=} and {torch.version.${versionAttr}=}"
assert torch.cuda.is_available() and torch.version.${versionAttr}, message
print(message)
'';
in
runCommandNoCC name
{
nativeBuildInputs = [unwrapped];
requiredSystemFeatures = [feature];
passthru = {
inherit unwrapped;
};
}
''
${name}-unwrapped
touch $out
'';
in
{
cudaAvailable = callPackage accelAvailable {
feature = "cuda";
versionAttr = "cuda";
torch = torchWithCuda;
};
rocmAvailable = callPackage accelAvailable {
feature = "rocm";
versionAttr = "hip";
torch = torchWithRocm;
};
}
@@ -1,21 +0,0 @@
{ runCommandNoCC
, python
, torch
}:
runCommandNoCC "${torch.name}-gpu-test"
{
nativeBuildInputs = [
(python.withPackages (_: [ torch ]))
];
requiredSystemFeatures = [
"cuda"
];
} ''
python3 << EOF
import torch
assert torch.cuda.is_available(), f"{torch.cuda.is_available()=}"
EOF
touch $out
''