xref: /llvm-project/clang/test/Driver/rocm-detect.hip (revision 12949c952c4fbad776a860c003ccf176973278a0)
1// UNSUPPORTED: system-windows
2
3// Make sure the appropriate device specific library is available.
4
5// We don't include every target in the test directory, so just pick a valid
6// target not included in the test.
7
8// RUN: not %clang -### -v --target=x86_64-linux-gnu --cuda-gpu-arch=gfx902 \
9// RUN:   --rocm-path=%S/Inputs/rocm %s 2>&1 \
10// RUN:   | FileCheck -check-prefixes=COMMON,GFX902-DEFAULTLIBS %s
11
12// Should not interpret -nostdlib as disabling offload libraries.
13// RUN: not %clang -### -v --target=x86_64-linux-gnu --cuda-gpu-arch=gfx902 -nostdlib \
14// RUN:   --rocm-path=%S/Inputs/rocm %s 2>&1 \
15// RUN:   | FileCheck -check-prefixes=COMMON,GFX902-DEFAULTLIBS %s
16
17// RUN: %clang -### -v -target x86_64-linux-gnu --cuda-gpu-arch=gfx902 -nogpulib \
18// RUN:   --rocm-path=%S/Inputs/rocm %s 2>&1 \
19// RUN:   | FileCheck -check-prefixes=COMMON,NODEFAULTLIBS %s
20
21// Test environment variable ROCM_PATH.
22// RUN: env ROCM_PATH=%S/Inputs/rocm %clang -### --target=x86_64-linux-gnu \
23// RUN:   --print-rocm-search-dirs --offload-arch=gfx1010 %s 2>&1 \
24// RUN:   | FileCheck -check-prefixes=ROCM-ENV %s
25
26// Test interaction between environment variables HIP_PATH and ROCM_PATH.
27// Device libs are found under ROCM_PATH. HIP include files and HIP runtime library
28// are found under HIP_PATH.
29
30// RUN: rm -rf %t/myhip
31// RUN: mkdir -p %t/myhip
32// RUN: cp -r %S/Inputs/rocm/bin %t/myhip
33
34// Test HIP_PATH overrides ROCM_PATH.
35// RUN: env ROCM_PATH=%S/Inputs/rocm HIP_PATH=%t/myhip \
36// RUN:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
37// RUN:   --print-rocm-search-dirs %s 2>&1 \
38// RUN:   | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s
39
40// Test --hip-path overrides ROCM_PATH.
41// RUN: env ROCM_PATH=%S/Inputs/rocm \
42// RUN:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
43// RUN:   --hip-path=%t/myhip \
44// RUN:   --print-rocm-search-dirs %s 2>&1 \
45// RUN:   | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s
46
47// Test --hip-path overrides --rocm-path.
48// RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
49// RUN:   --hip-path=%t/myhip --rocm-path=%S/Inputs/rocm \
50// RUN:   --print-rocm-search-dirs %s 2>&1 \
51// RUN:   | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s
52
53// Test HIP_PATH overrides --rocm-path.
54// RUN: env HIP_PATH=%t/myhip %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
55// RUN:   --rocm-path=%S/Inputs/rocm \
56// RUN:   --print-rocm-search-dirs %s 2>&1 \
57// RUN:   | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s
58
59// Test empty HIP_PATH does not override --rocm-path.
60// RUN: env HIP_PATH= \
61// RUN:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
62// RUN:   --rocm-path=%S/Inputs/rocm --print-rocm-search-dirs %s 2>&1 \
63// RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
64
65// Test --hip-path option overrides environment variable HIP_PATH.
66
67// RUN: rm -rf %t/myhip
68// RUN: rm -rf %t/myhip_nouse
69// RUN: mkdir -p %t/myhip
70// RUN: mkdir -p %t/myhip_nouse
71// RUN: cp -r %S/Inputs/rocm/bin %t/myhip
72// RUN: cp -r %S/Inputs/rocm/bin %t/myhip_nouse
73// RUN: env ROCM_PATH=%S/Inputs/rocm HIP_PATH=%t/myhip_nouse \
74// RUN:   %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 --hip-link \
75// RUN:   --hip-path=%t/myhip --print-rocm-search-dirs %s 2>&1 \
76// RUN:   | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s
77
78// Test detecting /usr directory.
79// RUN: rm -rf %t/*
80// RUN: cp -r %S/Inputs/rocm %t/usr
81// RUN: mkdir -p %t/usr/share/hip
82// RUN: mv %t/usr/bin/.hipVersion %t/usr/share/hip/version
83// RUN: mkdir -p %t/usr/local
84// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=gfx1010 --sysroot=%t \
85// RUN:   --print-rocm-search-dirs --hip-link %s 2>&1 \
86// RUN:   | FileCheck -check-prefixes=USR %s
87
88// Test detecting latest /opt/rocm-{release} directory.
89// RUN: rm -rf %t/*
90// RUN: mkdir -p %t/opt
91// RUN: cp -r %S/Inputs/rocm %t/opt/rocm-3.9.0-1234
92// RUN: cp -r %S/Inputs/rocm %t/opt/rocm-3.10.0
93// RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=gfx1010 --sysroot=%t \
94// RUN:   --print-rocm-search-dirs %s 2>&1 \
95// RUN:   | FileCheck -check-prefixes=ROCM-REL %s
96
97// Test ROCm installation built by SPACK by invoke clang at %t/rocm-spack/llvm-amdgpu-*
98// directory through a soft link.
99
100// RUN: rm -rf %t/rocm-spack
101// RUN: cp -r %S/Inputs/rocm-spack %t
102// RUN: ln -fs %clang %t/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang
103// RUN: %t/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### -no-canonical-prefixes -v \
104// RUN:   -resource-dir=%t/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/lib/clang \
105// RUN:   -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 --print-rocm-search-dirs %s 2>&1 \
106// RUN:   | FileCheck -check-prefixes=SPACK %s
107
108// Test SPACK installation with multiple hip and rocm-device-libs packages of the same
109// ROCm release. --hip-path and --rocm-device-lib-path can be used to specify them.
110
111// RUN: cp -r %t/rocm-spack/hip-* %t/rocm-spack/hip-4.0.0-abcd
112// RUN: %t/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### -no-canonical-prefixes -v \
113// RUN:   -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 \
114// RUN:   --hip-path=%t/rocm-spack/hip-4.0.0-abcd \
115// RUN:    %s 2>&1 | FileCheck -check-prefixes=SPACK-SET %s
116
117// Test invalid SPACK ROCm installation missing hip and rocm-device-libs packages.
118
119// RUN: rm -rf %t/rocm-spack/hip-*
120// RUN: rm -rf %t/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn
121// RUN: %t/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang --version 2>&1 \
122// RUN:   | FileCheck -check-prefixes=SPACK-MISS-SILENT %s
123
124// GFX902-DEFAULTLIBS: error: cannot find ROCm device library for gfx902; provide its path via '--rocm-path' or '--rocm-device-lib-path', or pass '-nogpulib' to build without ROCm device library
125
126// NODEFAULTLIBS-NOT: error: cannot find
127
128// COMMON: "-triple" "amdgcn-amd-amdhsa"
129
130// ROCM-ENV: ROCm installation search path: [[ROCM_PATH:.*/Inputs/rocm]]
131
132// HIP-PATH: "-mlink-builtin-bitcode" "[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
133// HIP-PATH: "-idirafter" "[[HIP_PATH:.*/myhip]]/include"
134// HIP-PATH: "-L[[HIP_PATH]]/lib" {{.*}}"-lamdhip64"
135
136// ROCM-PATH: ROCm installation search path: [[ROCM_PATH:.*/Inputs/rocm]]
137// ROCM-PATH: "-mlink-builtin-bitcode" "[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
138// ROCM-PATH: "-idirafter" "[[ROCM_PATH]]/include"
139// ROCM-PATH: "-L[[ROCM_PATH]]/lib" {{.*}}"-lamdhip64"
140
141// USR: ROCm installation search path: [[ROCM_PATH:.*/usr$]]
142// USR: "-mlink-builtin-bitcode" "[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
143// USR: "-idirafter" "[[ROCM_PATH]]/include"
144// USR: "-L[[ROCM_PATH]]/lib" {{.*}}"-lamdhip64"
145
146// ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm
147// ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm-3.10.0
148
149// SPACK: InstalledDir: [[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
150// SPACK: ROCm installation search path (Spack 4.0.0): [[DIR]]
151// SPACK: ROCm installation search path: [[CLANG:.*]]
152// SPACK: ROCm installation search path: [[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z
153// SPACK: ROCm installation search path: [[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/lib/clang
154// SPACK: ROCm installation search path: /opt/rocm
155// SPACK: Found HIP installation: [[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
156// SPACK: "-triple" "amdgcn-amd-amdhsa"
157// SPACK-SAME: "-mlink-builtin-bitcode" "[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/hip.bc"
158// SPACK-SAME: "-idirafter" "[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
159
160// SPACK-SET: InstalledDir: [[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
161// SPACK-SET: Found HIP installation: [[DIR]]/hip-4.0.0-abcd, version 4.0.20214-a2917cd
162// SPACK-SET: "-triple" "amdgcn-amd-amdhsa"
163// SPACK-SET-SAME: "-mlink-builtin-bitcode" "[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/hip.bc"
164// SPACK-SET-SAME: "-idirafter" "[[DIR]]/hip-4.0.0-abcd/include"
165
166// SPACK-MISS-SILENT-NOT: SPACK package hip-{{.*}} not found at
167// SPACK-MISS-SILENT-NOT: Found HIP installation
168