[Mlir-commits] [mlir] 8939b5f - [mlir][spirv] Add printf op from SPIRV OpenCL extension set spec

Jakub Kuderski llvmlistbot at llvm.org
Wed May 31 13:44:49 PDT 2023


Author: Dimple Prajapati
Date: 2023-05-31T16:44:14-04:00
New Revision: 8939b5f5d2f30186a72f4ad44480ee9978663998

URL: https://github.com/llvm/llvm-project/commit/8939b5f5d2f30186a72f4ad44480ee9978663998
DIFF: https://github.com/llvm/llvm-project/commit/8939b5f5d2f30186a72f4ad44480ee9978663998.diff

LOG: [mlir][spirv] Add printf op from SPIRV OpenCL extension set spec

This change adds op to support printf instruction from OpenCL extensions set.
This op helps writing out debug details from SPIRV kernel in a given format.

Patch By: drprajap
Reviewed By: antiagainst, kuhar

Differential Revision: https://reviews.llvm.org/D151731

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
    mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
index 2561eca97c0c0..66ed2db681196 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
@@ -777,4 +777,48 @@ def SPIRV_CLUMinOp : SPIRV_CLBinaryArithmeticOp<"u_min", 159, SPIRV_Integer> {
   }];
 }
 
+// -----
+
+def SPIRV_CLPrintfOp : SPIRV_CLOp<"printf", 184, []> {
+  let summary = [{
+    The printf extended instruction writes output to an implementation-
+    defined stream such as stdout under control of the string pointed to by
+    format that specifies how subsequent arguments are converted for output.
+  }];
+
+  let description = [{
+    printf returns 0 if it was executed successfully and -1 otherwise.
+
+    Result Type must be i32.
+
+    Format must be a pointer(constant) to i8. If there are insufficient 
+    arguments for the format, the behavior is undefined. If the format 
+    is exhausted while arguments remain, the excess arguments are evaluated
+    (as always) but are otherwise ignored. The printf instruction returns 
+    when the end of the format string is encountered.
+
+    <!-- End of AutoGen section -->
+
+    #### Example:
+
+    ```mlir
+    %0 = spirv.CL.printf %0 %1 %2 : (!spirv.ptr<i8, UniformConstant>, (i32, i32)) -> i32
+    ```
+  }];
+
+  let arguments = (ins
+    SPIRV_AnyPtr:$format,
+    Variadic<SPIRV_Type>:$arguments
+  );
+  
+   let results = (outs
+    SPIRV_Integer:$result
+  );
+
+  let assemblyFormat = [{
+  $format `,` $arguments  attr-dict `:`  `(` type($format) `,` `(` type($arguments) `)` `)` `->` type($result)
+  }];
+
+  let hasVerifier = 0;
+}
 #endif // MLIR_DIALECT_SPIRV_IR_CL_OPS

diff  --git a/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
index 57a65d446d3fb..29a4a46136156 100644
--- a/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/ocl-ops.mlir
@@ -247,3 +247,16 @@ func.func @rintvec(%arg0 : vector<3xf16>) -> () {
   %0 = spirv.CL.rint %arg0 : vector<3xf16>
   return
 }
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.CL.printf
+//===----------------------------------------------------------------------===//
+// CHECK-LABEL: func.func @printf(
+func.func @printf(%arg0 : !spirv.ptr<i8, UniformConstant>, %arg1 : i32, %arg2 : i32) -> i32 {
+  // CHECK: spirv.CL.printf {{%.*}}, {{%.*}}, {{%.*}} : (!spirv.ptr<i8, UniformConstant>, (i32, i32)) -> i32
+  %0 = spirv.CL.printf %arg0, %arg1, %arg2 : (!spirv.ptr<i8, UniformConstant>, (i32, i32)) -> i32
+  return %0 : i32
+}
+


        


More information about the Mlir-commits mailing list