-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[mlir][spirv] Add definition for GL Log2 #143409
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-mlir-spirv @llvm/pr-subscribers-mlir Author: Igor Wodiany (IgWod-IMG) ChangesFull diff: https://github.com/llvm/llvm-project/pull/143409.diff 3 Files Affected:
diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
index 057dfac4d6308..8c5a0b858c42d 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
@@ -767,6 +767,36 @@ def SPIRV_GLTanhOp : SPIRV_GLUnaryArithmeticOp<"Tanh", 21, SPIRV_Float16or32> {
// -----
+def SPIRV_GLLog2Op : SPIRV_GLUnaryArithmeticOp<"Log2", 30, SPIRV_Float16or32> {
+ let summary = "Result is the base-2 logarithm of x";
+
+ let description = [{
+ Result is the base-2 logarithm of x, i.e., the value y which satisfies the
+ equation x = 2y. The resulting value is NaN if x < 0. Moreover:
+
+ ```
+ log(Inf) = Inf
+ log(1.0) = +0
+ log(±0) = -Inf
+ ```
+
+ The operand x must be a scalar or vector whose component type is 16-bit or
+ 32-bit floating-point.
+
+ Result Type and the type of x must be the same type. Results are computed
+ per component.
+
+ #### Example:
+
+ ```mlir
+ %2 = spirv.GL.Log2 %0 : f32
+ %3 = spirv.GL.Log2 %1 : vector<3xf16>
+ ```
+ }];
+}
+
+// -----
+
def SPIRV_GLFClampOp : SPIRV_GLTernaryArithmeticOp<"FClamp", 43, SPIRV_Float> {
let summary = "Clamp x between min and max values.";
diff --git a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
index 0be047932c1f3..8f8e9e3a2417d 100644
--- a/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
@@ -689,3 +689,29 @@ func.func @fract_invalid_type(%arg0 : i32) {
%0 = spirv.GL.Fract %arg0 : i32
return
}
+
+// -----
+
+//===----------------------------------------------------------------------===//
+// spirv.GL.Log2
+//===----------------------------------------------------------------------===//
+
+func.func @log2(%arg0 : f32) -> () {
+ // CHECK: spirv.GL.Log2 {{%.*}} : f32
+ %0 = spirv.GL.Log2 %arg0 : f32
+ return
+}
+
+func.func @log2vec(%arg0 : vector<3xf16>) -> () {
+ // CHECK: spirv.GL.Log2 {{%.*}} : vector<3xf16>
+ %0 = spirv.GL.Log2 %arg0 : vector<3xf16>
+ return
+}
+
+// -----
+
+func.func @log2_invalid_type(%arg0 : i32) -> () {
+ // expected-error @+1 {{op operand #0 must be 16/32-bit float or vector of 16/32-bit float values}}
+ %0 = spirv.GL.Log2 %arg0 : i32
+ return
+}
diff --git a/mlir/test/Target/SPIRV/gl-ops.mlir b/mlir/test/Target/SPIRV/gl-ops.mlir
index 7f9771220b75d..bd6cf5957fac6 100644
--- a/mlir/test/Target/SPIRV/gl-ops.mlir
+++ b/mlir/test/Target/SPIRV/gl-ops.mlir
@@ -34,6 +34,8 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
%15 = spirv.GL.FMix %arg0 : f32, %arg1 : f32, %arg0 : f32 -> f32
// CHECK: {{%.*}} = spirv.GL.Fract {{%.*}} : f32
%16 = spirv.GL.Fract %arg0 : f32
+ // CHECK: {{%.*}} = spirv.GL.Log2 {{%.*}} : f32
+ %17 = spirv.GL.Log2 %arg0 : f32
spirv.Return
}
|
kuhar
approved these changes
Jun 9, 2025
Co-authored-by: Jakub Kuderski <[email protected]>
rorth
pushed a commit
to rorth/llvm-project
that referenced
this pull request
Jun 11, 2025
tomtor
pushed a commit
to tomtor/llvm-project
that referenced
this pull request
Jun 14, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.