@@ -5520,6 +5520,121 @@ func.func @torch.aten.mm$f32(%arg0: !torch.vtensor<[1,22],f32>, %arg1: !torch.vt
55205520 return %0 : !torch.vtensor<[1,10],f32>
55215521}
55225522
5523+ // -----
5524+ // CHECK-LABEL: func.func @torch.aten.addmm$f32
5525+ // CHECK: %[[MATMUL:.*]] = tosa.matmul
5526+ // CHECK-SAME: -> tensor<1x6x4xf32>
5527+ // CHECK: %[[ADD:.*]] = tosa.add
5528+ // CHECK-SAME: (tensor<1x6x4xf32>, tensor<1x1x4xf32>) -> tensor<1x6x4xf32>
5529+ // CHECK: %[[RESULT:.*]] = tosa.reshape %[[ADD]]
5530+ // CHECK-SAME: -> tensor<6x4xf32>
5531+ // CHECK-NOT: torch.aten.addmm
5532+ func.func @torch.aten.addmm$f32(%bias: !torch.vtensor<[4],f32>, %mat1: !torch.vtensor<[6,8],f32>, %mat2: !torch.vtensor<[8,4],f32>) -> !torch.vtensor<[6,4],f32> {
5533+ %one = torch.constant.int 1
5534+ %0 = torch.aten.addmm %bias, %mat1, %mat2, %one, %one : !torch.vtensor<[4],f32>, !torch.vtensor<[6,8],f32>, !torch.vtensor<[8,4],f32>, !torch.int, !torch.int -> !torch.vtensor<[6,4],f32>
5535+ return %0 : !torch.vtensor<[6,4],f32>
5536+ }
5537+
5538+ // -----
5539+ // CHECK-LABEL: func.func @torch.aten.addmm$scaled_f32
5540+ // CHECK: %[[MATMUL:.*]] = tosa.matmul
5541+ // CHECK-SAME: -> tensor<1x6x4xf32>
5542+ // CHECK-DAG: %[[BETA:.*]] = tosa.mul {{.*}} -> tensor<4xf32>
5543+ // CHECK-DAG: %[[ALPHA:.*]] = tosa.mul %[[MATMUL]]{{.*}} -> tensor<1x6x4xf32>
5544+ // CHECK: %[[ADD:.*]] = tosa.add
5545+ // CHECK-SAME: -> tensor<1x6x4xf32>
5546+ // CHECK: tosa.reshape %[[ADD]]
5547+ // CHECK-SAME: -> tensor<6x4xf32>
5548+ // CHECK-NOT: torch.aten.addmm
5549+ func.func @torch.aten.addmm$scaled_f32(%bias: !torch.vtensor<[4],f32>, %mat1: !torch.vtensor<[6,8],f32>, %mat2: !torch.vtensor<[8,4],f32>) -> !torch.vtensor<[6,4],f32> {
5550+ %two = torch.constant.int 2
5551+ %three = torch.constant.int 3
5552+ %0 = torch.aten.addmm %bias, %mat1, %mat2, %three, %two : !torch.vtensor<[4],f32>, !torch.vtensor<[6,8],f32>, !torch.vtensor<[8,4],f32>, !torch.int, !torch.int -> !torch.vtensor<[6,4],f32>
5553+ return %0 : !torch.vtensor<[6,4],f32>
5554+ }
5555+
5556+ // -----
5557+ // CHECK-LABEL: func.func @torch.aten.addmm$float_scalars_scalar_bias
5558+ // CHECK: %[[MATMUL:.*]] = tosa.matmul
5559+ // CHECK-SAME: -> tensor<1x6x4xf32>
5560+ // CHECK: tosa.mul %[[MATMUL]]
5561+ // CHECK-SAME: -> tensor<1x6x4xf32>
5562+ // CHECK: tosa.mul
5563+ // CHECK-SAME: -> tensor<f32>
5564+ // CHECK: %[[ADD:.*]] = tosa.add
5565+ // CHECK-SAME: -> tensor<1x6x4xf32>
5566+ // CHECK: tosa.reshape %[[ADD]]
5567+ // CHECK-SAME: -> tensor<6x4xf32>
5568+ // CHECK-NOT: torch.aten.addmm
5569+ func.func @torch.aten.addmm$float_scalars_scalar_bias(%bias: !torch.vtensor<[],f32>, %mat1: !torch.vtensor<[6,8],f32>, %mat2: !torch.vtensor<[8,4],f32>) -> !torch.vtensor<[6,4],f32> {
5570+ %half = torch.constant.float 5.000000e-01
5571+ %two = torch.constant.float 2.000000e+00
5572+ %0 = torch.aten.addmm %bias, %mat1, %mat2, %two, %half : !torch.vtensor<[],f32>, !torch.vtensor<[6,8],f32>, !torch.vtensor<[8,4],f32>, !torch.float, !torch.float -> !torch.vtensor<[6,4],f32>
5573+ return %0 : !torch.vtensor<[6,4],f32>
5574+ }
5575+
5576+ // -----
5577+ // CHECK-LABEL: func.func @torch.aten.addmm$beta_zero_f32
5578+ // CHECK: %[[MATMUL:.*]] = tosa.matmul
5579+ // CHECK-SAME: -> tensor<1x6x4xf32>
5580+ // CHECK-NOT: tosa.mul
5581+ // CHECK-NOT: tosa.add
5582+ // CHECK: tosa.reshape %[[MATMUL]]
5583+ // CHECK-SAME: -> tensor<6x4xf32>
5584+ // CHECK-NOT: torch.aten.addmm
5585+ func.func @torch.aten.addmm$beta_zero_f32(%bias: !torch.vtensor<[4],f32>, %mat1: !torch.vtensor<[6,8],f32>, %mat2: !torch.vtensor<[8,4],f32>) -> !torch.vtensor<[6,4],f32> {
5586+ %zero = torch.constant.int 0
5587+ %one = torch.constant.int 1
5588+ %0 = torch.aten.addmm %bias, %mat1, %mat2, %zero, %one : !torch.vtensor<[4],f32>, !torch.vtensor<[6,8],f32>, !torch.vtensor<[8,4],f32>, !torch.int, !torch.int -> !torch.vtensor<[6,4],f32>
5589+ return %0 : !torch.vtensor<[6,4],f32>
5590+ }
5591+
5592+ // -----
5593+ // CHECK-LABEL: func.func @torch.aten.addmm$f16
5594+ // CHECK: %[[MATMUL:.*]] = tosa.matmul
5595+ // CHECK-SAME: -> tensor<1x6x4xf32>
5596+ // CHECK: %[[CAST:.*]] = tosa.cast %[[MATMUL]]
5597+ // CHECK-SAME: -> tensor<1x6x4xf16>
5598+ // CHECK: %[[ADD:.*]] = tosa.add
5599+ // CHECK-SAME: -> tensor<1x6x4xf16>
5600+ // CHECK: tosa.reshape %[[ADD]]
5601+ // CHECK-SAME: -> tensor<6x4xf16>
5602+ // CHECK-NOT: torch.aten.addmm
5603+ func.func @torch.aten.addmm$f16(%bias: !torch.vtensor<[4],f16>, %mat1: !torch.vtensor<[6,8],f16>, %mat2: !torch.vtensor<[8,4],f16>) -> !torch.vtensor<[6,4],f16> {
5604+ %one = torch.constant.int 1
5605+ %0 = torch.aten.addmm %bias, %mat1, %mat2, %one, %one : !torch.vtensor<[4],f16>, !torch.vtensor<[6,8],f16>, !torch.vtensor<[8,4],f16>, !torch.int, !torch.int -> !torch.vtensor<[6,4],f16>
5606+ return %0 : !torch.vtensor<[6,4],f16>
5607+ }
5608+
5609+ // -----
5610+ // CHECK-LABEL: func.func @torch.aten.addmm$rank2_bias
5611+ // CHECK: %[[MATMUL:.*]] = tosa.matmul
5612+ // CHECK-SAME: -> tensor<1x6x4xf32>
5613+ // CHECK: %[[ADD:.*]] = tosa.add
5614+ // CHECK-SAME: -> tensor<1x6x4xf32>
5615+ // CHECK: tosa.reshape %[[ADD]]
5616+ // CHECK-SAME: -> tensor<6x4xf32>
5617+ // CHECK-NOT: torch.aten.addmm
5618+ func.func @torch.aten.addmm$rank2_bias(%bias: !torch.vtensor<[6,4],f32>, %mat1: !torch.vtensor<[6,8],f32>, %mat2: !torch.vtensor<[8,4],f32>) -> !torch.vtensor<[6,4],f32> {
5619+ %one = torch.constant.int 1
5620+ %0 = torch.aten.addmm %bias, %mat1, %mat2, %one, %one : !torch.vtensor<[6,4],f32>, !torch.vtensor<[6,8],f32>, !torch.vtensor<[8,4],f32>, !torch.int, !torch.int -> !torch.vtensor<[6,4],f32>
5621+ return %0 : !torch.vtensor<[6,4],f32>
5622+ }
5623+
5624+ // -----
5625+ // CHECK-LABEL: func.func @torch.aten.addmm$zero_k
5626+ // CHECK-NOT: tosa.matmul
5627+ // CHECK: %[[ZERO:.*]] = "tosa.const"()
5628+ // CHECK-SAME: tensor<6x4xf32>
5629+ // CHECK: %[[ADD:.*]] = tosa.add
5630+ // CHECK-SAME: (tensor<6x4xf32>, tensor<1x4xf32>) -> tensor<6x4xf32>
5631+ // CHECK-NOT: torch.aten.addmm
5632+ func.func @torch.aten.addmm$zero_k(%bias: !torch.vtensor<[4],f32>, %mat1: !torch.vtensor<[6,0],f32>, %mat2: !torch.vtensor<[0,4],f32>) -> !torch.vtensor<[6,4],f32> {
5633+ %one = torch.constant.int 1
5634+ %0 = torch.aten.addmm %bias, %mat1, %mat2, %one, %one : !torch.vtensor<[4],f32>, !torch.vtensor<[6,0],f32>, !torch.vtensor<[0,4],f32>, !torch.int, !torch.int -> !torch.vtensor<[6,4],f32>
5635+ return %0 : !torch.vtensor<[6,4],f32>
5636+ }
5637+
55235638// -----
55245639// CHECK-LABEL: func.func @torch.aten.mm$si8
55255640// CHECK: tosa.matmul
0 commit comments