-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-mlir-spirv @llvm/pr-subscribers-mlir Author: Igor Wodiany (IgWod-IMG) ChangesWith 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 Full diff: https://github.com/llvm/llvm-project/pull/138685.diff 2 Files Affected:
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} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing // CHECK
line here?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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
andRelaxedPrecision
. 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.