1! Test that flang OpenMP and OpenMP offload related 2! commands forward or expand to the appropriate commands 3! for flang -fc1 as expected. Assumes a gfx90a, aarch64, 4! and sm_70 architecture, but doesn't require one to be 5! installed or compiled for, just testing the appropriate 6! generation of jobs are created with the correct 7! corresponding arguments. 8 9! Test regular -fopenmp with no offload 10! RUN: %flang -### -fopenmp %s 2>&1 | FileCheck --check-prefixes=CHECK-OPENMP %s 11! CHECK-OPENMP: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}}.f90" 12! CHECK-OPENMP-NOT: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" {{.*}}.f90" 13 14! Test regular -fopenmp with offload, and invocation filtering options 15! RUN: %flang -S -### %s -o %t 2>&1 \ 16! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 \ 17! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\ 18! RUN: | FileCheck %s --check-prefix=OFFLOAD-HOST-AND-DEVICE 19 20! RUN: %flang -S -### %s -o %t 2>&1 \ 21! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 --offload-host-device \ 22! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\ 23! RUN: | FileCheck %s --check-prefix=OFFLOAD-HOST-AND-DEVICE 24 25! OFFLOAD-HOST-AND-DEVICE: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" 26! OFFLOAD-HOST-AND-DEVICE-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "amdgcn-amd-amdhsa" 27! OFFLOAD-HOST-AND-DEVICE-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "nvptx64-nvidia-cuda" 28! OFFLOAD-HOST-AND-DEVICE: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" 29 30! RUN: %flang -S -### %s -o %t 2>&1 \ 31! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 --offload-host-only \ 32! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\ 33! RUN: | FileCheck %s --check-prefix=OFFLOAD-HOST 34 35! OFFLOAD-HOST: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" 36! OFFLOAD-HOST-NOT: "-triple" "amdgcn-amd-amdhsa" 37! OFFLOAD-HOST-NOT: "-triple" "nvptx64-nvidia-cuda" 38! OFFLOAD-HOST-NOT: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" 39 40! RUN: %flang -S -### %s 2>&1 \ 41! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 --offload-device-only \ 42! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\ 43! RUN: | FileCheck %s --check-prefix=OFFLOAD-DEVICE 44 45! OFFLOAD-DEVICE: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" 46! OFFLOAD-DEVICE-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "amdgcn-amd-amdhsa" 47! OFFLOAD-DEVICE-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "nvptx64-nvidia-cuda" 48! OFFLOAD-DEVICE-NOT: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" 49 50! 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 -nogpulib %s 2>&1 | FileCheck --check-prefixes=CHECK-OPENMP-IS-TARGET-DEVICE %s 52! CHECK-OPENMP-IS-TARGET-DEVICE: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" {{.*}}.f90" 53 54! Testing appropriate flags are gnerated and appropriately assigned by the driver when offloading 55! RUN: %flang -S -### %s -o %t 2>&1 \ 56! RUN: -fopenmp --offload-arch=gfx90a \ 57! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\ 58! RUN: | FileCheck %s --check-prefix=OPENMP-OFFLOAD-ARGS 59! OPENMP-OFFLOAD-ARGS: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}}.f90" 60! OPENMP-OFFLOAD-ARGS-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "amdgcn-amd-amdhsa" 61! OPENMP-OFFLOAD-ARGS-SAME: "-fopenmp" 62! OPENMP-OFFLOAD-ARGS-SAME: "-fopenmp-host-ir-file-path" "{{.*}}.bc" "-fopenmp-is-target-device" 63! OPENMP-OFFLOAD-ARGS-SAME: {{.*}}.f90" 64! OPENMP-OFFLOAD-ARGS: "{{[^"]*}}clang-offload-packager{{.*}}" {{.*}} "--image=file={{.*}}.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp" 65! OPENMP-OFFLOAD-ARGS-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" 66! OPENMP-OFFLOAD-ARGS-SAME: "-fopenmp" 67! OPENMP-OFFLOAD-ARGS-SAME: "-fembed-offload-object={{.*}}.out" {{.*}}.bc" 68 69! Test -fopenmp with offload for RTL Flag Options 70! RUN: %flang -### %s -o %t 2>&1 \ 71! RUN: -fopenmp --offload-arch=gfx90a \ 72! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \ 73! RUN: -fopenmp-assume-threads-oversubscription -nogpulib \ 74! RUN: | FileCheck %s --check-prefixes=CHECK-THREADS-OVS 75! RUN: %flang -### %s -o %t 2>&1 \ 76! RUN: -fopenmp --offload-arch=sm_70 \ 77! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \ 78! RUN: -fopenmp-assume-threads-oversubscription \ 79! RUN: | FileCheck %s --check-prefixes=CHECK-THREADS-OVS 80! CHECK-THREADS-OVS: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-threads-oversubscription" {{.*}}.f90" 81 82! RUN: %flang -### %s -o %t 2>&1 \ 83! RUN: -fopenmp --offload-arch=gfx90a \ 84! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \ 85! RUN: -fopenmp-assume-teams-oversubscription -nogpulib\ 86! RUN: | FileCheck %s --check-prefixes=CHECK-TEAMS-OVS 87! RUN: %flang -### %s -o %t 2>&1 \ 88! RUN: -fopenmp --offload-arch=sm_70 \ 89! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \ 90! RUN: -fopenmp-assume-teams-oversubscription \ 91! RUN: | FileCheck %s --check-prefixes=CHECK-TEAMS-OVS 92! CHECK-TEAMS-OVS: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-teams-oversubscription" {{.*}}.f90" 93 94! RUN: %flang -### %s -o %t 2>&1 \ 95! RUN: -fopenmp --offload-arch=gfx90a \ 96! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \ 97! RUN: -fopenmp-assume-no-nested-parallelism -nogpulib\ 98! RUN: | FileCheck %s --check-prefixes=CHECK-NEST-PAR 99! RUN: %flang -### %s -o %t 2>&1 \ 100! RUN: -fopenmp --offload-arch=sm_70 \ 101! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \ 102! RUN: -fopenmp-assume-no-nested-parallelism \ 103! RUN: | FileCheck %s --check-prefixes=CHECK-NEST-PAR 104! CHECK-NEST-PAR: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-no-nested-parallelism" {{.*}}.f90" 105 106! RUN: %flang -### %s -o %t 2>&1 \ 107! RUN: -fopenmp --offload-arch=gfx90a \ 108! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \ 109! RUN: -fopenmp-assume-no-thread-state -nogpulib\ 110! RUN: | FileCheck %s --check-prefixes=CHECK-THREAD-STATE 111! RUN: %flang -### %s -o %t 2>&1 \ 112! RUN: -fopenmp --offload-arch=sm_70 \ 113! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \ 114! RUN: -fopenmp-assume-no-thread-state \ 115! RUN: | FileCheck %s --check-prefixes=CHECK-THREAD-STATE 116! CHECK-THREAD-STATE: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-assume-no-thread-state" {{.*}}.f90" 117 118! RUN: %flang -### %s -o %t 2>&1 \ 119! RUN: -fopenmp --offload-arch=gfx90a \ 120! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \ 121! RUN: -fopenmp-target-debug -nogpulib\ 122! RUN: | FileCheck %s --check-prefixes=CHECK-TARGET-DEBUG 123! RUN: %flang -### %s -o %t 2>&1 \ 124! RUN: -fopenmp --offload-arch=sm_70 \ 125! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \ 126! RUN: -fopenmp-target-debug \ 127! RUN: | FileCheck %s --check-prefixes=CHECK-TARGET-DEBUG 128! CHECK-TARGET-DEBUG: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-target-debug" {{.*}}.f90" 129 130! RUN: %flang -### %s -o %t 2>&1 \ 131! RUN: -fopenmp --offload-arch=gfx90a \ 132! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \ 133! RUN: -fopenmp-target-debug -nogpulib\ 134! RUN: | FileCheck %s --check-prefixes=CHECK-TARGET-DEBUG 135! RUN: %flang -### %s -o %t 2>&1 \ 136! RUN: -fopenmp --offload-arch=sm_70 \ 137! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \ 138! RUN: -fopenmp-target-debug \ 139! RUN: | FileCheck %s --check-prefixes=CHECK-TARGET-DEBUG 140! CHECK-TARGET-DEBUG-EQ: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-target-debug=111" {{.*}}.f90" 141 142! RUN: %flang -S -### %s -o %t 2>&1 \ 143! RUN: -fopenmp --offload-arch=gfx90a \ 144! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \ 145! RUN: -fopenmp-target-debug -fopenmp-assume-threads-oversubscription \ 146! RUN: -fopenmp-assume-teams-oversubscription -fopenmp-assume-no-nested-parallelism \ 147! RUN: -fopenmp-assume-no-thread-state -nogpulib\ 148! RUN: | FileCheck %s --check-prefixes=CHECK-RTL-ALL 149! RUN: %flang -S -### %s -o %t 2>&1 \ 150! RUN: -fopenmp --offload-arch=sm_70 \ 151! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \ 152! RUN: -fopenmp-target-debug -fopenmp-assume-threads-oversubscription \ 153! RUN: -fopenmp-assume-teams-oversubscription -fopenmp-assume-no-nested-parallelism \ 154! RUN: -fopenmp-assume-no-thread-state \ 155! RUN: | FileCheck %s --check-prefixes=CHECK-RTL-ALL 156! CHECK-RTL-ALL: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-target-device" "-fopenmp-target-debug" "-fopenmp-assume-teams-oversubscription" 157! CHECK-RTL-ALL: "-fopenmp-assume-threads-oversubscription" "-fopenmp-assume-no-thread-state" "-fopenmp-assume-no-nested-parallelism" 158! CHECK-RTL-ALL: {{.*}}.f90" 159 160! RUN: %flang -### %s -o %t 2>&1 \ 161! RUN: -fopenmp --offload-arch=gfx90a \ 162! RUN: -fopenmp-targets=amdgcn-amd-amdhsa \ 163! RUN: -fopenmp-version=45 -nogpulib\ 164! RUN: | FileCheck %s --check-prefixes=CHECK-OPENMP-VERSION 165! RUN: %flang -### %s -o %t 2>&1 \ 166! RUN: -fopenmp --offload-arch=sm_70 \ 167! RUN: -fopenmp-targets=nvptx64-nvidia-cuda \ 168! RUN: -fopenmp-version=45 \ 169! RUN: | FileCheck %s --check-prefixes=CHECK-OPENMP-VERSION 170! CHECK-OPENMP-VERSION: "{{[^"]*}}flang" "-fc1" {{.*}} "-fopenmp" "-fopenmp-version=45" {{.*}}.f90" 171 172! Test diagnostic error when host IR file is non-existent 173! RUN: not %flang_fc1 %s -o %t 2>&1 -fopenmp -fopenmp-is-target-device \ 174! RUN: -fopenmp-host-ir-file-path non-existant-file.bc \ 175! RUN: | FileCheck %s --check-prefix=HOST-IR-MISSING 176! HOST-IR-MISSING: error: provided host compiler IR file 'non-existant-file.bc' is required to generate code for OpenMP target regions but cannot be found 177 178! RUN: %flang -### -v --target=x86_64-unknown-linux-gnu -fopenmp \ 179! RUN: --offload-arch=gfx900 \ 180! RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \ 181! RUN: | FileCheck --check-prefix=ROCM-PATH %s 182! ROCM-PATH: Found HIP installation: {{.*Inputs.*rocm}}, version 3.6.20214-a2917cd 183 184! Test -fopenmp-force-usm option without offload 185! RUN: %flang -S -### %s -o %t 2>&1 \ 186! RUN: -fopenmp -fopenmp-force-usm \ 187! RUN: --target=aarch64-unknown-linux-gnu \ 188! RUN: | FileCheck %s --check-prefix=FORCE-USM-NO-OFFLOAD 189 190! FORCE-USM-NO-OFFLOAD: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" 191! FORCE-USM-NO-OFFLOAD-SAME: "-fopenmp" "-fopenmp-force-usm" 192 193! Test -fopenmp-force-usm option with offload 194! RUN: %flang -S -### %s -o %t 2>&1 \ 195! RUN: -fopenmp -fopenmp-force-usm --offload-arch=gfx90a \ 196! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\ 197! RUN: | FileCheck %s --check-prefix=FORCE-USM-OFFLOAD 198 199! FORCE-USM-OFFLOAD: "{{[^"]*}}flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" 200! FORCE-USM-OFFLOAD-SAME: "-fopenmp" "-fopenmp-force-usm" 201! FORCE-USM-OFFLOAD-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "amdgcn-amd-amdhsa" 202! FORCE-USM-OFFLOAD-SAME: "-fopenmp" "-fopenmp-force-usm" 203 204! RUN: %flang -### -v --target=x86_64-unknown-linux-gnu -fopenmp \ 205! RUN: --offload-arch=gfx900 \ 206! RUN: --rocm-path=%S/Inputs/rocm %s 2>&1 \ 207! RUN: | FileCheck --check-prefix=MLINK-BUILTIN-BITCODE %s 208! MLINK-BUILTIN-BITCODE: "{{[^"]*}}flang" "-fc1" "-triple" "amdgcn-amd-amdhsa" 209! MLINK-BUILTIN-BITCODE-SAME: "-mlink-builtin-bitcode" {{.*Inputs.*rocm.*amdgcn.*bitcode.*}}oclc_isa_version_900.bc 210 211! Test that the -fopenmp-targets option is added to host compilation invocations 212! when --offload-arch or -fopenmp-targets are set. 213! RUN: %flang -S -### %s -o %t 2>&1 \ 214! RUN: -fopenmp --offload-arch=gfx90a \ 215! RUN: --target=x86_64-unknown-linux-gnu -nogpulib \ 216! RUN: | FileCheck %s --check-prefix=OFFLOAD-TARGETS 217! RUN: %flang -S -### %s -o %t 2>&1 \ 218! RUN: -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa --offload-arch=gfx90a \ 219! RUN: --target=x86_64-unknown-linux-gnu -nogpulib \ 220! RUN: | FileCheck %s --check-prefix=OFFLOAD-TARGETS 221 222! OFFLOAD-TARGETS: "{{[^"]*}}flang" "-fc1" "-triple" "x86_64-unknown-linux-gnu" 223! OFFLOAD-TARGETS-SAME: "-fopenmp-targets=amdgcn-amd-amdhsa" 224! OFFLOAD-TARGETS-NEXT: "{{[^"]*}}flang" "-fc1" "-triple" "amdgcn-amd-amdhsa" 225! OFFLOAD-TARGETS-NOT: -fopenmp-targets 226! OFFLOAD-TARGETS: "{{[^"]*}}flang" "-fc1" "-triple" "x86_64-unknown-linux-gnu" 227! OFFLOAD-TARGETS-SAME: "-fopenmp-targets=amdgcn-amd-amdhsa" 228