Skip to content

Commit 5b487aa

Browse files
[Flang-new][OpenMP] Add offload related flags for AMDGPU
Flang-new needs to add mlink-builtin-bitcode objects to properly support offload code generation for AMD GPU. fcuda-is-device flag is not used by Flang currently. In the future it will be needed for Flang equivalent function: AMDGPUTargetCodeGenInfo::getGlobalVarAddressSpace.
1 parent f782ff8 commit 5b487aa

File tree

5 files changed

+41
-30
lines changed

5 files changed

+41
-30
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8016,7 +8016,7 @@ def source_date_epoch : Separate<["-"], "source-date-epoch">,
80168016
// CUDA Options
80178017
//===----------------------------------------------------------------------===//
80188018

8019-
let Visibility = [CC1Option] in {
8019+
let Visibility = [CC1Option, FC1Option] in {
80208020

80218021
def fcuda_is_device : Flag<["-"], "fcuda-is-device">,
80228022
HelpText<"Generate code for CUDA device">,
@@ -8031,7 +8031,7 @@ def fno_cuda_host_device_constexpr : Flag<["-"], "fno-cuda-host-device-constexpr
80318031
HelpText<"Don't treat unattributed constexpr functions as __host__ __device__.">,
80328032
MarshallingInfoNegativeFlag<LangOpts<"CUDAHostDeviceConstexpr">>;
80338033

8034-
} // let Visibility = [CC1Option]
8034+
} // let Visibility = [CC1Option, FC1Option]
80358035

80368036
//===----------------------------------------------------------------------===//
80378037
// OpenMP Options

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ void Flang::AddAMDGPUTargetArgs(const ArgList &Args,
333333
StringRef Val = A->getValue();
334334
CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val));
335335
}
336+
337+
const ToolChain &TC = getToolChain();
338+
TC.addClangTargetOptions(Args, CmdArgs, Action::OffloadKind::OFK_OpenMP);
336339
}
337340

338341
void Flang::addTargetOptions(const ArgList &Args,

flang/test/Driver/omp-driver-offload.f90

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
! Test regular -fopenmp with offload, and invocation filtering options
1515
! RUN: %flang -S -### %s -o %t 2>&1 \
1616
! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 \
17-
! RUN: --target=aarch64-unknown-linux-gnu \
17+
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
1818
! RUN: | FileCheck %s --check-prefix=OFFLOAD-HOST-AND-DEVICE
1919

2020
! RUN: %flang -S -### %s -o %t 2>&1 \
2121
! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 --offload-host-device \
22-
! RUN: --target=aarch64-unknown-linux-gnu \
22+
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
2323
! RUN: | FileCheck %s --check-prefix=OFFLOAD-HOST-AND-DEVICE
2424

2525
! OFFLOAD-HOST-AND-DEVICE: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
@@ -29,7 +29,7 @@
2929

3030
! RUN: %flang -S -### %s -o %t 2>&1 \
3131
! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 --offload-host-only \
32-
! RUN: --target=aarch64-unknown-linux-gnu \
32+
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
3333
! RUN: | FileCheck %s --check-prefix=OFFLOAD-HOST
3434

3535
! OFFLOAD-HOST: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
@@ -39,7 +39,7 @@
3939

4040
! RUN: %flang -S -### %s 2>&1 \
4141
! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 --offload-device-only \
42-
! RUN: --target=aarch64-unknown-linux-gnu \
42+
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
4343
! RUN: | FileCheck %s --check-prefix=OFFLOAD-DEVICE
4444

4545
! OFFLOAD-DEVICE: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
@@ -48,13 +48,13 @@
4848
! OFFLOAD-DEVICE-NOT: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
4949

5050
! Test regular -fopenmp with offload for basic fopenmp-is-target-device flag addition and correct fopenmp
51-
! RUN: %flang -### -fopenmp --offload-arch=gfx90a -fopenmp-targets=amdgcn-amd-amdhsa %s 2>&1 | FileCheck --check-prefixes=CHECK-OPENMP-IS-TARGET-DEVICE %s
51+
! RUN: %flang -### -fopenmp --offload-arch=gfx90a -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib %s 2>&1 | FileCheck --check-prefixes=CHECK-OPENMP-IS-TARGET-DEVICE %s
5252
! CHECK-OPENMP-IS-TARGET-DEVICE: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" {{.*}}.f90"
5353

5454
! Testing appropriate flags are gnerated and appropriately assigned by the driver when offloading
5555
! RUN: %flang -S -### %s -o %t 2>&1 \
5656
! RUN: -fopenmp --offload-arch=gfx90a \
57-
! RUN: --target=aarch64-unknown-linux-gnu \
57+
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
5858
! RUN: | FileCheck %s --check-prefix=OPENMP-OFFLOAD-ARGS
5959
! OPENMP-OFFLOAD-ARGS: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}}.f90"
6060
! OPENMP-OFFLOAD-ARGS-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa"
@@ -70,72 +70,72 @@
7070
! RUN: %flang -### %s -o %t 2>&1 \
7171
! RUN: -fopenmp --offload-arch=gfx90a \
7272
! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \
73-
! RUN: -fopenmp-assume-threads-oversubscription \
73+
! RUN: -fopenmp-assume-threads-oversubscription -nogpulib \
7474
! RUN: | FileCheck %s --check-prefixes=CHECK-THREADS-OVS
7575
! RUN: %flang -### %s -o %t 2>&1 \
7676
! RUN: -fopenmp --offload-arch=sm_70 \
7777
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
78-
! RUN: -fopenmp-assume-threads-oversubscription \
78+
! RUN: -fopenmp-assume-threads-oversubscription -nogpulib \
7979
! RUN: | FileCheck %s --check-prefixes=CHECK-THREADS-OVS
8080
! CHECK-THREADS-OVS: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-threads-oversubscription" {{.*}}.f90"
8181

8282
! RUN: %flang -### %s -o %t 2>&1 \
8383
! RUN: -fopenmp --offload-arch=gfx90a \
8484
! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \
85-
! RUN: -fopenmp-assume-teams-oversubscription \
85+
! RUN: -fopenmp-assume-teams-oversubscription -nogpulib\
8686
! RUN: | FileCheck %s --check-prefixes=CHECK-TEAMS-OVS
8787
! RUN: %flang -### %s -o %t 2>&1 \
8888
! RUN: -fopenmp --offload-arch=sm_70 \
89-
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
89+
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda -nogpulib\
9090
! RUN: -fopenmp-assume-teams-oversubscription \
9191
! RUN: | FileCheck %s --check-prefixes=CHECK-TEAMS-OVS
9292
! CHECK-TEAMS-OVS: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-teams-oversubscription" {{.*}}.f90"
9393

9494
! RUN: %flang -### %s -o %t 2>&1 \
9595
! RUN: -fopenmp --offload-arch=gfx90a \
9696
! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \
97-
! RUN: -fopenmp-assume-no-nested-parallelism \
97+
! RUN: -fopenmp-assume-no-nested-parallelism -nogpulib\
9898
! RUN: | FileCheck %s --check-prefixes=CHECK-NEST-PAR
9999
! RUN: %flang -### %s -o %t 2>&1 \
100100
! RUN: -fopenmp --offload-arch=sm_70 \
101101
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
102-
! RUN: -fopenmp-assume-no-nested-parallelism \
102+
! RUN: -fopenmp-assume-no-nested-parallelism -nogpulib\
103103
! RUN: | FileCheck %s --check-prefixes=CHECK-NEST-PAR
104104
! CHECK-NEST-PAR: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-no-nested-parallelism" {{.*}}.f90"
105105

106106
! RUN: %flang -### %s -o %t 2>&1 \
107107
! RUN: -fopenmp --offload-arch=gfx90a \
108108
! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \
109-
! RUN: -fopenmp-assume-no-thread-state \
109+
! RUN: -fopenmp-assume-no-thread-state -nogpulib\
110110
! RUN: | FileCheck %s --check-prefixes=CHECK-THREAD-STATE
111111
! RUN: %flang -### %s -o %t 2>&1 \
112112
! RUN: -fopenmp --offload-arch=sm_70 \
113113
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
114-
! RUN: -fopenmp-assume-no-thread-state \
114+
! RUN: -fopenmp-assume-no-thread-state -nogpulib\
115115
! RUN: | FileCheck %s --check-prefixes=CHECK-THREAD-STATE
116116
! CHECK-THREAD-STATE: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-no-thread-state" {{.*}}.f90"
117117

118118
! RUN: %flang -### %s -o %t 2>&1 \
119119
! RUN: -fopenmp --offload-arch=gfx90a \
120120
! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \
121-
! RUN: -fopenmp-target-debug \
121+
! RUN: -fopenmp-target-debug -nogpulib\
122122
! RUN: | FileCheck %s --check-prefixes=CHECK-TARGET-DEBUG
123123
! RUN: %flang -### %s -o %t 2>&1 \
124124
! RUN: -fopenmp --offload-arch=sm_70 \
125125
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
126-
! RUN: -fopenmp-target-debug \
126+
! RUN: -fopenmp-target-debug -nogpulib\
127127
! RUN: | FileCheck %s --check-prefixes=CHECK-TARGET-DEBUG
128128
! CHECK-TARGET-DEBUG: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-target-debug" {{.*}}.f90"
129129

130130
! RUN: %flang -### %s -o %t 2>&1 \
131131
! RUN: -fopenmp --offload-arch=gfx90a \
132132
! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \
133-
! RUN: -fopenmp-target-debug \
133+
! RUN: -fopenmp-target-debug -nogpulib\
134134
! RUN: | FileCheck %s --check-prefixes=CHECK-TARGET-DEBUG
135135
! RUN: %flang -### %s -o %t 2>&1 \
136136
! RUN: -fopenmp --offload-arch=sm_70 \
137137
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
138-
! RUN: -fopenmp-target-debug \
138+
! RUN: -fopenmp-target-debug -nogpulib\
139139
! RUN: | FileCheck %s --check-prefixes=CHECK-TARGET-DEBUG
140140
! CHECK-TARGET-DEBUG-EQ: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-target-debug=111" {{.*}}.f90"
141141

@@ -144,14 +144,14 @@
144144
! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \
145145
! RUN: -fopenmp-target-debug -fopenmp-assume-threads-oversubscription \
146146
! RUN: -fopenmp-assume-teams-oversubscription -fopenmp-assume-no-nested-parallelism \
147-
! RUN: -fopenmp-assume-no-thread-state \
147+
! RUN: -fopenmp-assume-no-thread-state -nogpulib\
148148
! RUN: | FileCheck %s --check-prefixes=CHECK-RTL-ALL
149149
! RUN: %flang -S -### %s -o %t 2>&1 \
150150
! RUN: -fopenmp --offload-arch=sm_70 \
151151
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
152152
! RUN: -fopenmp-target-debug -fopenmp-assume-threads-oversubscription \
153153
! RUN: -fopenmp-assume-teams-oversubscription -fopenmp-assume-no-nested-parallelism \
154-
! RUN: -fopenmp-assume-no-thread-state \
154+
! RUN: -fopenmp-assume-no-thread-state -nogpulib\
155155
! RUN: | FileCheck %s --check-prefixes=CHECK-RTL-ALL
156156
! CHECK-RTL-ALL: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-target-debug" "-fopenmp-assume-teams-oversubscription"
157157
! CHECK-RTL-ALL: "-fopenmp-assume-threads-oversubscription" "-fopenmp-assume-no-thread-state" "-fopenmp-assume-no-nested-parallelism"
@@ -160,12 +160,12 @@
160160
! RUN: %flang -### %s -o %t 2>&1 \
161161
! RUN: -fopenmp --offload-arch=gfx90a \
162162
! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \
163-
! RUN: -fopenmp-version=45 \
163+
! RUN: -fopenmp-version=45 -nogpulib\
164164
! RUN: | FileCheck %s --check-prefixes=CHECK-OPENMP-VERSION
165165
! RUN: %flang -### %s -o %t 2>&1 \
166166
! RUN: -fopenmp --offload-arch=sm_70 \
167167
! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \
168-
! RUN: -fopenmp-version=45 \
168+
! RUN: -fopenmp-version=45 -nogpulib\
169169
! RUN: | FileCheck %s --check-prefixes=CHECK-OPENMP-VERSION
170170
! CHECK-OPENMP-VERSION: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" "-fopenmp-version=45" {{.*}}.f90"
171171

@@ -190,15 +190,15 @@
190190
! NO-LIBC-GPU-NVPTX-NOT: "-lcgpu-nvptx"
191191

192192
! RUN: %flang -### --target=x86_64-unknown-linux-gnu -fopenmp \
193-
! RUN: --offload-arch=gfx90a \
193+
! RUN: --offload-arch=gfx900 --rocm-path=%S/Inputs/rocm \
194194
! RUN: -gpulibc %s 2>&1 \
195195
! RUN: | FileCheck --check-prefix=LIBC-GPU-AMDGPU %s
196196
! LIBC-GPU-AMDGPU-DAG: "-lcgpu-amdgpu"
197197
! LIBC-GPU-AMDGPU-DAG: "-lmgpu-amdgpu"
198198

199199
! RUN: %flang -### --target=x86_64-unknown-linux-gnu -fopenmp \
200200
! RUN: --offload-arch=gfx90a \
201-
! RUN: -nogpulibc %s 2>&1 \
201+
! RUN: -nogpulibc -nogpulib %s 2>&1 \
202202
! RUN: | FileCheck --check-prefix=NO-LIBC-GPU-AMDGPU %s
203203
! NO-LIBC-GPU-AMDGPU-NOT: "-lcgpu-amdgpu"
204204

@@ -220,10 +220,18 @@
220220
! Test -fopenmp-force-usm option with offload
221221
! RUN: %flang -S -### %s -o %t 2>&1 \
222222
! RUN: -fopenmp -fopenmp-force-usm --offload-arch=gfx90a \
223-
! RUN: --target=aarch64-unknown-linux-gnu \
223+
! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
224224
! RUN: | FileCheck %s --check-prefix=FORCE-USM-OFFLOAD
225225

226226
! FORCE-USM-OFFLOAD: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu"
227227
! FORCE-USM-OFFLOAD-SAME: "-fopenmp" "-fopenmp-force-usm"
228228
! FORCE-USM-OFFLOAD-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa"
229229
! FORCE-USM-OFFLOAD-SAME: "-fopenmp" "-fopenmp-force-usm"
230+
231+
! RUN: %flang -### -v --target=x86_64-unknown-linux-gnu -fopenmp \
232+
! RUN: --offload-arch=gfx900 \
233+
! RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \
234+
! RUN: | FileCheck --check-prefix=MLINK-BUILTIN-BITCODE %s
235+
! MLINK-BUILTIN-BITCODE: "{{[^"]*}}flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa"
236+
! MLINK-BUILTIN-BITCODE-SAME: "-fcuda-is-device"
237+
! MLINK-BUILTIN-BITCODE-SAME: "-mlink-builtin-bitcode" {{.*Inputs.*rocm.*amdgcn.*bitcode.*}}oclc_isa_version_900.bc

flang/test/Driver/target-cpu-features.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
! RUN: %flang --target=riscv64-linux-gnu -c %s -### 2>&1 \
2424
! RUN: | FileCheck %s -check-prefix=CHECK-RV64
2525

26-
! RUN: %flang --target=amdgcn-amd-amdhsa -mcpu=gfx908 -c %s -### 2>&1 \
26+
! RUN: %flang --target=amdgcn-amd-amdhsa -mcpu=gfx908 -nogpulib -c %s -### 2>&1 \
2727
! RUN: | FileCheck %s -check-prefix=CHECK-AMDGPU
2828

29-
! RUN: %flang --target=r600-unknown-unknown -mcpu=cayman -c %s -### 2>&1 \
29+
! RUN: %flang --target=r600-unknown-unknown -mcpu=cayman -nogpulib -c %s -### 2>&1 \
3030
! RUN: | FileCheck %s -check-prefix=CHECK-AMDGPU-R600
3131

3232
! CHECK-A57: "-fc1" "-triple" "aarch64-unknown-linux-gnu"

flang/test/Driver/target-gpu-features.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
! Test that -mcpu are used and that the -target-cpu and -target-features
44
! are also added to the fc1 command.
55

6-
! RUN: %flang --target=amdgcn-amd-amdhsa -mcpu=gfx902 -c %s -### 2>&1 \
6+
! RUN: %flang --target=amdgcn-amd-amdhsa -mcpu=gfx902 -nogpulib -c %s -### 2>&1 \
77
! RUN: | FileCheck %s -check-prefix=CHECK-AMDGCN
88

99
! CHECK-AMDGCN: "-fc1" "-triple" "amdgcn-amd-amdhsa"

0 commit comments

Comments
 (0)