Skip to content

Commit e0326b6

Browse files
authored
[OpenMP] Map omp_default_mem_alloc to global memory (#104790)
Summary: Currently, we assign this to private memory. This causes failures on some SOLLVE tests. The standard isn't clear on the semantics of this allocation type, but there seems to be a consensus that it's supposed to be shared memory.
1 parent e6751bf commit e0326b6

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,14 +2048,12 @@ Address CGOpenMPRuntimeGPU::getAddressOfLocalVariable(CodeGenFunction &CGF,
20482048
const auto *A = VD->getAttr<OMPAllocateDeclAttr>();
20492049
auto AS = LangAS::Default;
20502050
switch (A->getAllocatorType()) {
2051-
// Use the default allocator here as by default local vars are
2052-
// threadlocal.
20532051
case OMPAllocateDeclAttr::OMPNullMemAlloc:
20542052
case OMPAllocateDeclAttr::OMPDefaultMemAlloc:
2055-
case OMPAllocateDeclAttr::OMPThreadMemAlloc:
20562053
case OMPAllocateDeclAttr::OMPHighBWMemAlloc:
20572054
case OMPAllocateDeclAttr::OMPLowLatMemAlloc:
2058-
// Follow the user decision - use default allocation.
2055+
break;
2056+
case OMPAllocateDeclAttr::OMPThreadMemAlloc:
20592057
return Address::invalid();
20602058
case OMPAllocateDeclAttr::OMPUserDefinedMemAlloc:
20612059
// TODO: implement aupport for user-defined allocators.
@@ -2208,11 +2206,11 @@ bool CGOpenMPRuntimeGPU::hasAllocateAttributeForGlobalVar(const VarDecl *VD,
22082206
case OMPAllocateDeclAttr::OMPNullMemAlloc:
22092207
case OMPAllocateDeclAttr::OMPDefaultMemAlloc:
22102208
// Not supported, fallback to the default mem space.
2211-
case OMPAllocateDeclAttr::OMPThreadMemAlloc:
22122209
case OMPAllocateDeclAttr::OMPLargeCapMemAlloc:
22132210
case OMPAllocateDeclAttr::OMPCGroupMemAlloc:
22142211
case OMPAllocateDeclAttr::OMPHighBWMemAlloc:
22152212
case OMPAllocateDeclAttr::OMPLowLatMemAlloc:
2213+
case OMPAllocateDeclAttr::OMPThreadMemAlloc:
22162214
AS = LangAS::Default;
22172215
return true;
22182216
case OMPAllocateDeclAttr::OMPConstMemAlloc:

clang/test/OpenMP/nvptx_allocate_codegen.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ void bar() {
8787
// CHECK1-SAME: () #[[ATTR0:[0-9]+]] {
8888
// CHECK1-NEXT: entry:
8989
// CHECK1-NEXT: [[RETVAL:%.*]] = alloca i32, align 4
90-
// CHECK1-NEXT: [[B:%.*]] = alloca double, align 8
9190
// CHECK1-NEXT: store i32 0, ptr [[RETVAL]], align 4
9291
// CHECK1-NEXT: store i32 2, ptr @_ZZ4mainE1a, align 4
93-
// CHECK1-NEXT: store double 3.000000e+00, ptr [[B]], align 8
92+
// CHECK1-NEXT: store double 3.000000e+00, ptr @b1, align 8
9493
// CHECK1-NEXT: [[CALL:%.*]] = call noundef i32 @_Z3fooIiET_v() #[[ATTR7:[0-9]+]]
9594
// CHECK1-NEXT: ret i32 [[CALL]]
9695
//

offload/test/api/omp_device_alloc.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
#include <stdio.h>
66

77
int main() {
8-
#pragma omp target teams num_teams(4)
9-
#pragma omp parallel
8+
#pragma omp target
109
{
11-
int *ptr = (int *)omp_alloc(sizeof(int), omp_default_mem_alloc);
10+
int *ptr;
11+
#pragma omp allocate(ptr) allocator(omp_default_mem_alloc)
12+
ptr = omp_alloc(sizeof(int), omp_default_mem_alloc);
1213
assert(ptr && "Ptr is (null)!");
13-
*ptr = 1;
14-
assert(*ptr == 1 && "Ptr is not 1");
14+
*ptr = 0;
15+
#pragma omp parallel num_threads(32)
16+
{
17+
#pragma omp atomic
18+
*ptr += 1;
19+
}
20+
assert(*ptr == 32 && "Ptr is not 32");
1521
omp_free(ptr, omp_default_mem_alloc);
1622
}
1723

0 commit comments

Comments
 (0)