Skip to content

Instantly share code, notes, and snippets.

@Birch-san
Created April 27, 2023 21:58
Show Gist options
  • Save Birch-san/5be1709aedf12cb5874f7ff59c5fb030 to your computer and use it in GitHub Desktop.
Save Birch-san/5be1709aedf12cb5874f7ff59c5fb030 to your computer and use it in GitHub Desktop.
Build magma from source

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:

Build Magma from source

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/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment