Skip to content

[OpenMP] Map omp_default_mem_alloc to global memory #104790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2048,14 +2048,12 @@ Address CGOpenMPRuntimeGPU::getAddressOfLocalVariable(CodeGenFunction &CGF,
const auto *A = VD->getAttr<OMPAllocateDeclAttr>();
auto AS = LangAS::Default;
switch (A->getAllocatorType()) {
// Use the default allocator here as by default local vars are
// threadlocal.
case OMPAllocateDeclAttr::OMPNullMemAlloc:
case OMPAllocateDeclAttr::OMPDefaultMemAlloc:
case OMPAllocateDeclAttr::OMPThreadMemAlloc:
case OMPAllocateDeclAttr::OMPHighBWMemAlloc:
case OMPAllocateDeclAttr::OMPLowLatMemAlloc:
// Follow the user decision - use default allocation.
break;
case OMPAllocateDeclAttr::OMPThreadMemAlloc:
return Address::invalid();
case OMPAllocateDeclAttr::OMPUserDefinedMemAlloc:
// TODO: implement aupport for user-defined allocators.
Expand Down Expand Up @@ -2208,11 +2206,11 @@ bool CGOpenMPRuntimeGPU::hasAllocateAttributeForGlobalVar(const VarDecl *VD,
case OMPAllocateDeclAttr::OMPNullMemAlloc:
case OMPAllocateDeclAttr::OMPDefaultMemAlloc:
// Not supported, fallback to the default mem space.
case OMPAllocateDeclAttr::OMPThreadMemAlloc:
case OMPAllocateDeclAttr::OMPLargeCapMemAlloc:
case OMPAllocateDeclAttr::OMPCGroupMemAlloc:
case OMPAllocateDeclAttr::OMPHighBWMemAlloc:
case OMPAllocateDeclAttr::OMPLowLatMemAlloc:
case OMPAllocateDeclAttr::OMPThreadMemAlloc:
AS = LangAS::Default;
return true;
case OMPAllocateDeclAttr::OMPConstMemAlloc:
Expand Down
3 changes: 1 addition & 2 deletions clang/test/OpenMP/nvptx_allocate_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ void bar() {
// CHECK1-SAME: () #[[ATTR0:[0-9]+]] {
// CHECK1-NEXT: entry:
// CHECK1-NEXT: [[RETVAL:%.*]] = alloca i32, align 4
// CHECK1-NEXT: [[B:%.*]] = alloca double, align 8
// CHECK1-NEXT: store i32 0, ptr [[RETVAL]], align 4
// CHECK1-NEXT: store i32 2, ptr @_ZZ4mainE1a, align 4
// CHECK1-NEXT: store double 3.000000e+00, ptr [[B]], align 8
// CHECK1-NEXT: store double 3.000000e+00, ptr @b1, align 8
// CHECK1-NEXT: [[CALL:%.*]] = call noundef i32 @_Z3fooIiET_v() #[[ATTR7:[0-9]+]]
// CHECK1-NEXT: ret i32 [[CALL]]
//
Expand Down
16 changes: 11 additions & 5 deletions offload/test/api/omp_device_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
#include <stdio.h>

int main() {
#pragma omp target teams num_teams(4)
#pragma omp parallel
#pragma omp target
{
int *ptr = (int *)omp_alloc(sizeof(int), omp_default_mem_alloc);
int *ptr;
#pragma omp allocate(ptr) allocator(omp_default_mem_alloc)
ptr = omp_alloc(sizeof(int), omp_default_mem_alloc);
assert(ptr && "Ptr is (null)!");
*ptr = 1;
assert(*ptr == 1 && "Ptr is not 1");
*ptr = 0;
#pragma omp parallel num_threads(32)
{
#pragma omp atomic
*ptr += 1;
}
assert(*ptr == 32 && "Ptr is not 32");
omp_free(ptr, omp_default_mem_alloc);
}

Expand Down
Loading