[Mlir-commits] [mlir] [mlir][spirv] Convert `bf16` to `spirv` as a `i16` (PR #76114)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Dec 20 17:25:11 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Rob Suderman (rsuderman)

<details>
<summary>Changes</summary>

`bf16` is not support currently in `spirv`. Current conversions treat it as an `i16` with bit-shifting, extending, and other manipulations. Change to `i16` appropriately.

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


1 Files Affected:

- (modified) mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp (+3) 


``````````diff
diff --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
index 2b79c8022b8e85..87f85314afad06 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
@@ -713,6 +713,9 @@ SPIRVTypeConverter::SPIRVTypeConverter(spirv::TargetEnvAttr targetAttr,
   });
 
   addConversion([this](FloatType floatType) -> std::optional<Type> {
+    if (floatType.isBF16())
+      return convertType(IntegerType::get(floatType.getContext(), 16));
+
     if (auto scalarType = dyn_cast<spirv::ScalarType>(floatType))
       return convertScalarType(this->targetEnv, this->options, scalarType);
     return Type();

``````````

</details>


https://github.com/llvm/llvm-project/pull/76114


More information about the Mlir-commits mailing list