From ac292abfcf0caad18fe23087706737d5608af03d Mon Sep 17 00:00:00 2001 From: Polykarpos Thomadakis Date: Fri, 13 Oct 2023 14:34:56 -0700 Subject: [PATCH] (#32) Fixed chain multiplication factorization pass. Also fixed compound multiplication (D=A*B*C) for dense tensors. --- .../compound_exps/Dense_chain_mult_matrix.ta | 30 +++++++++++++++++++ integration_test/opts/chain_mult_factorize.ta | 30 +++++++++++++++++++ .../Transforms/CheckImplicitTensorDecls.cpp | 1 + 3 files changed, 61 insertions(+) create mode 100644 integration_test/compound_exps/Dense_chain_mult_matrix.ta create mode 100644 integration_test/opts/chain_mult_factorize.ta diff --git a/integration_test/compound_exps/Dense_chain_mult_matrix.ta b/integration_test/compound_exps/Dense_chain_mult_matrix.ta new file mode 100644 index 00000000..4ba8acac --- /dev/null +++ b/integration_test/compound_exps/Dense_chain_mult_matrix.ta @@ -0,0 +1,30 @@ +# RUN: comet-opt --convert-ta-to-it --convert-to-loops --convert-to-llvm %s &> Dense_chain_mult_matrix.llvm +# RUN: mlir-cpu-runner Dense_chain_mult_matrix.llvm -O3 -e main -entry-point-result=void -shared-libs=%mlir_utility_library_dir/libmlir_runner_utils%shlibext,%comet_utility_library_dir/libcomet_runner_utils%shlibext | FileCheck %s + + +def main() { + #IndexLabel Declarations + IndexLabel [i] = [2]; + IndexLabel [j] = [2]; + IndexLabel [k] = [5]; + IndexLabel [l] = [2]; + + #Tensor Declarations + Tensor A([i, j], {Dense}); + Tensor B([j, k], {Dense}); + Tensor C([k, l], {Dense}); + Tensor D([i, l], {Dense}); + + #Tensor Fill Operation + A[i, j] = 2.2; + B[j, k] = 3.4; + C[k, l] = 1.0; + D[i, l] = 0.0; + + D[i, l] = A[i, j] * B[j, k] * C[k,l]; + print(D); +} + +# Print the result for verification. +# CHECK: data = +# CHECK-NEXT: 74.8,74.8,74.8,74.8, \ No newline at end of file diff --git a/integration_test/opts/chain_mult_factorize.ta b/integration_test/opts/chain_mult_factorize.ta new file mode 100644 index 00000000..47cc5e00 --- /dev/null +++ b/integration_test/opts/chain_mult_factorize.ta @@ -0,0 +1,30 @@ +# RUN: comet-opt --opt-multiop-factorize --convert-ta-to-it --convert-to-loops --convert-to-llvm %s &> chain_mult_factorize.llvm +# RUN: mlir-cpu-runner chain_mult_factorize.llvm -O3 -e main -entry-point-result=void -shared-libs=%mlir_utility_library_dir/libmlir_runner_utils%shlibext,%comet_utility_library_dir/libcomet_runner_utils%shlibext | FileCheck %s + + +def main() { + #IndexLabel Declarations + IndexLabel [i] = [2]; + IndexLabel [j] = [2]; + IndexLabel [k] = [5]; + IndexLabel [l] = [2]; + + #Tensor Declarations + Tensor A([i, j], {Dense}); + Tensor B([j, k], {Dense}); + Tensor C([k, l], {Dense}); + Tensor D([i, l], {Dense}); + + #Tensor Fill Operation + A[i, j] = 2.2; + B[j, k] = 3.4; + C[k, l] = 1.0; + D[i, l] = 0.0; + + D[i, l] = A[i, j] * B[j, k] * C[k,l]; + print(D); +} + +# Print the result for verification. +# CHECK: data = +# CHECK-NEXT: 74.8,74.8,74.8,74.8, \ No newline at end of file diff --git a/lib/Dialect/TensorAlgebra/Transforms/CheckImplicitTensorDecls.cpp b/lib/Dialect/TensorAlgebra/Transforms/CheckImplicitTensorDecls.cpp index 4e45711a..94d0f51d 100644 --- a/lib/Dialect/TensorAlgebra/Transforms/CheckImplicitTensorDecls.cpp +++ b/lib/Dialect/TensorAlgebra/Transforms/CheckImplicitTensorDecls.cpp @@ -178,6 +178,7 @@ void addTensorDecl(t op) if (ret_format.compare("Dense") == 0) { itensor = builder.create(location, ret_value.getType(), lbls_value, ret_format); + builder.create(location, itensor, builder.getF64FloatAttr(0)); } else {