[clang] [openmp] [OpenMP][USM] Introduces -fopenmp-force-usm flag (PR #76571)
https://github.com/jplehr closed https://github.com/llvm/llvm-project/pull/76571 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [OpenMP][USM] Introduces -fopenmp-force-usm flag (PR #76571)
jplehr wrote: I just realized that I need to update the clang lit tests, so this is *not ready to land*, but I don't see a button to indicate that. https://github.com/llvm/llvm-project/pull/76571 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [OpenMP][USM] Introduces -fopenmp-force-usm flag (PR #76571)
https://github.com/jplehr updated https://github.com/llvm/llvm-project/pull/76571 >From 41b227e2c84b3c7eeedb6a9ebf559bec2c34aec3 Mon Sep 17 00:00:00 2001 From: JP Lehr Date: Fri, 29 Dec 2023 04:32:24 -0500 Subject: [PATCH] [OpenMP][USM] Introduces -fopenmp-force-usm flag This flag forces the compiler to generate code for OpenMP target regions as if the user specified the #pragma omp requires unified_shared_memory in each source file. The option does not have a -fno-* friend since OpenMP requires the unified_shared_memory clause to be present in all source files. Since this flag does no harm if the clause is present, it can be used in conjunction. My understanding is that USM should not be turned off selectively, hence, no -fno- version. This adds a basic test to check the correct generation of double indirect access to declare target globals in USM mode vs non-USM mode. Which I think is the only difference observable in code generation. This runtime test checks for the (non-)occurence of data movement between host and device. It does one run without the flag and one with the flag to also see that both versions behave as expected. In the case w/o the new flag data movement between host and device is expected. In the case with the flag such data movement should not be present / reported. --- clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Driver/Options.td | 4 + clang/lib/CodeGen/CGOpenMPRuntime.cpp | 7 ++ clang/lib/Driver/ToolChains/Clang.cpp | 2 + clang/test/OpenMP/force-usm.c | 74 +++ openmp/libomptarget/test/lit.cfg | 8 ++ .../test/offloading/force-usm.cpp | 59 +++ 7 files changed, 155 insertions(+) create mode 100644 clang/test/OpenMP/force-usm.c create mode 100644 openmp/libomptarget/test/offloading/force-usm.cpp diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 21abc346cf17ac..81cf2ad9498a7f 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -260,6 +260,7 @@ LANGOPT(OpenMPTeamSubscription , 1, 0, "Assume distributed loops do not have mo LANGOPT(OpenMPNoThreadState , 1, 0, "Assume that no thread in a parallel region will modify an ICV.") LANGOPT(OpenMPNoNestedParallelism , 1, 0, "Assume that no thread in a parallel region will encounter a parallel region") LANGOPT(OpenMPOffloadMandatory , 1, 0, "Assert that offloading is mandatory and do not create a host fallback.") +LANGOPT(OpenMPForceUSM , 1, 0, "Enable OpenMP unified shared memory mode via compiler.") LANGOPT(NoGPULib , 1, 0, "Indicate a build without the standard GPU libraries.") LANGOPT(RenderScript , 1, 0, "RenderScript") diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 2b93ddf033499c..28290da438c62d 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3451,6 +3451,10 @@ def fopenmp_offload_mandatory : Flag<["-"], "fopenmp-offload-mandatory">, Group< Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>, HelpText<"Do not create a host fallback if offloading to the device fails.">, MarshallingInfoFlag>; +def fopenmp_force_usm : Flag<["-"], "fopenmp-force-usm">, Group, + Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>, + HelpText<"Force behvaior as if the user specified pragma omp requires unified_shared_memory.">, + MarshallingInfoFlag>; def fopenmp_target_jit : Flag<["-"], "fopenmp-target-jit">, Group, Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CLOption]>, HelpText<"Emit code that can be JIT compiled for OpenMP offloading. Implies -foffload-lto=full">; diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index ea6645a39e8321..4855e7410a015a 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1044,6 +1044,13 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule ) ? CGM.getLangOpts().OMPHostIRFile : StringRef{}); OMPBuilder.setConfig(Config); + + // The user forces the compiler to behave as if omp requires + // unified_shared_memory was given. + if (CGM.getLangOpts().OpenMPForceUSM) { +HasRequiresUnifiedSharedMemory = true; +OMPBuilder.Config.setHasRequiresUnifiedSharedMemory(true); + } } void CGOpenMPRuntime::clear() { diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index acfa119805068d..ffc24201ab2e0b 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6382,6 +6382,8 @@ void Clang::ConstructJob(Compilation , const JobAction , CmdArgs.push_back("-fopenmp-assume-no-nested-parallelism"); if
[clang] [openmp] [OpenMP][USM] Introduces -fopenmp-force-usm flag (PR #76571)
jplehr wrote: > Automatic zero-copy doesn't work on some of the bbot's. I will have to land > this once the lit test harness extension in #77851 re-lands. Having your work landed would be very helpful indeed. https://github.com/llvm/llvm-project/pull/76571 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [OpenMP][USM] Introduces -fopenmp-force-usm flag (PR #76571)
carlobertolli wrote: Automatic zero-copy doesn't work on some of the bbot's. I will have to land this once the lit test harness extension in #77851 re-lands. https://github.com/llvm/llvm-project/pull/76571 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [OpenMP][USM] Introduces -fopenmp-force-usm flag (PR #76571)
https://github.com/jplehr updated https://github.com/llvm/llvm-project/pull/76571 >From bf25a538e7c020efde557b595eba64b804cbb817 Mon Sep 17 00:00:00 2001 From: JP Lehr Date: Fri, 29 Dec 2023 04:32:24 -0500 Subject: [PATCH 1/5] [OpenMP][USM] Introduces -fopenmp-force-usm flag This flag forces the compiler to generate code for OpenMP target regions as if the user specified the #pragma omp requires unified_shared_memory in each source file. The option does not have a -fno-* friend since OpenMP requires the unified_shared_memory clause to be present in all source files. Since this flag does no harm if the clause is present, it can be used in conjunction. My understanding is that USM should not be turned off selectively, hence, no -fno- version. --- clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Driver/Options.td | 4 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 7 +++ clang/lib/Driver/ToolChains/Clang.cpp | 2 ++ 4 files changed, 14 insertions(+) diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 21abc346cf17ac..81cf2ad9498a7f 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -260,6 +260,7 @@ LANGOPT(OpenMPTeamSubscription , 1, 0, "Assume distributed loops do not have mo LANGOPT(OpenMPNoThreadState , 1, 0, "Assume that no thread in a parallel region will modify an ICV.") LANGOPT(OpenMPNoNestedParallelism , 1, 0, "Assume that no thread in a parallel region will encounter a parallel region") LANGOPT(OpenMPOffloadMandatory , 1, 0, "Assert that offloading is mandatory and do not create a host fallback.") +LANGOPT(OpenMPForceUSM , 1, 0, "Enable OpenMP unified shared memory mode via compiler.") LANGOPT(NoGPULib , 1, 0, "Indicate a build without the standard GPU libraries.") LANGOPT(RenderScript , 1, 0, "RenderScript") diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 2b93ddf033499c..28290da438c62d 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3451,6 +3451,10 @@ def fopenmp_offload_mandatory : Flag<["-"], "fopenmp-offload-mandatory">, Group< Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>, HelpText<"Do not create a host fallback if offloading to the device fails.">, MarshallingInfoFlag>; +def fopenmp_force_usm : Flag<["-"], "fopenmp-force-usm">, Group, + Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>, + HelpText<"Force behvaior as if the user specified pragma omp requires unified_shared_memory.">, + MarshallingInfoFlag>; def fopenmp_target_jit : Flag<["-"], "fopenmp-target-jit">, Group, Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CLOption]>, HelpText<"Emit code that can be JIT compiled for OpenMP offloading. Implies -foffload-lto=full">; diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index ea6645a39e8321..4855e7410a015a 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1044,6 +1044,13 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule ) ? CGM.getLangOpts().OMPHostIRFile : StringRef{}); OMPBuilder.setConfig(Config); + + // The user forces the compiler to behave as if omp requires + // unified_shared_memory was given. + if (CGM.getLangOpts().OpenMPForceUSM) { +HasRequiresUnifiedSharedMemory = true; +OMPBuilder.Config.setHasRequiresUnifiedSharedMemory(true); + } } void CGOpenMPRuntime::clear() { diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index acfa119805068d..ffc24201ab2e0b 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6382,6 +6382,8 @@ void Clang::ConstructJob(Compilation , const JobAction , CmdArgs.push_back("-fopenmp-assume-no-nested-parallelism"); if (Args.hasArg(options::OPT_fopenmp_offload_mandatory)) CmdArgs.push_back("-fopenmp-offload-mandatory"); + if (Args.hasArg(options::OPT_fopenmp_force_usm)) +CmdArgs.push_back("-fopenmp-force-usm"); break; default: // By default, if Clang doesn't know how to generate useful OpenMP code >From 11ad5633889870d897bfc4e77bc41b569e5ce539 Mon Sep 17 00:00:00 2001 From: JP Lehr Date: Wed, 12 Jul 2023 05:04:41 -0400 Subject: [PATCH 2/5] [OpenMP][USM] Adds test for -fopenmp-force-usm flag This adds a basic test to check the correct generation of double indirect access to declare target globals in USM mode vs non-USM mode. Marked as XFAIL to first land test and then enable in subsequent patch. --- clang/test/OpenMP/force-usm.c | 74 +++ 1 file changed, 74 insertions(+) create mode 100644 clang/test/OpenMP/force-usm.c diff --git
[clang] [openmp] [OpenMP][USM] Introduces -fopenmp-force-usm flag (PR #76571)
https://github.com/jplehr updated https://github.com/llvm/llvm-project/pull/76571 >From bf25a538e7c020efde557b595eba64b804cbb817 Mon Sep 17 00:00:00 2001 From: JP Lehr Date: Fri, 29 Dec 2023 04:32:24 -0500 Subject: [PATCH 1/4] [OpenMP][USM] Introduces -fopenmp-force-usm flag This flag forces the compiler to generate code for OpenMP target regions as if the user specified the #pragma omp requires unified_shared_memory in each source file. The option does not have a -fno-* friend since OpenMP requires the unified_shared_memory clause to be present in all source files. Since this flag does no harm if the clause is present, it can be used in conjunction. My understanding is that USM should not be turned off selectively, hence, no -fno- version. --- clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Driver/Options.td | 4 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 7 +++ clang/lib/Driver/ToolChains/Clang.cpp | 2 ++ 4 files changed, 14 insertions(+) diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 21abc346cf17ac3..81cf2ad9498a7f9 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -260,6 +260,7 @@ LANGOPT(OpenMPTeamSubscription , 1, 0, "Assume distributed loops do not have mo LANGOPT(OpenMPNoThreadState , 1, 0, "Assume that no thread in a parallel region will modify an ICV.") LANGOPT(OpenMPNoNestedParallelism , 1, 0, "Assume that no thread in a parallel region will encounter a parallel region") LANGOPT(OpenMPOffloadMandatory , 1, 0, "Assert that offloading is mandatory and do not create a host fallback.") +LANGOPT(OpenMPForceUSM , 1, 0, "Enable OpenMP unified shared memory mode via compiler.") LANGOPT(NoGPULib , 1, 0, "Indicate a build without the standard GPU libraries.") LANGOPT(RenderScript , 1, 0, "RenderScript") diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 2b93ddf033499cc..28290da438c62db 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3451,6 +3451,10 @@ def fopenmp_offload_mandatory : Flag<["-"], "fopenmp-offload-mandatory">, Group< Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>, HelpText<"Do not create a host fallback if offloading to the device fails.">, MarshallingInfoFlag>; +def fopenmp_force_usm : Flag<["-"], "fopenmp-force-usm">, Group, + Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>, + HelpText<"Force behvaior as if the user specified pragma omp requires unified_shared_memory.">, + MarshallingInfoFlag>; def fopenmp_target_jit : Flag<["-"], "fopenmp-target-jit">, Group, Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CLOption]>, HelpText<"Emit code that can be JIT compiled for OpenMP offloading. Implies -foffload-lto=full">; diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index ea6645a39e83218..4855e7410a015aa 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1044,6 +1044,13 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule ) ? CGM.getLangOpts().OMPHostIRFile : StringRef{}); OMPBuilder.setConfig(Config); + + // The user forces the compiler to behave as if omp requires + // unified_shared_memory was given. + if (CGM.getLangOpts().OpenMPForceUSM) { +HasRequiresUnifiedSharedMemory = true; +OMPBuilder.Config.setHasRequiresUnifiedSharedMemory(true); + } } void CGOpenMPRuntime::clear() { diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index acfa119805068d2..ffc24201ab2e0b5 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6382,6 +6382,8 @@ void Clang::ConstructJob(Compilation , const JobAction , CmdArgs.push_back("-fopenmp-assume-no-nested-parallelism"); if (Args.hasArg(options::OPT_fopenmp_offload_mandatory)) CmdArgs.push_back("-fopenmp-offload-mandatory"); + if (Args.hasArg(options::OPT_fopenmp_force_usm)) +CmdArgs.push_back("-fopenmp-force-usm"); break; default: // By default, if Clang doesn't know how to generate useful OpenMP code >From 11ad5633889870d897bfc4e77bc41b569e5ce539 Mon Sep 17 00:00:00 2001 From: JP Lehr Date: Wed, 12 Jul 2023 05:04:41 -0400 Subject: [PATCH 2/4] [OpenMP][USM] Adds test for -fopenmp-force-usm flag This adds a basic test to check the correct generation of double indirect access to declare target globals in USM mode vs non-USM mode. Marked as XFAIL to first land test and then enable in subsequent patch. --- clang/test/OpenMP/force-usm.c | 74 +++ 1 file changed, 74 insertions(+) create mode 100644 clang/test/OpenMP/force-usm.c diff --git
[clang] [openmp] [OpenMP][USM] Introduces -fopenmp-force-usm flag (PR #76571)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 90802e652db348fd3218fcbfc3e6ac9e90702acd e093db3f1bc432654c2105430f2f647f6d2ab362 -- clang/test/OpenMP/force-usm.c openmp/libomptarget/test/offloading/force-usm.cpp clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/lib/Driver/ToolChains/Clang.cpp `` View the diff from clang-format here. ``diff diff --git a/openmp/libomptarget/test/offloading/force-usm.cpp b/openmp/libomptarget/test/offloading/force-usm.cpp index f51f7e782e..e961f315f8 100644 --- a/openmp/libomptarget/test/offloading/force-usm.cpp +++ b/openmp/libomptarget/test/offloading/force-usm.cpp @@ -1,9 +1,11 @@ // RUN: %libomptarget-compilexx-generic -// RUN: env LIBOMPTARGET_INFO=32 %libomptarget-run-generic 2>&1 | %fcheck-generic --check-prefix=NO-USM +// RUN: env LIBOMPTARGET_INFO=32 %libomptarget-run-generic 2>&1 | +// %fcheck-generic --check-prefix=NO-USM // // RUN: %libomptarget-compilexxx-generic-force-usm // RUN: env HSA_XNACK=1 LIBOMPTARGET_INFO=32 \ -// RUN: %libomptarget-run-generic 2>&1 | %fcheck-generic --check-prefix=FORCE-USM +// RUN: %libomptarget-run-generic 2>&1 | %fcheck-generic +// --check-prefix=FORCE-USM // // UNSUPPORTED: nvptx64-nvidia-cuda // UNSUPPORTED: nvptx64-nvidia-cuda-LTO @@ -11,7 +13,6 @@ #include #include - int GI; #pragma omp declare target int *pGI; @@ -21,10 +22,10 @@ int main(void) { GI = 0; - pGI = (int *) malloc(sizeof(int)); + pGI = (int *)malloc(sizeof(int)); *pGI = 42; -#pragma omp target map(pGI[:1], GI) +#pragma omp target map(pGI[ : 1], GI) { GI = 1; *pGI = 2; @@ -35,11 +36,13 @@ int main(void) { return 0; } -// NO-USM: omptarget device 0 info: Copying data from host to device, HstPtr={{.*}}, TgtPtr={{.*}}, Size=4 -// NO-USM: omptarget device 0 info: Copying data from host to device, HstPtr={{.*}}, TgtPtr={{.*}}, Size=4 -// NO-USM: omptarget device 0 info: Copying data from host to device, HstPtr={{.*}}, TgtPtr={{.*}}, Size=8, Name=pGI -// NO-USM: omptarget device 0 info: Copying data from device to host, TgtPtr={{.*}}, HstPtr={{.*}}, Size=4 -// NO-USM: omptarget device 0 info: Copying data from device to host, TgtPtr={{.*}}, HstPtr={{.*}}, Size=4 -// NO-USM: SUCCESS +// NO-USM: omptarget device 0 info: Copying data from host to device, +// HstPtr={{.*}}, TgtPtr={{.*}}, Size=4 NO-USM: omptarget device 0 info: Copying +// data from host to device, HstPtr={{.*}}, TgtPtr={{.*}}, Size=4 NO-USM: +// omptarget device 0 info: Copying data from host to device, HstPtr={{.*}}, +// TgtPtr={{.*}}, Size=8, Name=pGI NO-USM: omptarget device 0 info: Copying data +// from device to host, TgtPtr={{.*}}, HstPtr={{.*}}, Size=4 NO-USM: omptarget +// device 0 info: Copying data from device to host, TgtPtr={{.*}}, +// HstPtr={{.*}}, Size=4 NO-USM: SUCCESS // FORCE-USM: SUCCESS `` https://github.com/llvm/llvm-project/pull/76571 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [OpenMP][USM] Introduces -fopenmp-force-usm flag (PR #76571)
https://github.com/jhuber6 approved this pull request. https://github.com/llvm/llvm-project/pull/76571 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [OpenMP][USM] Introduces -fopenmp-force-usm flag (PR #76571)
jplehr wrote: While I add some documentation, I'd appreciate feedback especially on the lit side of things. I would very much like to rename the pretty happy tripple-X workaround for substitution debugging into something sane. https://github.com/llvm/llvm-project/pull/76571 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [openmp] [OpenMP][USM] Introduces -fopenmp-force-usm flag (PR #76571)
https://github.com/jplehr updated https://github.com/llvm/llvm-project/pull/76571 >From bf25a538e7c020efde557b595eba64b804cbb817 Mon Sep 17 00:00:00 2001 From: JP Lehr Date: Fri, 29 Dec 2023 04:32:24 -0500 Subject: [PATCH 1/3] [OpenMP][USM] Introduces -fopenmp-force-usm flag This flag forces the compiler to generate code for OpenMP target regions as if the user specified the #pragma omp requires unified_shared_memory in each source file. The option does not have a -fno-* friend since OpenMP requires the unified_shared_memory clause to be present in all source files. Since this flag does no harm if the clause is present, it can be used in conjunction. My understanding is that USM should not be turned off selectively, hence, no -fno- version. --- clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Driver/Options.td | 4 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 7 +++ clang/lib/Driver/ToolChains/Clang.cpp | 2 ++ 4 files changed, 14 insertions(+) diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 21abc346cf17ac..81cf2ad9498a7f 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -260,6 +260,7 @@ LANGOPT(OpenMPTeamSubscription , 1, 0, "Assume distributed loops do not have mo LANGOPT(OpenMPNoThreadState , 1, 0, "Assume that no thread in a parallel region will modify an ICV.") LANGOPT(OpenMPNoNestedParallelism , 1, 0, "Assume that no thread in a parallel region will encounter a parallel region") LANGOPT(OpenMPOffloadMandatory , 1, 0, "Assert that offloading is mandatory and do not create a host fallback.") +LANGOPT(OpenMPForceUSM , 1, 0, "Enable OpenMP unified shared memory mode via compiler.") LANGOPT(NoGPULib , 1, 0, "Indicate a build without the standard GPU libraries.") LANGOPT(RenderScript , 1, 0, "RenderScript") diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 2b93ddf033499c..28290da438c62d 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3451,6 +3451,10 @@ def fopenmp_offload_mandatory : Flag<["-"], "fopenmp-offload-mandatory">, Group< Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>, HelpText<"Do not create a host fallback if offloading to the device fails.">, MarshallingInfoFlag>; +def fopenmp_force_usm : Flag<["-"], "fopenmp-force-usm">, Group, + Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CC1Option]>, + HelpText<"Force behvaior as if the user specified pragma omp requires unified_shared_memory.">, + MarshallingInfoFlag>; def fopenmp_target_jit : Flag<["-"], "fopenmp-target-jit">, Group, Flags<[NoArgumentUnused]>, Visibility<[ClangOption, CLOption]>, HelpText<"Emit code that can be JIT compiled for OpenMP offloading. Implies -foffload-lto=full">; diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index ea6645a39e8321..4855e7410a015a 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1044,6 +1044,13 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule ) ? CGM.getLangOpts().OMPHostIRFile : StringRef{}); OMPBuilder.setConfig(Config); + + // The user forces the compiler to behave as if omp requires + // unified_shared_memory was given. + if (CGM.getLangOpts().OpenMPForceUSM) { +HasRequiresUnifiedSharedMemory = true; +OMPBuilder.Config.setHasRequiresUnifiedSharedMemory(true); + } } void CGOpenMPRuntime::clear() { diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index acfa119805068d..ffc24201ab2e0b 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -6382,6 +6382,8 @@ void Clang::ConstructJob(Compilation , const JobAction , CmdArgs.push_back("-fopenmp-assume-no-nested-parallelism"); if (Args.hasArg(options::OPT_fopenmp_offload_mandatory)) CmdArgs.push_back("-fopenmp-offload-mandatory"); + if (Args.hasArg(options::OPT_fopenmp_force_usm)) +CmdArgs.push_back("-fopenmp-force-usm"); break; default: // By default, if Clang doesn't know how to generate useful OpenMP code >From 11ad5633889870d897bfc4e77bc41b569e5ce539 Mon Sep 17 00:00:00 2001 From: JP Lehr Date: Wed, 12 Jul 2023 05:04:41 -0400 Subject: [PATCH 2/3] [OpenMP][USM] Adds test for -fopenmp-force-usm flag This adds a basic test to check the correct generation of double indirect access to declare target globals in USM mode vs non-USM mode. Marked as XFAIL to first land test and then enable in subsequent patch. --- clang/test/OpenMP/force-usm.c | 74 +++ 1 file changed, 74 insertions(+) create mode 100644 clang/test/OpenMP/force-usm.c diff --git