Skip to content

Commit a093563

Browse files
committed
Error fixes in adding allBlocks to IT #20
1 parent 065f76d commit a093563

File tree

11 files changed

+1171
-568
lines changed

11 files changed

+1171
-568
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
2929
if (MSVC)
3030
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c- /GR-")
3131
else ()
32-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
32+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -g")
3333
endif ()
3434

3535
#-------------------------------------------------------------------------------

first.mlir

+1,074-542
Large diffs are not rendered by default.

first.ta

+33-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
1+
# Sparse matrix sparse matrix elementwise addition
2+
# Sparse matrix is in CSR format. Currently workspace transformation on the IndexTree dialect works for only CSR format
3+
# RUN: comet-opt --opt-comp-workspace --convert-ta-to-it --convert-to-loops --convert-to-llvm %s &> eltwise_add_CSRxCSR_oCSR.llvm
4+
# RUN: export SPARSE_FILE_NAME0=%comet_integration_test_data_dir/test_rank2.mtx
5+
# RUN: export SPARSE_FILE_NAME1=%comet_integration_test_data_dir/test_rank2_transpose.mtx
6+
# RUN: mlir-cpu-runner eltwise_add_CSRxCSR_oCSR.llvm -O3 -e main -entry-point-result=void -shared-libs=%comet_utility_library_dir/libcomet_runner_utils%shlibext | FileCheck %s
7+
8+
19
def main() {
2-
#IndexLabel Declarations
3-
IndexLabel [a] = [?];
4-
IndexLabel [b] = [?];
10+
#IndexLabel Declarations
11+
IndexLabel [i] = [?];
12+
IndexLabel [j] = [?];
13+
14+
#Tensor Declarations
15+
Tensor<double> A([i, j], {CSR});
16+
Tensor<double> B([i, j], {CSR});
17+
Tensor<double> C([i, j], {CSR});
518

6-
Tensor<double> A([a, b], {CSR});
7-
Tensor<double> B([b, a], {Dense});
8-
Tensor<double> C([b, a], {Dense});
9-
10-
A[a, b] = comet_read(0);
11-
B[b, a] = 1.0;
12-
C[b, a] = A[a, b] * B[b, a];
13-
#C[b, a] = 1.0;
19+
#Tensor Readfile Operation
20+
A[i, j] = comet_read(0);
21+
B[i, j] = comet_read(1);
1422

15-
print(A);
16-
print(B);
17-
print(C);
23+
#Tensor Contraction
24+
C[i, j] = A[i, j] + B[i, j];
25+
print(C);
1826
}
1927

28+
# Print the result for verification.
29+
# CHECK: data =
30+
# CHECK-NEXT: 5,
31+
# CHECK-NEXT: data =
32+
# CHECK-NEXT: 0,
33+
# CHECK-NEXT: data =
34+
# CHECK-NEXT: 0,2,4,5,7,9,
35+
# CHECK-NEXT: data =
36+
# CHECK-NEXT: 0,3,1,4,2,0,3,1,4,
37+
# CHECK-NEXT: data =
38+
# CHECK-NEXT: 2,5.5,4,7.7,6,5.5,8,7.7,10,

include/comet/Dialect/Utils/Utils.h

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ namespace mlir
214214

215215
void getFormatsPermsOfComputeOp(Value computeOp,
216216
std::vector<std::vector<std::string>> &opFormats,
217+
std::vector<std::vector<std::string>> &opBlocks,
217218
std::vector<std::vector<int>> &opPerms,
218219
std::vector<std::vector<bool>> &inputOutputMapping);
219220

lib/Dialect/IndexTree/Transforms/Fusion.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ void IndexTreeKernelFusionPass::test(mlir::func::FuncOp &funcop)
185185
comet_debug() << " is_comp_worksp_opt: " << is_comp_worksp_opt << " semiring: " << semiring << "\n";
186186

187187
std::vector<std::vector<std::string>> opFormats;
188+
std::vector<std::vector<std::string>> opBlocks;
188189
std::vector<std::vector<int>> opPerms;
189190
std::vector<std::vector<bool> > inputOutputMapping;
190-
getFormatsPermsOfComputeOp(computeOp, opFormats, opPerms, inputOutputMapping);
191+
getFormatsPermsOfComputeOp(computeOp, opFormats, opBlocks, opPerms, inputOutputMapping);
191192
/// opFormats
192193
comet_debug() << "[";
193194
for (auto strings: opFormats) {
@@ -538,7 +539,7 @@ mlir::Value IndexTreeKernelFusionPass::createReducedComputeRHS(
538539
SmallVector<StringRef, 8> blocks;
539540
if (b_i == tensor_id)
540541
{ /// for the new reduced tensor
541-
blocks.insert(blocks.end(), old_formats_strs[b_i].begin() + rank_base, old_blocks_strs[b_i].end());
542+
blocks.insert(blocks.end(), old_blocks_strs[b_i].begin() + rank_base, old_blocks_strs[b_i].end());
542543
}
543544
else
544545
{ /// for other remaining old operands

lib/Dialect/IndexTree/Transforms/WorkspaceTransforms.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ std::vector<Value> CompressedWorkspaceOutput(std::vector<int> sparseDimsOutput,
661661

662662
/// Convert blocks string array into StrAttr
663663
std::vector<std::string> c3_blocks_str_0 = {"UNK"};
664-
std::vector<std::string> c3_blocks_str_1 = opFormats[2];
664+
std::vector<std::string> c3_blocks_str_1 = opBlocks[2];
665665
std::vector<std::vector<std::string>> c3_blocks_str = {c3_blocks_str_0, c3_blocks_str_1};
666666

667667
std::vector<mlir::Value> c3_rhs = workspaceTensors;
@@ -769,7 +769,7 @@ void CompressedWorkspaceInput(std::vector<Value> computeOps, OpBuilder &builder,
769769
std::vector<std::vector<std::string>> opBlocks;
770770
std::vector<std::vector<int>> opPerms;
771771
std::vector<std::vector<bool>> inputOutputMapping;
772-
getFormatsPermsOfComputeOp(computeOp, opFormats, opPerms, inputOutputMapping);
772+
getFormatsPermsOfComputeOp(computeOp, opFormats, opBlocks, opPerms, inputOutputMapping);
773773
comet_debug() << " \n";
774774
for (auto n : opFormats)
775775
{
@@ -896,8 +896,8 @@ void CompressedWorkspaceInput(std::vector<Value> computeOps, OpBuilder &builder,
896896
std::vector<std::string> c2_formats_str_1 = {"D"};
897897
std::vector<std::vector<std::string>> c2_formats_str = {c2_formats_str_0, c2_formats_str_1};
898898

899-
std::vector<std::string> c2_blocks_str_0 = opFormats[sparseDimsInput[0].tensorId];
900-
std::vector<std::string> c2_blocks_str_1 = {"D"};
899+
std::vector<std::string> c2_blocks_str_0 = opBlocks[sparseDimsInput[0].tensorId];
900+
std::vector<std::string> c2_blocks_str_1 = {"UNK"};
901901
std::vector<std::vector<std::string>> c2_blocks_str = {c2_blocks_str_0, c2_blocks_str_1};
902902

903903
std::vector<mlir::Value> c2_rhs = {tensors_rhs[sparseDimsInput[0].tensorId]};
@@ -1074,7 +1074,7 @@ void IndexTreeWorkspaceTransformationsPass::CompressedWorkspaceTransforms(mlir::
10741074
std::vector<std::vector<std::string>> opBlocks;
10751075
std::vector<std::vector<int>> opPerms;
10761076
std::vector<std::vector<bool>> inputOutputMapping;
1077-
getFormatsPermsOfComputeOp(computeOp, opFormats, opPerms, inputOutputMapping);
1077+
getFormatsPermsOfComputeOp(computeOp, opFormats, opBlocks, opPerms, inputOutputMapping);
10781078

10791079
#ifdef DEBUG_MODE_WorkspaceTransformsPass
10801080
comet_debug() << "Print opFormats:\n";

lib/Dialect/TensorAlgebra/Transforms/TensorDeclLowering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ using namespace mlir::indexTree;
5151
#define DEBUG_TYPE "tensor-decl-lowering"
5252

5353
// *********** For debug purpose *********//
54-
#define COMET_DEBUG_MODE
54+
// #define COMET_DEBUG_MODE
5555
#include "comet/Utils/debug.h"
5656
#undef COMET_DEBUG_MODE
5757
// *********** For debug purpose *********//

lib/Dialect/Utils/Utils.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -1459,15 +1459,19 @@ namespace mlir
14591459
/// Get the perms and formats of the itCompute op
14601460
void getFormatsPermsOfComputeOp(Value computeOp,
14611461
std::vector<std::vector<std::string>> &opFormats,
1462+
std::vector<std::vector<std::string>> &opBlocks,
14621463
std::vector<std::vector<int>> &opPerms,
14631464
std::vector<std::vector<bool>> &inputOutputMapping)
14641465
{
14651466
indexTree::IndexTreeComputeRHSOp itComputeOp_rhs = dyn_cast<indexTree::IndexTreeComputeRHSOp>(computeOp.getDefiningOp()->getOperand(0).getDefiningOp());
14661467
ArrayAttr opFormatsArrayAttr_rhs = itComputeOp_rhs.getAllFormats();
1468+
ArrayAttr opBlocksArrayAttr_rhs = itComputeOp_rhs.getAllBlocks();
14671469
ArrayAttr opPermsArrayAttr_rhs = itComputeOp_rhs.getAllPerms();
14681470
indexTree::IndexTreeComputeLHSOp itComputeOp_lhs = dyn_cast<indexTree::IndexTreeComputeLHSOp>(computeOp.getDefiningOp()->getOperand(1).getDefiningOp());
14691471
ArrayAttr opFormatsArrayAttr_lhs = itComputeOp_lhs.getAllFormats();
1472+
ArrayAttr opBlocksArrayAttr_lhs = itComputeOp_lhs.getAllBlocks();
14701473
ArrayAttr opPermsArrayAttr_lhs = itComputeOp_lhs.getAllPerms();
1474+
///TODO(patrick) We should probably verify the block sizes
14711475
assert(opFormatsArrayAttr_rhs.size() == opPermsArrayAttr_rhs.size() && "not equal RHS formats size with perms size\n");
14721476
assert(opFormatsArrayAttr_lhs.size() == opPermsArrayAttr_lhs.size() && "not equal LHS formats size with perms size\n");
14731477

@@ -1476,17 +1480,25 @@ namespace mlir
14761480
comet_debug() << "Start printing opFormats_rhs\n";
14771481
std::vector<std::vector<std::string>> opFormats_rhs = convertArrayAttrStrTo2DVector(opFormatsArrayAttr_rhs);
14781482
comet_debug() << "End printing opFormats_rhs\n";
1483+
comet_debug() << "Start printing opBlocks_rhs\n";
1484+
std::vector<std::vector<std::string>> opBlocks_rhs = convertArrayAttrStrTo2DVector(opBlocksArrayAttr_rhs);
1485+
comet_debug() << "End printing opBlocks_rhs\n";
14791486
std::vector<std::vector<int>> opPerms_rhs = convertArrayAttrIntTo2DVector(opPermsArrayAttr_rhs);
14801487
std::vector<std::vector<bool>> inputMapping = createInputOutputMapping(opPermsArrayAttr_rhs, true);
14811488

14821489
comet_debug() << "Start printing opFormats_lhs\n";
14831490
std::vector<std::vector<std::string>> opFormats_lhs = convertArrayAttrStrTo2DVector(opFormatsArrayAttr_lhs);
14841491
comet_debug() << "End printing opFormats_lhs\n";
1492+
comet_debug() << "Start printing opBlocks_lhs\n";
1493+
std::vector<std::vector<std::string>> opBlocks_lhs = convertArrayAttrStrTo2DVector(opBlocksArrayAttr_lhs);
1494+
comet_debug() << "End printing opBlocks_lhs\n";
14851495
std::vector<std::vector<int>> opPerms_lhs = convertArrayAttrIntTo2DVector(opPermsArrayAttr_lhs);
14861496
std::vector<std::vector<bool>> outputMapping = createInputOutputMapping(opPermsArrayAttr_lhs, false);
14871497

14881498
opFormats = opFormats_rhs;
14891499
opFormats.insert(opFormats.end(), opFormats_lhs.begin(), opFormats_lhs.end());
1500+
opBlocks = opBlocks_rhs;
1501+
opBlocks.insert(opBlocks.end(), opBlocks_lhs.begin(), opBlocks_lhs.end());
14901502
opPerms = opPerms_rhs;
14911503
opPerms.insert(opPerms.end(), opPerms_lhs.begin(), opPerms_lhs.end());
14921504
inputOutputMapping = inputMapping;
@@ -1599,10 +1611,11 @@ namespace mlir
15991611
{
16001612
comet_debug() << " getFormatsInfo:leafs[" << j << "] is computeOp\n";
16011613
std::vector<std::vector<std::string>> allFormats;
1614+
std::vector<std::vector<std::string>> allBlocks;
16021615
std::vector<std::vector<int>> allPerms;
16031616
std::vector<std::vector<bool>> inputOutputMapping;
16041617
OpBuilder builder(leafop);
1605-
getFormatsPermsOfComputeOp(leafop, allFormats, allPerms, inputOutputMapping);
1618+
getFormatsPermsOfComputeOp(leafop, allFormats, allBlocks, allPerms, inputOutputMapping);
16061619

16071620
comet_debug() << " getFormatsInfo:Allformats allFormats.size(): " << allFormats.size() << "\n";
16081621
for (auto m : allFormats)

run.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/bin/bash
22

33
export LD_LIBRARY_PATH="/home/patrick/Work/PNNL/COMET/install/lib"
4-
export SPARSE_FILE_NAME0=first.mtx
54

6-
build/bin/comet-opt --convert-ta-to-it --convert-to-loops --convert-to-llvm first.ta &> first.mlir
5+
#export SPARSE_FILE_NAME0=first.mtx
6+
#build/bin/comet-opt --convert-ta-to-it --convert-to-loops --convert-to-llvm first.ta &> first.mlir
7+
8+
export SPARSE_FILE_NAME0=integration_test/data/test_rank2.mtx
9+
export SPARSE_FILE_NAME1=integration_test/data/test_rank2_transpose.mtx
10+
build/bin/comet-opt --opt-comp-workspace --convert-ta-to-it --convert-to-loops --convert-to-llvm first.ta &> first.mlir
711

812
llvm/build/bin/mlir-cpu-runner first.mlir -O3 -e main -entry-point-result=void \
913
-shared-libs=build/lib/libcomet_runner_utils.so

test.mtx

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
%%MatrixMarket matrix coordinate real general
2+
%
3+
% This is a test sparse matrix in Matrix Market Exchange Format.
4+
% see https://math.nist.gov/MatrixMarket
5+
%
6+
4 6 7
7+
1 1 5.0
8+
1 2 1.0
9+
2 1 7.0
10+
2 2 3.0
11+
4 1 8.0
12+
4 4 4.0
13+
4 5 9.0

test.ta

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def main() {
2+
#IndexLabel Declarations
3+
IndexLabel [a] = [4];
4+
IndexLabel [b] = [?];
5+
IndexLabel [c] = [?];
6+
7+
#Tensor Declarations
8+
Tensor<double> B([b, c], {CSR}); #sparse tensor declarations should be before dense tensor declarations
9+
Tensor<double> A([a, b], {Dense});
10+
Tensor<double> C([a, c], {Dense});
11+
12+
#Tensor Fill Operation
13+
A[a, b] = 1.0;
14+
B[b, c] = comet_read(0);
15+
C[a, c] = 0.0;
16+
17+
C[a, c] = A[a, b] * B[b, c];
18+
print(C);
19+
#print(B);
20+
}

0 commit comments

Comments
 (0)