Skip to content

Commit 7d166fa

Browse files
authored
[flang][cuda] Correct the number of blocks when setting the grid to * (llvm#121000)
We set the `gridX` argument of `_FortranACUFLaunchKernel` to `-1` when `*` is passed to the grid parameter. We store it in one of `dim3` members. However, `dim3` members are unsigned, so positive-value checks we use later, such as `gridDim.x > 0`, are invalid. This PR utilizes the original gird-size arguments to compute the number of blocks.
1 parent 0d6a584 commit 7d166fa

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

flang/runtime/CUDA/kernel.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ void RTDEF(CUFLaunchKernel)(const void *kernel, intptr_t gridX, intptr_t gridY,
4848
maxBlocks = multiProcCount * maxBlocks;
4949
}
5050
if (maxBlocks > 0) {
51-
if (gridDim.x > 0) {
51+
if (gridX > 0) {
5252
maxBlocks = maxBlocks / gridDim.x;
5353
}
54-
if (gridDim.y > 0) {
54+
if (gridY > 0) {
5555
maxBlocks = maxBlocks / gridDim.y;
5656
}
57-
if (gridDim.z > 0) {
57+
if (gridZ > 0) {
5858
maxBlocks = maxBlocks / gridDim.z;
5959
}
6060
if (maxBlocks < 1) {
@@ -113,13 +113,13 @@ void RTDEF(CUFLaunchClusterKernel)(const void *kernel, intptr_t clusterX,
113113
maxBlocks = multiProcCount * maxBlocks;
114114
}
115115
if (maxBlocks > 0) {
116-
if (config.gridDim.x > 0) {
116+
if (gridX > 0) {
117117
maxBlocks = maxBlocks / config.gridDim.x;
118118
}
119-
if (config.gridDim.y > 0) {
119+
if (gridY > 0) {
120120
maxBlocks = maxBlocks / config.gridDim.y;
121121
}
122-
if (config.gridDim.z > 0) {
122+
if (gridZ > 0) {
123123
maxBlocks = maxBlocks / config.gridDim.z;
124124
}
125125
if (maxBlocks < 1) {

0 commit comments

Comments
 (0)