Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[mlir][spirv] Add support for RelaxedPrecision in function arguments #138685

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

IgWod-IMG
Copy link
Contributor

With the current implementation only one attribute is attached to the argument and the deserializer fails if more decorations are specified, however I believe that the spec does not prohibit having both Aliased/Restrict and RelaxedPrecision. I am not sure how to attach multiple attributes to a single argument with the current code and at the same time I do not have a use case for it, so I think the patch in the current state is a good starting point and can be extended in the future.

@llvmbot
Copy link
Member

llvmbot commented May 6, 2025

@llvm/pr-subscribers-mlir-spirv

@llvm/pr-subscribers-mlir

Author: Igor Wodiany (IgWod-IMG)

Changes

With the current implementation only one attribute is attached to the argument and the deserializer fails if more decorations are specified, however I believe that the spec does not prohibit having both Aliased/Restrict and RelaxedPrecision. I am not sure how to attach multiple attributes to a single argument with the current code and at the same time I do not have a use case for it, so I think the patch in the current state is a good starting point and can be extended in the future.


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

2 Files Affected:

  • (modified) mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp (+11)
  • (modified) mlir/test/Target/SPIRV/decorations.mlir (+8)
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index 1e867dde51001..9b015448a6ac2 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -448,6 +448,17 @@ LogicalResult spirv::Deserializer::setFunctionArgAttrs(
       foundDecorationAttr = spirv::DecorationAttr::get(context, decoration);
       break;
     }
+
+    if (decAttr.getName() == getSymbolDecoration(stringifyDecoration(
+                                 spirv::Decoration::RelaxedPrecision))) {
+      if (foundDecorationAttr)
+        return emitError(unknownLoc, "already found a decoration for function "
+                                     "argument with result <id> ")
+               << argID;
+
+      foundDecorationAttr = spirv::DecorationAttr::get(
+          context, spirv::Decoration::RelaxedPrecision);
+    }
   }
 
   if (!foundDecorationAttr)
diff --git a/mlir/test/Target/SPIRV/decorations.mlir b/mlir/test/Target/SPIRV/decorations.mlir
index d66ac74dc4ef9..fac47f7bd1086 100644
--- a/mlir/test/Target/SPIRV/decorations.mlir
+++ b/mlir/test/Target/SPIRV/decorations.mlir
@@ -151,3 +151,11 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [CacheControlsINTEL], [SP
     spirv.Return
   }
 }
+
+// -----
+
+spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
+  spirv.func @relaxed_precision_arg(%arg0: !spirv.ptr<f32, Function> {spirv.decoration = #spirv.decoration<RelaxedPrecision>}) -> () "None" attributes {relaxed_precision} {
+    spirv.Return
+  }
+}

// -----

spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
spirv.func @relaxed_precision_arg(%arg0: !spirv.ptr<f32, Function> {spirv.decoration = #spirv.decoration<RelaxedPrecision>}) -> () "None" attributes {relaxed_precision} {
Copy link
Member

Choose a reason for hiding this comment

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

Missing // CHECK line here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's indeed missing. Fixed now.


if (decAttr.getName() == getSymbolDecoration(stringifyDecoration(
spirv::Decoration::RelaxedPrecision))) {
if (foundDecorationAttr)
Copy link
Member

Choose a reason for hiding this comment

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

This follows the old behavior which restricts it to only support one decoration per function parameter; we should relax this. But fine to do it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's good to know, I was wondering whether I missed something. I will leave the PR as it is, but I added a TODO, so it can be addressed in the future.

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