add script to install amd mockgpu on macOS (#8536)

* upload artifact every time

* hm

* sh script

* hm

* hm2

* hm2

* hm2

* no sudo

* def paths

* small comments

* text

* try auth for bigger limits
This commit is contained in:
nimlgen
2025-01-09 01:29:25 +03:00
committed by GitHub
parent 31fcfe764d
commit aa3d612df2
5 changed files with 33 additions and 61 deletions
+8 -59
View File
@@ -595,70 +595,19 @@ jobs:
key: mockgpu-osx-${{ matrix.backend }}-packages-${{ hashFiles('**/setup.py') }}
- name: Set env
run: printf "${{ matrix.backend == 'amd' && 'MOCKGPU=1\nAMD=1\nFORWARD_ONLY=1' }}" >> $GITHUB_ENV
- name: Cache comgr
if: matrix.backend == 'amd'
id: cache-comgr
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/llvm-project/amd/comgr/build
key: macos-15-comgr-aarch64-669db884972e769450470020c06a6f132a8a065b
- name: Cache remu
uses: actions/cache@v4
id: cache-remu
with:
path: ${{ github.workspace }}/remu/target
key: remu-osx-b873f2d254ebfdc81fc113e311c80efaedf061f8
- name: Clone LLVM and AMD projects
if: matrix.backend == 'amd' && steps.cache-comgr.outputs.cache-hit != 'true' && steps.cache-remu.outputs.cache-hit != 'true'
run: |
git clone --depth 10 -b rocm-6.1.x https://github.com/ROCm/llvm-project ${{ github.workspace }}/llvm-project
cd ${{ github.workspace }}/llvm-project
git checkout 669db884972e769450470020c06a6f132a8a065b
rm -rf .git
- name: Install build dependencies
if: matrix.backend == 'amd' && steps.cache-comgr.outputs.cache-hit != 'true'
run: |
brew update
brew install --formula cmake rust
# Comgr depends on LLVM, clang, lld, and device-libs. (https://github.com/ROCm/llvm-project/tree/rocm-6.1.x/amd/comgr)
- name: Build LLVM
if: matrix.backend == 'amd' && steps.cache-comgr.outputs.cache-hit != 'true'
run: |
cd ${{ github.workspace }}/llvm-project
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="llvm;clang;lld" -DLLVM_TARGETS_TO_BUILD="AMDGPU;AArch64" ../llvm
make -j$(sysctl -n hw.ncpu)
- name: Build device-libs
if: matrix.backend == 'amd' && steps.cache-comgr.outputs.cache-hit != 'true'
run: |
cd ${{ github.workspace }}/llvm-project/amd/device-libs
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="${{ github.workspace }}/llvm-project/build" ..
make -j$(sysctl -n hw.ncpu)
- name: Build comgr
if: matrix.backend == 'amd' && steps.cache-comgr.outputs.cache-hit != 'true'
run: |
cd ${{ github.workspace }}/llvm-project/amd/comgr
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="${{ github.workspace }}/llvm-project/build;${{ github.workspace }}/llvm-project/amd/device-libs/build" -DCOMGR_DISABLE_SPIRV=1 -DBUILD_TESTING=OFF ..
make -j$(sysctl -n hw.ncpu)
- name: Install comgr
if: matrix.backend == 'amd'
run: sudo mkdir /usr/local/lib && sudo cp ${{ github.workspace }}/llvm-project/amd/comgr/build/libamd_comgr.dylib /usr/local/lib/
- name: Clone remu
if: matrix.backend == 'amd' && steps.cache-remu.outputs.cache-hit != 'true'
run: |
git clone https://github.com/Qazalin/remu ${{ github.workspace }}/remu
cd ${{ github.workspace }}/remu
git checkout b873f2d254ebfdc81fc113e311c80efaedf061f8
- name: Compile remu
if: matrix.backend == 'amd' && steps.cache-remu.outputs.cache-hit != 'true'
run: |
cd ${{ github.workspace }}/remu
cargo build --release
sudo mkdir -p /usr/local/lib
curl -s -H "Authorization: token $GH_TOKEN" curl -s https://api.github.com/repos/nimlgen/amdcomgr_dylib/releases/latest | \
jq -r '.assets[] | select(.name == "libamd_comgr.dylib").browser_download_url' | \
sudo xargs curl -L -o /usr/local/lib/libamd_comgr.dylib
- name: Install remu
if: matrix.backend == 'amd'
run: sudo cp ${{ github.workspace }}/remu/target/release/libremu.dylib /usr/local/lib/
run: |
curl -s -H "Authorization: token $GH_TOKEN" curl -s https://api.github.com/repos/Qazalin/remu/releases/latest | \
jq -r '.assets[] | select(.name == "libremu.dylib").browser_download_url' | \
sudo xargs curl -L -o /usr/local/lib/libremu.dylib
- name: Install dependencies
run: pip install --user -e '.[testing]' --extra-index-url https://download.pytorch.org/whl/cpu
- name: Check Device.DEFAULT and print some source
+1 -1
View File
@@ -69,7 +69,7 @@ generate_comgr() {
--clang-args="-D__HIP_PLATFORM_AMD__ -I/opt/rocm/include -x c++" -o $BASE/comgr.py -l /opt/rocm/lib/libamd_comgr.so
fixup $BASE/comgr.py
sed -i "s\import ctypes\import ctypes, ctypes.util, os\g" $BASE/comgr.py
patch_dlopen $BASE/comgr.py amd_comgr "'/opt/rocm/lib/libamd_comgr.so'" "os.getenv('ROCM_PATH', '')+'/lib/libamd_comgr.so'" "'/usr/local/lib/libamd_comgr.dylib'"
patch_dlopen $BASE/comgr.py amd_comgr "'/opt/rocm/lib/libamd_comgr.so'" "os.getenv('ROCM_PATH', '')+'/lib/libamd_comgr.so'" "'/usr/local/lib/libamd_comgr.dylib'" "'/opt/homebrew/lib/libamd_comgr.dylib'"
sed -i "s\ctypes.CDLL('/opt/rocm/lib/libamd_comgr.so')\_try_dlopen_amd_comgr()\g" $BASE/comgr.py
python3 -c "import tinygrad.runtime.autogen.comgr"
}
+22
View File
@@ -0,0 +1,22 @@
#!/bin/bash
INSTALL_PATH="${1:-/opt/homebrew/lib}"
if [ ! -d "$INSTALL_PATH" ]; then
USER=$(whoami)
echo "No path $INSTALL_PATH. Will create. Might need your password..."
echo "You can stop now and provide any location as an argument where you want to save the libs (note, that not default locations should be in LD_LIBRARY_PATH, so tinygrad can find the libs)."
echo "Press any key or symbol to continue..."
read -n 1 -s
sudo mkdir -p "$INSTALL_PATH"
sudo chown -R "$USER":staff "$INSTALL_PATH"
fi
# Download libremu.dylib
curl -s https://api.github.com/repos/Qazalin/remu/releases/latest | \
jq -r '.assets[] | select(.name == "libremu.dylib").browser_download_url' | \
xargs curl -L -o $INSTALL_PATH/libremu.dylib
# Download libamd_comgr.dylib
curl -s https://api.github.com/repos/nimlgen/amdcomgr_dylib/releases/latest | \
jq -r '.assets[] | select(.name == "libamd_comgr.dylib").browser_download_url' | \
xargs curl -L -o $INSTALL_PATH/libamd_comgr.dylib
+1 -1
View File
@@ -19,7 +19,7 @@ WAIT_REG_MEM_FUNCTION_ALWAYS = 0
WAIT_REG_MEM_FUNCTION_EQ = 3 # ==
WAIT_REG_MEM_FUNCTION_GEQ = 5 # >=
REMU_PATHS = ["libremu.so", "/usr/local/lib/libremu.so", "libremu.dylib", "/usr/local/lib/libremu.dylib"]
REMU_PATHS = ["libremu.so", "/usr/local/lib/libremu.so", "libremu.dylib", "/usr/local/lib/libremu.dylib", "/opt/homebrew/lib/libremu.dylib"]
def _try_dlopen_remu():
for path in REMU_PATHS:
try:
+1
View File
@@ -11,6 +11,7 @@ PATHS_TO_TRY = [
'/opt/rocm/lib/libamd_comgr.so',
os.getenv('ROCM_PATH', '')+'/lib/libamd_comgr.so',
'/usr/local/lib/libamd_comgr.dylib',
'/opt/homebrew/lib/libamd_comgr.dylib',
]
def _try_dlopen_amd_comgr():
library = ctypes.util.find_library("amd_comgr")