#!/bin/bash ARCH=$(uname -m) if [ "$ARCH" = "x86_64" ]; then ARCH=x64 fi if [ ! -f "bin/micromamba" ]; then if [ "$ARCH" = "x64" ]; then curl -Ls https://anaconda.org/conda-forge/micromamba/1.5.3/download/linux-64/micromamba-1.5.3-0.tar.bz2 | tar -xvj bin/micromamba elif [ "$ARCH" = "aarch64" ]; then curl -Ls https://anaconda.org/conda-forge/micromamba/1.5.3/download/linux-aarch64/micromamba-1.5.3-0.tar.bz2 | tar -xvj bin/micromamba else echo "CPU Architecture $ARCH is not supported by this script, please try compiling manually." exit 1 fi fi NVIDIA_GPU=0 if command -v nvidia-smi >/dev/null 2>&1 && nvidia-smi -L 2>/dev/null | grep -qE '^GPU [0-9]+:'; then NVIDIA_GPU=1 fi if [[ ! -f "conda/envs/linux/bin/python" || $1 == "rebuild" ]] && [ -z "$KCPP_CUDA" ]; then if [ "$NVIDIA_GPU" = 1 ]; then if nvidia-smi | grep -qE 'CUDA Version: (11|12\.0)'; then KCPP_CUDA=11.4.0 ARCHES_CU11=true else KCPP_CUDA=12.1.0 fi elif command -v rocmsmi >/dev/null 2>&1 || [ -d /opt/rocm ]; then KCPP_CUDA=rocm else KCPP_CUDA=12.1.0 fi fi if [[ ! -f "conda/envs/linux/bin/python" && $KCPP_CUDA != "rocm" || $1 == "rebuild" && $KCPP_CUDA != "rocm" ]]; then cp environment.yaml environment.tmp.yaml sed -i -e "s/nvidia\/label\/cuda-12.1.0/nvidia\/label\/cuda-$KCPP_CUDA/g" environment.tmp.yaml bin/micromamba create --no-rc --no-shortcuts -r conda -p conda/envs/linux -f environment.tmp.yaml -y bin/micromamba run -r conda -p conda/envs/linux make clean echo $KCPP_CUDA > conda/envs/linux/cudaver rm environment.tmp.yaml fi if [[ ! -f "conda/envs/linux/bin/python" && $KCPP_CUDA == "rocm" || $1 == "rebuild" && $KCPP_CUDA == "rocm" ]]; then bin/micromamba create --no-rc --no-shortcuts -r conda -p conda/envs/linux -f environment-nocuda.yaml -y bin/micromamba run -r conda -p conda/envs/linux make clean echo "rocm" > conda/envs/linux/cudaver fi KCPP_CUDA=$(