1 // REQUIRES: x86-registered-target
2 // REQUIRES: amdgpu-registered-target
3 // UNSUPPORTED: system-windows
5 // Make sure the appropriate device specific library is available.
7 // We don't include every target in the test directory, so just pick a valid
8 // target not included in the test.
10 // RUN: not %clang -### -v --target=x86_64-linux-gnu --cuda-gpu-arch=gfx902 \
11 // RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \
12 // RUN: | FileCheck -check-prefixes=COMMON,GFX902-DEFAULTLIBS %s
14 // Should not interpret -nostdlib as disabling offload libraries.
15 // RUN: not %clang -### -v --target=x86_64-linux-gnu --cuda-gpu-arch=gfx902 -nostdlib \
16 // RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \
17 // RUN: | FileCheck -check-prefixes=COMMON,GFX902-DEFAULTLIBS %s
19 // RUN: %clang -### -v -target x86_64-linux-gnu --cuda-gpu-arch=gfx902 -nogpulib \
20 // RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \
21 // RUN: | FileCheck -check-prefixes=COMMON,NODEFAULTLIBS %s
23 // Test environment variable ROCM_PATH.
24 // RUN: env ROCM_PATH=%S/Inputs/rocm %clang -### --target=x86_64-linux-gnu \
25 // RUN: --print-rocm-search-dirs --offload-arch=gfx1010 %s 2>&1 \
26 // RUN: | FileCheck -check-prefixes=ROCM-ENV %s
28 // Test interaction between environment variables HIP_PATH and ROCM_PATH.
29 // Device libs are found under ROCM_PATH. HIP include files and HIP runtime library
30 // are found under HIP_PATH.
32 // RUN: rm -rf %t/myhip
33 // RUN: mkdir -p %t/myhip
34 // RUN: cp -r %S/Inputs/rocm/bin %t/myhip
36 // Test HIP_PATH overrides ROCM_PATH.
37 // RUN: env ROCM_PATH=%S/Inputs/rocm HIP_PATH=%t/myhip \
38 // RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
39 // RUN: --print-rocm-search-dirs %s 2>&1 \
40 // RUN: | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s
42 // Test --hip-path overrides ROCM_PATH.
43 // RUN: env ROCM_PATH=%S/Inputs/rocm \
44 // RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
45 // RUN: --hip-path=%t/myhip \
46 // RUN: --print-rocm-search-dirs %s 2>&1 \
47 // RUN: | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s
49 // Test --hip-path overrides --rocm-path.
50 // RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
51 // RUN: --hip-path=%t/myhip --rocm-path=%S/Inputs/rocm \
52 // RUN: --print-rocm-search-dirs %s 2>&1 \
53 // RUN: | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s
55 // Test HIP_PATH overrides --rocm-path.
56 // RUN: env HIP_PATH=%t/myhip %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
57 // RUN: --rocm-path=%S/Inputs/rocm \
58 // RUN: --print-rocm-search-dirs %s 2>&1 \
59 // RUN: | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s
61 // Test empty HIP_PATH does not override --rocm-path.
62 // RUN: env HIP_PATH= \
63 // RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 \
64 // RUN: --rocm-path=%S/Inputs/rocm --print-rocm-search-dirs %s 2>&1 \
65 // RUN: | FileCheck -check-prefixes=ROCM-PATH %s
67 // Test --hip-path option overrides environment variable HIP_PATH.
69 // RUN: rm -rf %t/myhip
70 // RUN: rm -rf %t/myhip_nouse
71 // RUN: mkdir -p %t/myhip
72 // RUN: mkdir -p %t/myhip_nouse
73 // RUN: cp -r %S/Inputs/rocm/bin %t/myhip
74 // RUN: cp -r %S/Inputs/rocm/bin %t/myhip_nouse
75 // RUN: env ROCM_PATH=%S/Inputs/rocm HIP_PATH=%t/myhip_nouse \
76 // RUN: %clang -### -target x86_64-linux-gnu --offload-arch=gfx1010 --hip-link \
77 // RUN: --hip-path=%t/myhip --print-rocm-search-dirs %s 2>&1 \
78 // RUN: | FileCheck -check-prefixes=ROCM-ENV,HIP-PATH %s
80 // Test detecting latest /opt/rocm-{release} directory.
82 // RUN: mkdir -p %T/opt
83 // RUN: cp -r %S/Inputs/rocm %T/opt/rocm-3.9.0-1234
84 // RUN: cp -r %S/Inputs/rocm %T/opt/rocm-3.10.0
85 // RUN: %clang -### --target=x86_64-linux-gnu --offload-arch=gfx1010 --sysroot=%T \
86 // RUN: --print-rocm-search-dirs %s 2>&1 \
87 // RUN: | FileCheck -check-prefixes=ROCM-REL %s
89 // Test ROCm installation built by SPACK by invoke clang at %T/rocm-spack/llvm-amdgpu-*
90 // directory through a soft link.
92 // RUN: rm -rf %T/rocm-spack
93 // RUN: cp -r %S/Inputs/rocm-spack %T
94 // RUN: ln -fs %clang %T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang
95 // RUN: %T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### -v \
96 // RUN: -resource-dir=%T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/lib/clang \
97 // RUN: -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 --print-rocm-search-dirs %s 2>&1 \
98 // RUN: | FileCheck -check-prefixes=SPACK %s
100 // Test SPACK installation with multiple hip and rocm-device-libs packages of the same
101 // ROCm release. --hip-path and --rocm-device-lib-path can be used to specify them.
103 // RUN: cp -r %T/rocm-spack/hip-* %T/rocm-spack/hip-4.0.0-abcd
104 // RUN: %T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### -v \
105 // RUN: -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 \
106 // RUN: --hip-path=%T/rocm-spack/hip-4.0.0-abcd \
107 // RUN: %s 2>&1 | FileCheck -check-prefixes=SPACK-SET %s
109 // Test invalid SPACK ROCm installation missing hip and rocm-device-libs packages.
111 // RUN: rm -rf %T/rocm-spack/hip-*
112 // RUN: rm -rf %T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn
113 // RUN: %T/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang --version 2>&1 \
114 // RUN: | FileCheck -check-prefixes=SPACK-MISS-SILENT %s
116 // 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
118 // NODEFAULTLIBS-NOT: error: cannot find
120 // COMMON: "-triple" "amdgcn-amd-amdhsa"
122 // ROCM-ENV: ROCm installation search path: [[ROCM_PATH:.*/Inputs/rocm]]
124 // HIP-PATH: "-mlink-builtin-bitcode" "[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
125 // HIP-PATH: "-idirafter" "[[HIP_PATH:.*/myhip]]/include"
126 // HIP-PATH: "-L[[HIP_PATH]]/lib" {{.*}}"-lamdhip64"
128 // ROCM-PATH: ROCm installation search path: [[ROCM_PATH:.*/Inputs/rocm]]
129 // ROCM-PATH: "-mlink-builtin-bitcode" "[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
130 // ROCM-PATH: "-idirafter" "[[ROCM_PATH]]/include"
131 // ROCM-PATH: "-L[[ROCM_PATH]]/lib" {{.*}}"-lamdhip64"
133 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm
134 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm-3.10.0
136 // SPACK: InstalledDir: [[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
137 // SPACK: ROCm installation search path (Spack 4.0.0): [[DIR]]
138 // SPACK: ROCm installation search path: [[CLANG:.*]]
139 // SPACK: ROCm installation search path: [[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z
140 // SPACK: ROCm installation search path: [[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/lib/clang
141 // SPACK: ROCm installation search path: /opt/rocm
142 // SPACK: Found HIP installation: [[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
143 // SPACK: "-triple" "amdgcn-amd-amdhsa"
144 // SPACK-SAME: "-mlink-builtin-bitcode" "[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/hip.bc"
145 // SPACK-SAME: "-idirafter" "[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"
147 // SPACK-SET: InstalledDir: [[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
148 // SPACK-SET: Found HIP installation: [[DIR]]/hip-4.0.0-abcd, version 4.0.20214-a2917cd
149 // SPACK-SET: "-triple" "amdgcn-amd-amdhsa"
150 // SPACK-SET-SAME: "-mlink-builtin-bitcode" "[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/hip.bc"
151 // SPACK-SET-SAME: "-idirafter" "[[DIR]]/hip-4.0.0-abcd/include"
153 // SPACK-MISS-SILENT-NOT: SPACK package hip-{{.*}} not found at
154 // SPACK-MISS-SILENT-NOT: Found HIP installation