diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index f7a4d65..a96eee6 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) ROOT_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH))) - -GPP:= /usr/bin/g++ +ROCM_DIR := /opt/rocm/ +HIPCC := $(ROCM_DIR)/bin/hipcc +GPP:= g++ ifeq ($(CUDA_HOME),) CUDA_HOME:= $(shell which nvcc | rev | cut -d'/' -f3- | rev) endif @@ -113,12 +114,12 @@ cpuonly: $(BUILD_DIR) env HIP_INCLUDE := -I $(ROOT_DIR)/csrc -I $(ROOT_DIR)/include # -I /opt/rocm-5.3.0/hipcub/include -HIP_LIB := -L/opt/rocm-5.3.0/lib -L/opt/rocm-5.3.0/llvm/bin/../lib/clang/15.0.0/lib/linux -L/usr/lib/gcc/x86_64-linux-gnu/11 -L/usr/lib/gcc/x86_64-linux-gnu/11/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/lib -L/usr/lib -lgcc_s -lgcc -lpthread -lm -lrt -lamdhip64 -lhipblas -lhipsparse -lclang_rt.builtins-x86_64 -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc +HIP_LIB := -L$(ROCM_DIR)/lib -L$(ROCM_DIR)/llvm/bin/../lib/clang/`ls $(ROCM_DIR)/llvm/bin/../lib/clang/ | sort -n | tail -1`/lib/linux -L/usr/lib/gcc/x86_64-linux-gnu/11 -L/usr/lib/gcc/x86_64-linux-gnu/11/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/lib -L/usr/lib -lgcc_s -lgcc -lpthread -lm -lrt -lamdhip64 -lhipblas -lhipsparse -lclang_rt.builtins-x86_64 -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc hip: $(BUILD_DIR) - /usr/bin/hipcc -std=c++14 -c -fPIC --amdgpu-target=gfx1030 $(HIP_INCLUDE) -o $(BUILD_DIR)/ops.o -D NO_CUBLASLT $(CSRC)/ops.cu - /usr/bin/hipcc -std=c++14 -c -fPIC --amdgpu-target=gfx1030 $(HIP_INCLUDE) -o $(BUILD_DIR)/kernels.o -D NO_CUBLASLT $(CSRC)/kernels.cu - # /usr/bin/hipcc -fPIC -static $(BUILD_DIR)/ops.o $(BUILD_DIR)/kernels.o -o $(BUILD_DIR)/link.so + $(HIPCC) -std=c++14 -c -fPIC --amdgpu-target=`rocminfo | grep -oE "gfx.*" | grep -v gfx000 | sort -u -t 'x' -k 2n | tail -1` $(HIP_INCLUDE) -o $(BUILD_DIR)/ops.o -D NO_CUBLASLT $(CSRC)/ops.cu + $(HIPCC) -std=c++14 -c -fPIC --amdgpu-target=`rocminfo | grep -oE "gfx.*" | grep -v gfx000 | sort -u -t 'x' -k 2n | tail -1` $(HIP_INCLUDE) -o $(BUILD_DIR)/kernels.o -D NO_CUBLASLT $(CSRC)/kernels.cu + # $(HIPCC) -fPIC -static $(BUILD_DIR)/ops.o $(BUILD_DIR)/kernels.o -o $(BUILD_DIR)/link.so $(GPP) -std=c++14 -D__HIP_PLATFORM_AMD__ -DBUILD_CUDA -shared -fPIC -I /opt/rocm/include $(HIP_INCLUDE) $(BUILD_DIR)/ops.o $(BUILD_DIR)/kernels.o $(FILES_CPP) $(HIP_LIB) -o ./bitsandbytes/libbitsandbytes_hip_nocublaslt.so env: diff --git a/README.md b/README.md old mode 100644 new mode 100755 index d420e6c..1148751 --- a/README.md +++ b/README.md @@ -1,3 +1,36 @@ +# bitsandbytes-rocm + +Credits/History: +- Original library [TimDettmers/bitsandbytes](https://github.com/TimDettmers/bitsandbytes) - CUDA-only +- [broncotc/bitsandbytes-rocm](https://github.com/broncotc/bitsandbytes-rocm) original fork to add ROCm support +- [0cc4m/bitsandbytes-rocm](https://github.com/0cc4m/bitsandbytes-rocm) update of broncotc's fork +- [mrq/bitsandbytes-rocm](https://git.ecker.tech/mrq/bitsandbytes-rocm) update of 0cc4m's fork to add Makefile and instructions +- [deftdawg/bitsandbytes-rocm](https://github.com/deftdawg/bitsandbytes-rocm) update mrq's fork with changes to README, tweaks to auto detect card using ROCm tools, change to make compiler ROCm version agnostic + +The library was tested inside the [Docker ROCm/PyTorch:latest](https://hub.docker.com/r/rocm/pytorch) container image - Ubuntu 20.04/ROCm 5.0.0/Python3.8: +```sh +docker run --net=host -it --device=/dev/kfd --device=/dev/dri rocm/pytorch:latest # NOTE: /dev/kfd and /dev/dri must be passed into Docker for ROCm to work +``` + +## Pre-Requisites + +* An AMD GPU capable of supporting ROCm and an appropriate `amdgpu` driver + +* Assumes your ROCm tools are installed in `/opt/rocm/` and `rocminfo` is in your path (often found in `/opt/rocm/bin/`), if not edit the `Makefile` to match your distro and/or update your `PATH` before running. + +## Compiling + +```sh +# activate your VENV, if using this within a VENV +git clone https://github.com/deftdawg/bitsandbytes-rocm +export CUDA_VERSION=$(rocminfo | grep -oE "gfx.*" | grep -v gfx000 | sort -u -t 'x' -k 2n | tail -1) # Use ROCm tools to auto detect card +make hip +python setup.py install +python3 -m bitsandbytes # to validate it works +``` + +--- + # bitsandbytes The bitsandbytes is a lightweight wrapper around CUDA custom functions, in particular 8-bit optimizers, matrix multiplication (LLM.int8()), and quantization functions.