[Openmp-commits] [openmp] [offload] Add global addrspace qualifier to KLE and member pointers (PR #213918)
Robert Imschweiler via Openmp-commits
openmp-commits at lists.llvm.org
Tue Aug 4 05:09:19 PDT 2026
https://github.com/ro-i created https://github.com/llvm/llvm-project/pull/213918
Claude assisted with this patch.
>From f661a4b1c9acb60243f50cc1bcb5ab614f43a870 Mon Sep 17 00:00:00 2001
From: Robert Imschweiler <robert.imschweiler at amd.com>
Date: Tue, 4 Aug 2026 07:06:10 -0500
Subject: [PATCH] [offload] Add global addrspace qualifier to KLE and member
pointers
Claude assisted with this patch.
---
openmp/device/include/State.h | 2 +-
openmp/device/src/Reduction.cpp | 3 ++-
openmp/device/src/State.cpp | 10 +++++-----
3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/openmp/device/include/State.h b/openmp/device/include/State.h
index d3cd3d981e29d..f6e3250a9dfe1 100644
--- a/openmp/device/include/State.h
+++ b/openmp/device/include/State.h
@@ -123,7 +123,7 @@ void init(bool IsSPMD, KernelEnvironmentTy &KernelEnvironment,
/// holds for all instances of the kernel. The latter is dynamic and provides
/// per-launch information.
KernelEnvironmentTy &getKernelEnvironment();
-KernelLaunchEnvironmentTy &getKernelLaunchEnvironment();
+Global<KernelLaunchEnvironmentTy> &getKernelLaunchEnvironment();
/// TODO
enum ValueKind {
diff --git a/openmp/device/src/Reduction.cpp b/openmp/device/src/Reduction.cpp
index df444fb9d90e4..9d0a5121995af 100644
--- a/openmp/device/src/Reduction.cpp
+++ b/openmp/device/src/Reduction.cpp
@@ -256,7 +256,8 @@ int32_t __kmpc_gpu_xteam_reduce_nowait(IdentTy *Loc, void *reduce_data,
if (NumTeams <= 1)
return ThreadId == 0;
- uint32_t &TeamsDone = state::getKernelLaunchEnvironment().ReductionTeamsDone;
+ Global<uint32_t> &TeamsDone =
+ state::getKernelLaunchEnvironment().ReductionTeamsDone;
void *GlobalBuffer = state::getKernelLaunchEnvironment().ReductionBuffer;
[[clang::loader_uninitialized]] static Local<uint32_t> TeamsDoneResult;
diff --git a/openmp/device/src/State.cpp b/openmp/device/src/State.cpp
index 243af1f2cb5e2..779f4d5159311 100644
--- a/openmp/device/src/State.cpp
+++ b/openmp/device/src/State.cpp
@@ -36,9 +36,9 @@ using namespace ompx;
KernelEnvironmentPtr;
/// The kernel launch environment passed as argument to the kernel by the
-/// runtime.
-[[clang::loader_uninitialized]] static Local<KernelLaunchEnvironmentTy *>
- KernelLaunchEnvironmentPtr;
+/// runtime. (The runtime allocates it in device global memory.)
+[[clang::loader_uninitialized]] static Local<
+ Global<KernelLaunchEnvironmentTy> *> KernelLaunchEnvironmentPtr;
/// The pointer type for dynamic shared memory. This is important to keep
/// the alignment and address space information.
@@ -295,7 +295,7 @@ void state::init(bool IsSPMD, KernelEnvironmentTy &KernelEnvironment,
TeamState.init(IsSPMD);
ThreadStates = nullptr;
KernelEnvironmentPtr = &KernelEnvironment;
- KernelLaunchEnvironmentPtr = KLE;
+ KernelLaunchEnvironmentPtr = (Global<KernelLaunchEnvironmentTy> *)KLE;
}
}
@@ -303,7 +303,7 @@ KernelEnvironmentTy &state::getKernelEnvironment() {
return *KernelEnvironmentPtr;
}
-KernelLaunchEnvironmentTy &state::getKernelLaunchEnvironment() {
+Global<KernelLaunchEnvironmentTy> &state::getKernelLaunchEnvironment() {
return *KernelLaunchEnvironmentPtr;
}
More information about the Openmp-commits
mailing list