<aside> 🪄
Pixi Advent Calendar 2025 17日目の記事です。
</aside>
pixi では CUDA の version を仮想環境で自在に切り替えることができます. 以前は環境毎に Docker image を再度作り直していましたが, ちょっとした検証が随分楽にできるようになりました. conda エコシステムは強力なので python 不在のプロジェクトでこそ pixi を使います.
<aside> 📝
メモ帳 をかき集めてきたら長くなりました. 結論だけ知りたい人は実践編だけ読んで下さい
</aside>
channel label で絞り込んで cuda version を指定する
pixi add cuda=12.9
✔ Added cuda=12.9
[workspace]
channels = ["nvidia/label/cuda-12.9.0", "nvidia", "conda-forge"]
platforms = "linux-64"
cuda-version メタパッケージで version を指定する
pixi add cuda cuda-version=12.9
✔ Added cuda >=12.9.1,<13
✔ Added cuda-version=12.9
[workspace]
channels = ["conda-forge"]
platforms = "linux-64"
これで大概のケースは解決するはずです(CUDA11以下は nvidia channel 推奨)
仮想環境の中では $CONDA_PREFIX を介してCUDA の場所が参照できます.
これらは全てプロジェクトローカルに配置されるため, .pixi/envs/cuda12 .pixi/envs/cuda13 のように仮想環境を分けて複数の cuda version を多頭飼いすることもできます.
$CONDA_PREFIX |
$PROJECT_ROOT/.pixi/envs/$ENV_NAME |
|---|
<aside> 📋
cmake は nvcc の場所から cuda prefix を特定するので, nvcc を含む cuda 又は cuda-toolkit package を入れれば勝手に検出されます
The script will prompt the user to specify
CUDA_TOOLKIT_ROOT_DIRif the prefix cannot be determined by the location of nvcc in the system path
cmake_minimum_required(VERSION 3.18)
project(test LANGUAGES CUDA CXX)
cmake -H. -Bbuild
cmake -H. -Bbuild
-- The CUDA compiler identification is NVIDIA 12.6.85 with host compiler GNU 13.3.0
-- The CXX compiler identification is GNU 13.3.0
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: $PROJECT_ROOT/.pixi/envs/default/bin/nvcc - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
</aside>