-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into zhewen_channels
- Loading branch information
Showing
20 changed files
with
561 additions
and
272 deletions.
There are no files selected for viewing
This file contains 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
17 changes: 17 additions & 0 deletions
17
build_tools/ci/cpu_comparison/matmul_template/matmul4d_MxKxM0xK0_NxKxK0xN0.mlir
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// input ${M}x${K}x32x64x${TYPE1} | ||
// input ${N}x${K}x64x32x${TYPE1} | ||
|
||
func.func @matmul4d(%arg0: tensor<${M}x${K}x32x64x${TYPE1}>, %arg1: tensor<${N}x${K}x64x32x${TYPE1}>) -> tensor<${N}x${M}x32x32x${TYPE2}> { | ||
%cst = arith.constant ${ZERO} : ${TYPE2} | ||
%0 = tensor.empty() : tensor<${N}x${M}x32x32x${TYPE2}> | ||
%1 = linalg.fill ins(%cst : ${TYPE2}) outs(%0 : tensor<${N}x${M}x32x32x${TYPE2}>) -> tensor<${N}x${M}x32x32x${TYPE2}> | ||
%2 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2, d3, d4, d5) -> (d0, d2, d3, d5)>, affine_map<(d0, d1, d2, d3, d4, d5) -> (d1, d2, d5, d4)>, affine_map<(d0, d1, d2, d3, d4, d5) -> (d1, d0, d3, d4)>], iterator_types = ["parallel", "parallel", "reduction", "parallel", "parallel", "reduction"]} ins(%arg0, %arg1 : tensor<${M}x${K}x32x64x${TYPE1}>, tensor<${N}x${K}x64x32x${TYPE1}>) outs(%1 : tensor<${N}x${M}x32x32x${TYPE2}>) { | ||
^bb0(%in: ${TYPE1}, %in_1: ${TYPE1}, %out: ${TYPE2}): | ||
%12 = ${EXT} %in : ${TYPE1} to ${TYPE2} | ||
%13 = ${EXT} %in_1 : ${TYPE1} to ${TYPE2} | ||
%14 = ${MUL} %12, %13 : ${TYPE2} | ||
%15 = ${ADD} %out, %14 : ${TYPE2} | ||
linalg.yield %15 : ${TYPE2} | ||
} -> tensor<${N}x${M}x32x32x${TYPE2}> | ||
return %2 : tensor<${N}x${M}x32x32x${TYPE2}> | ||
} |
This file contains 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
33 changes: 33 additions & 0 deletions
33
build_tools/ci/cpu_comparison/matmul_template/matmul_trunci_scaling_MxK_KxN.mlir
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// input ${M}x${K}x${TYPE1} | ||
// input ${K}x${N}x${TYPE1} | ||
|
||
// Matmul + Trunci variant with scaling. | ||
// In an actual quantized model, truncating from a higher bitwidth to a lower precision bitwidth | ||
// won't work and we need to scale. | ||
// Since the output of the Matmul here is an integer cannot be multiplied with a floating point | ||
// scale factor, we need to represent the scale factor with a multiplier and a shift operator instead. | ||
func.func @matmul_trunci(%arg0: tensor<${M}x${K}x${TYPE1}>, %arg1: tensor<${K}x${N}x${TYPE1}>) -> tensor<${M}x${N}x${TYPE1}> | ||
{ | ||
%cst = arith.constant ${ZERO} : ${TYPE2} | ||
%cst_mul = arith.constant 10 : ${TYPE_MUL_RESULT} | ||
%cst_shift = arith.constant 7 : ${TYPE_MUL_RESULT} | ||
%0 = tensor.empty() : tensor<${M}x${N}x${TYPE2}> | ||
%i8out = tensor.empty() : tensor<${M}x${N}x${TYPE1}> | ||
%1 = linalg.fill ins(%cst : ${TYPE2}) outs(%0 : tensor<${M}x${N}x${TYPE2}>) -> tensor<${M}x${N}x${TYPE2}> | ||
%2 = linalg.matmul ins(%arg0, %arg1 : tensor<${M}x${K}x${TYPE1}>, tensor<${K}x${N}x${TYPE1}>) | ||
outs(%1: tensor<${M}x${N}x${TYPE2}>) -> tensor<${M}x${N}x${TYPE2}> | ||
%3 = linalg.generic {indexing_maps = [ | ||
affine_map<(d0, d1) -> (d0, d1)>, | ||
affine_map<(d0, d1) -> (d0, d1)> | ||
], | ||
iterator_types = ["parallel", "parallel"] | ||
} ins(%2 : tensor<${M}x${N}x${TYPE2}>) outs(%i8out : tensor<${M}x${N}x${TYPE1}>) { | ||
^bb0(%in: ${TYPE2}, %out: ${TYPE1}): | ||
%4 = arith.extsi %in : ${TYPE2} to ${TYPE_MUL_RESULT} | ||
%5 = arith.muli %4, %cst_mul : ${TYPE_MUL_RESULT} | ||
%6 = arith.shrsi %5, %cst_shift : ${TYPE_MUL_RESULT} | ||
%7 = arith.trunci %6 : ${TYPE_MUL_RESULT} to ${TYPE1} | ||
linalg.yield %7 : ${TYPE1} | ||
} -> tensor<${M}x${N}x${TYPE1}> | ||
return %3: tensor<${M}x${N}x${TYPE1}> | ||
} |
Oops, something went wrong.