Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push updates upstream #2

Open
wants to merge 2 commits into
base: rocm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
33 changes: 33 additions & 0 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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.
Expand Down