Skip to content

Conversation

@ubfx
Copy link
Member

@ubfx ubfx commented Oct 24, 2024

Continuation of #3809 for the matmul tests.

@ubfx ubfx requested a review from zjgarvey October 24, 2024 11:08
@ubfx
Copy link
Member Author

ubfx commented Oct 24, 2024

linalg IR of one of the tests, showing the expected integer matmul op:

#map = affine_map<(d0, d1) -> (d0, d1)>
module {
  ml_program.global private mutable @global_seed(dense<0> : tensor<i64>) : tensor<i64>
  func.func @AtenMmQuint8(%arg0: tensor<3x4xi8>, %arg1: tensor<4x3xi8>) -> tensor<3x3xf32> {
    %c0_i32 = arith.constant 0 : i32
    %c-128_i8 = arith.constant -128 : i8
    %c0_i8 = arith.constant 0 : i8
    %c-1_i8 = arith.constant -1 : i8
    %c-63_i32 = arith.constant -63 : i32
    %c32_i32 = arith.constant 32 : i32
    %cst = arith.constant 4.278500e-03 : f64
    %0 = tensor.empty() : tensor<3x4xi8>
    %1 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel"]} ins(%arg0 : tensor<3x4xi8>) outs(%0 : tensor<3x4xi8>) {
    ^bb0(%in: i8, %out: i8):
      %11 = arith.cmpi ult, %in, %c0_i8 : i8
      %12 = arith.select %11, %c0_i8, %in : i8
      %13 = arith.cmpi uge, %12, %c-1_i8 : i8
      %14 = arith.select %13, %c-1_i8, %12 : i8
      linalg.yield %14 : i8
    } -> tensor<3x4xi8>
    %2 = tensor.empty() : tensor<4x3xi8>
    %3 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel"]} ins(%arg1 : tensor<4x3xi8>) outs(%2 : tensor<4x3xi8>) {
    ^bb0(%in: i8, %out: i8):
      %11 = arith.cmpi ult, %in, %c0_i8 : i8
      %12 = arith.select %11, %c0_i8, %in : i8
      %13 = arith.cmpi uge, %12, %c-1_i8 : i8
      %14 = arith.select %13, %c-1_i8, %12 : i8
      linalg.yield %14 : i8
    } -> tensor<4x3xi8>
    %4 = tensor.empty() : tensor<3x3xi32>
    %5 = linalg.fill ins(%c0_i32 : i32) outs(%4 : tensor<3x3xi32>) -> tensor<3x3xi32>
    %6 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel"]} ins(%1 : tensor<3x4xi8>) outs(%0 : tensor<3x4xi8>) {
    ^bb0(%in: i8, %out: i8):
      %11 = arith.addi %in, %c-128_i8 : i8
      linalg.yield %11 : i8
    } -> tensor<3x4xi8>
    %7 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel"]} ins(%3 : tensor<4x3xi8>) outs(%2 : tensor<4x3xi8>) {
    ^bb0(%in: i8, %out: i8):
      %11 = arith.addi %in, %c-128_i8 : i8
      linalg.yield %11 : i8
    } -> tensor<4x3xi8>
    %8 = linalg.quantized_matmul ins(%6, %7, %c-63_i32, %c32_i32 : tensor<3x4xi8>, tensor<4x3xi8>, i32, i32) outs(%5 : tensor<3x3xi32>) -> tensor<3x3xi32>
    %9 = tensor.empty() : tensor<3x3xf32>
    %10 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel"]} ins(%8 : tensor<3x3xi32>) outs(%9 : tensor<3x3xf32>) {
    ^bb0(%in: i32, %out: f32):
      %11 = arith.sitofp %in : i32 to f32
      %12 = arith.truncf %cst : f64 to f32
      %13 = arith.mulf %11, %12 : f32
      linalg.yield %13 : f32
    } -> tensor<3x3xf32>
    return %10 : tensor<3x3xf32>
  }
}

@ubfx ubfx merged commit 76209db into llvm:main Oct 24, 2024
3 checks passed
@ubfx ubfx deleted the fake-quant-matmul-tests branch October 24, 2024 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants