-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathfind_gpu_and_install_dir.mk
More file actions
101 lines (91 loc) · 3.8 KB
/
find_gpu_and_install_dir.mk
File metadata and controls
101 lines (91 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#-----------------------------------------------------------------------
#
# find_gpu_and_install_dir.mk
# Include for examples to find LLVM installation and GPU arch.
# This include
# - sets LLVM_INSTALL_DIR, LLVM_GPU_TRIPLE, and LLVM_GPU_ARCH, and LLVM_COMPILER_NAME
# - sets CUDA and LFLAGS to find CUDA lib if NVIDIA gpu
# CUDA and LFLAGS to find CUDA lib if NVIDIA gpu
# - HIPDIR and HIPCC=$(HIPDIR)/bin/hipcc
# If LLVM_INSTALL_DIR not preset and AOMP is, then use AOMP and print deprecation warning
ifeq ("$(wildcard $(LLVM_INSTALL_DIR))","")
ifneq ("$(wildcard $(AOMP)/lib/llvm/bin/clang)","")
LLVM_INSTALL_DIR = $(AOMP)/lib/llvm
else ifneq ("$(wildcard $(AOMP)/bin/clang)","")
LLVM_INSTALL_DIR = $(AOMP)
else ifneq ("$(wildcard /opt/rocm/lib/llvm/bin/clang)","")
LLVM_INSTALL_DIR = /opt/rocm/lib/llvm
else
$(error ERROR: Could not determine LLVM_INSTALL_DIR)
endif
ifneq ("$(llvm_install_dir_warn)","warned")
$(info WARNING: Setting LLVM_INSTALL_DIR=$(LLVM_INSTALL_DIR))
endif
llvm_install_dir_warn := warned
export llvm_install_dir_warn
endif
# If LLVM_INSTALL_DIR not preset, seach rocm at /opt/rocm/lib/llvm, and then ~/rocm/aomp
ifeq ("$(wildcard $(LLVM_INSTALL_DIR))","")
ifneq ($(LLVM_INSTALL_DIR),)
$(warning Specified LLVM_INSTALL_DIR:$(LLVM_INSTALL_DIR) NOT FOUND)
endif
this_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# this_dir ... finds the compiler if example Make is run directly from the installation e.g.:
# make -f /opt/rocm/share/openmp-extras/examples/openmp/veccopy/Makefile run
LLVM_INSTALL_SEARCH_DIRS ?= /opt/rocm/lib/llvm $(this_dir)../../../llvm $(HOME)/rocm/aomp
# Select the first directory found from above list.
LLVM_INSTALL_DIR := $(word 1, $(strip $(foreach dir,$(LLVM_INSTALL_SEARCH_DIRS),$(wildcard $(dir)))))
ifeq ("$(wildcard $(LLVM_INSTALL_DIR))","")
$(error Please install ROCm, AOMP, or set LLVM_INSTALL_DIR to LLVM install dir)
endif
endif
# Determine clang host target
CLANG_HOST_TARGET=$(shell $(LLVM_INSTALL_DIR)/bin/clang --version | grep Target: | cut -d" " -f2)
# Determine COMPILER_NAME (AMD, AOMP, or clang)
LLVM_COMPILER_NAME := $(shell $(LLVM_INSTALL_DIR)/bin/clang --version | head -n1 | cut -d" " -f1 | cut -d"_" -f1 )
FLANG ?= flang
# Test for preset GPUs
ifeq ($(LLVM_GPU_ARCH),)
# If not preset, get offload arch from either nvidia-arch or amdgpu-arch
_amdgpu_mod_dir = $(shell ls -d /sys/module/amdgpu 2>/dev/null)
ifeq ("$(wildcard $(_amdgpu_mod_dir))","")
LLVM_GPU_ARCH = $(shell $(LLVM_INSTALL_DIR)/bin/nvptx-arch | head -n 1 )
else
LLVM_GPU_ARCH = $(shell $(LLVM_INSTALL_DIR)/bin/amdgpu-arch | head -n 1 )
endif
endif
ifeq ($(strip $(LLVM_GPU_ARCH)),)
$(error Could NOT detect a GPU to set LLVM_GPU_ARCH! To test compile only, set LLVM_GPU_ARCH=gfx90a)
endif
ifeq (sm_,$(findstring sm_,$(LLVM_GPU_ARCH)))
LLVM_GPU_TRIPLE = nvptx64-nvidia-cuda
else
LLVM_GPU_TRIPLE = amdgcn-amd-amdhsa
endif
_supports_xnack= gfx90a, gfx90a:xnack+,\
gfx90c, gfx90c:xnack+,\
gfx940, gfx940:xnack+,\
gfx941, gfx941:xnack+,\
gfx942, gfx942:xnack+,\
gfx950, gfx950:xnack+,\
gfx1010, gfx1010:xnack+\
gfx1011, gfx1011:xnack+\
gfx1012, gfx1012:xnack+\
gfx1013, gfx1013:xnack+
ifeq ($(findstring $(LLVM_GPU_ARCH), $(_supports_xnack)),)
LLVM_GPU_IS_XNACKABLE=0
else
LLVM_GPU_IS_XNACKABLE=1
endif
# Find where HIP is installed and set HIPDIR and HIPCC
HIPDIR ?= $(LLVM_INSTALL_DIR)
ifeq ("$(wildcard $(HIPDIR)/bin/hipcc)","")
HIPDIR := $(LLVM_INSTALL_DIR)/..
ifeq ("$(wildcard $(HIPDIR)/bin/hipcc)","")
HIPDIR := $(LLVM_INSTALL_DIR)/../..
ifeq ("$(wildcard $(HIPDIR)/bin/hipcc)","")
HIPDIR := /opt/rocm
endif
endif
endif
HIPCC := $(HIPDIR)/bin/hipcc