-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Flang][OpenMP] Add support for schedule clause for GPU #81618
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
Open
DominikAdamski
wants to merge
2
commits into
llvm:main
Choose a base branch
from
DominikAdamski:target_wsloop_static_schedule
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -683,38 +683,38 @@ template <typename Ty> class StaticLoopChunker { | |
Ty NumIters, | ||
bool OneIterationPerThread) { | ||
Ty KernelIteration = NumBlocks * BlockChunk; | ||
Ty BlockIV = BId * BlockChunk; | ||
|
||
// Start index in the chunked space. | ||
Ty IV = BId * BlockChunk + TId; | ||
ASSERT(IV >= 0, "Bad index"); | ||
|
||
ASSERT((BlockIV + TId * ThreadChunk) >= 0, "Bad index"); | ||
// Cover the entire iteration space, assumptions in the caller might allow | ||
// to simplify this loop to a conditional. | ||
do { | ||
|
||
Ty BlockChunkLeft = | ||
BlockChunk >= TId * ThreadChunk ? BlockChunk - TId * ThreadChunk : 0; | ||
Ty ThreadChunkLeft = | ||
ThreadChunk <= BlockChunkLeft ? ThreadChunk : BlockChunkLeft; | ||
|
||
while (ThreadChunkLeft--) { | ||
|
||
// Given the blocking it's hard to keep track of what to execute. | ||
if (IV >= NumIters) | ||
return; | ||
|
||
// Execute the loop body. | ||
LoopBody(IV, Arg); | ||
|
||
if (OneIterationPerThread) | ||
return; | ||
|
||
++IV; | ||
Ty ThreadIV = TId * ThreadChunk; | ||
// Cover the block space | ||
while (ThreadIV < BlockChunk) { | ||
Ty ThreadCnt = 0; | ||
// Cover the thread space | ||
while ((ThreadCnt < ThreadChunk) && | ||
((ThreadIV + ThreadCnt) < BlockChunk)) { | ||
// Index in the chunked space. | ||
Ty IV = BlockIV + ThreadIV + ThreadCnt; | ||
|
||
// Given the blocking it's hard to keep track of what to execute. | ||
if (IV >= NumIters) | ||
return; | ||
|
||
// Execute the loop body. | ||
LoopBody(IV, Arg); | ||
|
||
if (OneIterationPerThread) | ||
return; | ||
++ThreadCnt; | ||
Comment on lines
+695
to
+711
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to make this a for loop with a min condition:
|
||
}; | ||
ThreadIV += (NumThreads * ThreadChunk); | ||
} | ||
|
||
IV += KernelIteration; | ||
|
||
} while (IV < NumIters); | ||
BlockIV += KernelIteration; | ||
} while (BlockIV < NumIters); | ||
} | ||
|
||
public: | ||
|
@@ -731,8 +731,8 @@ template <typename Ty> class StaticLoopChunker { | |
// from the `omp` getter and not the mapping directly. | ||
Ty TId = omp_get_thread_num(); | ||
|
||
// There are no blocks involved here. | ||
Ty BlockChunk = 0; | ||
// There is only one block for the whole iteration space. | ||
Ty BlockChunk = NumIters; | ||
Ty NumBlocks = 1; | ||
Ty BId = 0; | ||
|
||
|
46 changes: 46 additions & 0 deletions
46
openmp/libomptarget/test/offloading/fortran/target_workshare_loop_static_chunk.f90
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
! Offloading test with a target region and chunks | ||
! REQUIRES: flang | ||
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO | ||
! UNSUPPORTED: aarch64-unknown-linux-gnu | ||
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO | ||
! UNSUPPORTED: x86_64-pc-linux-gnu | ||
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO | ||
|
||
! RUN: %libomptarget-compile-fortran-generic | ||
! RUN: env LIBOMPTARGET_INFO=16 %libomptarget-run-generic 2>&1 | %fcheck-generic | ||
|
||
program main | ||
use omp_lib | ||
integer :: A(100) | ||
!$omp target map(from:A) | ||
!$omp parallel do schedule(static,2) num_threads(10) | ||
do index_ = 1, 100 | ||
A(index_) = omp_get_team_num() * 1000 + omp_get_thread_num() | ||
end do | ||
!$omp end target | ||
write(*,"(A)"), "omp target parallel for thread chunk size 2" | ||
call printArray(A) | ||
|
||
end program main | ||
|
||
subroutine printArray(Array) | ||
integer :: Array(*) | ||
do i = 1, 100 | ||
write(*, "(A, I0, A, I0, A)", advance="no") "B",Array(i)/1000,"T",modulo(Array(i),1000)," " | ||
end do | ||
write(*,'(/)') | ||
end subroutine printArray | ||
|
||
!CHECK: omp target parallel for thread chunk size 2 | ||
|
||
!CHECK-NEXT: B0T0 B0T0 B0T1 B0T1 B0T2 B0T2 B0T3 B0T3 B0T4 B0T4 | ||
!CHECK-SAME: B0T5 B0T5 B0T6 B0T6 B0T7 B0T7 B0T8 B0T8 B0T9 B0T9 | ||
!CHECK-SAME: B0T0 B0T0 B0T1 B0T1 B0T2 B0T2 B0T3 B0T3 B0T4 B0T4 | ||
!CHECK-SAME: B0T5 B0T5 B0T6 B0T6 B0T7 B0T7 B0T8 B0T8 B0T9 B0T9 | ||
!CHECK-SAME: B0T0 B0T0 B0T1 B0T1 B0T2 B0T2 B0T3 B0T3 B0T4 B0T4 | ||
!CHECK-SAME: B0T5 B0T5 B0T6 B0T6 B0T7 B0T7 B0T8 B0T8 B0T9 B0T9 | ||
!CHECK-SAME: B0T0 B0T0 B0T1 B0T1 B0T2 B0T2 B0T3 B0T3 B0T4 B0T4 | ||
!CHECK-SAME: B0T5 B0T5 B0T6 B0T6 B0T7 B0T7 B0T8 B0T8 B0T9 B0T9 | ||
!CHECK-SAME: B0T0 B0T0 B0T1 B0T1 B0T2 B0T2 B0T3 B0T3 B0T4 B0T4 | ||
!CHECK-SAME: B0T5 B0T5 B0T6 B0T6 B0T7 B0T7 B0T8 B0T8 B0T9 B0T9 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need *ThreadChunk here too?
Let's say we have 5 blocks, and each block does a chunk of 3.
Each block has 11 threads and a chunk size of 2.
What I'd expect to work on in one iteration of the do loop below is:
So, 2 * 11 = 22 iterations for a block and 5 * 22 = 110 iterations for the kernel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current implementation matches clang chunking scheme.