Skip to content

Commit 3484653

Browse files
pflynn157pthomadakis
authored andcommitted
Error fixes in adding allBlocks to IT #20
1 parent 45ac02b commit 3484653

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
@@ -211,6 +211,7 @@ namespace mlir
211211

212212
void getFormatsPermsOfComputeOp(Value computeOp,
213213
std::vector<std::vector<std::string>> &opFormats,
214+
std::vector<std::vector<std::string>> &opBlocks,
214215
std::vector<std::vector<int>> &opPerms,
215216
std::vector<std::vector<bool>> &inputOutputMapping);
216217

lib/Dialect/IndexTree/Transforms/Fusion.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ namespace
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) {
@@ -537,7 +538,7 @@ mlir::Value IndexTreeKernelFusionPass::createReducedComputeRHS(
537538
SmallVector<StringRef, 8> blocks;
538539
if (b_i == tensor_id)
539540
{ /// for the new reduced tensor
540-
blocks.insert(blocks.end(), old_formats_strs[b_i].begin() + rank_base, old_blocks_strs[b_i].end());
541+
blocks.insert(blocks.end(), old_blocks_strs[b_i].begin() + rank_base, old_blocks_strs[b_i].end());
541542
}
542543
else
543544
{ /// for other remaining old operands

lib/Dialect/IndexTree/Transforms/WorkspaceTransforms.cpp

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

672672
/// Convert blocks string array into StrAttr
673673
std::vector<std::string> c3_blocks_str_0 = {"UNK"};
674-
std::vector<std::string> c3_blocks_str_1 = opFormats[2];
674+
std::vector<std::string> c3_blocks_str_1 = opBlocks[2];
675675
std::vector<std::vector<std::string>> c3_blocks_str = {c3_blocks_str_0, c3_blocks_str_1};
676676

677677
std::vector<mlir::Value> c3_rhs = workspaceTensors;
@@ -779,7 +779,7 @@ void CompressedWorkspaceInput(std::vector<Value> computeOps, OpBuilder &builder,
779779
std::vector<std::vector<std::string>> opBlocks;
780780
std::vector<std::vector<int>> opPerms;
781781
std::vector<std::vector<bool>> inputOutputMapping;
782-
getFormatsPermsOfComputeOp(computeOp, opFormats, opPerms, inputOutputMapping);
782+
getFormatsPermsOfComputeOp(computeOp, opFormats, opBlocks, opPerms, inputOutputMapping);
783783
comet_debug() << " \n";
784784
for (auto n : opFormats)
785785
{
@@ -903,8 +903,8 @@ void CompressedWorkspaceInput(std::vector<Value> computeOps, OpBuilder &builder,
903903
std::vector<std::string> c2_formats_str_1 = {"D"};
904904
std::vector<std::vector<std::string>> c2_formats_str = {c2_formats_str_0, c2_formats_str_1};
905905

906-
std::vector<std::string> c2_blocks_str_0 = opFormats[sparseDimsInput[0].tensorId];
907-
std::vector<std::string> c2_blocks_str_1 = {"D"};
906+
std::vector<std::string> c2_blocks_str_0 = opBlocks[sparseDimsInput[0].tensorId];
907+
std::vector<std::string> c2_blocks_str_1 = {"UNK"};
908908
std::vector<std::vector<std::string>> c2_blocks_str = {c2_blocks_str_0, c2_blocks_str_1};
909909

910910
std::vector<mlir::Value> c2_rhs = {tensors_rhs[sparseDimsInput[0].tensorId]};
@@ -1081,7 +1081,7 @@ void IndexTreeWorkspaceTransformationsPass::CompressedWorkspaceTransforms(mlir::
10811081
std::vector<std::vector<std::string>> opBlocks;
10821082
std::vector<std::vector<int>> opPerms;
10831083
std::vector<std::vector<bool>> inputOutputMapping;
1084-
getFormatsPermsOfComputeOp(computeOp, opFormats, opPerms, inputOutputMapping);
1084+
getFormatsPermsOfComputeOp(computeOp, opFormats, opBlocks, opPerms, inputOutputMapping);
10851085

10861086
#ifdef DEBUG_MODE_WorkspaceTransformsPass
10871087
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
@@ -1476,15 +1476,19 @@ namespace mlir
14761476
/// Get the perms and formats of the itCompute op
14771477
void getFormatsPermsOfComputeOp(Value computeOp,
14781478
std::vector<std::vector<std::string>> &opFormats,
1479+
std::vector<std::vector<std::string>> &opBlocks,
14791480
std::vector<std::vector<int>> &opPerms,
14801481
std::vector<std::vector<bool>> &inputOutputMapping)
14811482
{
14821483
indexTree::IndexTreeComputeRHSOp itComputeOp_rhs = dyn_cast<indexTree::IndexTreeComputeRHSOp>(computeOp.getDefiningOp()->getOperand(0).getDefiningOp());
14831484
ArrayAttr opFormatsArrayAttr_rhs = itComputeOp_rhs.getAllFormats();
1485+
ArrayAttr opBlocksArrayAttr_rhs = itComputeOp_rhs.getAllBlocks();
14841486
ArrayAttr opPermsArrayAttr_rhs = itComputeOp_rhs.getAllPerms();
14851487
indexTree::IndexTreeComputeLHSOp itComputeOp_lhs = dyn_cast<indexTree::IndexTreeComputeLHSOp>(computeOp.getDefiningOp()->getOperand(1).getDefiningOp());
14861488
ArrayAttr opFormatsArrayAttr_lhs = itComputeOp_lhs.getAllFormats();
1489+
ArrayAttr opBlocksArrayAttr_lhs = itComputeOp_lhs.getAllBlocks();
14871490
ArrayAttr opPermsArrayAttr_lhs = itComputeOp_lhs.getAllPerms();
1491+
///TODO(patrick) We should probably verify the block sizes
14881492
assert(opFormatsArrayAttr_rhs.size() == opPermsArrayAttr_rhs.size() && "not equal RHS formats size with perms size\n");
14891493
assert(opFormatsArrayAttr_lhs.size() == opPermsArrayAttr_lhs.size() && "not equal LHS formats size with perms size\n");
14901494

@@ -1493,17 +1497,25 @@ namespace mlir
14931497
comet_debug() << "Start printing opFormats_rhs\n";
14941498
std::vector<std::vector<std::string>> opFormats_rhs = convertArrayAttrStrTo2DVector(opFormatsArrayAttr_rhs);
14951499
comet_debug() << "End printing opFormats_rhs\n";
1500+
comet_debug() << "Start printing opBlocks_rhs\n";
1501+
std::vector<std::vector<std::string>> opBlocks_rhs = convertArrayAttrStrTo2DVector(opBlocksArrayAttr_rhs);
1502+
comet_debug() << "End printing opBlocks_rhs\n";
14961503
std::vector<std::vector<int>> opPerms_rhs = convertArrayAttrIntTo2DVector(opPermsArrayAttr_rhs);
14971504
std::vector<std::vector<bool>> inputMapping = createInputOutputMapping(opPermsArrayAttr_rhs, true);
14981505

14991506
comet_debug() << "Start printing opFormats_lhs\n";
15001507
std::vector<std::vector<std::string>> opFormats_lhs = convertArrayAttrStrTo2DVector(opFormatsArrayAttr_lhs);
15011508
comet_debug() << "End printing opFormats_lhs\n";
1509+
comet_debug() << "Start printing opBlocks_lhs\n";
1510+
std::vector<std::vector<std::string>> opBlocks_lhs = convertArrayAttrStrTo2DVector(opBlocksArrayAttr_lhs);
1511+
comet_debug() << "End printing opBlocks_lhs\n";
15021512
std::vector<std::vector<int>> opPerms_lhs = convertArrayAttrIntTo2DVector(opPermsArrayAttr_lhs);
15031513
std::vector<std::vector<bool>> outputMapping = createInputOutputMapping(opPermsArrayAttr_lhs, false);
15041514

15051515
opFormats = opFormats_rhs;
15061516
opFormats.insert(opFormats.end(), opFormats_lhs.begin(), opFormats_lhs.end());
1517+
opBlocks = opBlocks_rhs;
1518+
opBlocks.insert(opBlocks.end(), opBlocks_lhs.begin(), opBlocks_lhs.end());
15071519
opPerms = opPerms_rhs;
15081520
opPerms.insert(opPerms.end(), opPerms_lhs.begin(), opPerms_lhs.end());
15091521
inputOutputMapping = inputMapping;
@@ -1616,10 +1628,11 @@ namespace mlir
16161628
{
16171629
comet_debug() << " getFormatsInfo:leafs[" << j << "] is computeOp\n";
16181630
std::vector<std::vector<std::string>> allFormats;
1631+
std::vector<std::vector<std::string>> allBlocks;
16191632
std::vector<std::vector<int>> allPerms;
16201633
std::vector<std::vector<bool>> inputOutputMapping;
16211634
OpBuilder builder(leafop);
1622-
getFormatsPermsOfComputeOp(leafop, allFormats, allPerms, inputOutputMapping);
1635+
getFormatsPermsOfComputeOp(leafop, allFormats, allBlocks, allPerms, inputOutputMapping);
16231636

16241637
comet_debug() << " getFormatsInfo:Allformats allFormats.size(): " << allFormats.size() << "\n";
16251638
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)