Skip to content

Conversation

@IgWod-IMG
Copy link
Contributor

Creating this patch as an example on using the new mlir-translate flag. Eventually all tests will be updated to validate SPIR-V modules.

@llvmbot
Copy link
Member

llvmbot commented Aug 12, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-spirv

Author: Igor Wodiany (IgWod-IMG)

Changes

Creating this patch as an example on using the new mlir-translate flag. Eventually all tests will be updated to validate SPIR-V modules.


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

1 Files Affected:

  • (modified) mlir/test/Target/SPIRV/module.mlir (+13-5)
diff --git a/mlir/test/Target/SPIRV/module.mlir b/mlir/test/Target/SPIRV/module.mlir
index dcdcab8097e41..e610001a3a71f 100644
--- a/mlir/test/Target/SPIRV/module.mlir
+++ b/mlir/test/Target/SPIRV/module.mlir
@@ -1,21 +1,29 @@
-// RUN: mlir-translate -no-implicit-module -test-spirv-roundtrip -split-input-file %s | FileCheck %s
+// RUN: mlir-translate --no-implicit-module --test-spirv-roundtrip --split-input-file %s | FileCheck %s
+
+// REQUIRES: shell
+// RUN: %if spirv-tools %{ rm -rf %t %}
+// RUN: %if spirv-tools %{ mkdir %t && mlir-translate --no-implicit-module --serialize-spirv \ %}
+// RUN: %if spirv-tools %{ --split-input-file --spirv-save-validation-files-with-prefix=%t/module %s \ %}
+// RUN: %if spirv-tools %{ && ls %t/module* | xargs -I{} bash -c 'spirv-val {}' %}
 
 // CHECK:      spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
 // CHECK-NEXT:   spirv.func @foo() "Inline" {
 // CHECK-NEXT:     spirv.Return
 // CHECK-NEXT:   }
+// CHECK-NEXT:   spirv.EntryPoint "Vertex" @foo
 // CHECK-NEXT: }
 
 spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
   spirv.func @foo() -> () "Inline" {
      spirv.Return
   }
+  spirv.EntryPoint "Vertex" @foo
 }
 
 // -----
 
 // CHECK: v1.5
-spirv.module Logical GLSL450 requires #spirv.vce<v1.5, [Shader], []> {
+spirv.module Logical GLSL450 requires #spirv.vce<v1.5, [Shader, Linkage], []> {
 }
 
 // -----
@@ -26,13 +34,13 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.6, [Shader, Linkage], []> {
 
 // -----
 
-// CHECK: [Shader, Float16]
-spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Float16], []> {
+// CHECK: [Shader, Float16, Linkage]
+spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Float16, Linkage], []> {
 }
 
 // -----
 
 // CHECK: [SPV_KHR_float_controls, SPV_KHR_subgroup_vote]
-spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], [SPV_KHR_float_controls, SPV_KHR_subgroup_vote]> {
+spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], [SPV_KHR_float_controls, SPV_KHR_subgroup_vote]> {
 }
 

@IgWod-IMG
Copy link
Contributor Author

One more thing. Do we want to use the xargs approach (or similar) across the tests or should we try first to teach spirv-val to consume multiple files / directories?

I'll also update the SPIR-V dialect documentation once this PR is merged to make it clear in the contributions section that Target tests need to be validated.

CC @davidegrohmann @mahabadm

@IgWod-IMG IgWod-IMG changed the title [mlir][spirv] Add spirv validation for modules.mlir [mlir][spirv] Add spirv validation for module.mlir target test Aug 12, 2025
Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

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

Nice to see it caught legitimate issues already

Copy link
Member

Choose a reason for hiding this comment

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

Can we specify the extension?

Also, why not xargs -I{} spirv-val {}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by the extension?

Also, why not xargs -I{} spirv-val {}?

Good point, I'll simplfy it. The current code was an evolution of various attempts.

Copy link
Member

Choose a reason for hiding this comment

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

File extension like .spv

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To have an extension I need to update the logic that writes files. I created a seperate PR #153440 for that.

@kuhar
Copy link
Member

kuhar commented Aug 12, 2025

Do we want to use the xargs approach (or similar) across the tests or should we try first to teach spirv-val to consume multiple files / directories?

I think it's fine to have xargs / for loop in a single test like this one, but I wouldn't use it elsewhere until spirv-val learns to take directories.

Creating this patch as an example on using the new
`mlir-translate` flag. Eventually all the tests will
be updated to validate SPIR-V modules.
@IgWod-IMG IgWod-IMG force-pushed the img_modules-mlir-test-validation branch from fce65ed to e4decc3 Compare August 14, 2025 07:36
@IgWod-IMG
Copy link
Contributor Author

I had to replace:

// RUN: %if spirv-tools %{ mkdir %t && mlir-translate --no-implicit-module --serialize-spirv \ %}
// RUN: %if spirv-tools %{ --split-input-file --spirv-save-validation-files-with-prefix=%t/module %s \ %}
// RUN: %if spirv-tools %{ && ls %t/module* | xargs -I{} spirv-val {} %}

with the code below, where every command occupies a single RUN line. This makes mlir-translate to go over the ~80 character limit, however there seem to be issues when conditional substitution and line splitting (\) are used together - shell parser keep tripping over (e.g., shell parser error on RUN: at line 7: && ls /home/user/build-debug/tools/mlir/test/Target/SPIRV/Output/module.mlir.tmp/module*.spv | xargs -I{}/home/user/build-debug/./bin/spirv-val {}).

// RUN: %if spirv-tools %{ mkdir %t %}
// RUN: %if spirv-tools %{ mlir-translate --no-implicit-module --serialize-spirv --split-input-file --spirv-save-validation-files-with-prefix=%t/module %s %}
// RUN: %if spirv-tools %{ ls %t/module*.spv | xargs -I{} spirv-val {} %}

@IgWod-IMG IgWod-IMG merged commit 87de48d into llvm:main Aug 14, 2025
10 checks passed
@IgWod-IMG IgWod-IMG deleted the img_modules-mlir-test-validation branch August 14, 2025 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants