From f49686029ac656c4fa7f77c49963df1e0088d43f Mon Sep 17 00:00:00 2001 From: mrq Date: Fri, 3 Mar 2023 02:53:16 +0000 Subject: [PATCH 1/2] slight tweaks to make it easy to work for Arch Linux users btw --- Makefile | 13 +++++++------ README.md | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) mode change 100644 => 100755 Makefile mode change 100644 => 100755 README.md diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index f7a4d65..a568995 --- 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/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: $(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=gfx1030 $(HIP_INCLUDE) -o $(BUILD_DIR)/ops.o -D NO_CUBLASLT $(CSRC)/ops.cu + $(HIPCC) -std=c++14 -c -fPIC --amdgpu-target=gfx1030 $(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..f535ba4 --- a/README.md +++ b/README.md @@ -1,3 +1,29 @@ +# bitsandbytes-rocm + +Credits to [broncotc/bitsandbytes-rocm](https://github.com/broncotc/bitsandbytes-rocm) for the original fork, and [0cc4m/bitsandbytes-rocm](https://github.com/0cc4m/bitsandbytes-rocm) for updating it. I'm only hosting a local copy as this has some slight tweaks in the Makefile, and instructions + +## Pre-Requisite + +This assumes you're an Arch Linux user like me (or derivation). If you're using a different distro, you can easily adapt it. + +In `Makefile`: +* edit line 3 to point to your ROCm install folder (default: `/opt/rocm/`), if your distro installs it in an exotic place +* that should be it! + +## Compiling + +``` +# activate your VENV, if using this within a VENV +git clone https://git.ecker.tech/mrq/bitsandbytes-rocm +make hip +CUDA_VERSION=gfx1030 python setup.py install # assumes you're using a 6XXX series card +python3 -m bitsandbytes # to validate it works +``` + +**!**NOTE**!**: this assumes you have a AMD 6XXX series card. Adapt this to your proper GFX version if different. + +--- + # bitsandbytes The bitsandbytes is a lightweight wrapper around CUDA custom functions, in particular 8-bit optimizers, matrix multiplication (LLM.int8()), and quantization functions. From 82857414cf2fc359d61e94f45fcf359507a33793 Mon Sep 17 00:00:00 2001 From: DeftDawg Date: Mon, 8 May 2023 19:50:53 -0400 Subject: [PATCH 2/2] - Update README with history - Use `rocminfo` to auto detect GPU target in Makefile - Update Makefile to detect and use clang compiler that comes with installed ROCm tools --- Makefile | 6 +++--- README.md | 29 ++++++++++++++++++----------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index a568995..a96eee6 100755 --- a/Makefile +++ b/Makefile @@ -114,11 +114,11 @@ 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$(ROCM_DIR)/lib -L$(ROCM_DIR)/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) - $(HIPCC) -std=c++14 -c -fPIC --amdgpu-target=gfx1030 $(HIP_INCLUDE) -o $(BUILD_DIR)/ops.o -D NO_CUBLASLT $(CSRC)/ops.cu - $(HIPCC) -std=c++14 -c -fPIC --amdgpu-target=gfx1030 $(HIP_INCLUDE) -o $(BUILD_DIR)/kernels.o -D NO_CUBLASLT $(CSRC)/kernels.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)/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 diff --git a/README.md b/README.md index f535ba4..1148751 100755 --- a/README.md +++ b/README.md @@ -1,27 +1,34 @@ # bitsandbytes-rocm -Credits to [broncotc/bitsandbytes-rocm](https://github.com/broncotc/bitsandbytes-rocm) for the original fork, and [0cc4m/bitsandbytes-rocm](https://github.com/0cc4m/bitsandbytes-rocm) for updating it. I'm only hosting a local copy as this has some slight tweaks in the Makefile, and instructions +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-Requisite +## Pre-Requisites -This assumes you're an Arch Linux user like me (or derivation). If you're using a different distro, you can easily adapt it. +* An AMD GPU capable of supporting ROCm and an appropriate `amdgpu` driver -In `Makefile`: -* edit line 3 to point to your ROCm install folder (default: `/opt/rocm/`), if your distro installs it in an exotic place -* that should be it! +* 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://git.ecker.tech/mrq/bitsandbytes-rocm +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 -CUDA_VERSION=gfx1030 python setup.py install # assumes you're using a 6XXX series card +python setup.py install python3 -m bitsandbytes # to validate it works ``` -**!**NOTE**!**: this assumes you have a AMD 6XXX series card. Adapt this to your proper GFX version if different. - --- # bitsandbytes