Skip to content

Commit

Permalink
Makefile to detect device and auto set most common build flags
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonix committed Jul 10, 2024
1 parent e47843d commit 72ce690
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 19 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ AMDGPU_TARGETS ?= $(shell $(ROCM_PATH)/llvm/bin/amdgpu-offload-arch)
HIPCC := $(shell which hipcc 2>/dev/null)
HIPIFY := $(shell which hipify-perl 2>/dev/null)
HIPCC_FLAGS = -O3 -march=native -I$(BUILD_DIR)/hip -fno-strict-aliasing
HIPCC_LDFLAGS += -lamdhip64
ifneq ($(filter gfx1100,$(AMDGPU_TARGETS)),)
CUMODE ?= 1
USE_HIPBLAS ?= 1
USE_CK ?= 1
AMDGPU_TARGETS := gfx1100
else ifneq ($(filter gfx90a,$(AMDGPU_TARGETS)),)
WAVEFRONTSIZE64 ?= 1
BUILD_XDL ?= 1
AMDGPU_TARGETS := gfx90a
else
$(error Did not find a supported AMD device. Rebuild with AMDGPU_TARGETS env variable to force build for device)
endif
ifeq ($(shell test `$(ROCM_PATH)/llvm/bin/amdgpu-arch | grep $(AMDGPU_TARGETS) | wc -l` -lt 2; echo $$?),0)
NO_MULTI_GPU ?= 1
endif
HIPCC_FLAGS += $(addprefix --offload-arch=,$(AMDGPU_TARGETS))
ifneq ($(NO_MULTI_GPU), 1)
ifdef RCCL_PATH
Expand All @@ -84,6 +100,8 @@ ifdef USE_HIPBLAS
endif
HIPCC_FLAGS += -DUSE_HIPBLAS
HIPCC_LDFLAGS += -lhipblas
else
HIPCC_LDFLAGS += -lhipblaslt
endif
ifdef HIPBLASLT_PATH
HIPCC_FLAGS += -I$(HIPBLASLT_PATH)/include
Expand Down Expand Up @@ -303,7 +321,7 @@ endif
ifeq ($(HIPCC),)
$(info ✗ hipcc not found, skipping GPU/AMD builds)
else
$(info ✓ hipcc found, including GPU/AMD builds)
$(info ✓ hipcc found, building for $(AMDGPU_TARGETS))
TARGETS += train_gpt2amd test_gpt2amd train_gpt2_fp32amd test_gpt2_fp32amd profile_gpt2amd
HIPCC_FLAGS += -DBUILD_AMD
endif
Expand All @@ -314,7 +332,6 @@ else
HIPCC_FLAGS += -DXDNN -I$(XDNN_PATH)
HIPCC_LDFLAGS += -L$(XDNN_PATH) -lxdnn
endif
HIPCC_LDFLAGS += -lhipblaslt -lamdhip64

$(info ---------------------------------------------)

Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ make train_gpt2amd
./train_gpt2amd
```

The Makefile will build for all AMD targets detected in your machine, but if you wish to only only build for a particular target (e.g., if you have a iGPU that you want to ignore), pass the target arch with AMDGPU_TARGETS like so:

```
make train_gpt2amd AMDGPU_TARGETS=gfx1100
```
The Makefile will build for gfx1100 or gfx90a (whichever is found first), but if you are attempting to cross compile or have mixed devices in your machine, please see the Makefile for various environment variables that determine the build target.

## Performance tuning

Expand Down

0 comments on commit 72ce690

Please sign in to comment.