[Mlir-commits] [mlir] [MLIR][NVVM] Add support for converting fp4/6/8 to fp16x2 (PR #162439)
Srinivasa Ravi
llvmlistbot at llvm.org
Wed Oct 8 04:05:45 PDT 2025
================
@@ -1855,6 +1855,55 @@ def NVVM_ConvertBF16x2ToF8x2Op : NVVM_Op<"convert.bf16x2.to.f8x2"> {
}];
}
+class NVVM_ConvertToFP16x2Op_Base <string srcType, Type srcArgType, string dstType>
+: NVVM_Op<"convert." # srcType # "x2.to." # !tolower(dstType) # "x2"> {
+ let summary = "Convert a pair of " # srcType # " inputs to " # !tolower(dstType) # "x2";
+ let description = [{
+ This Op converts the given }] # srcType # [{ inputs in a }] #
+ !if(!eq(srcType, "f4"), "packed i8", "i8x2 vector") # [{ to }] #
+ !tolower(dstType) # [{.
+
+ The result `dst` is represented as a vector of }] # !tolower(dstType) # [{ elements.
+ }] #
+ !if(!eq(dstType, "F16"),
+ [{The `relu` attribute, when set, lowers to the '.relu' variant of
+ the cvt instruction."}], "") # [{
+
+ [For more information, see PTX ISA](https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#data-movement-and-conversion-instructions-cvt)
+ }];
+ let results = (outs VectorOfLengthAndType<[2], [!cast<Type>(dstType)]>:$dst);
+ let arguments = !if(!eq(dstType, "F16"),
+ (ins srcArgType:$src,
+ DefaultValuedAttr<BoolAttr, "false">:$relu,
+ TypeAttr:$srcType),
+ (ins srcArgType:$src,
+ TypeAttr:$srcType));
+ let assemblyFormat = "$src attr-dict `:` type($src) `(` $srcType `)` `->` type($dst)";
+ let hasVerifier = 1;
+
+ let extraClassDeclaration = [{
+ static IDArgPair
+ getIntrinsicIDAndArgs(Operation &op, LLVM::ModuleTranslation &mt,
+ llvm::IRBuilderBase &builder);
+ }];
+
+ string llvmBuilder = [{
+ auto [intId, args] =
+ NVVM::Convert}] # !toupper(srcType) # [{x2To}] # dstType #
+ [{x2Op::getIntrinsicIDAndArgs(*op, moduleTranslation, builder);
+ $dst = createIntrinsicCall(builder, intId, args);
+ }];
+}
+
+def NVVM_ConvertF8x2ToF16x2Op :
+ NVVM_ConvertToFP16x2Op_Base<"f8", VectorOfLengthAndType<[2], [I8]>, "F16">;
----------------
Wolfram70 wrote:
Yeah, we'd have to do some string truncation in that case which I think will not be as clean as it currently.
https://github.com/llvm/llvm-project/pull/162439
More information about the Mlir-commits
mailing list