Skip to content

[mlir][spirv] Add definition for GL Exp2 #143678

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 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,34 @@ def SPIRV_GLAtanhOp : SPIRV_GLUnaryArithmeticOp<"Atanh", 24, SPIRV_Float16or32>

// -----

def SPIRV_GLExp2Op : SPIRV_GLUnaryArithmeticOp<"Exp2", 29, SPIRV_Float16or32> {
let summary = "Result is 2 raised to the x power";

let description = [{
Result is 2 raised to the x power; 2**x.

```
exp2(Inf) = Inf.
exp2(-Inf) = +0.
```

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.Exp2 %0 : f32
%3 = spirv.GL.Exp2 %1 : vector<3xf16>
```
}];
}

// -----

def SPIRV_GLLog2Op : SPIRV_GLUnaryArithmeticOp<"Log2", 30, SPIRV_Float16or32> {
let summary = "Result is the base-2 logarithm of x";

Expand Down
26 changes: 26 additions & 0 deletions mlir/test/Dialect/SPIRV/IR/gl-ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -789,3 +789,29 @@ func.func @tanh_invalid_type(%arg0 : i32) -> () {
%0 = spirv.GL.Tanh %arg0 : i32
return
}

// -----

//===----------------------------------------------------------------------===//
// spirv.GL.Exp2
//===----------------------------------------------------------------------===//

func.func @exp2(%arg0 : f32) -> () {
// CHECK: spirv.GL.Exp2 {{%.*}} : f32
%0 = spirv.GL.Exp2 %arg0 : f32
return
}

func.func @exp2vec(%arg0 : vector<3xf16>) -> () {
// CHECK: spirv.GL.Exp2 {{%.*}} : vector<3xf16>
%0 = spirv.GL.Exp2 %arg0 : vector<3xf16>
return
}

// -----

func.func @exp2_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.Exp2 %arg0 : i32
return
}
2 changes: 2 additions & 0 deletions mlir/test/Target/SPIRV/gl-ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader], []> {
%20 = spirv.GL.Log2 %arg0 : f32
// CHECK: {{%.*}} = spirv.GL.Tanh {{%.*}} : f32
%21 = spirv.GL.Tanh %arg0 : f32
// CHECK: {{%.*}} = spirv.GL.Exp2 {{%.*}} : f32
%22 = spirv.GL.Exp2 %arg0 : f32
spirv.Return
}

Expand Down
Loading