Makefile 4.59 KB
Newer Older
1
#
2
# Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
3
#
Gilbert Lee's avatar
Gilbert Lee committed
4

5
6
7
# Configuration options
ROCM_PATH ?= /opt/rocm
CUDA_PATH ?= /usr/local/cuda
8
MPI_PATH  ?= /usr/local/openmpi
9

gilbertlee-amd's avatar
gilbertlee-amd committed
10
11
12
HIPCC ?= $(ROCM_PATH)/bin/amdclang++
NVCC ?= $(CUDA_PATH)/bin/nvcc

13
14
15
16
17
18
19
20
21
# ROCm device libraries can live in different locations depending on packaging.
# hipcc/clang needs to find the amdgcn bitcode directory at link time.
ROCM_DEVICE_LIB_PATH ?=
ifneq ($(wildcard $(ROCM_PATH)/amdgcn/bitcode),)
  ROCM_DEVICE_LIB_PATH := $(ROCM_PATH)/amdgcn/bitcode
else ifneq ($(wildcard $(ROCM_PATH)/lib/llvm/amdgcn/bitcode),)
  ROCM_DEVICE_LIB_PATH := $(ROCM_PATH)/lib/llvm/amdgcn/bitcode
endif

22
23
24
# Option to compile with single GFX kernel to drop compilation time
SINGLE_KERNEL ?= 0

gilbertlee-amd's avatar
gilbertlee-amd committed
25
26
27
28
# This can be a space separated string of multiple GPU targets
# Default is the native GPU target
GPU_TARGETS ?= native

29
EXE=TransferBench
gilbertlee-amd's avatar
gilbertlee-amd committed
30
31
DEBUG ?= 0

32
# Only perform this check if 'make clean' is not the target
gilbertlee-amd's avatar
gilbertlee-amd committed
33
ifeq ($(filter clean,$(MAKECMDGOALS)),)
34
35
36
37
38
39
40
41
  ifeq ($(MAKECMDGOALS),TransferBenchCuda)
    # Check for nvcc
    ifneq ($(shell test -e $(NVCC) && echo found), found)
      $(error "Could not find $(NVCC).  Please set CUDA_PATH appropriately")
    else
      $(info Compiling TransferBenchCuda using $(NVCC))
    endif
    NVFLAGS = -x cu -lnuma -arch=native
gilbertlee-amd's avatar
gilbertlee-amd committed
42
  else
43
    # Check for HIP compiler
gilbertlee-amd's avatar
gilbertlee-amd committed
44
45
46
47
48
49
50
51
52
    ifeq ("$(shell test -e $(HIPCC) && echo found)", "found")
      CXX=$(HIPCC)
    else ifeq ("$(shell test -e $(ROCM_PATH)/bin/hipcc && echo found)", "found")
      CXX=$(ROCM_PATH)/bin/hipcc
      $(warning "Could not find $(HIPCC). Using fallback to $(CXX)")
    else
      $(error "Could not find $(HIPCC) or $(ROCM_PATH)/bin/hipcc. Check if the path is correct if you want to build $(EXE)")
    endif
    GPU_TARGETS_FLAGS = $(foreach target,$(GPU_TARGETS),"--offload-arch=$(target)")
53

54
55
56
57
58
59
    CXXFLAGS = -I$(ROCM_PATH)/include -I$(ROCM_PATH)/include/hip -I$(ROCM_PATH)/include/hsa
    HIPLDFLAGS= -lnuma -L$(ROCM_PATH)/lib -lhsa-runtime64 -lamdhip64
    HIPFLAGS = -Wall -x hip -D__HIP_PLATFORM_AMD__ -D__HIPCC__ $(GPU_TARGETS_FLAGS)
    ifneq ($(strip $(ROCM_DEVICE_LIB_PATH)),)
      HIPFLAGS += --rocm-device-lib-path=$(ROCM_DEVICE_LIB_PATH)
    endif
60
  endif
gilbertlee-amd's avatar
gilbertlee-amd committed
61

62
  ifeq ($(SINGLE_KERNEL), 1)
63
    COMMON_FLAGS += -DSINGLE_KERNEL
64
65
  endif

gilbertlee-amd's avatar
gilbertlee-amd committed
66
67
  ifeq ($(DEBUG), 0)
    COMMON_FLAGS += -O3
gilbertlee-amd's avatar
gilbertlee-amd committed
68
  else
gilbertlee-amd's avatar
gilbertlee-amd committed
69
    COMMON_FLAGS += -O0 -g -ggdb3
gilbertlee-amd's avatar
gilbertlee-amd committed
70
  endif
gilbertlee-amd's avatar
gilbertlee-amd committed
71
72
73
74
  COMMON_FLAGS += -I./src/header -I./src/client -I./src/client/Presets

  LDFLAGS += -lpthread

75
  NIC_ENABLED = 0
gilbertlee-amd's avatar
gilbertlee-amd committed
76
77
78
79
80
81
82
83
84
85
86
  # Compile RDMA executor if
  # 1) DISABLE_NIC_EXEC is not set to 1
  # 2) IBVerbs is found in the Dynamic Linker cache
  # 3) infiniband/verbs.h is found in the default include path
  DISABLE_NIC_EXEC ?= 0
  ifneq ($(DISABLE_NIC_EXEC),1)
    ifeq ("$(shell ldconfig -p | grep -c ibverbs)", "0")
      $(info lib IBVerbs not found)
    else ifeq ("$(shell echo '#include <infiniband/verbs.h>' | $(CXX) -E - 2>/dev/null | grep -c 'infiniband/verbs.h')", "0")
      $(info infiniband/verbs.h not found)
    else
87
      COMMON_FLAGS += -DNIC_EXEC_ENABLED
gilbertlee-amd's avatar
gilbertlee-amd committed
88
89
90
91
92
93
94
95
96
      LDFLAGS += -libverbs
      NIC_ENABLED = 1
    endif
    ifeq ($(NIC_ENABLED), 0)
      $(info Building without NIC executor support)
      $(info To use the TransferBench RDMA executor, check if your system has NICs, the NIC drivers are installed, and libibverbs-dev is installed)
    else
      $(info Building with NIC executor support. Can set DISABLE_NIC_EXEC=1 to disable)
    endif
gilbertlee-amd's avatar
gilbertlee-amd committed
97
  endif
98
99
100
101
102
103
104
105
106
107
108

  MPI_ENABLED = 0
  # Compile with MPI communicator support if
  # 1) DISABLE_MPI_COMM is not set to 1
  # 2) mpi.h is found in the MPI_PATH
  DISABLE_MPI_COMM ?= 0
  ifneq ($(DISABLE_MPI_COMM), 1)
    ifeq ($(wildcard $(MPI_PATH)/include/mpi.h),)
      $(info Unable to find mpi.h at $(MPI_PATH)/include.  Please specify appropriate MPI_PATH)
    else
      MPI_ENABLED = 1
109
      COMMON_FLAGS += -DMPI_COMM_ENABLED -I$(MPI_PATH)/include
110
111
112
113
114
115
116
117
118
119
120
121
122
      LDFLAGS += -L/$(MPI_PATH)/lib -lmpi
      ifeq ($(DEBUG), 1)
        LDFLAGS += -lmpi_cxx
      endif
    endif

    ifeq ($(MPI_ENABLED), 0)
      $(info Building without MPI communicator support)
      $(info To use TransferBench with MPI support, install MPI libraries and specify appropriate MPI_PATH)
    else
      $(info Building with MPI communicator support.  Can set DISABLE_MPI_COMM=1 to disable)
   endif
  endif
gilbertlee-amd's avatar
gilbertlee-amd committed
123
124
endif

125

gilbertlee-amd's avatar
gilbertlee-amd committed
126
127
.PHONY : all clean

128
129
all: $(EXE)

gilbertlee-amd's avatar
gilbertlee-amd committed
130
TransferBench: ./src/client/Client.cpp $(shell find -regex ".*\.\hpp")
131
	$(CXX) $(CXXFLAGS) $(HIPFLAGS) $(COMMON_FLAGS) $< -o $@ $(HIPLDFLAGS) $(LDFLAGS)
132

gilbertlee-amd's avatar
gilbertlee-amd committed
133
TransferBenchCuda: ./src/client/Client.cpp $(shell find -regex ".*\.\hpp")
134
	$(NVCC) $(NVFLAGS) $(COMMON_FLAGS) $< -o $@ $(LDFLAGS)
Gilbert Lee's avatar
Gilbert Lee committed
135
136

clean:
gilbertlee-amd's avatar
gilbertlee-amd committed
137
	rm -f ./TransferBench ./TransferBenchCuda