I wrote these instructions as part of "installing PyTorch with CUDA 12.1.1".
I extracted them into this separate gist, because I realised there's a much easier way to install magma for CUDA 12.1.1:
https://anaconda.org/pytorch/magma-cuda121
There's a conda package!
conda install -c pytorch magma-cuda121
Anyway, if you still need to compile from source… here's how:
This is a dependency of PyTorch, which is sensitive to CUDA version.
Clone Magma:
git clone --depth 1 https://bitbucket.org/icl/magma.git
cd magma
Look up your CUDA Architecture, e.g. 4090 has architecture 8.9. Use this to determine the two GPU_TARGET
variables below.
Activate your conda environment, if you haven't done so already.
Install a Fortran compiler:
sudo apt-get install gfortran
Configure Magma (see README):
echo -e "GPU_TARGET = sm_89\nBACKEND = cuda\nFORT = false" > make.inc
make generate
CUDA_DIR=/usr/local/cuda-12.1
# be careful here; they didn't accept sm_89 so I had to round it down to major version, sm_80
cmake -DGPU_TARGET=sm_80 -DCMAKE_CUDA_COMPILER="$CUDA_DIR/bin/nvcc" -DCMAKE_INSTALL_PREFIX=build/target . -Bbuild
Build Magma:
cmake --build build -j $(nproc) --target install
Install Magma:
sudo cp build/target/include/* /usr/local/include/
sudo cp build/target/lib/*.so /usr/local/lib/
sudo cp build/target/lib/pkgconfig/*.pc /usr/local/lib/pkgconfig/