Skip to content

[flang][cuda] Fix fir.cuda_kernel_launch assembly with no args #85987

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 1 commit into from
Mar 20, 2024

Conversation

clementval
Copy link
Contributor

When the kernel launch has no arguments, the generated parser was expecting at least a type to be present. Make the last part of the assemble format optional.
Add a run line to round-trip the output through fir-opt so we make sure the IR can be parsed and printed correctly.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Mar 20, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 20, 2024

@llvm/pr-subscribers-flang-fir-hlfir

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

When the kernel launch has no arguments, the generated parser was expecting at least a type to be present. Make the last part of the assemble format optional.
Add a run line to round-trip the output through fir-opt so we make sure the IR can be parsed and printed correctly.


Full diff: https://github.com/llvm/llvm-project/pull/85987.diff

2 Files Affected:

  • (modified) flang/include/flang/Optimizer/Dialect/FIROps.td (+1-1)
  • (modified) flang/test/Lower/CUDA/cuda-kernel-calls.cuf (+1)
diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 8a7e36e42457f5..b991ec76fdd956 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -2466,7 +2466,7 @@ def fir_CUDAKernelLaunch : fir_Op<"cuda_kernel_launch", [CallOpInterface,
   let assemblyFormat = [{
     $callee `<` `<` `<` $grid_x `,` $grid_y `,` $grid_z `,`$block_x `,`
         $block_y `,` $block_z ( `,` $bytes^ ( `,` $stream^ )? )? `>` `>` `>`
-        `` `(` $args `)` `:` `(` type($args) `)` attr-dict
+        `` `(` $args `)` ( `:` `(` type($args)^ `)` )? attr-dict
   }];
 
   let extraClassDeclaration = [{
diff --git a/flang/test/Lower/CUDA/cuda-kernel-calls.cuf b/flang/test/Lower/CUDA/cuda-kernel-calls.cuf
index f4327b3261751f..7e28fbb2231a2d 100644
--- a/flang/test/Lower/CUDA/cuda-kernel-calls.cuf
+++ b/flang/test/Lower/CUDA/cuda-kernel-calls.cuf
@@ -1,4 +1,5 @@
 ! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
+! RUN: bbc -emit-hlfir -fcuda %s -o - | fir-opt | FileCheck %s
 
 ! Test lowering of CUDA procedure calls.
 

Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

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

LGTM

@clementval clementval merged commit 0177a95 into llvm:main Mar 20, 2024
@clementval clementval deleted the cuda_kernel_launch_syntax_fix branch March 20, 2024 19:58
chencha3 pushed a commit to chencha3/llvm-project that referenced this pull request Mar 23, 2024
…85987)

When the kernel launch has no arguments, the generated parser was
expecting at least a type to be present. Make the last part of the
assemble format optional.
Add a run line to round-trip the output through fir-opt so we make sure
the IR can be parsed and printed correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants