llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[MLIR] XeVM `gpu-lower-to-xevm-pipeline` leaves scalar `math.isinf` unconverted

Open Zustin opened this issue 4 months ago • 2 comments

On LLVM main, the XeVM lowering pipeline leaves a scalar math.isinf operation inside an otherwise LLVM-lowered gpu.module. Kernel serialization then fails because the Math dialect operation cannot be translated to LLVM IR.

Input Program

input.mlir

module attributes {gpu.container_module} {
  gpu.module @kernels {
    gpu.func @classify_inf(%input : memref<1xf32>,
                           %output : memref<1xi32>) kernel {
      %c0 = arith.constant 0 : index
      %zero = arith.constant 0 : i32
      %one = arith.constant 1 : i32
      %value = memref.load %input[%c0] : memref<1xf32>
      %is_inf = math.isinf %value : f32
      %result = arith.select %is_inf, %one, %zero : i32
      memref.store %result, %output[%c0] : memref<1xi32>
      gpu.return
    }
  }
}

Reproduction Command

mlir-opt input.mlir '-gpu-lower-to-xevm-pipeline=xegpu-op-level=lane zebin-triple=spirv64-unknown-unknown zebin-chip=bmg opt-level=2 binary-format=fatbin'

The command fails with:

input.mlir:9:17: error: cannot be converted to LLVM IR: missing
LLVMTranslationDialectInterface registration for dialect for op: math.isinf
      %is_inf = math.isinf %value : f32
                ^
input.mlir:9:17: note: see current operation:
%3 = "math.isinf"(%2) ... : (f32) -> i1
input.mlir:2:3: error: Failed creating the llvm::Module.
input.mlir:2:3: error: An error happened while serializing the module.

Version: 13e5ce40eff159ed9b2db3660b41c47ca640ce51.

Zustin avatar Aug 03 '26 03:08 Zustin

@llvm/issue-subscribers-mlir

Author: Zustin

On LLVM main, the XeVM lowering pipeline leaves a scalar `math.isinf` operation inside an otherwise LLVM-lowered `gpu.module`. Kernel serialization then fails because the Math dialect operation cannot be translated to LLVM IR.

Input Program

input.mlir

module attributes {gpu.container_module} {
  gpu.module @<!-- -->kernels {
    gpu.func @<!-- -->classify_inf(%input : memref&lt;1xf32&gt;,
                           %output : memref&lt;1xi32&gt;) kernel {
      %c0 = arith.constant 0 : index
      %zero = arith.constant 0 : i32
      %one = arith.constant 1 : i32
      %value = memref.load %input[%c0] : memref&lt;1xf32&gt;
      %is_inf = math.isinf %value : f32
      %result = arith.select %is_inf, %one, %zero : i32
      memref.store %result, %output[%c0] : memref&lt;1xi32&gt;
      gpu.return
    }
  }
}

Reproduction Command

mlir-opt input.mlir '-gpu-lower-to-xevm-pipeline=xegpu-op-level=lane zebin-triple=spirv64-unknown-unknown zebin-chip=bmg opt-level=2 binary-format=fatbin'

The command fails with:

input.mlir:9:17: error: cannot be converted to LLVM IR: missing
LLVMTranslationDialectInterface registration for dialect for op: math.isinf
      %is_inf = math.isinf %value : f32
                ^
input.mlir:9:17: note: see current operation:
%3 = "math.isinf"(%2) ... : (f32) -&gt; i1
input.mlir:2:3: error: Failed creating the llvm::Module.
input.mlir:2:3: error: An error happened while serializing the module.

Version: 13e5ce40eff159ed9b2db3660b41c47ca640ce51.

I think there is already a PR for this: https://github.com/llvm/llvm-project/pull/184370

ktanishqk avatar Aug 03 '26 06:08 ktanishqk