-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[flang][cuda] Support logical(4) in syncthread_and|count|or functions #164706
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
Conversation
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
Member
|
@llvm/pr-subscribers-flang-fir-hlfir Author: Valentin Clement (バレンタイン クレメン) (clementval) ChangesFull diff: https://github.com/llvm/llvm-project/pull/164706.diff 3 Files Affected:
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 29eedfb0ce9cd..d2a36d4bdcc86 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -989,9 +989,18 @@ static constexpr IntrinsicHandler handlers[]{
{"mask", asBox, handleDynamicOptional}}},
/*isElemental=*/false},
{"syncthreads", &I::genSyncThreads, {}, /*isElemental=*/false},
- {"syncthreads_and", &I::genSyncThreadsAnd, {}, /*isElemental=*/false},
- {"syncthreads_count", &I::genSyncThreadsCount, {}, /*isElemental=*/false},
- {"syncthreads_or", &I::genSyncThreadsOr, {}, /*isElemental=*/false},
+ {"syncthreads_and_i4", &I::genSyncThreadsAnd, {}, /*isElemental=*/false},
+ {"syncthreads_and_l4", &I::genSyncThreadsAnd, {}, /*isElemental=*/false},
+ {"syncthreads_count_i4",
+ &I::genSyncThreadsCount,
+ {},
+ /*isElemental=*/false},
+ {"syncthreads_count_l4",
+ &I::genSyncThreadsCount,
+ {},
+ /*isElemental=*/false},
+ {"syncthreads_or_i4", &I::genSyncThreadsOr, {}, /*isElemental=*/false},
+ {"syncthreads_or_l4", &I::genSyncThreadsOr, {}, /*isElemental=*/false},
{"syncwarp", &I::genSyncWarp, {}, /*isElemental=*/false},
{"system",
&I::genSystem,
diff --git a/flang/module/cudadevice.f90 b/flang/module/cudadevice.f90
index 22df9cdf410d5..5182950cbffea 100644
--- a/flang/module/cudadevice.f90
+++ b/flang/module/cudadevice.f90
@@ -21,23 +21,32 @@ module cudadevice
procedure :: syncthreads
end interface
- interface
- attributes(device) integer function syncthreads_and(value)
- integer, value :: value
+ interface syncthreads_and
+ attributes(device) integer function syncthreads_and_i4(value)
+ integer(4), value :: value
end function
- end interface
+ attributes(device) integer function syncthreads_and_l4(value)
+ logical(4), value :: value
+ end function
+ end interface syncthreads_and
- interface
- attributes(device) integer function syncthreads_count(value)
- integer, value :: value
+ interface syncthreads_count
+ attributes(device) integer function syncthreads_count_i4(value)
+ integer(4), value :: value
end function
- end interface
+ attributes(device) integer function syncthreads_count_l4(value)
+ logical(4), value :: value
+ end function
+ end interface syncthreads_count
- interface
- attributes(device) integer function syncthreads_or(value)
- integer, value :: value
+ interface syncthreads_or
+ attributes(device) integer function syncthreads_or_i4(value)
+ integer(4), value :: value
end function
- end interface
+ attributes(device) integer function syncthreads_or_l4(value)
+ logical(4), value :: value
+ end function
+ end interface syncthreads_or
interface
attributes(device) subroutine syncwarp(mask)
diff --git a/flang/test/Lower/CUDA/cuda-device-proc.cuf b/flang/test/Lower/CUDA/cuda-device-proc.cuf
index 29c348c5260a5..55bb587dcf681 100644
--- a/flang/test/Lower/CUDA/cuda-device-proc.cuf
+++ b/flang/test/Lower/CUDA/cuda-device-proc.cuf
@@ -12,17 +12,23 @@ attributes(global) subroutine devsub()
integer(8) :: al
integer(8) :: time
integer :: smalltime
- integer(4) :: res
+ integer(4) :: res, offset
integer(8) :: resl
+ integer :: tid
+ tid = threadIdx%x
+
call syncthreads()
call syncwarp(1)
call threadfence()
call threadfence_block()
call threadfence_system()
ret = syncthreads_and(1)
+ res = syncthreads_and(tid > offset)
ret = syncthreads_count(1)
+ ret = syncthreads_count(tid > offset)
ret = syncthreads_or(1)
+ ret = syncthreads_or(tid > offset)
ai = atomicadd(ai, 1_4)
al = atomicadd(al, 1_8)
@@ -100,9 +106,21 @@ end
! CHECK: fir.call @llvm.nvvm.membar.gl() fastmath<contract> : () -> ()
! CHECK: fir.call @llvm.nvvm.membar.cta() fastmath<contract> : () -> ()
! CHECK: fir.call @llvm.nvvm.membar.sys() fastmath<contract> : () -> ()
-! CHECK: %{{.*}} = fir.call @llvm.nvvm.barrier0.and(%c1_i32_0) fastmath<contract> : (i32) -> i32
-! CHECK: %{{.*}} = fir.call @llvm.nvvm.barrier0.popc(%c1_i32_1) fastmath<contract> : (i32) -> i32
-! CHECK: %{{.*}} = fir.call @llvm.nvvm.barrier0.or(%c1_i32_2) fastmath<contract> : (i32) -> i32
+! CHECK: %{{.*}} = fir.call @llvm.nvvm.barrier0.and(%c1{{.*}}) fastmath<contract> : (i32) -> i32
+! CHECK: %[[A:.*]] = fir.load %{{.*}} : !fir.ref<i32>
+! CHECK: %[[B:.*]] = fir.load %{{.*}} : !fir.ref<i32>
+! CHECK: %[[CMP:.*]] = arith.cmpi sgt, %[[A]], %[[B]] : i32
+! CHECK: %{{.*}} = fir.call @llvm.nvvm.barrier0.and(%[[CMP]])
+! CHECK: %{{.*}} = fir.call @llvm.nvvm.barrier0.popc(%c1{{.*}}) fastmath<contract> : (i32) -> i32
+! CHECK: %[[A:.*]] = fir.load %{{.*}} : !fir.ref<i32>
+! CHECK: %[[B:.*]] = fir.load %{{.*}} : !fir.ref<i32>
+! CHECK: %[[CMP:.*]] = arith.cmpi sgt, %[[A]], %[[B]] : i32
+! CHECK: %{{.*}} = fir.call @llvm.nvvm.barrier0.popc(%[[CMP]]) fastmath<contract> : (i1) -> i32
+! CHECK: %{{.*}} = fir.call @llvm.nvvm.barrier0.or(%c1{{.*}}) fastmath<contract> : (i32) -> i32
+! CHECK: %[[A:.*]] = fir.load %{{.*}} : !fir.ref<i32>
+! CHECK: %[[B:.*]] = fir.load %{{.*}} : !fir.ref<i32>
+! CHECK: %[[CMP:.*]] = arith.cmpi sgt, %[[A]], %[[B]] : i32
+! CHECK: %{{.*}} = fir.call @llvm.nvvm.barrier0.or(%[[CMP]]) fastmath<contract> : (i1) -> i32
! CHECK: %{{.*}} = llvm.atomicrmw add %{{.*}}, %{{.*}} seq_cst : !llvm.ptr, i32
! CHECK: %{{.*}} = llvm.atomicrmw add %{{.*}}, %{{.*}} seq_cst : !llvm.ptr, i64
! CHECK: %{{.*}} = llvm.atomicrmw fadd %{{.*}}, %{{.*}} seq_cst : !llvm.ptr, f32
|
wangzpgi
approved these changes
Oct 22, 2025
mikolaj-pirog
pushed a commit
to mikolaj-pirog/llvm-project
that referenced
this pull request
Oct 23, 2025
dvbuka
pushed a commit
to dvbuka/llvm-project
that referenced
this pull request
Oct 27, 2025
Lukacma
pushed a commit
to Lukacma/llvm-project
that referenced
this pull request
Oct 29, 2025
aokblast
pushed a commit
to aokblast/llvm-project
that referenced
this pull request
Oct 30, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.