Skip to content
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

[Clang][OpenMP] Clang adding the addrSpace according to DataLayout fix #65483

Merged
merged 4 commits into from
Sep 12, 2023
Merged

[Clang][OpenMP] Clang adding the addrSpace according to DataLayout fix #65483

merged 4 commits into from
Sep 12, 2023

Conversation

ajarmusch
Copy link
Contributor

Fix for an issue where clang was not adding the address space according to the data layout, instead was using the default which resulted in a crash at times. The fix includes changes to the cases of LargeCapMemAlloc and CGroupMemAlloc where we are setting the AddrSpace according to the DataLayout.

@ajarmusch ajarmusch added clang Clang issues not falling into any other category openmp labels Sep 6, 2023
@ajarmusch ajarmusch requested a review from a team as a code owner September 6, 2023 14:08
@ajarmusch ajarmusch self-assigned this Sep 6, 2023
@@ -3362,6 +3362,8 @@ Address CGOpenMPRuntimeGPU::getAddressOfLocalVariable(CodeGenFunction &CGF,
break;
case OMPAllocateDeclAttr::OMPLargeCapMemAlloc:
case OMPAllocateDeclAttr::OMPCGroupMemAlloc:
if (VD->hasGlobalStorage())
AS = getLangASFromTargetAS(CGF.CGM.getModule().getDataLayout().getDefaultGlobalsAddressSpace());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is only for globals, so we don't need to check VD after all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the global variable check

@alexey-bataev
Copy link
Member

Tests?

@shiltian shiltian requested a review from a team September 8, 2023 19:28
@ajarmusch
Copy link
Contributor Author

@alexey-bataev sorry for the delay - the test is up

Comment on lines 102 to 110
#pragma omp target uses_allocators(omp_large_cap_mem_alloc) allocate(omp_large_cap_mem_alloc: x) firstprivate(x) map(from: device_result)
{
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
x += j + i;
}
}
device_result = x;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you simplify the test? We need just an empty target region, everything else can be dropped

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look now. Is that reduced enough?

Copy link
Member

@alexey-bataev alexey-bataev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@ajarmusch ajarmusch requested review from a team as code owners September 12, 2023 19:31
@ajarmusch ajarmusch merged commit e831a32 into llvm:main Sep 12, 2023
2 checks passed
@jrtc27
Copy link
Collaborator

jrtc27 commented Sep 12, 2023

The title isn't a proper commit subject, the tense/mood doesn't make sense

@@ -3362,6 +3362,7 @@ Address CGOpenMPRuntimeGPU::getAddressOfLocalVariable(CodeGenFunction &CGF,
break;
case OMPAllocateDeclAttr::OMPLargeCapMemAlloc:
case OMPAllocateDeclAttr::OMPCGroupMemAlloc:
AS = getLangASFromTargetAS(CGF.CGM.getModule().getDataLayout().getDefaultGlobalsAddressSpace());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is way too long compared to the 80 char line limit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see, what would be the best way to update that line? Push a commit or create another PR?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running clang-format on your commit (but just your commit, and only accepting changes to the lines you've changed, i.e. just this line) to fix this doesn't need pre-commit review

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks I updated it

@jplehr
Copy link
Contributor

jplehr commented Sep 12, 2023

I believe this broke one of the AMDGPU OpenMP buildbots https://lab.llvm.org/staging/#/builders/247/builds/6351

@dyung
Copy link
Collaborator

dyung commented Sep 12, 2023

This change seems to have broken quite a few build bots including:

https://lab.llvm.org/buildbot/#/builders/216/builds/27184
https://lab.llvm.org/buildbot/#/builders/139/builds/49574
https://lab.llvm.org/buildbot/#/builders/247/builds/8920

Could you please take a look and revert if you need time to investigate?

@ajarmusch
Copy link
Contributor Author

Yes I can

ajarmusch added a commit that referenced this pull request Sep 12, 2023
@gulfemsavrun
Copy link
Contributor

We also started seeing a test failure after this commit:

FAIL: Clang :: OpenMP/test_target_uses_allocators_large_cap_codegen.cpp (13374 of 19273)
--
/b/s/w/ir/x/w/llvm-llvm-project/clang/test/OpenMP/test_target_uses_allocators_large_cap_codegen.cpp:167:18: error: CHECK1-LABEL: expected string not found in input
// CHECK1-LABEL: define internal void @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z30test_uses_allocators_large_capv_l102(
                 ^
<stdin>:20:75: note: scanning from here
define dso_local noundef signext i32 @_Z30test_uses_allocators_large_capv() #0 {
                                                                          ^
<stdin>:87:1: note: possible intended match here
define internal void @__omp_offloading_801_2c05cbb__Z30test_uses_allocators_large_capv_l94(i64 noundef %x) #1 {
^

Input file: <stdin>
Check file: /b/s/w/ir/x/w/llvm-llvm-project/clang/test/OpenMP/test_target_uses_allocators_large_cap_codegen.cpp

-dump-input=help explains the following input dump.

Input was:
<<<<<<
             .
             .
             .
            15: @.omp_offloading.entry_name = internal unnamed_addr constant [69 x i8] c"__omp_offloading_801_2c05cbb__Z30test_uses_allocators_large_capv_l94\00" 
            16: @.omp_offloading.entry.__omp_offloading_801_2c05cbb__Z30test_uses_allocators_large_capv_l94 = weak constant %struct.__tgt_offload_entry { ptr @.__omp_offloading_801_2c05cbb__Z30test_uses_allocators_large_capv_l94.region_id, ptr @.omp_offloading.entry_name, i64 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1 
            17: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @.omp_offloading.requires_reg, ptr null }] 
            18:  
            19: ; Function Attrs: mustprogress noinline nounwind optnone 
            20: define dso_local noundef signext i32 @_Z30test_uses_allocators_large_capv() #0 { 
label:167'0                                                                               X~~~~~~ error: no match found
            21: entry: 
label:167'0     ~~~~~~~
            22:  %x = alloca i32, align 4 
label:167'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~
            23:  %device_result = alloca i32, align 4 
label:167'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            24:  %x.casted = alloca i64, align 8 
label:167'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            25:  %.offload_baseptrs = alloca [2 x ptr], align 8 
label:167'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             .
             .
             .
            82: omp_offload.cont: ; preds = %omp_offload.failed, %entry 
label:167'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            83:  ret i32 0 
label:167'0     ~~~~~~~~~~~
            84: } 
label:167'0     ~~
            85:  
label:167'0     ~
            86: ; Function Attrs: noinline norecurse nounwind optnone 
label:167'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            87: define internal void @__omp_offloading_801_2c05cbb__Z30test_uses_allocators_large_capv_l94(i64 noundef %x) #1 { 
label:167'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
label:167'1     ?                                                                                                                possible intended match
            88: entry: 
label:167'0     ~~~~~~~
            89:  %x.addr = alloca i64, align 8 
label:167'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            90:  %0 = call i32 @__kmpc_global_thread_num(ptr @1) 
label:167'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            91:  store i64 %x, ptr %x.addr, align 8 
label:167'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            92:  %.x..void.addr = call ptr @__kmpc_alloc(i32 %0, i64 4, ptr inttoptr (i64 2 to ptr)) 
label:167'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             .
             .
             .
>>>>>>

--

https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8770130626803585601/+/u/clang/test/stdout

@ajarmusch
Copy link
Contributor Author

@gulfemsavrun I reverted the commit and am currently trying to fix the issue.

ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
llvm#65483)

Fix for an issue where clang was not adding the address space according
to the data layout, instead was using the default which resulted in a
crash at times. The fix includes changes to the cases of
LargeCapMemAlloc and CGroupMemAlloc where we are setting the AddrSpace
according to the DataLayout.
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen clang Clang issues not falling into any other category openmp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants