From b958b36ca12986a5ef85ccb2cd40d6e09a4deaac Mon Sep 17 00:00:00 2001 From: Ritvik Sharma Date: Thu, 2 Feb 2023 02:01:38 -0800 Subject: [PATCH 01/76] changes for FIXMEs and added a memory mdoel flag --- sam/sim/src/accumulator.py | 59 ++----------------- sam/sim/src/array.py | 14 +---- sam/sim/src/base.py | 3 +- sam/sim/src/joiner.py | 5 -- sam/sim/src/rd_scanner.py | 18 +----- sam/sim/src/repeater.py | 10 ---- sam/sim/src/wr_scanner.py | 4 -- .../test_matmul_ikj_tile_pipeline_final.py | 51 ++++++++-------- sam/sim/test/conftest.py | 11 ++-- scripts/few_points_memory_model_runner.sh | 6 +- scripts/full_memory_model_runner.sh | 4 +- scripts/generate_gold_matmul_tiled.py | 2 +- scripts/single_point_memory_model_runner.sh | 2 +- 13 files changed, 49 insertions(+), 140 deletions(-) diff --git a/sam/sim/src/accumulator.py b/sam/sim/src/accumulator.py index a3500369..43cb8e5e 100644 --- a/sam/sim/src/accumulator.py +++ b/sam/sim/src/accumulator.py @@ -40,11 +40,6 @@ def set_backpressure(self, backpressure): if not backpressure: self.ready_backpressure = False - def fifo_available(self, br=""): - if self.backpressure_en: - return self.fifo_avail - return True - def update_ready(self): if self.backpressure_en: if len(self.in_val) > self.depth: @@ -52,11 +47,6 @@ def update_ready(self): else: self.fifo_avail = True - def add_child(self, child=None, branch=""): - if self.backpressure_en and child is not None: - self.backpressure.append(child) - self.branch.append(branch) - def update(self): self.update_ready() self.update_done() @@ -202,7 +192,7 @@ def update(self): if self.debug: if self.seen_done or self.done: print(self.seen_done, self.done) - print("@@@", self.outer_crdpt, self.inner_crdpt, self.in_val, self.emit_output, + print("current point value", self.outer_crdpt, self.inner_crdpt, self.in_val, self.emit_output, self.curr_in_outer_crdpt, self.curr_in_inner_crdpt, self.curr_val) self.print_debug() if len(self.in_val) > 0 and self.in_val[0] == "D": @@ -239,12 +229,6 @@ def update(self): self.curr_in_inner_crdpt = self.inner_crdpt.pop(0) ocrd = self.outer_crdpt.pop(0) - # if self.curr_in_val == 'D': - # print(self.curr_in_val, self.curr_in_inner_crdpt, ocrd) - # assert self.curr_in_val == "D" and self.curr_in_inner_crdpt == "D" and ocrd == "D" - # print("######", ocrd, self.curr_in_outer_crdpt, self.curr_in_inner_crdpt, self.emit_output) - # print(self.in_val, self.outer_crdpt, self.inner_crdpt, ocrd - # self.curr_in_outer_crdpt, self.curr_in_inner_crdpt, self.curr_in_val) emit_output = ocrd != self.curr_in_outer_crdpt and self.curr_in_outer_crdpt is not None and \ self.curr_in_outer_crdpt != "D" if emit_output: @@ -271,17 +255,11 @@ def update(self): self.seen_done = True else: self.storage[self.curr_in_outer_crdpt] = {self.curr_in_inner_crdpt: self.valtype(self.curr_in_val)} - # if self.curr_in_outer_crdpt == "D": - # print("__________", self.emit_output, self.seen_done) if len(self.emit_output) > 0: fiber = self.emit_output[0] self.curr_outer_crdpt = fiber[0] - # print("===, ", self.storage) - # print(fiber) - # print(self.emit_output) - # print(self.storage[self.curr_outer_crdpt].keys(), fiber[1]) self.curr_inner_crdpt = min( [item for item in self.storage[self.curr_outer_crdpt].keys() if item > fiber[1]]) self.curr_val = self.storage[self.curr_outer_crdpt][self.curr_inner_crdpt] @@ -433,26 +411,6 @@ def set_backpressure(self, backpressure): if not backpressure: self.ready_backpressure = False - # FIXME: (owhsu) This code is unreachable - def fifo_available(self, br=""): - assert False - if self.backpressure_en: - if br == "inner": - # and len(self.in_inner_crdpt) > self.depth: - return self.fifo_avail_inner - if br == "outer": # and len(self.in_outer_crdpt) > self.depth: - return self.fifo_avail_outer # return False - if br == "val": # and len(self.in_val) > self.depth: - return self.fifo_avail_val # return False - # return True - return True - - def add_child(self, child=None, branch=""): - if self.backpressure_en: - if child is not None: - self.backpressure.append(child) - self.branch.append(branch) - def update_ready(self): if self.backpressure_en: if len(self.in_inner_crdpt) > self.depth: @@ -480,16 +438,13 @@ def update(self): print(self.in_outer_crdpt, self.in_inner_crdpt, self.in_val) print(self.crdpt_spacc.print_debug()) print(self.crdpt_converter.print_debug()) - if self.done: + if self.done and self.memory_model_en: f1, f2, f3 = self.crdpt_spacc.return_fifo() f4, f5 = self.crdpt_converter.return_fifo() self.crdpt_spacc = SparseCrdPtAccumulator1(maxdim=self.temp_maxdim, valtype=self.temp_valtype, fifos=[f1, f2, f3]) self.crdpt_converter = CrdPtConverter(last_level=self.temp_last_level, fifos=[f4, f5]) - # FIXME: (owhsu) self.data_ready not defined in init - if self.backpressure_en: - self.data_ready = True if len(self.in_outer_crdpt) > 0 or len(self.in_inner_crdpt) > 0: self.block_start = False @@ -509,7 +464,7 @@ def update(self): self.crdpt_spacc.set_val(self.in_val.pop(0)) self.crdpt_spacc.update() - print(">>>>>>>>>>>>SPACC:", self.crdpt_spacc.out_outer_crdpt(), self.crdpt_spacc.out_inner_crdpt()) + # print(">>>>>>>>>>>>SPACC:", self.crdpt_spacc.out_outer_crdpt(), self.crdpt_spacc.out_inner_crdpt()) self.crdpt_converter.set_outer_crdpt(self.crdpt_spacc.out_outer_crdpt()) self.crdpt_converter.set_inner_crdpt(self.crdpt_spacc.out_inner_crdpt()) @@ -854,12 +809,6 @@ def set_backpressure(self, backpressure): if not backpressure: self.ready_backpressure = False - def add_child(self, child=None, branch=""): - if self.backpressure_en: - if child is not None: - self.backpressure.append(child) - self.branch.append(branch) - def update_ready(self): if self.backpressure_en: if len(self.in0_crdpt) > self.depth: @@ -881,7 +830,7 @@ def update(self): if self.backpressure_en: self.data_valid = False if (self.backpressure_en and self.check_backpressure()) or not self.backpressure_en: - if self.done: + if self.done and self.memory_model_en: f1, f2, f3 = self.crdpt_spacc.return_fifo() f4, f5 = self.crdpt_converter.return_fifo() self.crdpt_spacc = SparseCrdPtAccumulator2(maxdim=self.temp_maxdim, valtype=self.temp_valtype, diff --git a/sam/sim/src/array.py b/sam/sim/src/array.py index c05a017f..82c64831 100644 --- a/sam/sim/src/array.py +++ b/sam/sim/src/array.py @@ -44,15 +44,10 @@ def set_fifo(self, fifo): def get_fifo(self): return self.load_addrs - def add_child(self, child, branch=""): - if self.backpressure_en: - if child is not None: - self.backpressure.append(child) - self.branch.append(branch) - def set_path(self, path): self.path = path - + + # FIXME(ritvik): fix the initialization of array def reintilialize_arrs(self, load_vals, fifo): self.arr = load_vals self.set_fifo(fifo) @@ -111,11 +106,6 @@ def update(self): self.store(store_tup[0], store_tup[1]) self.store_en = False - def fifo_available(self, br=""): - if self.backpressure_en: - if len(self.load_addrs) > 1: - return False - return True def update_ready(self): if self.backpressure_en: diff --git a/sam/sim/src/base.py b/sam/sim/src/base.py index 38eaa778..0a0c6b02 100644 --- a/sam/sim/src/base.py +++ b/sam/sim/src/base.py @@ -67,7 +67,7 @@ def larger_stkn(a, b): class Primitive(ABC): - def __init__(self, debug=False, statistics=False, name="", back_en=False, **kwargs): + def __init__(self, debug=False, statistics=False, name="", back_en=False, memory_model_en=False, **kwargs): self.name = name self.done = False self.debug = debug @@ -78,6 +78,7 @@ def __init__(self, debug=False, statistics=False, name="", back_en=False, **kwar self.get_stats = statistics self.backpressure_en = back_en + self.memory_model_en = memory_model_en def out_done(self): return self.done diff --git a/sam/sim/src/joiner.py b/sam/sim/src/joiner.py index 51089e73..488c7bee 100644 --- a/sam/sim/src/joiner.py +++ b/sam/sim/src/joiner.py @@ -57,11 +57,6 @@ def update_ready(self): else: self.fifo_avail_in2 = True - def add_child(self, child=None, branch=""): - if self.backpressure_en: - self.backpressure.append(child) - self.branches.append(branch) - def set_in1(self, in_ref1, in_crd1, parent=None): if in_ref1 != '' and in_crd1 != '' and in_ref1 is not None and in_crd1 is not None: # print(in_ref1, " ", in_crd1) diff --git a/sam/sim/src/rd_scanner.py b/sam/sim/src/rd_scanner.py index fb17f949..d0c52c5b 100644 --- a/sam/sim/src/rd_scanner.py +++ b/sam/sim/src/rd_scanner.py @@ -44,18 +44,6 @@ def out_crd(self, child=None): if (self.backpressure_en and self.data_valid) or not self.backpressure_en: return self.curr_crd - def add_child(self, child, branch=""): - if self.backpressure_en and child is not None: - self.backpressure.append(child) - self.branches.append(branch) - - def fifo_available(self, br=""): - if self.backpressure_en: - return self.fifo_avail - # and len(self.in_ref) > self.depth: - # return False - return True - def update_ready(self): if self.backpressure_en: if len(self.in_ref) > self.depth: @@ -246,6 +234,7 @@ def __init__(self, crd_arr=[], seg_arr=[], skip=True, depth=1, tile_size=None, f if fifo is not None: self.set_fifo(fifo) + # FIXME (Ritvik): Use reinitialize array isntead of redeclaring the rd scanner def reinitialize_arrs(self, seg_arr, crd_arr, fifo): # assert False self.start_addr = 0 @@ -281,11 +270,6 @@ def set_fifo(self, fifo): def get_fifo(self): return self.in_ref - def fifo_available(self, br=""): - if self.backpressure_en and len(self.in_ref) > self.depth: - return False - return True - def set_in_ref(self, in_ref, parent=None): if in_ref != '' and in_ref is not None: self.in_ref.append(in_ref) diff --git a/sam/sim/src/repeater.py b/sam/sim/src/repeater.py index 66ccfebe..956506ad 100644 --- a/sam/sim/src/repeater.py +++ b/sam/sim/src/repeater.py @@ -52,11 +52,6 @@ def update_ready(self): else: self.fifo_avail_repeat = True - def add_child(self, child=None, branch=""): - if self.backpressure_en: - self.backpressure.append(child) - self.branches.append(branch) - def update(self): self.update_done() self.update_ready() @@ -359,11 +354,6 @@ def update_ready(self): else: self.fifo_avail = True - def add_child(self, child=None, branch=""): - if self.backpressure_en: - self.backpressure.append(child) - self.branches.append(branch) - # input can either be coordinates or references def set_istream(self, istream, parent=None): if istream != '' and istream is not None: diff --git a/sam/sim/src/wr_scanner.py b/sam/sim/src/wr_scanner.py index 9de01c2e..e835dc07 100644 --- a/sam/sim/src/wr_scanner.py +++ b/sam/sim/src/wr_scanner.py @@ -164,12 +164,8 @@ def update(self): self.update_ready() if self.done: return - # self.arr.print_debug(name="vals") - # self.seg_arr.print_debug(name="seg") if self.debug: print("RESET WR SCAN ", self.input) - # self.reset() - # self.done = False if self.debug: print("post reset: ", self.arr.out_done()) diff --git a/sam/sim/test/advanced-simulator/test_matmul_ikj_tile_pipeline_final.py b/sam/sim/test/advanced-simulator/test_matmul_ikj_tile_pipeline_final.py index 0d97bf04..19ffe48a 100755 --- a/sam/sim/test/advanced-simulator/test_matmul_ikj_tile_pipeline_final.py +++ b/sam/sim/test/advanced-simulator/test_matmul_ikj_tile_pipeline_final.py @@ -30,7 +30,8 @@ ) @pytest.mark.suitesparse def test_matmul_ikj_tiled_sparse(samBench, ssname, check_gold, debug_sim, report_stats, - skip_empty, yaml_name, nbuffer, backpressure, depth, nnz_value, fill=0): + skip_empty, yaml_name, nbuffer, backpressure, depth, memory_model, nnz_value, + fill=0): depth = int(depth) stats_dict = {"mul_6_ops": 0, "spacc1_3_rmw_ops": [], "out_arr_size": 0, "repsiggen_i_17_total_rep": 0, "repsiggen_j_10_total_rep": 0, "repsiggen_i_17_max_rep": 0, "repsiggen_j_10_max_rep": 0, @@ -340,7 +341,7 @@ def test_matmul_ikj_tiled_sparse(samBench, ssname, check_gold, debug_sim, report in_fifo.append("D") fiberlookup_Bi_19 = CompressedCrdRdScan(name="Bi", crd_arr=B_crd0, seg_arr=B_seg0, debug=debug_sim2, statistics=report_stats, fifo=in_fifo, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) mem_model_bi.valid_tile_received() nxt_tile_present[0] = True if mem_blocks_decl_flag and fiberlookup_Bk_14.out_done() and mem_model_bk.valid_tile() and not nxt_tile_present[1]: @@ -361,7 +362,7 @@ def test_matmul_ikj_tiled_sparse(samBench, ssname, check_gold, debug_sim, report in_fifo = fiberlookup_Bk_14.get_fifo() fiberlookup_Bk_14 = CompressedCrdRdScan(name="Bk", crd_arr=B_crd1, seg_arr=B_seg1, debug=debug_sim2, statistics=report_stats, fifo=in_fifo, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) mem_model_bk.valid_tile_received() nxt_tile_present[1] = True if mem_blocks_decl_flag and fiberlookup_Ck_15.out_done() and mem_model_ck.valid_tile() and not nxt_tile_present[2]: @@ -382,7 +383,7 @@ def test_matmul_ikj_tiled_sparse(samBench, ssname, check_gold, debug_sim, report in_fifo = fiberlookup_Ck_15.get_fifo() fiberlookup_Ck_15 = CompressedCrdRdScan(name="Ck", crd_arr=C_crd0, seg_arr=C_seg0, debug=debug_sim2, statistics=report_stats, fifo=in_fifo, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) mem_model_ck.valid_tile_received() repeat_Ci_16.set_in_ref(0, "") repeat_Ci_16.set_in_ref("D", "") @@ -404,7 +405,7 @@ def test_matmul_ikj_tiled_sparse(samBench, ssname, check_gold, debug_sim, report in_fifo = fiberlookup_Cj_12.get_fifo() fiberlookup_Cj_12 = CompressedCrdRdScan(name="Cj", crd_arr=C_crd1, seg_arr=C_seg1, debug=debug_sim2, statistics=report_stats, fifo=in_fifo, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) mem_model_cj.valid_tile_received() nxt_tile_present[3] = True if mem_blocks_decl_flag and arrayvals_B_7.out_done() and mem_model_bvals.valid_tile() and not nxt_tile_present[4]: @@ -422,7 +423,7 @@ def test_matmul_ikj_tiled_sparse(samBench, ssname, check_gold, debug_sim, report B_vals = read_inputs(B_vals_filename, float) in_fifo = arrayvals_B_7.get_fifo() arrayvals_B_7 = Array(name="Bvals", init_arr=B_vals, debug=debug_sim2, statistics=report_stats, fifo=in_fifo, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) mem_model_bvals.valid_tile_received() nxt_tile_present[4] = True if mem_blocks_decl_flag and arrayvals_C_8.out_done() and mem_model_cvals.valid_tile() and not nxt_tile_present[5]: @@ -440,7 +441,7 @@ def test_matmul_ikj_tiled_sparse(samBench, ssname, check_gold, debug_sim, report C_vals = read_inputs(C_vals_filename, float) in_fifo = arrayvals_C_8.get_fifo() arrayvals_C_8 = Array(name="Cvals", init_arr=C_vals, debug=debug_sim2, statistics=report_stats, fifo=in_fifo, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) mem_model_cvals.valid_tile_received() nxt_tile_present[5] = True @@ -613,50 +614,50 @@ def test_matmul_ikj_tiled_sparse(samBench, ssname, check_gold, debug_sim, report debug_sim2 = False # True # False fiberlookup_Bi_19 = CompressedCrdRdScan(name="Bi", crd_arr=B_crd0, seg_arr=B_seg0, debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) fiberlookup_Bk_14 = CompressedCrdRdScan(name="Bk", crd_arr=B_crd1, seg_arr=B_seg1, debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) repsiggen_i_17 = RepeatSigGen(debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) repeat_Ci_16 = Repeat(debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) fiberlookup_Ck_15 = CompressedCrdRdScan(name="Ck", crd_arr=C_crd0, seg_arr=C_seg0, debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) intersectk_13 = Intersect2(debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) crdhold_5 = CrdHold(debug=debug_sim2, statistics=report_stats, back_en=backpressure, - depth=depth) + depth=depth, memory_model_en=memory_model) fiberlookup_Cj_12 = CompressedCrdRdScan(name="Cj", crd_arr=C_crd1, seg_arr=C_seg1, debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) arrayvals_C_8 = Array(name="C", init_arr=C_vals, debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) crdhold_4 = CrdHold(debug=debug_sim2, statistics=report_stats, back_en=backpressure, depth=depth) repsiggen_j_10 = RepeatSigGen(debug=debug_sim2, statistics=report_stats, back_en=backpressure, - depth=depth) + depth=depth, memory_model_en=memory_model) repeat_Bj_9 = Repeat(debug=debug_sim2, statistics=report_stats, back_en=backpressure, depth=depth) arrayvals_B_7 = Array(name="B", init_arr=B_vals, debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) mul_6 = Multiply2(debug=debug_sim2, statistics=report_stats, back_en=backpressure, depth=depth) spaccumulator1_3 = SparseAccumulator1(debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) spaccumulator1_3_drop_crd_inner = StknDrop(debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) spaccumulator1_3_drop_crd_outer = StknDrop(debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) spaccumulator1_3_drop_val = StknDrop(debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) fiberwrite_Xvals_0 = ValsWrScan(name="vals", size=1 * B_shape[0] * C_shape[1], fill=fill, debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) fiberwrite_X1_1 = CompressWrScan(name="X1", seg_size=B_shape[0] + 1, size=B_shape[0] * C_shape[1], fill=fill, debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) fiberwrite_X0_2 = CompressWrScan(name="X0", seg_size=2, size=B_shape[0], fill=fill, debug=debug_sim2, statistics=report_stats, - back_en=backpressure, depth=depth) + back_en=backpressure, depth=depth, memory_model_en=memory_model) # print("INITIALIZE compute loop at ", time_cnt) initialize_cntr = time_cnt mem_model_b.valid_tile_received() diff --git a/sam/sim/test/conftest.py b/sam/sim/test/conftest.py index 8339e3f5..011af381 100644 --- a/sam/sim/test/conftest.py +++ b/sam/sim/test/conftest.py @@ -25,6 +25,8 @@ def pytest_addoption(parser): help="If nbuffering is enabled") parser.addoption("--back", action="store_true", default=False, help="Whether backpressure is enabled") + parser.addoption("--memory-model", action="store_true", default=False, + help="Whether memory model is wanted") parser.addoption("--depth", action="store", default=2, help="fifo depth value") parser.addoption("--nnz-value", action="store", default=5000, @@ -72,6 +74,11 @@ def backpressure(request): return request.config.getoption("--back") +@pytest.fixture +def memory_model(request): + return request.config.getoption("--memory-model") + + @pytest.fixture def skip_empty(request): return request.config.getoption("--skip-empty") @@ -87,10 +94,6 @@ def debug_sim(request): return request.config.getoption("--debug-sim") -@pytest.fixture -def backpressure(request): - return request.config.getoption("--back") - @pytest.fixture def depth(request): diff --git a/scripts/few_points_memory_model_runner.sh b/scripts/few_points_memory_model_runner.sh index 79811385..d561fc5e 100755 --- a/scripts/few_points_memory_model_runner.sh +++ b/scripts/few_points_memory_model_runner.sh @@ -61,11 +61,11 @@ for b in ${!BENCHMARKS[@]}; do line=random_sparsity cd $basedir/sam/sim if [ $2 -eq 1 ]; then - pytest test/advanced-simulator/test_$bench.py --ssname $line -s --check-gold --skip-empty --nbuffer --yaml_name=$1 --nnz-value=${NNZ[$nnz]} --benchmark-json=$path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json + pytest test/advanced-simulator/test_$bench.py --ssname $line -s --check-gold --skip-empty --nbuffer --memory-model --yaml_name=$1 --nnz-value=${NNZ[$nnz]} --benchmark-json=$path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json else - pytest test/advanced-simulator/test_$bench.py --ssname $line -s --skip-empty --nbuffer --yaml_name=$1 --nnz-value=${NNZ[$nnz]} --benchmark-json=$path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json + pytest test/advanced-simulator/test_$bench.py --ssname $line -s --skip-empty --nbuffer --memory-model --yaml_name=$1 --nnz-value=${NNZ[$nnz]} --benchmark-json=$path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json fi - python $basedir/scripts/converter.py --json_name $path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json + python $basedir/scripts/converter.py --json_name $path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json status=$? if [ $status -gt 0 ] diff --git a/scripts/full_memory_model_runner.sh b/scripts/full_memory_model_runner.sh index 447b7bc4..8807be2d 100755 --- a/scripts/full_memory_model_runner.sh +++ b/scripts/full_memory_model_runner.sh @@ -61,9 +61,9 @@ for b in ${!BENCHMARKS[@]}; do line=random_sparsity cd $basedir/sam/sim if [ $2 -eq 1 ]; then - pytest test/advanced-simulator/test_$bench.py --ssname $line -s --check-gold --skip-empty --nbuffer --yaml_name=$1 --nnz-value=${NNZ[$nnz]} --benchmark-json=$path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json + pytest test/advanced-simulator/test_$bench.py --ssname $line -s --check-gold --skip-empty --nbuffer --memory-model --yaml_name=$1 --nnz-value=${NNZ[$nnz]} --benchmark-json=$path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json else - pytest test/advanced-simulator/test_$bench.py --ssname $line -s --skip-empty --nbuffer --yaml_name=$1 --nnz-value=${NNZ[$nnz]} --benchmark-json=$path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json + pytest test/advanced-simulator/test_$bench.py --ssname $line -s --skip-empty --nbuffer --memory-model --yaml_name=$1 --nnz-value=${NNZ[$nnz]} --benchmark-json=$path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json fi python $basedir/scripts/converter.py --json_name $path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json diff --git a/scripts/generate_gold_matmul_tiled.py b/scripts/generate_gold_matmul_tiled.py index 64ff4946..068bb47e 100644 --- a/scripts/generate_gold_matmul_tiled.py +++ b/scripts/generate_gold_matmul_tiled.py @@ -78,7 +78,7 @@ def generate_gold_matmul_tiled(tile_crd_b, tile_crd_c, dirname, out_format="ss01 if __name__ == "__main__": parser = argparse.ArgumentParser(description="Generate tiled output gold") - parser.add_argument("--yaml_name", type=str, default="memory_config_real.yaml") + parser.add_argument("--yaml_name", type=str, default="memory_config_onyx.yaml") args = parser.parse_args() outdir = "./tiles/matmul_ikj/output/" outpath = Path(outdir) diff --git a/scripts/single_point_memory_model_runner.sh b/scripts/single_point_memory_model_runner.sh index e666769d..34117476 100755 --- a/scripts/single_point_memory_model_runner.sh +++ b/scripts/single_point_memory_model_runner.sh @@ -34,7 +34,7 @@ rm -rf $basedir/tiles/* ./scripts/prepare_files.sh $fname cd $basedir/sam/sim -pytest test/advanced-simulator/test_$bench.py --ssname $line -s --check-gold --skip-empty --nbuffer --yaml_name=$yaml_fname --nnz-value=$nnz --benchmark-json=$path/${line}_${nnz}_${dim}.json +pytest test/advanced-simulator/test_$bench.py --ssname $line -s --check-gold --skip-empty --nbuffer --yaml_name=$yaml_fname --memory-model --nnz-value=$nnz --benchmark-json=$path/${line}_${nnz}_${dim}.json python $basedir/scripts/converter.py --json_name $path/${line}_${nnz}_${dim}.json From 505bc56cb0769e0dcf30d46de101cef53d8a8288 Mon Sep 17 00:00:00 2001 From: Ritvik Sharma Date: Thu, 2 Feb 2023 23:24:43 -0800 Subject: [PATCH 02/76] corrected block start for rd scan --- sam/sim/src/rd_scanner.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sam/sim/src/rd_scanner.py b/sam/sim/src/rd_scanner.py index d0c52c5b..ac956c56 100644 --- a/sam/sim/src/rd_scanner.py +++ b/sam/sim/src/rd_scanner.py @@ -80,11 +80,11 @@ def __init__(self, dim=0, depth=4, **kwargs): def update(self): self.update_done() self.update_ready() - if len(self.in_ref) > 0: - self.block_start = False if self.backpressure_en: self.data_valid = False if (self.backpressure_en and self.check_backpressure()) or not self.backpressure_en: + if len(self.in_ref) > 0: + self.block_start = False if self.backpressure_en: self.data_valid = True if self.emit_tkn and len(self.in_ref) > 0: @@ -350,6 +350,9 @@ def update(self): if (self.backpressure_en and self.check_backpressure()) or not self.backpressure_en: if self.backpressure_en: self.data_valid = True + if len(self.in_ref) > 0: + self.block_start = False + # Process skip token first and save if len(self.in_crd_skip) > 0 and self.skip_processed: self.curr_skip = self.in_crd_skip.pop(0) From d70968f6d0c7421b17098985fe6f62a9e5d30fd8 Mon Sep 17 00:00:00 2001 From: Ritvik Sharma Date: Fri, 3 Feb 2023 00:32:14 -0800 Subject: [PATCH 03/76] code style correction --- sam/sim/src/array.py | 3 +-- sam/sim/src/rd_scanner.py | 2 +- sam/sim/test/conftest.py | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sam/sim/src/array.py b/sam/sim/src/array.py index 82c64831..669baef9 100644 --- a/sam/sim/src/array.py +++ b/sam/sim/src/array.py @@ -46,7 +46,7 @@ def get_fifo(self): def set_path(self, path): self.path = path - + # FIXME(ritvik): fix the initialization of array def reintilialize_arrs(self, load_vals, fifo): self.arr = load_vals @@ -106,7 +106,6 @@ def update(self): self.store(store_tup[0], store_tup[1]) self.store_en = False - def update_ready(self): if self.backpressure_en: if len(self.load_addrs) > self.depth: diff --git a/sam/sim/src/rd_scanner.py b/sam/sim/src/rd_scanner.py index ac956c56..e1556f1f 100644 --- a/sam/sim/src/rd_scanner.py +++ b/sam/sim/src/rd_scanner.py @@ -352,7 +352,7 @@ def update(self): self.data_valid = True if len(self.in_ref) > 0: self.block_start = False - + # Process skip token first and save if len(self.in_crd_skip) > 0 and self.skip_processed: self.curr_skip = self.in_crd_skip.pop(0) diff --git a/sam/sim/test/conftest.py b/sam/sim/test/conftest.py index 011af381..d3609bf5 100644 --- a/sam/sim/test/conftest.py +++ b/sam/sim/test/conftest.py @@ -94,7 +94,6 @@ def debug_sim(request): return request.config.getoption("--debug-sim") - @pytest.fixture def depth(request): return request.config.getoption("--depth") From 44faefaa57a04b5706be98a54512e384d00d64a1 Mon Sep 17 00:00:00 2001 From: Gina Sohn Date: Fri, 3 Feb 2023 01:35:38 -0800 Subject: [PATCH 04/76] Add gantt chart generation code --- .../test/final-apps/test_matmul_kij_FINAL.py | 3 ++ sam/sim/test/gen_gantt.py | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 sam/sim/test/gen_gantt.py diff --git a/sam/sim/test/final-apps/test_matmul_kij_FINAL.py b/sam/sim/test/final-apps/test_matmul_kij_FINAL.py index c1f0d212..7e50a8c9 100644 --- a/sam/sim/test/final-apps/test_matmul_kij_FINAL.py +++ b/sam/sim/test/final-apps/test_matmul_kij_FINAL.py @@ -14,6 +14,7 @@ from sam.sim.test.gold import * import os import csv +from sam.sim.test.gen_gantt import * cwd = os.getcwd() formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) @@ -239,6 +240,8 @@ def bench(): sample_dict = fiberlookup_Cj_11.return_statistics() for k in sample_dict.keys(): extra_info["fiberlookup_Cj_11" + "/" + k] = sample_dict[k] + + gen_gantt(extra_info, "matmul_kij") if check_gold: print("Checking gold...") diff --git a/sam/sim/test/gen_gantt.py b/sam/sim/test/gen_gantt.py new file mode 100644 index 00000000..985a5a47 --- /dev/null +++ b/sam/sim/test/gen_gantt.py @@ -0,0 +1,31 @@ +import pandas as pd +import numpy as np +import matplotlib +import matplotlib.pyplot as plt + +color_dict = {'fiberlookup': 'green', 'intersect': 'blueviolet', 'array':''} + +def gen_gantt(extra_info,testname): + block_list = [] + start_list = [] + duration_list = [] + + start_c='' + finish_c='' + sam_name='' + + for k in extra_info.keys(): + if "done_cycles" in k: + sam_name=k.split('/')[0] + finish_c=extra_info[k] + elif ("start_cycle" in k) and (sam_name in k.split('/')[0]): + start_c=extra_info[k] + if isinstance(start_c, int): + block_list.append(sam_name) + start_list.append(start_c) + duration_list.append(finish_c-start_c) + + plt.barh(y=block_list, width=duration_list, left=start_list) + + file_name = testname + '_' + extra_info["dataset"] + ".png" + plt.savefig(file_name,bbox_inches = "tight") From 29112a021fa4a3ac49addea655a9e1610f9b3fc1 Mon Sep 17 00:00:00 2001 From: Gina Sohn Date: Fri, 3 Feb 2023 09:45:54 -0800 Subject: [PATCH 05/76] Follow Flake8 formatting --- .../test/final-apps/test_matmul_kij_FINAL.py | 4 +-- sam/sim/test/gen_gantt.py | 30 ++++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/sam/sim/test/final-apps/test_matmul_kij_FINAL.py b/sam/sim/test/final-apps/test_matmul_kij_FINAL.py index 7e50a8c9..3aa74641 100644 --- a/sam/sim/test/final-apps/test_matmul_kij_FINAL.py +++ b/sam/sim/test/final-apps/test_matmul_kij_FINAL.py @@ -14,7 +14,7 @@ from sam.sim.test.gold import * import os import csv -from sam.sim.test.gen_gantt import * +from sam.sim.test.gen_gantt import gen_gantt cwd = os.getcwd() formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) @@ -240,7 +240,7 @@ def bench(): sample_dict = fiberlookup_Cj_11.return_statistics() for k in sample_dict.keys(): extra_info["fiberlookup_Cj_11" + "/" + k] = sample_dict[k] - + gen_gantt(extra_info, "matmul_kij") if check_gold: diff --git a/sam/sim/test/gen_gantt.py b/sam/sim/test/gen_gantt.py index 985a5a47..1fbd6ee6 100644 --- a/sam/sim/test/gen_gantt.py +++ b/sam/sim/test/gen_gantt.py @@ -1,31 +1,27 @@ -import pandas as pd -import numpy as np -import matplotlib import matplotlib.pyplot as plt -color_dict = {'fiberlookup': 'green', 'intersect': 'blueviolet', 'array':''} -def gen_gantt(extra_info,testname): +def gen_gantt(extra_info, testname): block_list = [] start_list = [] duration_list = [] - - start_c='' - finish_c='' - sam_name='' - + + start_c = '' + finish_c = '' + sam_name = '' + for k in extra_info.keys(): if "done_cycles" in k: - sam_name=k.split('/')[0] - finish_c=extra_info[k] + sam_name = k.split('/')[0] + finish_c = extra_info[k] elif ("start_cycle" in k) and (sam_name in k.split('/')[0]): - start_c=extra_info[k] - if isinstance(start_c, int): + start_c = extra_info[k] + if isinstance(start_c, int): block_list.append(sam_name) start_list.append(start_c) - duration_list.append(finish_c-start_c) + duration_list.append(finish_c - start_c) plt.barh(y=block_list, width=duration_list, left=start_list) - + file_name = testname + '_' + extra_info["dataset"] + ".png" - plt.savefig(file_name,bbox_inches = "tight") + plt.savefig(file_name, bbox_inches="tight") From 7daabe2b06a3919721b2e9b77c9f960d4f8352c4 Mon Sep 17 00:00:00 2001 From: Gina Sohn Date: Sun, 5 Feb 2023 18:35:57 -0800 Subject: [PATCH 06/76] update gen_gantt for string cycle numbers --- sam/sim/test/gen_gantt.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sam/sim/test/gen_gantt.py b/sam/sim/test/gen_gantt.py index 1fbd6ee6..b79dc1a1 100644 --- a/sam/sim/test/gen_gantt.py +++ b/sam/sim/test/gen_gantt.py @@ -16,8 +16,11 @@ def gen_gantt(extra_info, testname): finish_c = extra_info[k] elif ("start_cycle" in k) and (sam_name in k.split('/')[0]): start_c = extra_info[k] - if isinstance(start_c, int): - block_list.append(sam_name) + block_list.append(sam_name) + if not isinstance(start_c, int): + start_list.append(int(start_c)) + duration_list.append(finish_c - int(start_c)) + else: start_list.append(start_c) duration_list.append(finish_c - start_c) From 155e62c24379b45d99e7f207aaf8d8ada3cfa0dd Mon Sep 17 00:00:00 2001 From: Gina Sohn Date: Tue, 7 Feb 2023 18:02:52 -0800 Subject: [PATCH 07/76] reorder-ijk --- .../test_reorder_matmul_ijk_GINA.py | 259 ++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py diff --git a/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py b/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py new file mode 100644 index 00000000..f5ba89e5 --- /dev/null +++ b/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py @@ -0,0 +1,259 @@ +import pytest +import time +import scipy.sparse +from sam.sim.src.rd_scanner import UncompressCrdRdScan, CompressedCrdRdScan +from sam.sim.src.wr_scanner import ValsWrScan +from sam.sim.src.joiner import Intersect2, Union2 +from sam.sim.src.compute import Multiply2, Add2 +from sam.sim.src.crd_manager import CrdDrop, CrdHold +from sam.sim.src.repeater import Repeat, RepeatSigGen +from sam.sim.src.accumulator import Reduce +from sam.sim.src.accumulator import SparseAccumulator1, SparseAccumulator2 +from sam.sim.src.token import * +from sam.sim.test.test import * +from sam.sim.test.gold import * +import os +import csv +from sam.sim.test.gen_gantt import gen_gantt + +cwd = os.getcwd() +formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) + + +@pytest.mark.suitesparse +def test_matmul_ijk_FINAL(samBench, ssname, check_gold, report_stats, debug_sim, cast, backpressure, depth, fill=0): + B_dirname = os.path.join(formatted_dir, ssname, "matmul_ijk") + B_shape_filename = os.path.join(B_dirname, "tensor_B_mode_shape") + B_shape = read_inputs(B_shape_filename) + + B0_seg_filename = os.path.join(B_dirname, "tensor_B_mode_0_seg") + B_seg0 = read_inputs(B0_seg_filename) + B0_crd_filename = os.path.join(B_dirname, "tensor_B_mode_0_crd") + B_crd0 = read_inputs(B0_crd_filename) + + B1_seg_filename = os.path.join(B_dirname, "tensor_B_mode_1_seg") + B_seg1 = read_inputs(B1_seg_filename) + B1_crd_filename = os.path.join(B_dirname, "tensor_B_mode_1_crd") + B_crd1 = read_inputs(B1_crd_filename) + + B_vals_filename = os.path.join(B_dirname, "tensor_B_mode_vals") + B_vals = read_inputs(B_vals_filename, float) + + C_dirname = B_dirname + C_shape_filename = os.path.join(C_dirname, "tensor_C_mode_shape") + C_shape = read_inputs(C_shape_filename) + + C0_seg_filename = os.path.join(C_dirname, "tensor_C_mode_1_seg") + C_seg0 = read_inputs(C0_seg_filename) + C0_crd_filename = os.path.join(C_dirname, "tensor_C_mode_1_crd") + C_crd0 = read_inputs(C0_crd_filename) + + C1_seg_filename = os.path.join(C_dirname, "tensor_C_mode_0_seg") + C_seg1 = read_inputs(C1_seg_filename) + C1_crd_filename = os.path.join(C_dirname, "tensor_C_mode_0_crd") + C_crd1 = read_inputs(C1_crd_filename) + + C_vals_filename = os.path.join(C_dirname, "tensor_C_mode_vals") + C_vals = read_inputs(C_vals_filename, float) + + # THIS IS FOR SIZE INFO + Bs_dirname = B_dirname + Bs_seg = read_inputs(os.path.join(Bs_dirname, "tensor_B_mode_0_seg")) + + fiberlookup_Bi_17 = CompressedCrdRdScan(crd_arr=B_crd0, seg_arr=B_seg0, debug=debug_sim, + back_en=backpressure, depth=int(depth), statistics=report_stats) + fiberwrite_X0_2 = CompressWrScan(seg_size=2, size=B_shape[0], fill=fill, debug=debug_sim, + back_en=backpressure, depth=int(depth), statistics=report_stats) + repsiggen_i_15 = RepeatSigGen(debug=debug_sim, back_en=backpressure, depth=int(depth)) + repeat_Ci_14 = Repeat(debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) + fiberlookup_Cj_13 = CompressedCrdRdScan(crd_arr=C_crd1, seg_arr=C_seg1, debug=debug_sim, + back_en=backpressure, depth=int(depth), statistics=report_stats) + fiberlookup_Ck_9 = CompressedCrdRdScan(crd_arr=C_crd0, seg_arr=C_seg0, debug=debug_sim, + back_en=backpressure, depth=int(depth), statistics=report_stats) + fiberwrite_X1_1 = CompressWrScan(seg_size=B_shape[0] + 1, size=B_shape[0] * C_shape[1], fill=fill, + debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) + repsiggen_j_11 = RepeatSigGen(debug=debug_sim, back_en=backpressure, depth=int(depth)) + repeat_Bj_10 = Repeat(debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) + fiberlookup_Bk_8 = CompressedCrdRdScan(crd_arr=B_crd1, seg_arr=B_seg1, debug=debug_sim, + back_en=backpressure, depth=int(depth), statistics=report_stats) + intersectk_7 = Intersect2(debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) + arrayvals_B_5 = Array(init_arr=B_vals, debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) + arrayvals_C_6 = Array(init_arr=C_vals, debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) + mul_4 = Multiply2(debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) + reduce_3 = Reduce(debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) + fiberwrite_Xvals_0 = ValsWrScan(size=1 * B_shape[0] * C_shape[1], fill=fill, debug=debug_sim, + back_en=backpressure, depth=int(depth), statistics=report_stats) + in_ref_B = [0, 'D'] + in_ref_C = [0, 'D'] + done = False + time_cnt = 0 + + while not done and time_cnt < TIMEOUT: + if len(in_ref_B) > 0: + fiberlookup_Bi_17.set_in_ref(in_ref_B.pop(0), "") + + fiberwrite_X0_2.set_input(fiberlookup_Bi_17.out_crd(), fiberlookup_Bi_17) + + repsiggen_i_15.set_istream(fiberlookup_Bi_17.out_crd(), fiberlookup_Bi_17) + + if len(in_ref_C) > 0: + repeat_Ci_14.set_in_ref(in_ref_C.pop(0), "") + repeat_Ci_14.set_in_repsig(repsiggen_i_15.out_repsig(), repsiggen_i_15) + + fiberlookup_Cj_13.set_in_ref(repeat_Ci_14.out_ref(), repeat_Ci_14) + + fiberlookup_Ck_9.set_in_ref(fiberlookup_Cj_13.out_ref(), fiberlookup_Cj_13) + + fiberwrite_X1_1.set_input(fiberlookup_Cj_13.out_crd(), fiberlookup_Cj_13) + + repsiggen_j_11.set_istream(fiberlookup_Cj_13.out_crd(), fiberlookup_Cj_13) + + repeat_Bj_10.set_in_ref(fiberlookup_Bi_17.out_ref(), fiberlookup_Bi_17) + repeat_Bj_10.set_in_repsig(repsiggen_j_11.out_repsig(), repsiggen_j_11) + + fiberlookup_Bk_8.set_in_ref(repeat_Bj_10.out_ref(), repeat_Bj_10) + + intersectk_7.set_in1(fiberlookup_Bk_8.out_ref(), fiberlookup_Bk_8.out_crd(), fiberlookup_Bk_8) + intersectk_7.set_in2(fiberlookup_Ck_9.out_ref(), fiberlookup_Ck_9.out_crd(), fiberlookup_Ck_9) + + arrayvals_B_5.set_load(intersectk_7.out_ref1(), intersectk_7) + + arrayvals_C_6.set_load(intersectk_7.out_ref2(), intersectk_7) + + mul_4.set_in1(arrayvals_B_5.out_val(), arrayvals_B_5) + mul_4.set_in2(arrayvals_C_6.out_val(), arrayvals_C_6) + + reduce_3.set_in_val(mul_4.out_val(), mul_4) + + fiberwrite_Xvals_0.set_input(reduce_3.out_val(), reduce_3) + + fiberlookup_Bi_17.update() + fiberwrite_X0_2.update() + repsiggen_i_15.update() + repeat_Ci_14.update() + fiberlookup_Cj_13.update() + fiberlookup_Ck_9.update() + fiberwrite_X1_1.update() + repsiggen_j_11.update() + repeat_Bj_10.update() + fiberlookup_Bk_8.update() + intersectk_7.update() + arrayvals_B_5.update() + arrayvals_C_6.update() + mul_4.update() + reduce_3.update() + fiberwrite_Xvals_0.update() + + done = fiberwrite_X0_2.out_done() and fiberwrite_X1_1.out_done() and fiberwrite_Xvals_0.out_done() + time_cnt += 1 + + fiberwrite_X0_2.autosize() + fiberwrite_X1_1.autosize() + fiberwrite_Xvals_0.autosize() + + out_crds = [fiberwrite_X0_2.get_arr(), fiberwrite_X1_1.get_arr()] + out_segs = [fiberwrite_X0_2.get_seg_arr(), fiberwrite_X1_1.get_seg_arr()] + out_vals = fiberwrite_Xvals_0.get_arr() + + def bench(): + time.sleep(0.01) + + extra_info = dict() + extra_info["dataset"] = ssname + extra_info["cycles"] = time_cnt + extra_info["tensor_B_shape"] = B_shape + extra_info["tensor_C_shape"] = C_shape + extra_info["tensor_B/nnz"] = len(B_vals) + extra_info["tensor_C/nnz"] = len(C_vals) + + extra_info["result/vals_size"] = len(out_vals) + extra_info["result/nnz"] = len([x for x in out_vals if x != 0]) + + sample_dict = fiberlookup_Bi_17.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberlookup_Bi_17" + "/" + k] = sample_dict[k] + + sample_dict = fiberwrite_X0_2.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X0_2" + "/" + k] = sample_dict[k] + + sample_dict = repeat_Ci_14.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Ci_14" + "/" + k] = sample_dict[k] + + sample_dict = fiberlookup_Cj_13.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberlookup_Cj_13" + "/" + k] = sample_dict[k] + + sample_dict = fiberwrite_X1_1.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X1_1" + "/" + k] = sample_dict[k] + + sample_dict = repeat_Bj_10.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Bj_10" + "/" + k] = sample_dict[k] + + sample_dict = fiberlookup_Bk_8.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberlookup_Bk_8" + "/" + k] = sample_dict[k] + + sample_dict = fiberlookup_Ck_9.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberlookup_Ck_9" + "/" + k] = sample_dict[k] + + sample_dict = intersectk_7.return_statistics() + for k in sample_dict.keys(): + extra_info["intersectk_7" + "/" + k] = sample_dict[k] + + sample_dict = arrayvals_B_5.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_B_5" + "/" + k] = sample_dict[k] + + sample_dict = arrayvals_C_6.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_C_6" + "/" + k] = sample_dict[k] + + sample_dict = mul_4.return_statistics() + for k in sample_dict.keys(): + extra_info["mul_4" + "/" + k] = sample_dict[k] + + sample_dict = reduce_3.return_statistics() + for k in sample_dict.keys(): + extra_info["reduce_3" + "/" + k] = sample_dict[k] + + sample_dict = fiberwrite_Xvals_0.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_Xvals_0" + "/" + k] = sample_dict[k] + + # make open csv file, append (don't overwrite!!!) + with open('/home/ginasohn/sam-fixed/sam-fixed/small_50_matmul_ijk.csv', 'a', newline='') as file: + writer = csv.writer(file) + writer.writerow([ssname, time_cnt]) + + gen_gantt(extra_info, "matmul_ijk") + + if check_gold: + print("Checking gold...") + sim_pt_list = get_point_list(out_crds, out_segs, val_arr=out_vals) + sim_mg = create_matrix_from_point_list(name="X", pt_list=sim_pt_list, shape=[B_shape[0], C_shape[0]]) + x_mat_sim = sim_mg.get_matrix() + + # GET NUMPY REPS OF INPUT MATS + b_mg = get_tensor_from_files(name="B", files_dir=B_dirname, shape=B_shape) + b_mat = b_mg.get_matrix() + # print(b_mat) + # C is stored in DCSC - need to transpose upon reading. + c_mg = get_tensor_from_files(name="C", files_dir=C_dirname, shape=C_shape) + c_mat = c_mg.get_matrix() + c_mat_transpose = numpy.transpose(c_mat) + # print(c_mat_transpose) + # c_mat_transpose = c_mat + + x_mat_gold = numpy.matmul(b_mat, c_mat_transpose) + print(x_mat_gold) + print(x_mat_sim) + + assert numpy.array_equal(x_mat_gold, x_mat_sim) + + # check_gold_matmul(ssname, debug_sim, out_crds, out_segs, out_vals, "ss01") + samBench(bench, extra_info) \ No newline at end of file From 06b9b0c149a018aeb5d27d8acd77feb705d56ae3 Mon Sep 17 00:00:00 2001 From: Gina Sohn Date: Fri, 10 Feb 2023 10:03:35 -0800 Subject: [PATCH 08/76] gantt chart bars in a consistent order --- sam/sim/test/gen_gantt.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/sam/sim/test/gen_gantt.py b/sam/sim/test/gen_gantt.py index b79dc1a1..e716ce85 100644 --- a/sam/sim/test/gen_gantt.py +++ b/sam/sim/test/gen_gantt.py @@ -16,15 +16,22 @@ def gen_gantt(extra_info, testname): finish_c = extra_info[k] elif ("start_cycle" in k) and (sam_name in k.split('/')[0]): start_c = extra_info[k] - block_list.append(sam_name) + # We assume that the info to extra_info is added in the same order + # each block is updated + block_list.insert(0, sam_name) + # block_list.append(sam_name) if not isinstance(start_c, int): - start_list.append(int(start_c)) - duration_list.append(finish_c - int(start_c)) + # start_list.append(int(start_c)) + # duration_list.append(finish_c - int(start_c)) + start_list.insert(0, int(start_c)) + duration_list.insert(0, finish_c - int(start_c)) else: - start_list.append(start_c) - duration_list.append(finish_c - start_c) + # start_list.append(start_c) + # duration_list.append(finish_c - start_c) + start_list.insert(0, start_c) + duration_list.insert(0, finish_c - start_c) plt.barh(y=block_list, width=duration_list, left=start_list) - + file_name = testname + '_' + extra_info["dataset"] + ".png" plt.savefig(file_name, bbox_inches="tight") From f7036d7258b6506bbc472787532cb4be29d6341e Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 10 Feb 2023 11:52:19 -0800 Subject: [PATCH 09/76] Add in fixes for suitesparse_runner script --- Makefile | 12 ++++++------ scripts/suitesparse_runner.sh | 25 +++++++++++-------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 0a4882a9..b3ace47e 100644 --- a/Makefile +++ b/Makefile @@ -31,12 +31,12 @@ endif ifeq ("$(NEVA)","ON") CMD := OMP_PROC_BIND=true LD_LIBRARY_PATH=compiler/build/lib/:$(LD_LIBRARY_PATH) numactl -C 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 -m 0 compiler/build/taco-bench $(BENCHFLAGS) - export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse/ - export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt/ - export SUITESPARSE_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/suitesparse-formatted - export FROSTT_FORMATTED_TACO_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted/taco-tensor - export FROSTT_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted - export TACO_TENSOR_PATH=/nobackup/owhsu/sparse-datasets + #export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse/ + #export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt/ + #export SUITESPARSE_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/suitesparse-formatted + #export FROSTT_FORMATTED_TACO_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted/taco-tensor + #export FROSTT_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted + #export TACO_TENSOR_PATH=/nobackup/owhsu/sparse-datasets else ifeq ("$(LANKA)", "ON") CMD := OMP_PROC_BIND=true LD_LIBRARY_PATH=compiler/build/lib/:$(LD_LIBRARY_PATH) numactl -C 0,2,4,6,8,10,24,26,28,30,32,34 -m 0 compiler/build/taco-bench $(BENCHFLAGS) export SUITESPARSE_PATH=/data/scratch/changwan/florida_all diff --git a/scripts/suitesparse_runner.sh b/scripts/suitesparse_runner.sh index 33b95b6b..b933021e 100755 --- a/scripts/suitesparse_runner.sh +++ b/scripts/suitesparse_runner.sh @@ -8,28 +8,25 @@ set -u cwd=$(pwd) sspath=$SUITESPARSE_PATH + # LANKA -if [ $2 -eq 1 ]; then - lanka=ON - neva=OFF -elif [ $2 -eq 2 ]; then - lanka=OFF - neva=ON -else - lanka=OFF - neva=OFF -fi + if [ $2 -eq 1 ]; then + lanka=ON + neva=OFF + elif [ $2 -eq 2 ]; then + lanka=OFF + neva=ON + else + fi out=suitesparse-bench/taco mkdir -p "$out" while read line; do - if [ $2 -eq 1 ]; then + if [ $LANKA -eq 1 ]; then matrix="$sspath/$line/$line.mtx" - elif [ $2 -eq 2 ]; then - matrix="$sspath/$line.mtx" - else + else matrix="$sspath/$line.mtx" fi csvout="$out/result-$line.csv" From d485cdaf9a46b1976c066a322adbd14c9b0d43c9 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 10 Feb 2023 13:23:03 -0800 Subject: [PATCH 10/76] Fixes to suitesparse_runner --- Makefile | 32 ++++++++++++-------------------- scripts/suitesparse_runner.sh | 4 +++- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index b3ace47e..b65225ed 100644 --- a/Makefile +++ b/Makefile @@ -31,20 +31,20 @@ endif ifeq ("$(NEVA)","ON") CMD := OMP_PROC_BIND=true LD_LIBRARY_PATH=compiler/build/lib/:$(LD_LIBRARY_PATH) numactl -C 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 -m 0 compiler/build/taco-bench $(BENCHFLAGS) - #export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse/ - #export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt/ - #export SUITESPARSE_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/suitesparse-formatted - #export FROSTT_FORMATTED_TACO_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted/taco-tensor - #export FROSTT_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted - #export TACO_TENSOR_PATH=/nobackup/owhsu/sparse-datasets + # export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse/ + # export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt/ + # export SUITESPARSE_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/suitesparse-formatted + # export FROSTT_FORMATTED_TACO_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted/taco-tensor + # export FROSTT_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted + # export TACO_TENSOR_PATH=/nobackup/owhsu/sparse-datasets else ifeq ("$(LANKA)", "ON") CMD := OMP_PROC_BIND=true LD_LIBRARY_PATH=compiler/build/lib/:$(LD_LIBRARY_PATH) numactl -C 0,2,4,6,8,10,24,26,28,30,32,34 -m 0 compiler/build/taco-bench $(BENCHFLAGS) - export SUITESPARSE_PATH=/data/scratch/changwan/florida_all - export FROSTT_PATH=/data/scratch/owhsu/datasets/frostt - export TACO_TENSOR_PATH=/data/scratch/owhsu/datasets - export SUITESPARSE_FORMATTED_PATH=/data/scratch/owhsu/datasets/suitesparse-formatted - export FROSTT_FORMATTED_TACO_PATH=/data/scratch/owhsu/datasets/frostt-formatted/taco-tensor - export FROSTT_FORMATTED_PATH=/data/scratch/owhsu/datasets/frostt-formatted + # export SUITESPARSE_PATH=/data/scratch/changwan/florida_all + # export FROSTT_PATH=/data/scratch/owhsu/datasets/frostt + # export TACO_TENSOR_PATH=/data/scratch/owhsu/datasets + # export SUITESPARSE_FORMATTED_PATH=/data/scratch/owhsu/datasets/suitesparse-formatted + # export FROSTT_FORMATTED_TACO_PATH=/data/scratch/owhsu/datasets/frostt-formatted/taco-tensor + # export FROSTT_FORMATTED_PATH=/data/scratch/owhsu/datasets/frostt-formatted else CMD := LD_LIBRARY_PATH=compiler/build/lib/:$(LD_LIBRARY_PATH) compiler/build/taco-bench $(BENCHFLAGS) endif @@ -114,14 +114,6 @@ suitesparse-formats: guard-SUITESPARSE_FORMATTED_PATH guard-SUITESPARSE_PATH frostt-formats: taco/build guard-FROSTT_FORMATTED_PATH guard-FROSTT_PATH ./scripts/generate_frostt_formats.sh -.PHONY: env -env: - export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse/ - export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt/ - export SUITESPARSE_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/suitesparse-formatted - export FROSTT_FORMATTED_TACO_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted/taco-tensor - export FROSTT_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted - .PHONY: pydepends pydepends: conda env export > environment.yml diff --git a/scripts/suitesparse_runner.sh b/scripts/suitesparse_runner.sh index b933021e..8aa4aace 100755 --- a/scripts/suitesparse_runner.sh +++ b/scripts/suitesparse_runner.sh @@ -17,6 +17,8 @@ sspath=$SUITESPARSE_PATH lanka=OFF neva=ON else + lanka=OFF + neva=OFF fi out=suitesparse-bench/taco @@ -24,7 +26,7 @@ out=suitesparse-bench/taco mkdir -p "$out" while read line; do - if [ $LANKA -eq 1 ]; then + if [ $2 -eq 1 ]; then matrix="$sspath/$line/$line.mtx" else matrix="$sspath/$line.mtx" From f8b0fa5c5c8318bbd6bf5746800665d9458a195e Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 10 Feb 2023 13:40:00 -0800 Subject: [PATCH 11/76] Add in fix to bench_csv_aggregator --- scripts/bench_csv_aggregator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bench_csv_aggregator.py b/scripts/bench_csv_aggregator.py index 58a6f1f1..c24b7789 100644 --- a/scripts/bench_csv_aggregator.py +++ b/scripts/bench_csv_aggregator.py @@ -24,7 +24,7 @@ def aggregateTacoBenches(folder, outfile, taco=False, labelSet=None): # Discard the first 9 lines. This corresponds to the # google-benchmark generated header. if taco: - for i in range(0, 10): + for i in range(0, 9): f.readline() # Open the rest of the file as a CSV. reader = csv.reader(f) From 704d00c8d196a343b1f0a318711d1a5e4da4b943 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 10 Feb 2023 15:24:51 -0800 Subject: [PATCH 12/76] Add in info about scripts --- compiler/README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 compiler/README.md diff --git a/compiler/README.md b/compiler/README.md new file mode 100644 index 00000000..cfa57852 --- /dev/null +++ b/compiler/README.md @@ -0,0 +1,6 @@ +Name | Tags | Description | +-------------------------------- +`./scripts/suitesparse_runner.sh <0|1|2>` | `cpu-taco`, `ss`, `machine` | Gets the TACO CPU runtime baselines for SuiteSparse and stores it to `suitesparse-bench/taco/`. +`python scripts/bench_csv_aggregator.py [--taco] [--label_set_file ]` | `cpu-taco`, `sam`, `ss`, `frostt` | Aggregates all csvs from a directory into one file. Can do this for either the TACO-generated (`--taco`) or SAM-generated CSVs + + From f6b558e81d5ccb67461b2de331cbfddd11e18962 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 10 Feb 2023 15:33:42 -0800 Subject: [PATCH 13/76] Fix a README mistake --- compiler/README.md | 6 ------ scripts/README.md | 5 +++-- 2 files changed, 3 insertions(+), 8 deletions(-) delete mode 100644 compiler/README.md diff --git a/compiler/README.md b/compiler/README.md deleted file mode 100644 index cfa57852..00000000 --- a/compiler/README.md +++ /dev/null @@ -1,6 +0,0 @@ -Name | Tags | Description | --------------------------------- -`./scripts/suitesparse_runner.sh <0|1|2>` | `cpu-taco`, `ss`, `machine` | Gets the TACO CPU runtime baselines for SuiteSparse and stores it to `suitesparse-bench/taco/`. -`python scripts/bench_csv_aggregator.py [--taco] [--label_set_file ]` | `cpu-taco`, `sam`, `ss`, `frostt` | Aggregates all csvs from a directory into one file. Can do this for either the TACO-generated (`--taco`) or SAM-generated CSVs - - diff --git a/scripts/README.md b/scripts/README.md index b004db54..ae9b9207 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,4 +1,5 @@ ----------------------------------- | File Name | Usage | Description | ----------------------------------- -| +`./scripts/suitesparse_runner.sh <0|1|2>` | `cpu-taco`, `ss`, `machine` | Gets the TACO CPU runtime baselines for SuiteSparse and stores it to `suitesparse-bench/taco/`. +`python scripts/bench_csv_aggregator.py [--taco] [--label_set_file ]` | `cpu-taco`, `sam`, `ss`, `frostt` | Aggregates all csvs from a directory into one file. Can do this for either the TACO-generated (`--taco`) or SAM-generated CSVs + From 394581b5d55c562297ce87d0837bdfea9dfbf8d5 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 10 Feb 2023 15:34:35 -0800 Subject: [PATCH 14/76] Get md table working --- scripts/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index ae9b9207..468459ef 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,5 +1,5 @@ | File Name | Usage | Description | ----------------------------------- -`./scripts/suitesparse_runner.sh <0|1|2>` | `cpu-taco`, `ss`, `machine` | Gets the TACO CPU runtime baselines for SuiteSparse and stores it to `suitesparse-bench/taco/`. -`python scripts/bench_csv_aggregator.py [--taco] [--label_set_file ]` | `cpu-taco`, `sam`, `ss`, `frostt` | Aggregates all csvs from a directory into one file. Can do this for either the TACO-generated (`--taco`) or SAM-generated CSVs +| `./scripts/suitesparse_runner.sh <0|1|2>` | `cpu-taco`, `ss`, `machine` | Gets the TACO CPU runtime baselines for SuiteSparse and stores it to `suitesparse-bench/taco/` | +| `python scripts/bench_csv_aggregator.py [--taco] [--label_set_file ]` | `cpu-taco`, `sam`, `ss`, `frostt` | Aggregates all csvs from a directory into one file. Can do this for either the TACO-generated (`--taco`) or SAM-generated CSVs | From afabcc421686029631e6f37b819a2e5da8d0a7de Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 10 Feb 2023 16:41:56 -0800 Subject: [PATCH 15/76] Update README.md --- scripts/README.md | 52 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 468459ef..a4e0fac6 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,5 +1,49 @@ -| File Name | Usage | Description | ------------------------------------ -| `./scripts/suitesparse_runner.sh <0|1|2>` | `cpu-taco`, `ss`, `machine` | Gets the TACO CPU runtime baselines for SuiteSparse and stores it to `suitesparse-bench/taco/` | -| `python scripts/bench_csv_aggregator.py [--taco] [--label_set_file ]` | `cpu-taco`, `sam`, `ss`, `frostt` | Aggregates all csvs from a directory into one file. Can do this for either the TACO-generated (`--taco`) or SAM-generated CSVs | +# Tags +1. `cpu-taco` means it is used to get baseline runtime for TACO running on the CPU +2. `sam` means it is used to get cycles for SAM +3. `format` means it is used to format the data into the correct datastructures for SAM +4. `ss` means it is used to run SuiteSparse benchmarks +5. `frostt` means it is used to run FROSTT benchmarks +6. `synth` means it is used to run synthetic data benchmarks +7. `machine` means it needs an argument to tell the script about the machine running (local, Neva/Kiwi, or Lanka) +8. `sam-mem` means it is used for the SAM memory modeling simulator +9. `artifact` means it is used for the [SAM ASPLOS '23 artifact evaluation](https://github.com/weiya711/sam-artifact) (ASPLOS23 AE) +10. `plot` means it is used to plot data + +# Command and Desciption + +1. `./scriptsadvanced_simulator_runner.sh ... TODO` +2. `python scripts/artifact_docker_copy.py --output_dir --docker_id ` + + Tags: `artifact` + Description: Extracts all figures from docker to your local machine (see [Validate All Results](https://github.com/weiya711/sam-artifact#Validate-All-Results) in the SAM artifact evaluation README +3. `python scripts/bench_csv_aggregator.py [--taco] [--label_set_file ]` + + Tags: `cpu-taco`, `sam`, `ss`, `frostt` + Description: Aggregates all csvs from a directory into one file. Can do this for either the TACO-generated (`--taco`) or SAM-generated CSVs +4. `./scripts/clean_memory_model.sh` + + Tags: `sam-mem`, `artifact` + Description: Cleans all directories related to the SAM memory modeling simulator and is used in the ASPLOS23 AE +5. `python scripts/collect_node_counts.py [--sam_graphs --output_log ] + + Tags: `artifact` + Description: `make sam` must be run before this script. This generates Table 1 in the ASPLOS '23 SAM paper for the AE +6. `python converter.py ... TODO` + Tags: `sam` + Description: Converts JSONs to CSVs for SAM/pytest benchmarks +7. `python scripts/datastructure_suitesparse.py ... TODO` + Note: Do not use this, the `generate_suitesparse_formats.sh` script should be used instead +8. `python datastructure_tns.py` + TODO +9. `python divvy_runs.py` + TODO + + +43. `./scripts/suitesparse_runner.sh <0|1|2>` + + Tags: `cpu-taco`, `ss`, `machine` + Description: Gets the TACO CPU runtime baselines for SuiteSparse and stores it to `suitesparse-bench/taco/` + +50. From 9c3109bd1b16cb27d0c2cca473bb721f8851385e Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 17 Feb 2023 10:18:48 -0800 Subject: [PATCH 16/76] Add in scripts for onyx tiling --- sam/onyx/synthetic/generate_fixed_nnz_mats.py | 20 +++++++++++++++---- sam/sim/src/channel.py | 1 + sam/sim/src/tiling/memory_config_onyx.yaml | 4 ++-- sam/util.py | 4 ++-- scripts/generate_sparsity_sweep_mem_model.sh | 2 +- scripts/prepare_files.sh | 4 ++-- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/sam/onyx/synthetic/generate_fixed_nnz_mats.py b/sam/onyx/synthetic/generate_fixed_nnz_mats.py index ec099dfb..6671fcc2 100644 --- a/sam/onyx/synthetic/generate_fixed_nnz_mats.py +++ b/sam/onyx/synthetic/generate_fixed_nnz_mats.py @@ -1,7 +1,7 @@ import scipy.io import scipy.sparse import numpy as np - +import argparse def generate_mat(nnz, dim): return scipy.sparse.random(dim, dim, nnz / (dim**2), data_rvs=np.ones) @@ -14,9 +14,21 @@ def write_mtx(path, t): if __name__ == "__main__": seed = 0 np.random.seed(seed) - # 1024 - dims = list(range(1024, 15721, 1336)) - nnzs = [5000, 10000, 25000, 50000] + + parser = argparse.ArgumentParser(description="Create some random matrices of given nnz and dim") + parser.add_argument('--nnz', type=int, nargs='+', help='nnz') + parser.add_argument('--dim', type=int, nargs='+', help='dim') + parser.add_argument('--extensor', action='store_true', help='generate extensor dims and nnzs') + args = parser.parse_args() + + + if args.extensor: + dims = list(range(1024, 15721, 1336)) + nnzs = [5000, 10000, 25000, 50000] + else: + dims = args.dim + nnzs = args.nnz + print("RUNNING:", dims, nnzs) for nnz in nnzs: for dim in dims: diff --git a/sam/sim/src/channel.py b/sam/sim/src/channel.py index 87fd36fe..6e20222f 100644 --- a/sam/sim/src/channel.py +++ b/sam/sim/src/channel.py @@ -219,6 +219,7 @@ def input_token_(self, token): self.downstream_token = token +# FIXME: Follow code style and fix class naming convention and make sure it's base is primitive... class memory_block(): def __init__(self, name="B", skip_blocks=False, element_size=2, level=None, indexes=2, size=1000 * 2, nbuffer=False, latency=10, debug=False, bandwidth=2, diff --git a/sam/sim/src/tiling/memory_config_onyx.yaml b/sam/sim/src/tiling/memory_config_onyx.yaml index befb9cad..74c80c27 100644 --- a/sam/sim/src/tiling/memory_config_onyx.yaml +++ b/sam/sim/src/tiling/memory_config_onyx.yaml @@ -15,5 +15,5 @@ Bytes_per_element: 2 # Number n_levels: 3 level_names: ["Main", "Glb", "Mem"] Main_tile_size: None -Glb_tile_size: 16 # 16 # 120 # n = (nxn) elements -Mem_tile_size: 128 # Size of one dense dimension. 8 = (8x8) +Glb_tile_size: 8 # 8 = (8x8) = 64 elements +Mem_tile_size: 45 # Size of one dense dimension. 45 = (45*45) = 2025 diff --git a/sam/util.py b/sam/util.py index 96cc15c5..7044e94d 100644 --- a/sam/util.py +++ b/sam/util.py @@ -7,7 +7,7 @@ import shutil import numpy as np import math -import pydata +import sparse from pathlib import Path from dataclasses import dataclass @@ -601,7 +601,7 @@ def safeCastPydataTensorToInts(tensor): # else: # data[i] = int(tensor.data[i]) data[i] = round_sparse(tensor.data[i]) - return pydata.sparse.COO(tensor.coords, data, tensor.shape) + return sparse.COO(tensor.coords, data, tensor.shape) def parse_taco_format(infilename, outdir, tensorname, format_str): diff --git a/scripts/generate_sparsity_sweep_mem_model.sh b/scripts/generate_sparsity_sweep_mem_model.sh index 4ac85ed3..67a339b9 100755 --- a/scripts/generate_sparsity_sweep_mem_model.sh +++ b/scripts/generate_sparsity_sweep_mem_model.sh @@ -2,7 +2,7 @@ SECONDS=0 mkdir extensor_mtx cd extensor_mtx -python ../sam/onyx/synthetic/generate_fixed_nnz_mats.py +python ../sam/onyx/synthetic/generate_fixed_nnz_mats.py --extensor cd .. ELAPSED="Elapsed: $(($SECONDS / 3600))hrs $((($SECONDS / 60) % 60))min $(($SECONDS % 60))sec" printf "$ELAPSED" diff --git a/scripts/prepare_files.sh b/scripts/prepare_files.sh index bed6796c..f14f0380 100755 --- a/scripts/prepare_files.sh +++ b/scripts/prepare_files.sh @@ -9,6 +9,6 @@ basedir=$(pwd) rm -rf $basedir/tiles/* -./scripts/tile_ext.sh $1 memory_config_extensor_17M_llb.yaml +./scripts/tile_ext.sh $1 $2 -python scripts/generate_gold_matmul_tiled.py --yaml_name memory_config_extensor_17M_llb.yaml +python scripts/generate_gold_matmul_tiled.py --yaml_name $2 From 5968062fe822792ce92901b48d4407d884fd4afb Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 17 Feb 2023 10:26:54 -0800 Subject: [PATCH 17/76] Add in file, oops --- scripts/prepare_tiles_onyx.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 scripts/prepare_tiles_onyx.sh diff --git a/scripts/prepare_tiles_onyx.sh b/scripts/prepare_tiles_onyx.sh new file mode 100755 index 00000000..7bea7baf --- /dev/null +++ b/scripts/prepare_tiles_onyx.sh @@ -0,0 +1,33 @@ +#!/bin/bash +#sbatch -n 1 +#sbatch --mem 120000 +#sbatch -p lanka-v3 +#sbatch --exclusive + + +basedir=$(pwd) +yaml_fname=memory_config_onyx.yaml +line=random_sparsity + +nnz=$1 +dim=$2 +echo "running for point nnz=$nnz and dimsize=$dim" + +export sam_home=$basedir +export tiled_suitesparse_formatted_path=${sam_home}/tiles/matmul_ikj/formatted +export tiled_output_path=${sam_home}/tiles/matmul_ikj/output/ + +pushd . + +mkdir extensor_mtx +cd extensor_mtx +python ../sam/onyx/synthetic/generate_fixed_nnz_mats.py --nnz $nnz --dim $dim +cd .. + +mkdir -p $path + +mkdir -p $basedir/tiles/ +rm -rf $basedir/tiles/* + +./scripts/prepare_files.sh extensor_${nnz}_${dim}.mtx $yaml_fname + From b66156e41973075c5a95f65e78ce29313f1419e8 Mon Sep 17 00:00:00 2001 From: Gina Sohn Date: Tue, 21 Feb 2023 14:11:48 -0800 Subject: [PATCH 18/76] code to generate cycle info csv file & stats txt file --- sam/sim/test/gen_gantt.py | 45 ++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/sam/sim/test/gen_gantt.py b/sam/sim/test/gen_gantt.py index e716ce85..8adc676a 100644 --- a/sam/sim/test/gen_gantt.py +++ b/sam/sim/test/gen_gantt.py @@ -1,9 +1,11 @@ import matplotlib.pyplot as plt +import csv def gen_gantt(extra_info, testname): block_list = [] start_list = [] + finish_list = [] duration_list = [] start_c = '' @@ -14,24 +16,47 @@ def gen_gantt(extra_info, testname): if "done_cycles" in k: sam_name = k.split('/')[0] finish_c = extra_info[k] + if not isinstance(finish_c, int): + finish_list.insert(0, int(finish_c)) + else: + finish_list.insert(0, finish_c) elif ("start_cycle" in k) and (sam_name in k.split('/')[0]): - start_c = extra_info[k] - # We assume that the info to extra_info is added in the same order - # each block is updated + ''' + We assume that the info to extra_info is added + in the same order each block is updated. + If we assume the opposite order, use append function + instea of insert. + (e.g.) block_list.insert(0, sam_name) -> block_list.append(sam_name) + ''' block_list.insert(0, sam_name) - # block_list.append(sam_name) + start_c = extra_info[k] if not isinstance(start_c, int): - # start_list.append(int(start_c)) - # duration_list.append(finish_c - int(start_c)) start_list.insert(0, int(start_c)) duration_list.insert(0, finish_c - int(start_c)) else: - # start_list.append(start_c) - # duration_list.append(finish_c - start_c) start_list.insert(0, start_c) duration_list.insert(0, finish_c - start_c) - plt.barh(y=block_list, width=duration_list, left=start_list) + + back_depth = '0' + if extra_info["backpressure"]: + back_depth = extra_info["depth"] - file_name = testname + '_' + extra_info["dataset"] + ".png" + # Writing cycle info to csv file + with open(testname + '_' + extra_info["dataset"] + '_back'+back_depth+'.csv', 'w', newline='') as file: + writer = csv.writer(file) + writer.writerow(["block","start","finish","duration","valid_ops"]) + for idx, block in reversed(list(enumerate(block_list))): + writer.writerow([block, start_list[idx], finish_list[idx], duration_list[idx],'-']) + + # Print all the statistics to a text file + text_file = open(testname + '_' + extra_info["dataset"] + '_back'+back_depth+".txt","w") + for k in extra_info.keys(): + if "/" in k: + text_file.write(k+": "+str(extra_info[k])+"\n") + text_file.close() + + # Creating gantt chart + plt.barh(y=block_list, width=duration_list, left=start_list) + file_name = testname + '_' + extra_info["dataset"] + "_back"+back_depth+".png" plt.savefig(file_name, bbox_inches="tight") From 20d69ec2d634c15e2e400dcfdf0e600c4cc020de Mon Sep 17 00:00:00 2001 From: Gina Sohn Date: Mon, 6 Mar 2023 17:38:54 -0800 Subject: [PATCH 19/76] Add gant-chart generation for matmul --- .gitignore | 9 + datastructure_suitesparse.py | 281 ++++++++++++++++++ environment.yml | 4 +- .../test/final-apps/test_mat_elemadd_FINAL.py | 51 ++-- .../test_matmul_kij_FINAL.py | 249 ++++++++++++++++ .../reorder-study/test_reorder_matmul_ikj.py | 91 +++--- .../reorder-study/test_reorder_matmul_jik.py | 74 ++--- .../reorder-study/test_reorder_matmul_jki.py | 58 ++-- .../reorder-study/test_reorder_matmul_kij.py | 58 ++-- .../reorder-study/test_reorder_matmul_kji.py | 60 ++-- .../download_suitesparse_stream_overhead.sh | 75 +++++ scripts/download_unpack_format_suitesparse.sh | 20 +- 12 files changed, 839 insertions(+), 191 deletions(-) create mode 100644 datastructure_suitesparse.py create mode 100644 sam/sim/test/reorder-study-gina/test_matmul_kij_FINAL.py create mode 100755 scripts/download_suitesparse_stream_overhead.sh diff --git a/.gitignore b/.gitignore index 82490b68..bf36fd9e 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ cmake-build-*/ # Generated SAM Graphs *.gv +venv/ + # Generated images *.svg *.png @@ -54,3 +56,10 @@ tensor_*_mode_* # Tensor files tiles/ + +setenv.sh +parse_nnz.py +scripts/small50_script.sh +scripts/gen_cycle_csv.py +scripts/data_gen_suitesparse_g.sh +sam/sim/test/reorder-study-gina/* \ No newline at end of file diff --git a/datastructure_suitesparse.py b/datastructure_suitesparse.py new file mode 100644 index 00000000..5b36b313 --- /dev/null +++ b/datastructure_suitesparse.py @@ -0,0 +1,281 @@ +import argparse +import os +import shutil +import scipy.sparse +import numpy as np + +from pathlib import Path + +from scripts.util import FormatWriter, SuiteSparseTensor, InputCacheSuiteSparse +from sam.util import SUITESPARSE_FORMATTED_PATH, ScipyTensorShifter + +all_formats = ["coo", "cooT", "csr", "dcsr", "dcsc", "csc", "dense", "denseT"] +formats = ["coo", "cooT", "csr", "dcsr", "dcsc", "csc", "dense"] +scipy_formats = ["coo", "csr", "csc"] + + +def write_datastructure_tiles(args, tensor, out_path, tile_name): + print("Writing " + args.name + " for test " + args.benchname + "...") + + dirname = args.output_dir_path if args.output_dir_path is not None else os.path.join(out_path, args.name, args.benchname) + dirname = os.path.join(dirname, tile_name) + dirpath = Path(dirname) + if os.path.exists(dirpath): + shutil.rmtree(dirpath) + dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) + + print(tile_name) + tensorname = tile_name.split("_")[1] + + coo = inputCache.load(tensor, False) + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss01", hw=False) + + +def write_datastructure_bench(args, tensor, out_path, tiles=None): + shifter = ScipyTensorShifter() + + print("Writing " + args.name + " for test " + args.benchname + "...") + + dirname = args.output_dir_path if args.output_dir_path is not None else os.path.join(out_path, args.name, args.benchname) + if tiles is not None: + dirname = os.path.join(dirname, tiles) + dirpath = Path(dirname) + if os.path.exists(dirpath): + shutil.rmtree(dirpath) + dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) + + if "mat_mattransmul" in args.benchname or "mat_residual" in args.benchname: + tensorname = "C" + else: + tensorname = "B" + + coo = inputCache.load(tensor, False) + shape = coo.shape + + # These benchmarks need format_str == "ss10" + if args.benchname not in ["matmul_kij", "matmul_kji", "matmul_jki", "mat_vecmul", "mat_vecmul_ji", "mat_mattransmul"]: + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss01") + + if "matmul_ijk" in args.benchname: + shifted = shifter.shiftLastMode(coo) + + print("Writing " + args.name + " shifted and transposed...") + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss10") + + elif "matmul_jik" in args.benchname: + shifted = shifter.shiftLastMode(coo) + + print("Writing " + args.name + " shifted and transposed...") + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss10") + elif "matmul_ikj" in args.benchname: + shifted = shifter.shiftLastMode(coo) + + print("Writing " + args.name + " shifted and transposed...") + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss01") + + elif "matmul_jki" in args.benchname: + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + + shifted = shifter.shiftLastMode(coo) + + print("Writing " + args.name + " shifted and transposed...") + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss10") + + elif "matmul_kij" in args.benchname: + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + + shifted = shifter.shiftLastMode(coo) + + print("Writing " + args.name + " shifted and transposed...") + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss01") + + elif "matmul_kji" in args.benchname: + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + + shifted = shifter.shiftLastMode(coo) + + print("Writing " + args.name + " shifted and transposed...") + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss01") + + elif "mat_elemadd3" in args.benchname: + print("Writing " + args.name + " shifted...") + tensorname = "C" + shifted = shifter.shiftLastMode(coo) + formatWriter.writeout_separate_sparse_only(shifted, dirname, tensorname, format_str="ss01") + + print("Writing " + args.name + " shifted2...") + tensorname = "D" + shifted2 = shifter.shiftLastMode(shifted) + formatWriter.writeout_separate_sparse_only(shifted2, dirname, tensorname, format_str="ss01") + + elif "mat_elemadd" in args.benchname or "mat_elemmul" in args.benchname: + print("Writing " + args.name + " shifted...") + tensorname = "C" + shifted = shifter.shiftLastMode(coo) + formatWriter.writeout_separate_sparse_only(shifted, dirname, tensorname, format_str="ss01") + + elif "mat_mattransmul" in args.benchname: + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + if not args.no_gen_other: + tensorname = 'd' + vec = scipy.sparse.random(shape[0], 1, density=args.density, data_rvs=np.ones) + vec = vec.toarray().flatten() + formatWriter.writeout_separate_vec(vec, dirname, tensorname) + + tensorname = 'f' + vec = scipy.sparse.random(shape[1], 1, density=args.density, data_rvs=np.ones) + vec = vec.toarray().flatten() + formatWriter.writeout_separate_vec(vec, dirname, tensorname) + elif "mat_vecmul" == args.benchname or "mat_vecmul_ji" in args.benchname: + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + if not args.no_gen_other: + tensorname = 'c' + vec = scipy.sparse.random(shape[1], 1, density=args.density, data_rvs=np.ones) + vec = vec.toarray().flatten() + formatWriter.writeout_separate_vec(vec, dirname, tensorname) + elif "mat_vecmul_ij" in args.benchname: + pass + elif "mat_sddmm" in args.benchname: + pass + elif "mat_residual" in args.benchname: + if not args.no_gen_other: + tensorname = 'b' + vec = scipy.sparse.random(shape[0], 1, density=args.density, data_rvs=np.ones) + vec = vec.toarray().flatten() + formatWriter.writeout_separate_vec(vec, dirname, tensorname) + + tensorname = 'd' + vec = scipy.sparse.random(shape[1], 1, density=args.density, data_rvs=np.ones) + vec = vec.toarray().flatten() + formatWriter.writeout_separate_vec(vec, dirname, tensorname) + elif "mat_identity" in args.benchname: + pass + else: + raise NotImplementedError + + +parser = argparse.ArgumentParser(description="Process some suitesparse matrices into per-level datastructures") +parser.add_argument('-n', '--name', metavar='ssname', type=str, action='store', help='tensor name to run format ' + 'conversion on one SS tensor') +parser.add_argument('-f', '--format', metavar='ssformat', type=str, action='store', help='The format that the tensor ' + 'should be converted to') +parser.add_argument('-comb', '--combined', action='store_true', default=False, help='Whether the formatted datastructures ' + 'should be in separate files') +parser.add_argument('-o', '--omit-dense', action='store_true', default=False, help='Do not create fully dense format') +parser.add_argument('-cast', '--cast', action='store_true', default=False, help='Safe sparsity cast to int for values') +parser.add_argument('-hw', '--hw', action='store_true', default=False, + help='Only generate formats used for hardware testing (all sparse' + 'levels, concordant)') +parser.add_argument('-b', '--benchname', type=str, default=None, help='test name to run format ' + 'conversion on') +parser.add_argument('--input_path', type=str, default=None) +parser.add_argument('--output_dir_path', type=str, default=None) +parser.add_argument('--tiles', action='store_true') +parser.add_argument('--no_gen_other', action='store_true', help="Whether this" + "script should generate the randmo 'other' tensors") +parser.add_argument('--seed', type=int, default=0, help='Random seed needed for gen_other') +parser.add_argument('--density', type=int, default=0.25, help='If gen_other, used for density of "other" tensor') +args = parser.parse_args() + +np.random.seed(args.seed) + +inputCache = InputCacheSuiteSparse() +formatWriter = FormatWriter(args.cast) + +cwd = os.getcwd() +if args.output_dir_path is None: + out_dirname = SUITESPARSE_FORMATTED_PATH +else: + out_dirname = args.output_dir_path + +out_path = Path(out_dirname) +out_path.mkdir(parents=True, exist_ok=True, mode=0o777) + +if args.name is None: + print("Please enter a matrix name") + exit() + +if args.input_path is None: + SS_PATH = os.getenv('SUITESPARSE_TENSOR_PATH', default=os.path.join(cwd, 'suitesparse')) + +else: + SS_PATH = args.input_path + +tensor = None +mtx_files = None +if args.tiles: + # get all mtx tile files from args.input_path + mtx_files = [os.path.join(args.input_path, fname) for fname in os.listdir(args.input_path) if fname.endswith(".mtx")] + + tensor = [SuiteSparseTensor(mtx_file) for mtx_file in mtx_files] +elif args.input_path is not None: + tensor = SuiteSparseTensor(args.input_path) +else: + print(SS_PATH) + tensor = SuiteSparseTensor(SS_PATH) + +if args.format is not None: + assert args.format in formats + filename = os.path.join(out_path, args.name + "_" + args.format + ".txt") + + coo = inputCache.load(tensor, False) + formatWriter.writeout(coo, args.format, filename) +elif args.combined: + for format_str in formats: + filename = os.path.join(out_path, args.name + "_" + format_str + ".txt") + print("Writing " + args.name + " " + format_str + "...") + + coo = inputCache.load(tensor, False) + formatWriter.writeout(coo, format_str, filename) + + shifted_filename = os.path.join(out_path, args.name + "_shifted_" + format_str + ".txt") + shifted = ScipyTensorShifter().shiftLastMode(coo) + formatWriter.writeout(shifted, format_str, shifted_filename) + + trans_filename = os.path.join(out_path, args.name + "_trans_shifted_" + format_str + ".txt") + trans_shifted = shifted.transpose() + formatWriter.writeout(trans_shifted, format_str, trans_filename) +elif args.hw: + if args.tiles and tensor is not None: + for i, ten in enumerate(tensor): + tile_name = os.path.split(mtx_files[i])[1].split(".")[0] + write_datastructure_tiles(args, ten, out_path, tile_name) + else: + write_datastructure_bench(args, tensor, out_path) + +else: + print("Writing " + args.name + " original...") + dirname = os.path.join(out_path, args.name, "orig") + dirpath = Path(dirname) + dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) + tensorname = "B" + coo = inputCache.load(tensor, False) + formatWriter.writeout_separate(coo, dirname, tensorname, omit_dense=args.omit_dense) + + print("Writing " + args.name + " shifted...") + dirname = os.path.join(out_path, args.name, "shift") + dirpath = Path(dirname) + dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) + tensorname = "C" + shifted = ScipyTensorShifter().shiftLastMode(coo) + formatWriter.writeout_separate(shifted, dirname, tensorname, omit_dense=args.omit_dense) + + print("Writing " + args.name + " shifted and transposed...") + dirname = os.path.join(out_path, args.name, "shift-trans") + dirpath = Path(dirname) + dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate(trans_shifted, dirname, tensorname, omit_dense=args.omit_dense) diff --git a/environment.yml b/environment.yml index 991dd271..da05b414 100644 --- a/environment.yml +++ b/environment.yml @@ -1,4 +1,4 @@ -name: aha +name: py39 channels: - pytorch - anaconda @@ -201,4 +201,4 @@ dependencies: - statsmodels==0.13.2 - threadpoolctl==3.1.0 - traitlets==5.3.0 -prefix: /home/oliviahsu/miniconda3/envs/aha +prefix: /home/ginasohn/Anaconda3/envs/py39 diff --git a/sam/sim/test/final-apps/test_mat_elemadd_FINAL.py b/sam/sim/test/final-apps/test_mat_elemadd_FINAL.py index e230d329..5648a816 100644 --- a/sam/sim/test/final-apps/test_mat_elemadd_FINAL.py +++ b/sam/sim/test/final-apps/test_mat_elemadd_FINAL.py @@ -14,10 +14,13 @@ from sam.sim.test.gold import * import os import csv +from sam.sim.test.gen_gantt import gen_gantt + cwd = os.getcwd() formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) +# csv file path @pytest.mark.suitesparse def test_mat_elemadd_FINAL(samBench, ssname, cast, check_gold, report_stats, backpressure, depth, debug_sim, fill=0): @@ -147,18 +150,34 @@ def bench(): extra_info["result/vals_size"] = len(out_vals) extra_info["result/nnz"] = len([x for x in out_vals if x != 0]) - sample_dict = unioni_9.return_statistics() + sample_dict = fiberlookup_Bi_10.return_statistics() for k in sample_dict.keys(): - extra_info["unioni_9" + "/" + k] = sample_dict[k] + extra_info["fiberlookup_Bi_10" + "/" + k] = sample_dict[k] - sample_dict = unionj_6.return_statistics() + sample_dict = fiberlookup_Ci_11.return_statistics() for k in sample_dict.keys(): - extra_info["unionj_6" + "/" + k] = sample_dict[k] + extra_info["fiberlookup_Ci_11" + "/" + k] = sample_dict[k] + + sample_dict = unioni_9.return_statistics() + for k in sample_dict.keys(): + extra_info["unioni_9" + "/" + k] = sample_dict[k] sample_dict = fiberwrite_X0_2.return_statistics() for k in sample_dict.keys(): extra_info["fiberwrite_X0_2" + "/" + k] = sample_dict[k] + sample_dict = fiberlookup_Bj_7.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberlookup_Bj_7" + "/" + k] = sample_dict[k] + + sample_dict = fiberlookup_Cj_8.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberlookup_Cj_8" + "/" + k] = sample_dict[k] + + sample_dict = unionj_6.return_statistics() + for k in sample_dict.keys(): + extra_info["unionj_6" + "/" + k] = sample_dict[k] + sample_dict = fiberwrite_X1_1.return_statistics() for k in sample_dict.keys(): extra_info["fiberwrite_X1_1" + "/" + k] = sample_dict[k] @@ -167,10 +186,6 @@ def bench(): for k in sample_dict.keys(): extra_info["arrayvals_B_4" + "/" + k] = sample_dict[k] - sample_dict = fiberwrite_Xvals_0.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberwrite_Xvals_0" + "/" + k] = sample_dict[k] - sample_dict = arrayvals_C_5.return_statistics() for k in sample_dict.keys(): extra_info["arrayvals_C_5" + "/" + k] = sample_dict[k] @@ -179,21 +194,15 @@ def bench(): for k in sample_dict.keys(): extra_info["add_3" + "/" + k] = sample_dict[k] - sample_dict = fiberlookup_Bi_10.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberlookup_Bi_10" + "/" + k] = sample_dict[k] - - sample_dict = fiberlookup_Ci_11.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberlookup_Ci_11" + "/" + k] = sample_dict[k] - - sample_dict = fiberlookup_Bj_7.return_statistics() + sample_dict = fiberwrite_Xvals_0.return_statistics() for k in sample_dict.keys(): - extra_info["fiberlookup_Bj_7" + "/" + k] = sample_dict[k] + extra_info["fiberwrite_Xvals_0" + "/" + k] = sample_dict[k] + + # code for generating csv, gantt chart, txt file + extra_info["backpressure"]=backpressure + extra_info["depth"]=depth + gen_gantt(extra_info, "mat_elemadd") - sample_dict = fiberlookup_Cj_8.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberlookup_Cj_8" + "/" + k] = sample_dict[k] if check_gold: print("Checking gold...") diff --git a/sam/sim/test/reorder-study-gina/test_matmul_kij_FINAL.py b/sam/sim/test/reorder-study-gina/test_matmul_kij_FINAL.py new file mode 100644 index 00000000..57390a62 --- /dev/null +++ b/sam/sim/test/reorder-study-gina/test_matmul_kij_FINAL.py @@ -0,0 +1,249 @@ +import pytest +import time +import scipy.sparse +from sam.sim.src.rd_scanner import UncompressCrdRdScan, CompressedCrdRdScan +from sam.sim.src.wr_scanner import ValsWrScan +from sam.sim.src.joiner import Intersect2, Union2 +from sam.sim.src.compute import Multiply2, Add2 +from sam.sim.src.crd_manager import CrdDrop, CrdHold +from sam.sim.src.repeater import Repeat, RepeatSigGen +from sam.sim.src.accumulator import Reduce +from sam.sim.src.accumulator import SparseAccumulator1, SparseAccumulator2 +from sam.sim.src.token import * +from sam.sim.test.test import * +from sam.sim.test.gold import * +import os +import csv +from sam.sim.test.gen_gantt import gen_gantt + +cwd = os.getcwd() +formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) + + +@pytest.mark.suitesparse +def test_matmul_kij_FINAL(samBench, ssname, check_gold, report_stats, debug_sim, cast, backpressure, depth, fill=0): + B_dirname = os.path.join(formatted_dir, ssname, "matmul_kij") + B_shape_filename = os.path.join(B_dirname, "tensor_B_mode_shape") + B_shape = read_inputs(B_shape_filename) + + B0_seg_filename = os.path.join(B_dirname, "tensor_B_mode_0_seg") + B_seg0 = read_inputs(B0_seg_filename) + B0_crd_filename = os.path.join(B_dirname, "tensor_B_mode_0_crd") + B_crd0 = read_inputs(B0_crd_filename) + + B1_seg_filename = os.path.join(B_dirname, "tensor_B_mode_1_seg") + B_seg1 = read_inputs(B1_seg_filename) + B1_crd_filename = os.path.join(B_dirname, "tensor_B_mode_1_crd") + B_crd1 = read_inputs(B1_crd_filename) + + B_vals_filename = os.path.join(B_dirname, "tensor_B_mode_vals") + B_vals = read_inputs(B_vals_filename, float) + + C_dirname = B_dirname + C_shape_filename = os.path.join(C_dirname, "tensor_C_mode_shape") + C_shape = read_inputs(C_shape_filename) + + C0_seg_filename = os.path.join(C_dirname, "tensor_C_mode_0_seg") + C_seg0 = read_inputs(C0_seg_filename) + C0_crd_filename = os.path.join(C_dirname, "tensor_C_mode_0_crd") + C_crd0 = read_inputs(C0_crd_filename) + + C1_seg_filename = os.path.join(C_dirname, "tensor_C_mode_1_seg") + C_seg1 = read_inputs(C1_seg_filename) + C1_crd_filename = os.path.join(C_dirname, "tensor_C_mode_1_crd") + C_crd1 = read_inputs(C1_crd_filename) + + C_vals_filename = os.path.join(C_dirname, "tensor_C_mode_vals") + C_vals = read_inputs(C_vals_filename, float) + + # THIS IS FOR SIZE INFO + Bs_dirname = B_dirname + Bs_seg = read_inputs(os.path.join(Bs_dirname, "tensor_B_mode_0_seg")) + + fiberlookup_Bk_17 = CompressedCrdRdScan(crd_arr=B_crd1, seg_arr=B_seg1, debug=debug_sim, statistics=report_stats, + back_en=backpressure, depth=int(depth)) + fiberlookup_Ck_18 = CompressedCrdRdScan(crd_arr=C_crd0, seg_arr=C_seg0, debug=debug_sim, statistics=report_stats, + back_en=backpressure, depth=int(depth)) + intersectk_16 = Intersect2(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) + fiberlookup_Bi_15 = CompressedCrdRdScan(crd_arr=B_crd0, seg_arr=B_seg0, debug=debug_sim, statistics=report_stats, + back_en=backpressure, depth=int(depth)) + repsiggen_i_13 = RepeatSigGen(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) + repeat_Ci_12 = Repeat(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) + fiberlookup_Cj_11 = CompressedCrdRdScan(crd_arr=C_crd1, seg_arr=C_seg1, debug=debug_sim, statistics=report_stats, + back_en=backpressure, depth=int(depth)) + arrayvals_C_7 = Array(init_arr=C_vals, debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) + crdhold_4 = CrdHold(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) + repsiggen_j_9 = RepeatSigGen(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) + repeat_Bj_8 = Repeat(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) + arrayvals_B_6 = Array(init_arr=B_vals, debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) + mul_5 = Multiply2(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) + spaccumulator2_3 = SparseAccumulator2(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) + spaccumulator2_3_drop_crd_inner = StknDrop(debug=debug_sim, statistics=report_stats, + back_en=backpressure, depth=int(depth)) + spaccumulator2_3_drop_crd_outer = StknDrop(debug=debug_sim, statistics=report_stats, + back_en=backpressure, depth=int(depth)) + spaccumulator2_3_drop_val = StknDrop(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) + fiberwrite_Xvals_0 = ValsWrScan(size=1 * Bs_seg[-1] * Bs_seg[-1], fill=fill, debug=debug_sim, statistics=report_stats, + back_en=backpressure, depth=int(depth)) + fiberwrite_X1_1 = CompressWrScan(seg_size=Bs_seg[-1] + 1, size=Bs_seg[-1] * Bs_seg[-1], fill=fill, + debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) + fiberwrite_X0_2 = CompressWrScan(seg_size=2, size=Bs_seg[-1], fill=fill, debug=debug_sim, statistics=report_stats, + back_en=backpressure, depth=int(depth)) + in_ref_B = [0, 'D'] + in_ref_C = [0, 'D'] + done = False + time_cnt = 0 + while not done and time_cnt < TIMEOUT: + if len(in_ref_B) > 0: + fiberlookup_Bk_17.set_in_ref(in_ref_B.pop(0), "") + + if len(in_ref_C) > 0: + fiberlookup_Ck_18.set_in_ref(in_ref_C.pop(0), "") + + intersectk_16.set_in1(fiberlookup_Bk_17.out_ref(), fiberlookup_Bk_17.out_crd(), fiberlookup_Bk_17) + intersectk_16.set_in2(fiberlookup_Ck_18.out_ref(), fiberlookup_Ck_18.out_crd(), fiberlookup_Ck_18) + + fiberlookup_Bi_15.set_in_ref(intersectk_16.out_ref1(), intersectk_16) + + repsiggen_i_13.set_istream(fiberlookup_Bi_15.out_crd(), fiberlookup_Bi_15) + + repeat_Ci_12.set_in_ref(intersectk_16.out_ref2(), intersectk_16) + repeat_Ci_12.set_in_repsig(repsiggen_i_13.out_repsig(), repsiggen_i_13) + + fiberlookup_Cj_11.set_in_ref(repeat_Ci_12.out_ref(), repeat_Ci_12) + + arrayvals_C_7.set_load(fiberlookup_Cj_11.out_ref(), fiberlookup_Cj_11) + + crdhold_4.set_outer_crd(fiberlookup_Bi_15.out_crd(), fiberlookup_Bi_15) + crdhold_4.set_inner_crd(fiberlookup_Cj_11.out_crd(), fiberlookup_Cj_11) + repsiggen_j_9.set_istream(fiberlookup_Cj_11.out_crd(), fiberlookup_Cj_11) + + repeat_Bj_8.set_in_ref(fiberlookup_Bi_15.out_ref(), fiberlookup_Bi_15) + repeat_Bj_8.set_in_repsig(repsiggen_j_9.out_repsig(), repsiggen_j_9) + + arrayvals_B_6.set_load(repeat_Bj_8.out_ref(), repeat_Bj_8) + + mul_5.set_in1(arrayvals_B_6.out_val(), arrayvals_B_6) + mul_5.set_in2(arrayvals_C_7.out_val(), arrayvals_C_7) + + spaccumulator2_3_drop_crd_outer.set_in_stream(crdhold_4.out_crd_outer(), crdhold_4) + spaccumulator2_3_drop_crd_inner.set_in_stream(crdhold_4.out_crd_inner(), crdhold_4) + spaccumulator2_3_drop_val.set_in_stream(mul_5.out_val(), mul_5) + spaccumulator2_3.set_crd_outer(spaccumulator2_3_drop_crd_outer.out_val(), spaccumulator2_3_drop_crd_outer) + spaccumulator2_3.set_crd_inner(spaccumulator2_3_drop_crd_inner.out_val(), spaccumulator2_3_drop_crd_inner) + spaccumulator2_3.set_val(spaccumulator2_3_drop_val.out_val(), spaccumulator2_3_drop_val) + + fiberwrite_Xvals_0.set_input(spaccumulator2_3.out_val(), spaccumulator2_3) + + fiberwrite_X1_1.set_input(spaccumulator2_3.out_crd_inner(), spaccumulator2_3) + + fiberwrite_X0_2.set_input(spaccumulator2_3.out_crd_outer(), spaccumulator2_3) + + fiberlookup_Bk_17.update() + fiberlookup_Ck_18.update() + intersectk_16.update() + fiberlookup_Bi_15.update() + repsiggen_i_13.update() + repeat_Ci_12.update() + fiberlookup_Cj_11.update() + arrayvals_C_7.update() + crdhold_4.update() + repsiggen_j_9.update() + repeat_Bj_8.update() + arrayvals_B_6.update() + mul_5.update() + spaccumulator2_3_drop_crd_outer.update() + spaccumulator2_3_drop_crd_inner.update() + spaccumulator2_3_drop_val.update() + spaccumulator2_3.update() + fiberwrite_Xvals_0.update() + fiberwrite_X1_1.update() + fiberwrite_X0_2.update() + + done = fiberwrite_X0_2.out_done() and fiberwrite_X1_1.out_done() and fiberwrite_Xvals_0.out_done() + time_cnt += 1 + + fiberwrite_X0_2.autosize() + fiberwrite_X1_1.autosize() + fiberwrite_Xvals_0.autosize() + + out_crds = [fiberwrite_X0_2.get_arr(), fiberwrite_X1_1.get_arr()] + out_segs = [fiberwrite_X0_2.get_seg_arr(), fiberwrite_X1_1.get_seg_arr()] + out_vals = fiberwrite_Xvals_0.get_arr() + + def bench(): + time.sleep(0.01) + + extra_info = dict() + extra_info["dataset"] = ssname + extra_info["cycles"] = time_cnt + extra_info["tensor_B_shape"] = B_shape + extra_info["tensor_C_shape"] = C_shape + extra_info["tensor_B/nnz"] = len(B_vals) + extra_info["tensor_C/nnz"] = len(C_vals) + + extra_info["result/vals_size"] = len(out_vals) + extra_info["result/nnz"] = len([x for x in out_vals if x != 0]) + + sample_dict = fiberlookup_Bk_17.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberlookup_Bk_17" + "/" + k] = sample_dict[k] + + sample_dict = fiberlookup_Ck_18.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberlookup_Ck_18" + "/" + k] = sample_dict[k] + + sample_dict = intersectk_16.return_statistics() + for k in sample_dict.keys(): + extra_info["intersectk_16" + "/" + k] = sample_dict[k] + + sample_dict = fiberlookup_Bi_15.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberlookup_Bi_15" + "/" + k] = sample_dict[k] + + sample_dict = repeat_Ci_12.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Ci_12" + "/" + k] = sample_dict[k] + + sample_dict = fiberlookup_Cj_11.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberlookup_Cj_11" + "/" + k] = sample_dict[k] + + sample_dict = arrayvals_C_7.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_C_7" + "/" + k] = sample_dict[k] + + sample_dict = repeat_Bj_8.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Bj_8" + "/" + k] = sample_dict[k] + + sample_dict = arrayvals_B_6.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_B_6" + "/" + k] = sample_dict[k] + + sample_dict = mul_5.return_statistics() + for k in sample_dict.keys(): + extra_info["mul_5" + "/" + k] = sample_dict[k] + + sample_dict = spaccumulator2_3.return_statistics() + for k in sample_dict.keys(): + extra_info["spaccumulator2_3" + "/" + k] = sample_dict[k] + + sample_dict = fiberwrite_Xvals_0.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_Xvals_0" + "/" + k] = sample_dict[k] + + sample_dict = fiberwrite_X1_1.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X1_1" + "/" + k] = sample_dict[k] + + sample_dict = fiberwrite_X0_2.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X0_2" + "/" + k] = sample_dict[k] + + gen_gantt(extra_info, "matmul_kij") + + if check_gold: + print("Checking gold...") + check_gold_matmul(ssname, debug_sim, cast, out_crds, out_segs, out_vals, "ss01") + samBench(bench, extra_info) diff --git a/sam/sim/test/reorder-study/test_reorder_matmul_ikj.py b/sam/sim/test/reorder-study/test_reorder_matmul_ikj.py index af03c87a..0350a3ae 100644 --- a/sam/sim/test/reorder-study/test_reorder_matmul_ikj.py +++ b/sam/sim/test/reorder-study/test_reorder_matmul_ikj.py @@ -16,9 +16,11 @@ import os import csv import numpy +from sam.sim.test.gen_gantt import gen_gantt + cwd = os.getcwd() formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) -formatted_dir = os.getenv('FROSTT_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) +#formatted_dir = os.getenv('FROSTT_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) synthetic_dir = os.getenv('SYNTHETIC_PATH', default=os.path.join(cwd, 'synthetic')) @@ -29,11 +31,10 @@ reason='CI lacks datasets', ) @pytest.mark.synth -@pytest.mark.parametrize("sparsity", [0.95]) -def test_reorder_matmul_ikj(samBench, sparsity, check_gold, debug_sim, backpressure, depth, fill=0): - - # DCSR - B_dirname = os.path.join(synthetic_dir, f"matrix/DCSR/B_random_sp_{sparsity}/") +# @pytest.mark.parametrize("sparsity", [0.95]) +def test_reorder_matmul_ikj(samBench, ssname, check_gold, report_stats, debug_sim, cast, backpressure, depth, fill=0): + + B_dirname = os.path.join(formatted_dir, ssname, "matmul_kij") B_shape_filename = os.path.join(B_dirname, "tensor_B_mode_shape") B_shape = read_inputs(B_shape_filename) @@ -51,7 +52,7 @@ def test_reorder_matmul_ikj(samBench, sparsity, check_gold, debug_sim, backpress B_vals = read_inputs(B_vals_filename, float) # DCSR - C_dirname = os.path.join(synthetic_dir, f"matrix/DCSR/C_random_sp_{sparsity}/") + C_dirname = B_dirname C_shape_filename = os.path.join(C_dirname, "tensor_C_mode_shape") C_shape = read_inputs(C_shape_filename) @@ -68,6 +69,10 @@ def test_reorder_matmul_ikj(samBench, sparsity, check_gold, debug_sim, backpress C_vals_filename = os.path.join(C_dirname, "tensor_C_mode_vals") C_vals = read_inputs(C_vals_filename, float) + # THIS IS FOR SIZE INFO + Bs_dirname = B_dirname + Bs_seg = read_inputs(os.path.join(Bs_dirname, "tensor_B_mode_0_seg")) + # B_dirname = os.path.join(formatted_dir, ssname, "orig", "ss01") # B_shape_filename = os.path.join(B_dirname, "B_shape.txt") # B_shape = read_inputs(B_shape_filename) @@ -227,41 +232,43 @@ def bench(): extra_info["cycles"] = time_cnt extra_info["tensor_B_shape"] = B_shape extra_info["tensor_C_shape"] = C_shape - # sample_dict = spaccumulator1_3.return_statistics() - # for k in sample_dict.keys(): - # extra_info["spaccumulator1_3" + "_" + k] = sample_dict[k] - - # sample_dict = fiberwrite_Xvals_0.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_Xvals_0" + "_" + k] = sample_dict[k] - - # sample_dict = fiberwrite_X1_1.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_X1_1" + "_" + k] = sample_dict[k] - - # sample_dict = fiberwrite_X0_2.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_X0_2" + "_" + k] = sample_dict[k] - - # sample_dict = repeat_Ci_16.return_statistics() - # for k in sample_dict.keys(): - # extra_info["repeat_Ci_16" + "_" + k] = sample_dict[k] - - # sample_dict = intersectk_13.return_statistics() - # for k in sample_dict.keys(): - # extra_info["intersectk_13" + "_" + k] = sample_dict[k] - - # sample_dict = repeat_Bj_9.return_statistics() - # for k in sample_dict.keys(): - # extra_info["repeat_Bj_9" + "_" + k] = sample_dict[k] - - # sample_dict = arrayvals_B_7.return_statistics() - # for k in sample_dict.keys(): - # extra_info["arrayvals_B_7" + "_" + k] = sample_dict[k] - - # sample_dict = arrayvals_C_8.return_statistics() - # for k in sample_dict.keys(): - # extra_info["arrayvals_C_8" + "_" + k] = sample_dict[k] + sample_dict = spaccumulator1_3.return_statistics() + for k in sample_dict.keys(): + extra_info["spaccumulator1_3" + "_" + k] = sample_dict[k] + + sample_dict = fiberwrite_Xvals_0.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_Xvals_0" + "_" + k] = sample_dict[k] + + sample_dict = fiberwrite_X1_1.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X1_1" + "_" + k] = sample_dict[k] + + sample_dict = fiberwrite_X0_2.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X0_2" + "_" + k] = sample_dict[k] + + sample_dict = repeat_Ci_16.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Ci_16" + "_" + k] = sample_dict[k] + + sample_dict = intersectk_13.return_statistics() + for k in sample_dict.keys(): + extra_info["intersectk_13" + "_" + k] = sample_dict[k] + + sample_dict = repeat_Bj_9.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Bj_9" + "_" + k] = sample_dict[k] + + sample_dict = arrayvals_B_7.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_B_7" + "_" + k] = sample_dict[k] + + sample_dict = arrayvals_C_8.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_C_8" + "_" + k] = sample_dict[k] + + gen_gantt(extra_info, "matmul_ikj") if check_gold: print("Checking gold...") diff --git a/sam/sim/test/reorder-study/test_reorder_matmul_jik.py b/sam/sim/test/reorder-study/test_reorder_matmul_jik.py index 0b7e4388..c80a322f 100644 --- a/sam/sim/test/reorder-study/test_reorder_matmul_jik.py +++ b/sam/sim/test/reorder-study/test_reorder_matmul_jik.py @@ -16,6 +16,8 @@ import csv from sam.onyx.generate_matrices import create_matrix_from_point_list, get_tensor_from_files import numpy +from sam.sim.test.gen_gantt import gen_gantt + cwd = os.getcwd() formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) formatted_dir = os.getenv('FROSTT_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) @@ -212,41 +214,43 @@ def bench(): extra_info["cycles"] = time_cnt extra_info["tensor_B_shape"] = B_shape extra_info["tensor_C_shape"] = C_shape - # sample_dict = fiberwrite_X1_2.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_X1_2" + "_" + k] = sample_dict[k] - - # sample_dict = repeat_Bj_14.return_statistics() - # for k in sample_dict.keys(): - # extra_info["repeat_Bj_14" + "_" + k] = sample_dict[k] - - # sample_dict = fiberwrite_X0_1.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_X0_1" + "_" + k] = sample_dict[k] - - # sample_dict = repeat_Ci_10.return_statistics() - # for k in sample_dict.keys(): - # extra_info["repeat_Ci_10" + "_" + k] = sample_dict[k] - - # sample_dict = intersectk_7.return_statistics() - # for k in sample_dict.keys(): - # extra_info["intersectk_7" + "_" + k] = sample_dict[k] - - # sample_dict = arrayvals_B_5.return_statistics() - # for k in sample_dict.keys(): - # extra_info["arrayvals_B_5" + "_" + k] = sample_dict[k] - - # sample_dict = reduce_3.return_statistics() - # for k in sample_dict.keys(): - # extra_info["reduce_3" + "_" + k] = sample_dict[k] - - # sample_dict = fiberwrite_Xvals_0.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_Xvals_0" + "_" + k] = sample_dict[k] - - # sample_dict = arrayvals_C_6.return_statistics() - # for k in sample_dict.keys(): - # extra_info["arrayvals_C_6" + "_" + k] = sample_dict[k] + sample_dict = fiberwrite_X1_2.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X1_2" + "_" + k] = sample_dict[k] + + sample_dict = repeat_Bj_14.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Bj_14" + "_" + k] = sample_dict[k] + + sample_dict = fiberwrite_X0_1.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X0_1" + "_" + k] = sample_dict[k] + + sample_dict = repeat_Ci_10.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Ci_10" + "_" + k] = sample_dict[k] + + sample_dict = intersectk_7.return_statistics() + for k in sample_dict.keys(): + extra_info["intersectk_7" + "_" + k] = sample_dict[k] + + sample_dict = arrayvals_B_5.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_B_5" + "_" + k] = sample_dict[k] + + sample_dict = reduce_3.return_statistics() + for k in sample_dict.keys(): + extra_info["reduce_3" + "_" + k] = sample_dict[k] + + sample_dict = fiberwrite_Xvals_0.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_Xvals_0" + "_" + k] = sample_dict[k] + + sample_dict = arrayvals_C_6.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_C_6" + "_" + k] = sample_dict[k] + + gen_gantt(extra_info, "matmul_jik") if check_gold: print("Checking gold...") diff --git a/sam/sim/test/reorder-study/test_reorder_matmul_jki.py b/sam/sim/test/reorder-study/test_reorder_matmul_jki.py index 6511ddc6..8e12287d 100644 --- a/sam/sim/test/reorder-study/test_reorder_matmul_jki.py +++ b/sam/sim/test/reorder-study/test_reorder_matmul_jki.py @@ -16,6 +16,8 @@ import csv from sam.onyx.generate_matrices import create_matrix_from_point_list, get_tensor_from_files import numpy +from sam.sim.test.gen_gantt import gen_gantt + cwd = os.getcwd() formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) formatted_dir = os.getenv('FROSTT_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) @@ -234,41 +236,43 @@ def bench(): extra_info["cycles"] = time_cnt extra_info["tensor_B_shape"] = B_shape extra_info["tensor_C_shape"] = C_shape - # sample_dict = spaccumulator1_3.return_statistics() - # for k in sample_dict.keys(): - # extra_info["spaccumulator1_3" + "_" + k] = sample_dict[k] + sample_dict = spaccumulator1_3.return_statistics() + for k in sample_dict.keys(): + extra_info["spaccumulator1_3" + "_" + k] = sample_dict[k] + + sample_dict = fiberwrite_Xvals_0.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_Xvals_0" + "_" + k] = sample_dict[k] - # sample_dict = fiberwrite_Xvals_0.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_Xvals_0" + "_" + k] = sample_dict[k] + sample_dict = fiberwrite_X0_1.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X0_1" + "_" + k] = sample_dict[k] - # sample_dict = fiberwrite_X0_1.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_X0_1" + "_" + k] = sample_dict[k] + sample_dict = fiberwrite_X1_2.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X1_2" + "_" + k] = sample_dict[k] - # sample_dict = fiberwrite_X1_2.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_X1_2" + "_" + k] = sample_dict[k] + sample_dict = repeat_Bj_16.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Bj_16" + "_" + k] = sample_dict[k] - # sample_dict = repeat_Bj_16.return_statistics() - # for k in sample_dict.keys(): - # extra_info["repeat_Bj_16" + "_" + k] = sample_dict[k] + sample_dict = intersectk_13.return_statistics() + for k in sample_dict.keys(): + extra_info["intersectk_13" + "_" + k] = sample_dict[k] - # sample_dict = intersectk_13.return_statistics() - # for k in sample_dict.keys(): - # extra_info["intersectk_13" + "_" + k] = sample_dict[k] + sample_dict = repeat_Ci_9.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Ci_9" + "_" + k] = sample_dict[k] - # sample_dict = repeat_Ci_9.return_statistics() - # for k in sample_dict.keys(): - # extra_info["repeat_Ci_9" + "_" + k] = sample_dict[k] + sample_dict = arrayvals_C_8.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_C_8" + "_" + k] = sample_dict[k] - # sample_dict = arrayvals_C_8.return_statistics() - # for k in sample_dict.keys(): - # extra_info["arrayvals_C_8" + "_" + k] = sample_dict[k] + sample_dict = arrayvals_B_7.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_B_7" + "_" + k] = sample_dict[k] - # sample_dict = arrayvals_B_7.return_statistics() - # for k in sample_dict.keys(): - # extra_info["arrayvals_B_7" + "_" + k] = sample_dict[k] + gen_gantt(extra_info, "matmul_jki") if check_gold: print("Checking gold...") diff --git a/sam/sim/test/reorder-study/test_reorder_matmul_kij.py b/sam/sim/test/reorder-study/test_reorder_matmul_kij.py index c16f522a..8ea0851c 100644 --- a/sam/sim/test/reorder-study/test_reorder_matmul_kij.py +++ b/sam/sim/test/reorder-study/test_reorder_matmul_kij.py @@ -16,6 +16,8 @@ import csv from sam.onyx.generate_matrices import create_matrix_from_point_list, get_tensor_from_files import numpy +from sam.sim.test.gen_gantt import gen_gantt + cwd = os.getcwd() formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) formatted_dir = os.getenv('FROSTT_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) @@ -230,41 +232,43 @@ def bench(): extra_info["cycles"] = time_cnt extra_info["tensor_B_shape"] = B_shape extra_info["tensor_C_shape"] = C_shape - # sample_dict = intersectk_16.return_statistics() - # for k in sample_dict.keys(): - # extra_info["intersectk_16" + "_" + k] = sample_dict[k] + sample_dict = intersectk_16.return_statistics() + for k in sample_dict.keys(): + extra_info["intersectk_16" + "_" + k] = sample_dict[k] + + sample_dict = spaccumulator2_3.return_statistics() + for k in sample_dict.keys(): + extra_info["spaccumulator2_3" + "_" + k] = sample_dict[k] - # sample_dict = spaccumulator2_3.return_statistics() - # for k in sample_dict.keys(): - # extra_info["spaccumulator2_3" + "_" + k] = sample_dict[k] + sample_dict = fiberwrite_Xvals_0.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_Xvals_0" + "_" + k] = sample_dict[k] - # sample_dict = fiberwrite_Xvals_0.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_Xvals_0" + "_" + k] = sample_dict[k] + sample_dict = fiberwrite_X1_1.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X1_1" + "_" + k] = sample_dict[k] - # sample_dict = fiberwrite_X1_1.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_X1_1" + "_" + k] = sample_dict[k] + sample_dict = fiberwrite_X0_2.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X0_2" + "_" + k] = sample_dict[k] - # sample_dict = fiberwrite_X0_2.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_X0_2" + "_" + k] = sample_dict[k] + sample_dict = repeat_Ci_12.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Ci_12" + "_" + k] = sample_dict[k] - # sample_dict = repeat_Ci_12.return_statistics() - # for k in sample_dict.keys(): - # extra_info["repeat_Ci_12" + "_" + k] = sample_dict[k] + sample_dict = repeat_Bj_8.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Bj_8" + "_" + k] = sample_dict[k] - # sample_dict = repeat_Bj_8.return_statistics() - # for k in sample_dict.keys(): - # extra_info["repeat_Bj_8" + "_" + k] = sample_dict[k] + sample_dict = arrayvals_B_6.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_B_6" + "_" + k] = sample_dict[k] - # sample_dict = arrayvals_B_6.return_statistics() - # for k in sample_dict.keys(): - # extra_info["arrayvals_B_6" + "_" + k] = sample_dict[k] + sample_dict = arrayvals_C_7.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_C_7" + "_" + k] = sample_dict[k] - # sample_dict = arrayvals_C_7.return_statistics() - # for k in sample_dict.keys(): - # extra_info["arrayvals_C_7" + "_" + k] = sample_dict[k] + gen_gantt(extra_info, "matmul_kij") if check_gold: print("Checking gold...") diff --git a/sam/sim/test/reorder-study/test_reorder_matmul_kji.py b/sam/sim/test/reorder-study/test_reorder_matmul_kji.py index 184ca2c4..2dce7d6e 100644 --- a/sam/sim/test/reorder-study/test_reorder_matmul_kji.py +++ b/sam/sim/test/reorder-study/test_reorder_matmul_kji.py @@ -16,6 +16,8 @@ import csv from sam.onyx.generate_matrices import create_matrix_from_point_list, get_tensor_from_files import numpy +from sam.sim.test.gen_gantt import gen_gantt + cwd = os.getcwd() formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) formatted_dir = os.getenv('FROSTT_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) @@ -230,41 +232,45 @@ def bench(): extra_info["cycles"] = time_cnt extra_info["tensor_B_shape"] = B_shape extra_info["tensor_C_shape"] = C_shape - # sample_dict = intersectk_16.return_statistics() - # for k in sample_dict.keys(): - # extra_info["intersectk_16" + "_" + k] = sample_dict[k] - # sample_dict = repeat_Bj_12.return_statistics() - # for k in sample_dict.keys(): - # extra_info["repeat_Bj_12" + "_" + k] = sample_dict[k] + + sample_dict = intersectk_16.return_statistics() + for k in sample_dict.keys(): + extra_info["intersectk_16" + "_" + k] = sample_dict[k] + + sample_dict = repeat_Bj_12.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Bj_12" + "_" + k] = sample_dict[k] - # sample_dict = spaccumulator2_3.return_statistics() - # for k in sample_dict.keys(): - # extra_info["spaccumulator2_3" + "_" + k] = sample_dict[k] + sample_dict = spaccumulator2_3.return_statistics() + for k in sample_dict.keys(): + extra_info["spaccumulator2_3" + "_" + k] = sample_dict[k] - # sample_dict = fiberwrite_Xvals_0.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_Xvals_0" + "_" + k] = sample_dict[k] + sample_dict = fiberwrite_Xvals_0.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_Xvals_0" + "_" + k] = sample_dict[k] - # sample_dict = fiberwrite_X0_1.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_X0_1" + "_" + k] = sample_dict[k] + sample_dict = fiberwrite_X0_1.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X0_1" + "_" + k] = sample_dict[k] - # sample_dict = fiberwrite_X1_2.return_statistics() - # for k in sample_dict.keys(): - # extra_info["fiberwrite_X1_2" + "_" + k] = sample_dict[k] + sample_dict = fiberwrite_X1_2.return_statistics() + for k in sample_dict.keys(): + extra_info["fiberwrite_X1_2" + "_" + k] = sample_dict[k] - # sample_dict = repeat_Ci_8.return_statistics() - # for k in sample_dict.keys(): - # extra_info["repeat_Ci_8" + "_" + k] = sample_dict[k] + sample_dict = repeat_Ci_8.return_statistics() + for k in sample_dict.keys(): + extra_info["repeat_Ci_8" + "_" + k] = sample_dict[k] - # sample_dict = arrayvals_C_7.return_statistics() - # for k in sample_dict.keys(): - # extra_info["arrayvals_C_7" + "_" + k] = sample_dict[k] + sample_dict = arrayvals_C_7.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_C_7" + "_" + k] = sample_dict[k] - # sample_dict = arrayvals_B_6.return_statistics() - # for k in sample_dict.keys(): - # extra_info["arrayvals_B_6" + "_" + k] = sample_dict[k] + sample_dict = arrayvals_B_6.return_statistics() + for k in sample_dict.keys(): + extra_info["arrayvals_B_6" + "_" + k] = sample_dict[k] + + gen_gantt(extra_info, "matmul_kji") if check_gold: print("Checking gold...") diff --git a/scripts/download_suitesparse_stream_overhead.sh b/scripts/download_suitesparse_stream_overhead.sh new file mode 100755 index 00000000..2765ca67 --- /dev/null +++ b/scripts/download_suitesparse_stream_overhead.sh @@ -0,0 +1,75 @@ +mkdir -p /home/ginasohn/sam-fixed/sam-fixed/data/suitesparse +pushd . +cd /home/ginasohn/sam-fixed/sam-fixed/data/suitesparse +wget https://sparse.tamu.edu/MM/HB/pores_1.tar.gz +wget https://sparse.tamu.edu/MM/FIDAP/ex5.tar.gz +wget https://sparse.tamu.edu/MM/Grund/b1_ss.tar.gz +wget https://sparse.tamu.edu/MM/LPnetlib/lpi_bgprtr.tar.gz +wget https://sparse.tamu.edu/MM/LPnetlib/lpi_itest2.tar.gz +wget https://sparse.tamu.edu/MM/LPnetlib/lpi_itest6.tar.gz +wget https://sparse.tamu.edu/MM/vanHeukelum/cage3.tar.gz +wget https://sparse.tamu.edu/MM/vanHeukelum/cage4.tar.gz +wget https://sparse.tamu.edu/MM/vanHeukelum/cage5.tar.gz +wget https://sparse.tamu.edu/MM/Hamrle/Hamrle1.tar.gz +wget https://sparse.tamu.edu/MM/Oberwolfach/LF10000.tar.gz +wget https://sparse.tamu.edu/MM/Oberwolfach/LF10.tar.gz +wget https://sparse.tamu.edu/MM/Oberwolfach/LFAT5000.tar.gz +wget https://sparse.tamu.edu/MM/Oberwolfach/LFAT5.tar.gz +wget https://sparse.tamu.edu/MM/Pajek/football.tar.gz +wget https://sparse.tamu.edu/MM/Pajek/GD01_c.tar.gz +wget https://sparse.tamu.edu/MM/Pajek/Ragusa16.tar.gz +wget https://sparse.tamu.edu/MM/Pajek/Ragusa18.tar.gz +wget https://sparse.tamu.edu/MM/Meszaros/farm.tar.gz +wget https://sparse.tamu.edu/MM/Meszaros/kleemin.tar.gz +wget https://sparse.tamu.edu/MM/NYPA/Maragal_1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_G5/IG5-6.tar.gz +wget https://sparse.tamu.edu/MM/JGD_GL7d/GL7d10.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/ch3-3-b1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/ch3-3-b2.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/ch4-4-b1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/ch5-5-b1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/ch7-6-b1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/cis-n4c6-b1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/cis-n4c6-b13.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/cis-n4c6-b14.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/cis-n4c6-b15.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/klein-b1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/klein-b2.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/mk9-b1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n2c6-b10.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n2c6-b1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n3c4-b1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n3c4-b2.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n3c4-b3.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n3c4-b4.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n3c5-b1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n3c6-b10.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n3c6-b1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n3c6-b11.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n4c5-b10.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n4c5-b1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n4c5-b11.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b10.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b11.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b1.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b12.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b13.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b14.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b15.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Kocay/Trec5.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Kocay/Trec6.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Kocay/Trec7.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Relat/rel4.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Relat/rel5.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Relat/relat3.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Relat/relat4.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Relat/relat5.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_20b.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_20.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_200b.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_200.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_2000.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_20000b.tar.gz +wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_20000.tar.gz +wget https://sparse.tamu.edu/MM/Newman/football.tar.gz +popd diff --git a/scripts/download_unpack_format_suitesparse.sh b/scripts/download_unpack_format_suitesparse.sh index 5250d256..589e605b 100755 --- a/scripts/download_unpack_format_suitesparse.sh +++ b/scripts/download_unpack_format_suitesparse.sh @@ -14,15 +14,15 @@ BENCHMARKS=( matmul_ijk matmul_jik mat_elemadd - mat_elemmul - mat_identity - mat_elemadd3 - mat_mattransmul - mat_residual - mat_vecmul_ij - mat_vecmul_ji - mat_vecmul - mat_sddmm + # mat_elemmul + # mat_identity + # mat_elemadd3 + # mat_mattransmul + # mat_residual + # mat_vecmul_ij + # mat_vecmul_ji + # mat_vecmul + # mat_sddmm ) # Create download_script that downloads ONLY the suitesparse matrices listed in the text file that is passed in as the first argument of this script @@ -47,6 +47,6 @@ for b in ${!BENCHMARKS[@]}; do while read line; do echo "Generating input format files for $line..." sspath=${SUITESPARSE_PATH}/$line - SUITESPARSE_TENSOR_PATH=$sspath python $basedir/scripts/datastructure_suitesparse.py -n $line -hw -b $bench + SUITESPARSE_TENSOR_PATH=$sspath python $basedir/datastructure_suitesparse.py -n $line -hw -b $bench done <$(realpath $1) done From 0e2b789a12ce90da4140bdd06b7eb221de9f2c53 Mon Sep 17 00:00:00 2001 From: Gina Sohn Date: Mon, 6 Mar 2023 17:39:05 -0800 Subject: [PATCH 20/76] fix error in ijk (loading problem) --- .../test_reorder_matmul_ijk_GINA.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py b/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py index f5ba89e5..948614f6 100644 --- a/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py +++ b/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py @@ -43,22 +43,22 @@ def test_matmul_ijk_FINAL(samBench, ssname, check_gold, report_stats, debug_sim, C_shape_filename = os.path.join(C_dirname, "tensor_C_mode_shape") C_shape = read_inputs(C_shape_filename) - C0_seg_filename = os.path.join(C_dirname, "tensor_C_mode_1_seg") + C0_seg_filename = os.path.join(C_dirname, "tensor_C_mode_0_seg") C_seg0 = read_inputs(C0_seg_filename) - C0_crd_filename = os.path.join(C_dirname, "tensor_C_mode_1_crd") + C0_crd_filename = os.path.join(C_dirname, "tensor_C_mode_0_crd") C_crd0 = read_inputs(C0_crd_filename) - C1_seg_filename = os.path.join(C_dirname, "tensor_C_mode_0_seg") + C1_seg_filename = os.path.join(C_dirname, "tensor_C_mode_1_seg") C_seg1 = read_inputs(C1_seg_filename) - C1_crd_filename = os.path.join(C_dirname, "tensor_C_mode_0_crd") + C1_crd_filename = os.path.join(C_dirname, "tensor_C_mode_1_crd") C_crd1 = read_inputs(C1_crd_filename) C_vals_filename = os.path.join(C_dirname, "tensor_C_mode_vals") C_vals = read_inputs(C_vals_filename, float) # THIS IS FOR SIZE INFO - Bs_dirname = B_dirname - Bs_seg = read_inputs(os.path.join(Bs_dirname, "tensor_B_mode_0_seg")) + # Bs_dirname = B_dirname + # Bs_seg = read_inputs(os.path.join(Bs_dirname, "tensor_B_mode_0_seg")) fiberlookup_Bi_17 = CompressedCrdRdScan(crd_arr=B_crd0, seg_arr=B_seg0, debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) @@ -225,11 +225,14 @@ def bench(): for k in sample_dict.keys(): extra_info["fiberwrite_Xvals_0" + "/" + k] = sample_dict[k] - # make open csv file, append (don't overwrite!!!) - with open('/home/ginasohn/sam-fixed/sam-fixed/small_50_matmul_ijk.csv', 'a', newline='') as file: + # write total cycles to csv file + with open('small_50_matmul_ijk.csv', 'a', newline='') as file: writer = csv.writer(file) writer.writerow([ssname, time_cnt]) + # code for generating csv, gantt chart, txt file + extra_info["backpressure"]=backpressure + extra_info["depth"]=depth gen_gantt(extra_info, "matmul_ijk") if check_gold: From b90607eb6fff5ba5f4ab205c5ad6d5811a21d3d9 Mon Sep 17 00:00:00 2001 From: Gina Sohn Date: Thu, 6 Apr 2023 11:50:35 -0700 Subject: [PATCH 21/76] comment out code to record total cycles --- .../test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py b/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py index 948614f6..26d36101 100644 --- a/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py +++ b/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py @@ -226,9 +226,9 @@ def bench(): extra_info["fiberwrite_Xvals_0" + "/" + k] = sample_dict[k] # write total cycles to csv file - with open('small_50_matmul_ijk.csv', 'a', newline='') as file: - writer = csv.writer(file) - writer.writerow([ssname, time_cnt]) + # with open('small_50_matmul_ijk.csv', 'a', newline='') as file: + # writer = csv.writer(file) + # writer.writerow([ssname, time_cnt]) # code for generating csv, gantt chart, txt file extra_info["backpressure"]=backpressure From b4bf1679a118e82360c609ce360276c7e3f296a7 Mon Sep 17 00:00:00 2001 From: Gina Sohn Date: Fri, 7 Apr 2023 07:30:39 -0700 Subject: [PATCH 22/76] Change the default case into no backpressure --- sam/sim/test/gen_gantt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sam/sim/test/gen_gantt.py b/sam/sim/test/gen_gantt.py index 8adc676a..4c6c4f2f 100644 --- a/sam/sim/test/gen_gantt.py +++ b/sam/sim/test/gen_gantt.py @@ -38,12 +38,12 @@ def gen_gantt(extra_info, testname): duration_list.insert(0, finish_c - start_c) - back_depth = '0' + back_depth = 'N' # assume there is no back pressure for default if extra_info["backpressure"]: back_depth = extra_info["depth"] # Writing cycle info to csv file - with open(testname + '_' + extra_info["dataset"] + '_back'+back_depth+'.csv', 'w', newline='') as file: + with open(testname + '_' + extra_info["dataset"] + '_back_'+back_depth+'.csv', 'w', newline='') as file: writer = csv.writer(file) writer.writerow(["block","start","finish","duration","valid_ops"]) for idx, block in reversed(list(enumerate(block_list))): From 9bd41a0865c5f1619aa92b4ba4da629671afb911 Mon Sep 17 00:00:00 2001 From: Gina Sohn Date: Fri, 7 Apr 2023 07:35:47 -0700 Subject: [PATCH 23/76] change the name formatting for other files too --- sam/sim/test/gen_gantt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sam/sim/test/gen_gantt.py b/sam/sim/test/gen_gantt.py index 4c6c4f2f..8f15587c 100644 --- a/sam/sim/test/gen_gantt.py +++ b/sam/sim/test/gen_gantt.py @@ -50,7 +50,7 @@ def gen_gantt(extra_info, testname): writer.writerow([block, start_list[idx], finish_list[idx], duration_list[idx],'-']) # Print all the statistics to a text file - text_file = open(testname + '_' + extra_info["dataset"] + '_back'+back_depth+".txt","w") + text_file = open(testname + '_' + extra_info["dataset"] + '_back_'+back_depth+".txt","w") for k in extra_info.keys(): if "/" in k: text_file.write(k+": "+str(extra_info[k])+"\n") @@ -58,5 +58,5 @@ def gen_gantt(extra_info, testname): # Creating gantt chart plt.barh(y=block_list, width=duration_list, left=start_list) - file_name = testname + '_' + extra_info["dataset"] + "_back"+back_depth+".png" + file_name = testname + '_' + extra_info["dataset"] + "_back_"+back_depth+".png" plt.savefig(file_name, bbox_inches="tight") From b4dba5dfcbb770e02f7577ef0fd72090cbf35e21 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 7 Apr 2023 09:41:53 -0700 Subject: [PATCH 24/76] Add in fixes to tile script and add in a suitesparse runner --- sam/sim/src/tiling/tile.py | 7 ++-- scripts/suitesparse_memory_model_runner.sh | 38 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100755 scripts/suitesparse_memory_model_runner.sh diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 2ff1afe4..79d773d5 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -12,8 +12,9 @@ from sam.util import SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter from sam.sim.src.tiling.process_expr import parse_all, update_dict -SAM_STRS = {"matmul_ikj": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)"} - +SAM_STRS = {"matmul_kij": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)", + "matmul_ikj": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss -s=reorder(i,k,j)", + "matmul_ijk": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)"} def print_dict(dd): for k, v in dd.items(): @@ -275,7 +276,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): parser = argparse.ArgumentParser(description='Tile matrices') parser.add_argument("--input_tensor", type=str, default=None) parser.add_argument("--gen_tensor", action="store_true") - parser.add_argument("--cotile", type=str, default=None) + parser.add_argument("--cotile", type=str, default=None, description="Name of kernel if it needs to be cotiled") parser.add_argument("--output_dir_path", type=str, default="./tiles") parser.add_argument("--hw_config", type=str, default=None) parser.add_argument("--multilevel", action="store_true") diff --git a/scripts/suitesparse_memory_model_runner.sh b/scripts/suitesparse_memory_model_runner.sh new file mode 100755 index 00000000..0e9c2dd0 --- /dev/null +++ b/scripts/suitesparse_memory_model_runner.sh @@ -0,0 +1,38 @@ +#!/bin/bash +#SBATCH -N 1 +#SBATCH --mem 120000 +#SBATCH -p lanka-v3 +#SBATCH --exclusive + +benchout=memory_model_out + +basedir=$(pwd) +bench=matmul_ikj_tile_pipeline_final +yaml_fname=memory_config_onyx.yaml +path=$basedir/$benchout + +fname=$1 + +echo "Running for suitesparse $fname" + +export SAM_HOME=$basedir +export TILED_SUITESPARSE_FORMATTED_PATH=${SAM_HOME}/tiles/matmul_ikj/formatted +export TILED_OUTPUT_PATH=${SAM_HOME}/tiles/matmul_ikj/output/ + +pushd . + +mkdir -p $path + +mkdir -p $basedir/tiles/ +rm -rf $basedir/tiles/* + +./scripts/prepare_files.sh $fname.mtx $yaml_fname + +cd $basedir/sam/sim +pytest test/advanced-simulator/test_$bench.py --ssname $fname -s --check-gold --skip-empty --nbuffer --yaml_name=$yaml_fname --benchmark-json=$path/mem_model_$fname.json + +python $basedir/scripts/converter.py --json_name $path/mem_model_$fname.json + +python3 $basedir/scripts/bench_csv_aggregator.py $path $basedir/$benchout/$bench.csv + +popd From cc9667fff404824e9678e12be0c7f9185d2ffdbb Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 26 May 2023 09:25:05 -0700 Subject: [PATCH 25/76] Add in elemmul to cpu runs --- compiler/baseline.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler/baseline.cpp b/compiler/baseline.cpp index 9919a762..f911d9b0 100644 --- a/compiler/baseline.cpp +++ b/compiler/baseline.cpp @@ -315,7 +315,8 @@ enum SuiteSparseOp { SDDMM = 4, MATTRANSMUL = 5, RESIDUAL = 6, - MMADD = 7 + MMADD = 7, + MMMUL = 8 }; std::string opName(SuiteSparseOp op) { @@ -341,6 +342,9 @@ std::string opName(SuiteSparseOp op) { case MMADD: { return "mmadd"; } + case MMMUL: { + return "mmmul" + } default: return ""; } @@ -467,6 +471,13 @@ static void bench_suitesparse(benchmark::State &state, SuiteSparseOp op, int fil result(i, j) = ssTensor(i, j) + otherShifted(i, j); break; } + case MMMUL: { + result = Tensor("result", ssTensor.getDimensions(), ssTensor.getFormat(), fill_value); + + IndexVar i, j, k; + result(i, j) = ssTensor(i, j) * otherShifted(i, j); + break; + } case MATTRANSMUL: { result = Tensor("result", {DIM1}, Format(Sparse), fill_value); @@ -516,4 +527,5 @@ static void bench_suitesparse(benchmark::State &state, SuiteSparseOp op, int fil // TODO: need to fix for DCSC for this TACO_BENCH_ARGS(bench_suitesparse, mat_mattransmul, MATTRANSMUL); TACO_BENCH_ARGS(bench_suitesparse, matmul_spmm, SPMM); + TACO_BENCH_ARGS(bench_suitesparse, mat_elemmul, MMMUL); From 0af7d33aac3948670296698f479e138df9e585c4 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Thu, 29 Jun 2023 15:47:08 -0700 Subject: [PATCH 26/76] Add in all the files with the folders. WIP still need to clean up each script and add their commands at the top and add in READMEs in some folder locations --- .gitignore | 9 ++- scripts/artifact/README.md | 10 +++ .../{ => artifact}/artifact_docker_copy.py | 0 scripts/{ => artifact}/collect_node_counts.py | 0 scripts/{ => artifact}/plot_memory_model.py | 0 .../{ => artifact}/plot_stream_overhead.py | 0 scripts/{ => artifact}/stream_overhead.sh | 0 scripts/checker_diff.sh | 8 --- scripts/formatting/README.md | 16 +++++ .../datastructure_suitesparse.py | 0 scripts/{ => formatting}/datastructure_tns.py | 0 .../download_unpack_format_suitesparse.sh | 10 +-- .../generate_frostt_formats.sh | 6 +- .../generate_suitesparse_formats.sh | 8 ++- scripts/gen_sam_apps/README.md | 6 ++ .../test_generating_code.py | 0 scripts/generate_extensor_synthetic.py | 0 scripts/generate_synthetics_extensor.sh | 71 ------------------- scripts/get_data/README.md | 11 +++ scripts/{ => get_data}/download_frostt.sh | 4 +- .../{ => get_data}/download_suitesparse.sh | 4 +- scripts/{ => get_data}/generate_synthetics.sh | 0 scripts/{ => get_data}/unpack_suitesparse.sh | 2 + .../{ => get_data}/unpack_suitesparse_all.sh | 2 + scripts/{ => run_cpu}/frostt_runner.sh | 0 scripts/{ => run_cpu}/suitesparse_runner.sh | 0 .../sam_hw_suitesparse_runner.sh | 0 scripts/run_sam_sim/README.md | 14 ++++ scripts/{ => run_sam_sim}/pytest_frostt.sh | 0 .../pytest_frostt_with_benchmarks.sh | 0 .../{ => run_sam_sim}/pytest_suitesparse.sh | 0 .../pytest_suitesparse_with_benchmarks.sh | 0 scripts/{ => run_sam_sim}/run_suitesparse.sh | 5 +- scripts/run_sam_sim/run_suitesparse_final.sh | 14 ++++ .../run_sam_sim/run_suitesparse_generated.sh | 16 +++++ scripts/{ => run_sam_sim}/run_synthetics.sh | 3 + .../{ => run_sam_sim}/sam_frostt_runner.sh | 6 ++ .../sam_suitesparse_runner.sh | 0 .../sam_suitesparse_runner_sddmmonly.sh | 0 .../suitesparse_validator.sh | 0 scripts/{ => stats}/get_tensor_arrlen.py | 1 + scripts/{ => stats}/ss_stats.sh | 0 scripts/{ => stats}/suitesparse_stats.py | 0 scripts/tensor_names/README.md | 19 +++++ scripts/{ => tensor_names}/divvy_runs.py | 0 .../{ => tiling}/advanced_simulator_runner.sh | 4 +- scripts/{ => tiling}/clean_memory_model.sh | 0 scripts/{ => tiling}/ext_runner.sh | 0 .../few_points_memory_model_runner.sh | 0 scripts/{ => tiling}/full_ext_runner.sh | 0 .../{ => tiling}/full_memory_model_runner.sh | 0 .../generate_gold_matmul_tiled.py | 0 .../generate_sparsity_sweep_mem_model.sh | 0 scripts/{ => tiling}/prepare_files.sh | 0 scripts/{ => tiling}/prepare_files_no_gold.sh | 0 .../single_point_memory_model_runner.sh | 0 scripts/{ => tiling}/tile.sh | 0 scripts/{ => tiling}/tile_ext.sh | 0 scripts/util/README.md | 10 +++ scripts/{ => util}/bench_csv_aggregator.py | 0 scripts/{ => util}/converter.py | 0 scripts/{ => util}/util.py | 0 62 files changed, 165 insertions(+), 94 deletions(-) create mode 100644 scripts/artifact/README.md rename scripts/{ => artifact}/artifact_docker_copy.py (100%) rename scripts/{ => artifact}/collect_node_counts.py (100%) rename scripts/{ => artifact}/plot_memory_model.py (100%) rename scripts/{ => artifact}/plot_stream_overhead.py (100%) rename scripts/{ => artifact}/stream_overhead.sh (100%) delete mode 100755 scripts/checker_diff.sh create mode 100644 scripts/formatting/README.md rename scripts/{ => formatting}/datastructure_suitesparse.py (100%) rename scripts/{ => formatting}/datastructure_tns.py (100%) rename scripts/{ => formatting}/download_unpack_format_suitesparse.sh (71%) rename scripts/{ => formatting}/generate_frostt_formats.sh (81%) rename scripts/{ => formatting}/generate_suitesparse_formats.sh (68%) create mode 100644 scripts/gen_sam_apps/README.md rename scripts/{ => gen_sam_apps}/test_generating_code.py (100%) delete mode 100644 scripts/generate_extensor_synthetic.py delete mode 100755 scripts/generate_synthetics_extensor.sh create mode 100644 scripts/get_data/README.md rename scripts/{ => get_data}/download_frostt.sh (95%) rename scripts/{ => get_data}/download_suitesparse.sh (99%) rename scripts/{ => get_data}/generate_synthetics.sh (100%) rename scripts/{ => get_data}/unpack_suitesparse.sh (81%) rename scripts/{ => get_data}/unpack_suitesparse_all.sh (79%) rename scripts/{ => run_cpu}/frostt_runner.sh (100%) rename scripts/{ => run_cpu}/suitesparse_runner.sh (100%) rename scripts/{ => run_onyx}/sam_hw_suitesparse_runner.sh (100%) create mode 100644 scripts/run_sam_sim/README.md rename scripts/{ => run_sam_sim}/pytest_frostt.sh (100%) rename scripts/{ => run_sam_sim}/pytest_frostt_with_benchmarks.sh (100%) rename scripts/{ => run_sam_sim}/pytest_suitesparse.sh (100%) rename scripts/{ => run_sam_sim}/pytest_suitesparse_with_benchmarks.sh (100%) rename scripts/{ => run_sam_sim}/run_suitesparse.sh (87%) create mode 100755 scripts/run_sam_sim/run_suitesparse_final.sh create mode 100755 scripts/run_sam_sim/run_suitesparse_generated.sh rename scripts/{ => run_sam_sim}/run_synthetics.sh (94%) rename scripts/{ => run_sam_sim}/sam_frostt_runner.sh (96%) rename scripts/{ => run_sam_sim}/sam_suitesparse_runner.sh (100%) rename scripts/{ => run_sam_sim}/sam_suitesparse_runner_sddmmonly.sh (100%) rename scripts/{ => run_sam_sim}/suitesparse_validator.sh (100%) rename scripts/{ => stats}/get_tensor_arrlen.py (97%) rename scripts/{ => stats}/ss_stats.sh (100%) rename scripts/{ => stats}/suitesparse_stats.py (100%) create mode 100644 scripts/tensor_names/README.md rename scripts/{ => tensor_names}/divvy_runs.py (100%) rename scripts/{ => tiling}/advanced_simulator_runner.sh (95%) rename scripts/{ => tiling}/clean_memory_model.sh (100%) rename scripts/{ => tiling}/ext_runner.sh (100%) rename scripts/{ => tiling}/few_points_memory_model_runner.sh (100%) rename scripts/{ => tiling}/full_ext_runner.sh (100%) rename scripts/{ => tiling}/full_memory_model_runner.sh (100%) rename scripts/{ => tiling}/generate_gold_matmul_tiled.py (100%) rename scripts/{ => tiling}/generate_sparsity_sweep_mem_model.sh (100%) rename scripts/{ => tiling}/prepare_files.sh (100%) rename scripts/{ => tiling}/prepare_files_no_gold.sh (100%) rename scripts/{ => tiling}/single_point_memory_model_runner.sh (100%) rename scripts/{ => tiling}/tile.sh (100%) rename scripts/{ => tiling}/tile_ext.sh (100%) create mode 100644 scripts/util/README.md rename scripts/{ => util}/bench_csv_aggregator.py (100%) rename scripts/{ => util}/converter.py (100%) rename scripts/{ => util}/util.py (100%) diff --git a/.gitignore b/.gitignore index 82490b68..3c716691 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ __pycache__/ *.swo *.txt *.out +download_suitesparse_partial.sh # Files for MacOS and IDEs .DS_store @@ -38,8 +39,10 @@ compiler/benchmark/ # Generated SAM simulator tests */sim/test/apps/test_*.py +# Generated SAM graphs *.gv +# Downloaded data *.mtx *.tns @@ -52,5 +55,9 @@ tmp_mat*/ # Generated formatted tensor files tensor_*_mode_* -# Tensor files +# Tiling files tiles/ + +# sam package info +sam.egg-info/ + diff --git a/scripts/artifact/README.md b/scripts/artifact/README.md new file mode 100644 index 00000000..58c200c6 --- /dev/null +++ b/scripts/artifact/README.md @@ -0,0 +1,10 @@ +# Artifact Scripts + +The `scripts/artifact/` folder contains scripts used only for artifact evaluation of "The Sparse Abstract Machine" ASPLOS 2023. + +1. `artifact_docker_copy.py` - Python script that copies figures from docker to local machine for viewing. +2. `collect_node_counts.py` - Python script that counts and prints the number of each SAM primitive for Table 1 in "The Sparse Abstract Machine". +3. `plot_memory_model.py` - Python script that plots the memory model graph (Figure +4. `plot_stream_overhead.py` - +5. `stream_overhead.sh` - + diff --git a/scripts/artifact_docker_copy.py b/scripts/artifact/artifact_docker_copy.py similarity index 100% rename from scripts/artifact_docker_copy.py rename to scripts/artifact/artifact_docker_copy.py diff --git a/scripts/collect_node_counts.py b/scripts/artifact/collect_node_counts.py similarity index 100% rename from scripts/collect_node_counts.py rename to scripts/artifact/collect_node_counts.py diff --git a/scripts/plot_memory_model.py b/scripts/artifact/plot_memory_model.py similarity index 100% rename from scripts/plot_memory_model.py rename to scripts/artifact/plot_memory_model.py diff --git a/scripts/plot_stream_overhead.py b/scripts/artifact/plot_stream_overhead.py similarity index 100% rename from scripts/plot_stream_overhead.py rename to scripts/artifact/plot_stream_overhead.py diff --git a/scripts/stream_overhead.sh b/scripts/artifact/stream_overhead.sh similarity index 100% rename from scripts/stream_overhead.sh rename to scripts/artifact/stream_overhead.sh diff --git a/scripts/checker_diff.sh b/scripts/checker_diff.sh deleted file mode 100755 index b84cdeba..00000000 --- a/scripts/checker_diff.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -for numpy in $1/*-numpy.tns; do - taco=${numpy/-numpy/-taco} - if [ ! "$(wc -l < $numpy | xargs)" -eq "$(wc -l < $taco | xargs)" ]; then - echo "Files $numpy and $taco have a differing number of entries." - fi -done diff --git a/scripts/formatting/README.md b/scripts/formatting/README.md new file mode 100644 index 00000000..06d3241b --- /dev/null +++ b/scripts/formatting/README.md @@ -0,0 +1,16 @@ +# Formatting + +The `scripts/formatting/` folder contains scripts used to format the datasets from mtx/tns files to the seg/crd/vals arrays for CSF. The CSF files are expected by both the Onyx AHA flow and the SAM simulator. + +1. `datastructure_suitesparse.py` - Python script used by + `generate_suitesparse_formats.sh` to format from mtx to CSF files. + - +2. `datastructure_tns.py` - Python script used by + `generate_frostt_formats.sh` to format from tns to CSF files. +3. `download_unpack_format_suitesparse.sh` - Script that downloads, unpacks, + and formats a list of suitesparse matrices. To download and unpack it + calls scripts in `scripts/get_data`. +4. `generate_frostt_formats.sh` - Formats all FROSTT datasets. FIXME: This file needs fixing as it uses the old CSF formatting (e.g. `matrix_name/B_seg0`) instead of the new one (e.g. `app/tensor_B_mode_0_seg`) +5. `generate_suitesparse_formats.sh` - Formats all SuiteSparse datasets + +Formatted CSF files should reside in `$SUITESPARSE_FORMATTED_PATH` for SuiteSparse matrices. diff --git a/scripts/datastructure_suitesparse.py b/scripts/formatting/datastructure_suitesparse.py similarity index 100% rename from scripts/datastructure_suitesparse.py rename to scripts/formatting/datastructure_suitesparse.py diff --git a/scripts/datastructure_tns.py b/scripts/formatting/datastructure_tns.py similarity index 100% rename from scripts/datastructure_tns.py rename to scripts/formatting/datastructure_tns.py diff --git a/scripts/download_unpack_format_suitesparse.sh b/scripts/formatting/download_unpack_format_suitesparse.sh similarity index 71% rename from scripts/download_unpack_format_suitesparse.sh rename to scripts/formatting/download_unpack_format_suitesparse.sh index 5250d256..5dc4b09c 100755 --- a/scripts/download_unpack_format_suitesparse.sh +++ b/scripts/formatting/download_unpack_format_suitesparse.sh @@ -1,8 +1,10 @@ #!/bin/bash +# Command: ./scripts/formatting/download_unpack_format_suitesparse.sh + basedir=$(pwd) path=$basedir/jsons -download_script=scripts/download_suitesparse_stream_overhead.sh +download_script=scripts/get_data/download_suitesparse_partial.sh mkdir -p $path @@ -30,7 +32,7 @@ BENCHMARKS=( echo "mkdir -p ${SUITESPARSE_PATH}" >> $download_script echo "pushd ." >> $download_script echo "cd ${SUITESPARSE_PATH}" >> $download_script -grep -F -f $1 scripts/download_suitesparse.sh >> $download_script +grep -F -f $1 scripts/get_data/download_suitesparse.sh >> $download_script echo "popd" >> $download_script # Make it an executable @@ -40,13 +42,13 @@ chmod ugo+x $download_script ./$download_script # Unpack the downloaded suitesparse files since they come in .tar format -./scripts/unpack_suitesparse.sh $(realpath $1) +./scripts/get_data/unpack_suitesparse.sh $(realpath $1) for b in ${!BENCHMARKS[@]}; do bench=${BENCHMARKS[$b]} while read line; do echo "Generating input format files for $line..." sspath=${SUITESPARSE_PATH}/$line - SUITESPARSE_TENSOR_PATH=$sspath python $basedir/scripts/datastructure_suitesparse.py -n $line -hw -b $bench + SUITESPARSE_TENSOR_PATH=$sspath python $basedir/scripts/formatting/datastructure_suitesparse.py -n $line -hw -b $bench done <$(realpath $1) done diff --git a/scripts/generate_frostt_formats.sh b/scripts/formatting/generate_frostt_formats.sh similarity index 81% rename from scripts/generate_frostt_formats.sh rename to scripts/formatting/generate_frostt_formats.sh index 6417bbef..a83e76c7 100755 --- a/scripts/generate_frostt_formats.sh +++ b/scripts/formatting/generate_frostt_formats.sh @@ -2,6 +2,8 @@ #SBATCH -N 1 #SBATCH -t 360 +# Command: ./scripts/formatting/generate_frostt_formats.sh + DATASET_NAMES=( fb1k fb10k @@ -39,8 +41,8 @@ for i in ${!FORMATS[@]}; do name=${DATASET_NAMES[$j]} echo "Generating input format files for $name..." - python $basedir/scripts/datastructure_tns.py -n $name -f $format - python $basedir/scripts/datastructure_tns.py -n $name -f $format --other + python $basedir/scripts/formatting/datastructure_tns.py -n $name -f $format + python $basedir/scripts/formatting/datastructure_tns.py -n $name -f $format --other chmod -R 775 $FROSTT_FORMATTED_PATH done done diff --git a/scripts/generate_suitesparse_formats.sh b/scripts/formatting/generate_suitesparse_formats.sh similarity index 68% rename from scripts/generate_suitesparse_formats.sh rename to scripts/formatting/generate_suitesparse_formats.sh index a12d9eea..8e74b9a1 100755 --- a/scripts/generate_suitesparse_formats.sh +++ b/scripts/formatting/generate_suitesparse_formats.sh @@ -2,6 +2,8 @@ #SBATCH -N 1 #SBATCH -t 360 +# Command: ./scripts/formatting/generate_suitesparse_formats.sh + BENCHMARKS=( matmul_ikj matmul_ijk @@ -20,7 +22,7 @@ OTHERBENCHES='["mat_residual", "mat_mattransmul", "mat_vecmul"]' # THIS FILE MUST BE RUN FROM sam/ location outdir=${SUITESPARSE_FORMATTED_PATH} basedir=$(pwd) -textfile=$basedir/$1 +textfile=$basedir/scripts/tensor_names/$1 mkdir -p $outdir cd $outdir @@ -32,10 +34,10 @@ for b in ${!BENCHMARKS[@]}; do sspath=${SUITESPARSE_PATH}/$name echo "Generating input format files for $name..." - SUITESPARSE_TENSOR_PATH=$sspath python $basedir/scripts/datastructure_suitesparse.py -n $name -hw -b $bench + SUITESPARSE_TENSOR_PATH=$sspath python $basedir/scripts/formatting/datastructure_suitesparse.py -n $name -hw -b $bench if [[ $OTHERBENCHES =~ "$bench" ]]; then echo "Generating format of 'other' tensor" - python $basedir/scripts/datastructure_tns.py -n $line -f ss01 --other -ss -b $bench -hw + python $basedir/scripts/formatting/datastructure_tns.py -n $line -f ss01 --other -ss -b $bench -hw fi done <$textfile diff --git a/scripts/gen_sam_apps/README.md b/scripts/gen_sam_apps/README.md new file mode 100644 index 00000000..f644184d --- /dev/null +++ b/scripts/gen_sam_apps/README.md @@ -0,0 +1,6 @@ +# Generate SAM Simulator Applications + +The `scripts/gen_apps/` folder contains scripts used to generate the pytest applications (in Python) needed to run the SAM simulations + +1. `test_generating_code.py` - Python script that takes in a SAM graph and generates the pytest application in the `sam/sam/sim/test/apps/` directory. + diff --git a/scripts/test_generating_code.py b/scripts/gen_sam_apps/test_generating_code.py similarity index 100% rename from scripts/test_generating_code.py rename to scripts/gen_sam_apps/test_generating_code.py diff --git a/scripts/generate_extensor_synthetic.py b/scripts/generate_extensor_synthetic.py deleted file mode 100644 index e69de29b..00000000 diff --git a/scripts/generate_synthetics_extensor.sh b/scripts/generate_synthetics_extensor.sh deleted file mode 100755 index fd6ed055..00000000 --- a/scripts/generate_synthetics_extensor.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash - -# Vars -if [ -z "$2" ] -then - export SYNTHETIC_PATH="$(pwd)/synthetic/" -else - export SYNTHETIC_PATH="$2" -fi - -export SRC_PATH="$(pwd)/sam/onyx/synthetic/" - -# Create the main directories -mkdir -p $SYNTHETIC_PATH -pushd $SYNTHETIC_PATH -for vectype in "random" "blocks" "runs" -do - mkdir -p "${SYNTHETIC_PATH}/${vectype}/compressed/" - mkdir -p "${SYNTHETIC_PATH}/${vectype}/uncompressed/" - case $vectype in - random) - python ${SRC_PATH}/generate_random_mats.py --seed 0 --output_dir ${SYNTHETIC_PATH}/${vectype}/compressed/ --name B --shape 2000 --output_format CSF - python ${SRC_PATH}/generate_random_mats.py --seed 1 --output_dir ${SYNTHETIC_PATH}/${vectype}/compressed/ --name C --shape 2000 --output_format CSF - python ${SRC_PATH}/generate_random_mats.py --seed 0 --output_dir ${SYNTHETIC_PATH}/${vectype}/uncompressed/ --name B --shape 2000 --output_format UNC - python ${SRC_PATH}/generate_random_mats.py --seed 1 --output_dir ${SYNTHETIC_PATH}/${vectype}/uncompressed/ --name C --shape 2000 --output_format UNC - ;; - blocks) - for bs in 1 2 5 10 20 30 40 50 75 100 200 300 400 - do - nnz=400 - python ${SRC_PATH}/generate_blocks.py --seed 0 --output_dir ${SYNTHETIC_PATH}/${vectype}/compressed/ --number_nonzeros $nnz --len_blocks $bs --shape 2000 --output_format CSF - python ${SRC_PATH}/generate_blocks.py --seed 0 --output_dir ${SYNTHETIC_PATH}/${vectype}/uncompressed/ --number_nonzeros $nnz --len_blocks $bs --shape 2000 --output_format UNC - # python ${SRC_PATH}/generate_blocks.py --seed 0 --output_dir ${SYNTHETIC_PATH}/${vectype}/compressed/ --shape 2000 --output_format CSF - # python ${SRC_PATH}/generate_blocks.py --seed 0 --output_dir ${SYNTHETIC_PATH}/${vectype}/uncompressed/ --shape 2000 --output_format UNC - done - ;; - runs) - for rl in 1 2 5 10 20 30 40 50 75 100 200 300 400 - do - python ${SRC_PATH}/generate_runs.py --seed 0 --output_dir ${SYNTHETIC_PATH}/${vectype}/compressed/ --shape 2000 --number_nonzeros 400 --run_length $rl --output_format CSF - python ${SRC_PATH}/generate_runs.py --seed 0 --output_dir ${SYNTHETIC_PATH}/${vectype}/uncompressed/ --shape 2000 --number_nonzeros 400 --run_length $rl --output_format UNC - # python ${SRC_PATH}/generate_runs.py --seed 0 --output_dir ${SYNTHETIC_PATH}/${vectype}/compressed/ --output_format CSF --run_lengths 100 200 - # python ${SRC_PATH}/generate_runs.py --seed 0 --output_dir ${SYNTHETIC_PATH}/${vectype}/uncompressed/ --output_format UNC --run_lengths 100 200 - done - ;; - esac -done -popd - -# Now generate the matrices in both DCSR/DCSC formats -pushd $SYNTHETIC_PATH - -mkdir -p "${SYNTHETIC_PATH}/matrix/DCSR" -mkdir -p "${SYNTHETIC_PATH}/matrix/DCSC" -mkdir -p "${SYNTHETIC_PATH}/matrix/DENSE" - -i=250 -j=250 -k=100 - -sparsity="0.95" - -python ${SRC_PATH}/generate_random_mats.py --seed 0 --sparsity $sparsity --output_dir ${SYNTHETIC_PATH}/matrix/DCSR/ --name B --shape $i $k --output_format CSF -python ${SRC_PATH}/generate_random_mats.py --seed 0 --sparsity $sparsity --output_dir ${SYNTHETIC_PATH}/matrix/DCSC/ --name B --shape $i $k --output_format CSF --transpose -python ${SRC_PATH}/generate_random_mats.py --seed 0 --sparsity $sparsity --output_dir ${SYNTHETIC_PATH}/matrix/DENSE/ --name B --shape $i $k --output_format UNC - -python ${SRC_PATH}/generate_random_mats.py --seed 1 --sparsity $sparsity --output_dir ${SYNTHETIC_PATH}/matrix/DCSR/ --name C --shape $k $j --output_format CSF -python ${SRC_PATH}/generate_random_mats.py --seed 1 --sparsity $sparsity --output_dir ${SYNTHETIC_PATH}/matrix/DCSC/ --name C --shape $k $j --output_format CSF --transpose -python ${SRC_PATH}/generate_random_mats.py --seed 1 --sparsity $sparsity --output_dir ${SYNTHETIC_PATH}/matrix/DENSE/ --name C --shape $k $j --output_format UNC - -popd \ No newline at end of file diff --git a/scripts/get_data/README.md b/scripts/get_data/README.md new file mode 100644 index 00000000..116f1ae1 --- /dev/null +++ b/scripts/get_data/README.md @@ -0,0 +1,11 @@ +# Get Data + +The `scripts/get_data` folder contains scripts used to download and unpack +datasets (SuiteSparse matrices and FROSTT tensors) + +1. `download_frostt.sh` - Download and unpack FROSTT tns files into + `$FROSTT_PATH` +2. `download_suitesparse.sh` - Download SuiteSparse mtx files into + `$SUITESPARSE_PATH` +3. `unpack_suitesparse.sh` - Unpack SuiteSparse mtx files in `$SUITESPARSE_PATH` based on a file +4. `unpack_suitesparse_all.sh` - Unpack SuiteSparse mtx files in `$SUITESPARSE_PATH` for all `*.tar.gz` files that exist diff --git a/scripts/download_frostt.sh b/scripts/get_data/download_frostt.sh similarity index 95% rename from scripts/download_frostt.sh rename to scripts/get_data/download_frostt.sh index bcdda91f..0f5e57fb 100755 --- a/scripts/download_frostt.sh +++ b/scripts/get_data/download_frostt.sh @@ -3,6 +3,8 @@ #SBATCH -t 360 #SBATCH -p lanka-v3 +# Command: ./scripts/get_data/download_frostt.sh + set -e TENSOR_NAMES=( @@ -37,7 +39,7 @@ TENSOR_URLS=( "https://s3.us-east-2.amazonaws.com/frostt/frostt_data/vast-2015-mc1/vast-2015-mc1-5d.tns.gz" ) -outdir=/data/scratch/owhsu/datasets/frostt +outdir=$FROSTT_PATH mkdir -p $outdir diff --git a/scripts/download_suitesparse.sh b/scripts/get_data/download_suitesparse.sh similarity index 99% rename from scripts/download_suitesparse.sh rename to scripts/get_data/download_suitesparse.sh index e07b7d0c..5f1d1f6b 100755 --- a/scripts/download_suitesparse.sh +++ b/scripts/get_data/download_suitesparse.sh @@ -2,7 +2,9 @@ #SBATCH -N 1 #SBATCH -t 360 -outdir=/nobackup/owhsu/sparse-datasets/suitesparse +# Command: ./scripts/get_data/download_suitesparse.sh + +outdir=$SUITESPARSE_PATH mkdir -p $outdir cd $outdir diff --git a/scripts/generate_synthetics.sh b/scripts/get_data/generate_synthetics.sh similarity index 100% rename from scripts/generate_synthetics.sh rename to scripts/get_data/generate_synthetics.sh diff --git a/scripts/unpack_suitesparse.sh b/scripts/get_data/unpack_suitesparse.sh similarity index 81% rename from scripts/unpack_suitesparse.sh rename to scripts/get_data/unpack_suitesparse.sh index 1f91628e..1e089784 100755 --- a/scripts/unpack_suitesparse.sh +++ b/scripts/get_data/unpack_suitesparse.sh @@ -2,6 +2,8 @@ #SBATCH -N 1 #SBATCH -t 360 +# Command: ./scripts/get_data/unpack_suitesparse.sh + pushd . cd $SUITESPARSE_PATH diff --git a/scripts/unpack_suitesparse_all.sh b/scripts/get_data/unpack_suitesparse_all.sh similarity index 79% rename from scripts/unpack_suitesparse_all.sh rename to scripts/get_data/unpack_suitesparse_all.sh index 3e5e06f1..64030d31 100644 --- a/scripts/unpack_suitesparse_all.sh +++ b/scripts/get_data/unpack_suitesparse_all.sh @@ -2,6 +2,8 @@ #SBATCH -N 1 #SBATCH -t 360 +# Command: ./scripts/get_data/unpack_suitesparse_all.sh + cd $SUITESPARSE_PATH for f in *.tar.gz; do diff --git a/scripts/frostt_runner.sh b/scripts/run_cpu/frostt_runner.sh similarity index 100% rename from scripts/frostt_runner.sh rename to scripts/run_cpu/frostt_runner.sh diff --git a/scripts/suitesparse_runner.sh b/scripts/run_cpu/suitesparse_runner.sh similarity index 100% rename from scripts/suitesparse_runner.sh rename to scripts/run_cpu/suitesparse_runner.sh diff --git a/scripts/sam_hw_suitesparse_runner.sh b/scripts/run_onyx/sam_hw_suitesparse_runner.sh similarity index 100% rename from scripts/sam_hw_suitesparse_runner.sh rename to scripts/run_onyx/sam_hw_suitesparse_runner.sh diff --git a/scripts/run_sam_sim/README.md b/scripts/run_sam_sim/README.md new file mode 100644 index 00000000..5aaa119c --- /dev/null +++ b/scripts/run_sam_sim/README.md @@ -0,0 +1,14 @@ +# Scripts to Run SAM Simulations + +All scripts should ultimately run pytest to test the SAM +simulator applications + +the `scripts/run_sam_sim/` folder contains scripts that run the sam simulator for the following datasets: +1. SuiteSparse +2. FROSTT +3. Synthetically generated data + +There are three types of scripts: +1. +2. +3. diff --git a/scripts/pytest_frostt.sh b/scripts/run_sam_sim/pytest_frostt.sh similarity index 100% rename from scripts/pytest_frostt.sh rename to scripts/run_sam_sim/pytest_frostt.sh diff --git a/scripts/pytest_frostt_with_benchmarks.sh b/scripts/run_sam_sim/pytest_frostt_with_benchmarks.sh similarity index 100% rename from scripts/pytest_frostt_with_benchmarks.sh rename to scripts/run_sam_sim/pytest_frostt_with_benchmarks.sh diff --git a/scripts/pytest_suitesparse.sh b/scripts/run_sam_sim/pytest_suitesparse.sh similarity index 100% rename from scripts/pytest_suitesparse.sh rename to scripts/run_sam_sim/pytest_suitesparse.sh diff --git a/scripts/pytest_suitesparse_with_benchmarks.sh b/scripts/run_sam_sim/pytest_suitesparse_with_benchmarks.sh similarity index 100% rename from scripts/pytest_suitesparse_with_benchmarks.sh rename to scripts/run_sam_sim/pytest_suitesparse_with_benchmarks.sh diff --git a/scripts/run_suitesparse.sh b/scripts/run_sam_sim/run_suitesparse.sh similarity index 87% rename from scripts/run_suitesparse.sh rename to scripts/run_sam_sim/run_suitesparse.sh index 43cc9fb0..cb7918ed 100755 --- a/scripts/run_suitesparse.sh +++ b/scripts/run_sam_sim/run_suitesparse.sh @@ -2,6 +2,9 @@ #SBATCH -N 1 #SBATCH -t 360 +# 1. Formats input files +# 2. Runs suitesparse sam sims in pytest + # THIS FILE MUST BE RUN FROM sam/ location outdir=/nobackup/owhsu/sparse-datasets/suitesparse-formatted basedir=$(pwd) @@ -33,7 +36,7 @@ for i in ${!DATASET_NAMES[@]}; do cd $outdir echo "Generating input format files for $name..." - python $basedir/scripts/datastructure_suitesparse.py -n $name + python $basedir/scripts/formatting/datastructure_suitesparse.py -n $name chgrp -R sparsity $outdir chmod -R 777 $outdir diff --git a/scripts/run_sam_sim/run_suitesparse_final.sh b/scripts/run_sam_sim/run_suitesparse_final.sh new file mode 100755 index 00000000..886e58b5 --- /dev/null +++ b/scripts/run_sam_sim/run_suitesparse_final.sh @@ -0,0 +1,14 @@ +#!/bin/bash +#SBATCH -N 1 +#SBATCH --mem 120000 +#SBATCH -p lanka-v3 +#SBATCH --exclusive + +pushd . +cd sam/sim + +while read line; do + pytest test/final-apps/ --ssname $line --check-gold +done < $1 + +popd diff --git a/scripts/run_sam_sim/run_suitesparse_generated.sh b/scripts/run_sam_sim/run_suitesparse_generated.sh new file mode 100755 index 00000000..4f361850 --- /dev/null +++ b/scripts/run_sam_sim/run_suitesparse_generated.sh @@ -0,0 +1,16 @@ +#!/bin/bash +#SBATCH -N 1 +#SBATCH --mem 120000 +#SBATCH -p lanka-v3 +#SBATCH --exclusive + +pushd . +cd sam/sim + +echo $1 + +while read line; do + pytest test/apps/ --ssname $line --check-gold +done < $1 + +popd diff --git a/scripts/run_synthetics.sh b/scripts/run_sam_sim/run_synthetics.sh similarity index 94% rename from scripts/run_synthetics.sh rename to scripts/run_sam_sim/run_synthetics.sh index 35004921..4b6a1c47 100755 --- a/scripts/run_synthetics.sh +++ b/scripts/run_sam_sim/run_synthetics.sh @@ -2,6 +2,9 @@ #SBATCH -N 1 #SBATCH -t 360 +# Req: Need to run this after synthetic/ is generated +# 1. Runs all of the synthetic tests from the ASPLOS 2023 SAM paper + # Vars if [ -z "$2" ] then diff --git a/scripts/sam_frostt_runner.sh b/scripts/run_sam_sim/sam_frostt_runner.sh similarity index 96% rename from scripts/sam_frostt_runner.sh rename to scripts/run_sam_sim/sam_frostt_runner.sh index 2e48dc40..8df824cd 100644 --- a/scripts/sam_frostt_runner.sh +++ b/scripts/run_sam_sim/sam_frostt_runner.sh @@ -4,6 +4,12 @@ #SBATCH -p lanka-v3 #SBATCH --exclusive +# Script steps +# 1. Formats data +# 2. Runs SAM sim in Pytest +# 3. Converts data to CSV +# 4. Aggregates CSV + set -u BENCHMARKS=( diff --git a/scripts/sam_suitesparse_runner.sh b/scripts/run_sam_sim/sam_suitesparse_runner.sh similarity index 100% rename from scripts/sam_suitesparse_runner.sh rename to scripts/run_sam_sim/sam_suitesparse_runner.sh diff --git a/scripts/sam_suitesparse_runner_sddmmonly.sh b/scripts/run_sam_sim/sam_suitesparse_runner_sddmmonly.sh similarity index 100% rename from scripts/sam_suitesparse_runner_sddmmonly.sh rename to scripts/run_sam_sim/sam_suitesparse_runner_sddmmonly.sh diff --git a/scripts/suitesparse_validator.sh b/scripts/run_sam_sim/suitesparse_validator.sh similarity index 100% rename from scripts/suitesparse_validator.sh rename to scripts/run_sam_sim/suitesparse_validator.sh diff --git a/scripts/get_tensor_arrlen.py b/scripts/stats/get_tensor_arrlen.py similarity index 97% rename from scripts/get_tensor_arrlen.py rename to scripts/stats/get_tensor_arrlen.py index f914198d..4b5b91fc 100644 --- a/scripts/get_tensor_arrlen.py +++ b/scripts/stats/get_tensor_arrlen.py @@ -2,6 +2,7 @@ import os import csv +# This is using the old CSF file types def write_csv(path, outpath): with open(outpath, 'w+', newline='') as outcsv: diff --git a/scripts/ss_stats.sh b/scripts/stats/ss_stats.sh similarity index 100% rename from scripts/ss_stats.sh rename to scripts/stats/ss_stats.sh diff --git a/scripts/suitesparse_stats.py b/scripts/stats/suitesparse_stats.py similarity index 100% rename from scripts/suitesparse_stats.py rename to scripts/stats/suitesparse_stats.py diff --git a/scripts/tensor_names/README.md b/scripts/tensor_names/README.md new file mode 100644 index 00000000..8cf69143 --- /dev/null +++ b/scripts/tensor_names/README.md @@ -0,0 +1,19 @@ +# Tensor Names + +the `scripts/tensor_names` folder contains text files with lists of SuiteSparse matrix +names that are used for different scenarios + +The scripts in this folder are: +1. `suitesparse.txt` - All (ANY type) suitesparse matrices (alphabetical order) +2. `suitesparse_ci.txt` - All suitesparse matrices that are in the `sam/data/` folder in the SAM repo for CI purposes +3. `suitesparse_real.txt` - All real suitesparse matrices (alphabetical order) +4. `suitesparse_valid.txt` - All REAL and INTEGER suitesparse matrices that fit + in memory on LANKA (MIT) for at least ONE test from the original SAM paper + passed (unordered) +5. `suitesparse_valid_all.txt` - All real and integer suitesparse matrices that + fit in memory on LANKA (MIT) for ALL tests from the original SAM paper + (ordered by dense dimension) +6. `suitesparse_valid_large50.txt` - The largest 50 (by dense dimension) suitesparse matrices that passed ALL tests from the original SAM paper +7. `suitesparse_valid_mid50.txt` - The median 50 (by dense dimension) suitesparse matrices that passed ALL tests from the original SAM paper +8. `suitesparse_valid_small50.txt` - The smallest 50 (by dense dimension) suitesparse matrices that passed ALL tests from the original SAM paper +9. `temp_*.txt` - `suitesparse_valid.txt` split into various files for running tests in parallel diff --git a/scripts/divvy_runs.py b/scripts/tensor_names/divvy_runs.py similarity index 100% rename from scripts/divvy_runs.py rename to scripts/tensor_names/divvy_runs.py diff --git a/scripts/advanced_simulator_runner.sh b/scripts/tiling/advanced_simulator_runner.sh similarity index 95% rename from scripts/advanced_simulator_runner.sh rename to scripts/tiling/advanced_simulator_runner.sh index 397342fc..e7d772a0 100755 --- a/scripts/advanced_simulator_runner.sh +++ b/scripts/tiling/advanced_simulator_runner.sh @@ -117,10 +117,10 @@ for b in ${!BENCHMARKS[@]}; do if [ "$bench" == "matmul_ikj" ]; then echo "Generating input format files for $line..." - SUITESPARSE_TENSOR_PATH=$matrix python $basedir/scripts/datastructure_suitesparse.py -n $line + SUITESPARSE_TENSOR_PATH=$matrix python $basedir/scripts/formatting/datastructure_suitesparse.py -n $line SUITESPARSE_TENSOR_PATH=$matrix $basedir/compiler/taco/build/bin/taco-test sam.pack_other_ss - python $basedir/scripts/datastructure_frostt.py -n $line -f ss01 --other -ss + python $basedir/scripts/formatting/datastructure_frostt.py -n $line -f ss01 --other -ss fi cd $basedir/sam/sim diff --git a/scripts/clean_memory_model.sh b/scripts/tiling/clean_memory_model.sh similarity index 100% rename from scripts/clean_memory_model.sh rename to scripts/tiling/clean_memory_model.sh diff --git a/scripts/ext_runner.sh b/scripts/tiling/ext_runner.sh similarity index 100% rename from scripts/ext_runner.sh rename to scripts/tiling/ext_runner.sh diff --git a/scripts/few_points_memory_model_runner.sh b/scripts/tiling/few_points_memory_model_runner.sh similarity index 100% rename from scripts/few_points_memory_model_runner.sh rename to scripts/tiling/few_points_memory_model_runner.sh diff --git a/scripts/full_ext_runner.sh b/scripts/tiling/full_ext_runner.sh similarity index 100% rename from scripts/full_ext_runner.sh rename to scripts/tiling/full_ext_runner.sh diff --git a/scripts/full_memory_model_runner.sh b/scripts/tiling/full_memory_model_runner.sh similarity index 100% rename from scripts/full_memory_model_runner.sh rename to scripts/tiling/full_memory_model_runner.sh diff --git a/scripts/generate_gold_matmul_tiled.py b/scripts/tiling/generate_gold_matmul_tiled.py similarity index 100% rename from scripts/generate_gold_matmul_tiled.py rename to scripts/tiling/generate_gold_matmul_tiled.py diff --git a/scripts/generate_sparsity_sweep_mem_model.sh b/scripts/tiling/generate_sparsity_sweep_mem_model.sh similarity index 100% rename from scripts/generate_sparsity_sweep_mem_model.sh rename to scripts/tiling/generate_sparsity_sweep_mem_model.sh diff --git a/scripts/prepare_files.sh b/scripts/tiling/prepare_files.sh similarity index 100% rename from scripts/prepare_files.sh rename to scripts/tiling/prepare_files.sh diff --git a/scripts/prepare_files_no_gold.sh b/scripts/tiling/prepare_files_no_gold.sh similarity index 100% rename from scripts/prepare_files_no_gold.sh rename to scripts/tiling/prepare_files_no_gold.sh diff --git a/scripts/single_point_memory_model_runner.sh b/scripts/tiling/single_point_memory_model_runner.sh similarity index 100% rename from scripts/single_point_memory_model_runner.sh rename to scripts/tiling/single_point_memory_model_runner.sh diff --git a/scripts/tile.sh b/scripts/tiling/tile.sh similarity index 100% rename from scripts/tile.sh rename to scripts/tiling/tile.sh diff --git a/scripts/tile_ext.sh b/scripts/tiling/tile_ext.sh similarity index 100% rename from scripts/tile_ext.sh rename to scripts/tiling/tile_ext.sh diff --git a/scripts/util/README.md b/scripts/util/README.md new file mode 100644 index 00000000..cbad7835 --- /dev/null +++ b/scripts/util/README.md @@ -0,0 +1,10 @@ +# Utilities + +The `scripts/util` folder contains util.py (shared utility functions) and +shared utility scripts used to aggregate and format csv data. + +1. `util.py` - +2. `bench_csv_aggregator.py` - Script that aggregates all of the output CSVs. + This is useful since CPU tests are run using googlebench potentially one + tensor at a time (to run tests in parallel), which will produce one CSV per tensor. +3. `converter.py` - Converts JSON to CSV. diff --git a/scripts/bench_csv_aggregator.py b/scripts/util/bench_csv_aggregator.py similarity index 100% rename from scripts/bench_csv_aggregator.py rename to scripts/util/bench_csv_aggregator.py diff --git a/scripts/converter.py b/scripts/util/converter.py similarity index 100% rename from scripts/converter.py rename to scripts/util/converter.py diff --git a/scripts/util.py b/scripts/util/util.py similarity index 100% rename from scripts/util.py rename to scripts/util/util.py From 8fb90661bf398df0af314502400f3b3874df430d Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Thu, 29 Jun 2023 15:54:23 -0700 Subject: [PATCH 27/76] Fix codestyle for script refactor --- scripts/stats/get_tensor_arrlen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/stats/get_tensor_arrlen.py b/scripts/stats/get_tensor_arrlen.py index 4b5b91fc..897738b2 100644 --- a/scripts/stats/get_tensor_arrlen.py +++ b/scripts/stats/get_tensor_arrlen.py @@ -2,8 +2,8 @@ import os import csv -# This is using the old CSF file types +# This is using the old CSF file types def write_csv(path, outpath): with open(outpath, 'w+', newline='') as outcsv: writer = csv.writer(outcsv) From d22c73fa8e7ee8e920b2e74b83d605abc82ffe67 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Thu, 29 Jun 2023 16:06:28 -0700 Subject: [PATCH 28/76] Fix makefile with updated script locations --- Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 0a4882a9..d0e29ccb 100644 --- a/Makefile +++ b/Makefile @@ -57,16 +57,16 @@ guard-%: # ---- Run SAM python simulator stuff ---- csv: - scripts/pytest_suitesparse_with_benchmarks.sh + scripts/run_sam_sim/pytest_suitesparse_with_benchmarks.sh run-final: submodules - ./scripts/run_suitesparse_final.sh $(realpath ./scripts/tensor_names/$(TENSOR_TXT)) + ./scripts/run_sam_sim/run_suitesparse_final.sh $(realpath ./scripts/tensor_names/$(TENSOR_TXT)) run-gen: submodules - ./scripts/run_suitesparse_generated.sh $(realpath ./scripts/tensor_names/$(TENSOR_TXT)) + ./scripts/run_sam_sim/run_suitesparse_generated.sh $(realpath ./scripts/tensor_names/$(TENSOR_TXT)) tests: sam mkdir -p sam/sim/test/apps - python scripts/test_generating_code.py + python scripts/gen_sam_apps/test_generating_code.py # ---- Build taco and make sam graphs ---- .PHONY: sam @@ -109,10 +109,10 @@ endif # ---- Setup proper environment stuff ---- suitesparse-formats: guard-SUITESPARSE_FORMATTED_PATH guard-SUITESPARSE_PATH rm -rf ${SUITESPARSE_FORMATTED_PATH}/* - set -e && ./scripts/generate_suitesparse_formats.sh + set -e && ./scripts/formatting/generate_suitesparse_formats.sh frostt-formats: taco/build guard-FROSTT_FORMATTED_PATH guard-FROSTT_PATH - ./scripts/generate_frostt_formats.sh + ./scripts/formatting/generate_frostt_formats.sh .PHONY: env env: From 6aa012294234e0853f917df5784c00850cf7cdf1 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Thu, 29 Jun 2023 16:15:25 -0700 Subject: [PATCH 29/76] Add in README for scripts/ dir --- scripts/README.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index b004db54..561b5f0a 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,4 +1,23 @@ +# SAM Scripts + ---------------------------------- -| File Name | Usage | Description | +| Folder Name | Description | ----------------------------------- -| +| `artifact/` | Scripts used solely for The Sparse Abstract Machine ASPLOS 2023 AE | +| `formatting/` | Scripts used to format tensors from .mtx or .tns to other compressed formats | +| `gen_sam_apps/` | Scripts used to generate SAM apps from the compiler | +| `get_data/` | Scripts used to download and unpack datasets | +| `logs/` | Saved log files | +| `run_cpu/` | Scripts used to run the CPU baseline code | +| `run_onyx/` | Scripts used to run Onyx simulations | +| `run_sam_sim/` | Scripts used to run SAM simulations via Pytest | +| `stats/` | Scripts used to compute statistics on data (for DSE/development) | +| `tensor_names` | Scripts and files that have all the dataset tensor names | +| `tiling/` | Scripts used to generate, run, and check tiled simulations | +| `util/` | Utility code used by scripts under the `scripts/` directory | +----------------------------------- + + +Each folder has a README with a description of the corresponding scripts in +that directory. Also For each individual script, see the first line comment for how +to run the command. From 6448e0a4bea120a7de60e5919bea984c699a9e1a Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 30 Jun 2023 11:19:32 -0700 Subject: [PATCH 30/76] Update READMe for run_cpu directory --- scripts/formatting/README.md | 1 - scripts/run_cpu/README.md | 6 ++++++ scripts/run_cpu/frostt_runner.sh | 2 ++ scripts/run_cpu/suitesparse_runner.sh | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 scripts/run_cpu/README.md diff --git a/scripts/formatting/README.md b/scripts/formatting/README.md index 06d3241b..a78f55dc 100644 --- a/scripts/formatting/README.md +++ b/scripts/formatting/README.md @@ -4,7 +4,6 @@ The `scripts/formatting/` folder contains scripts used to format the datasets fr 1. `datastructure_suitesparse.py` - Python script used by `generate_suitesparse_formats.sh` to format from mtx to CSF files. - - 2. `datastructure_tns.py` - Python script used by `generate_frostt_formats.sh` to format from tns to CSF files. 3. `download_unpack_format_suitesparse.sh` - Script that downloads, unpacks, diff --git a/scripts/run_cpu/README.md b/scripts/run_cpu/README.md new file mode 100644 index 00000000..9cdf8ae5 --- /dev/null +++ b/scripts/run_cpu/README.md @@ -0,0 +1,6 @@ +# CPU Baseline Scripts + +The `scripts/run_cpu/` folder contains scripts used to run the CPU baseline tests. These are needed to compare against SAM and/or HW generated using SAM (e.g. Onyx). + +1. `frostt_runner.sh` - Script that runs the frostt tests in taco on the CPU +2. `suitesparse_runner.sh` - Script that runs the SuiteSparse tests in taco on the CPU diff --git a/scripts/run_cpu/frostt_runner.sh b/scripts/run_cpu/frostt_runner.sh index 9e68b46c..fda1153c 100755 --- a/scripts/run_cpu/frostt_runner.sh +++ b/scripts/run_cpu/frostt_runner.sh @@ -4,6 +4,8 @@ #SBATCH -p lanka-v3 #SBATCH --exclusive +# ./frostt_runner.sh <0|1|2> +# where 0 us for local, 1 is for Lanka, and 2 is for Kiwi/Neva DATASET_NAMES=( fb1k diff --git a/scripts/run_cpu/suitesparse_runner.sh b/scripts/run_cpu/suitesparse_runner.sh index 33b95b6b..01b74bbe 100755 --- a/scripts/run_cpu/suitesparse_runner.sh +++ b/scripts/run_cpu/suitesparse_runner.sh @@ -4,6 +4,10 @@ #SBATCH -p lanka-v3 #SBATCH --exclusive +# ./suitesparse_runner.sh <0|1|2> +# First argument - Textfile with names of suitesparse tensors to run +# Second argument - Which machine to run on + set -u cwd=$(pwd) From 257a74a9a94bbe736d04913b34e2adc5d25f880c Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Mon, 17 Jul 2023 16:44:38 -0700 Subject: [PATCH 31/76] Finish adding scripts/ hierarchy. Tried to add in all READMEs, comments, and fixed paths to get scripts running. --- .gitignore | 2 +- scripts/README.md | 30 +++-- .../formatting/datastructure_suitesparse.py | 2 +- scripts/formatting/datastructure_tns.py | 2 +- scripts/run_cpu/README.md | 10 +- scripts/run_cpu/frostt_runner.sh | 4 +- scripts/run_cpu/suitesparse_runner.sh | 6 +- scripts/run_onyx/README.md | 6 + scripts/run_onyx/sam_hw_suitesparse_runner.sh | 10 ++ scripts/run_sam_sim/README.md | 30 ++++- scripts/run_sam_sim/pytest_frostt.sh | 94 ++------------- .../pytest_frostt_with_benchmarks.sh | 26 ++-- scripts/run_sam_sim/pytest_suitesparse.sh | 83 ++----------- .../pytest_suitesparse_with_benchmarks.sh | 28 ++--- scripts/run_sam_sim/run_suitesparse.sh | 21 +--- scripts/run_sam_sim/run_suitesparse_final.sh | 2 + scripts/run_sam_sim/run_synthetics.sh | 29 +++-- scripts/run_sam_sim/sam_frostt_runner.sh | 62 ++-------- scripts/run_sam_sim/sam_suitesparse_runner.sh | 50 ++------ .../sam_suitesparse_runner_sddmmonly.sh | 113 ------------------ scripts/run_sam_sim/suitesparse_validator.sh | 14 ++- scripts/stats/README.md | 8 ++ scripts/stats/get_tensor_arrlen.py | 3 +- scripts/stats/ss_stats.sh | 9 -- scripts/stats/suitesparse_stats.py | 2 +- scripts/stats/suitesparse_stats.sh | 9 ++ scripts/tiling/README.md | 33 +++++ scripts/tiling/advanced_simulator_runner.sh | 63 ++-------- scripts/tiling/clean_memory_model.sh | 0 scripts/tiling/ext_runner.sh | 9 +- .../tiling/few_points_memory_model_runner.sh | 11 +- scripts/tiling/full_ext_runner.sh | 5 +- scripts/tiling/full_memory_model_runner.sh | 12 +- scripts/tiling/generate_gold_matmul_tiled.py | 13 +- .../generate_sparsity_sweep_mem_model.sh | 2 + scripts/tiling/prepare_files.sh | 7 +- scripts/tiling/prepare_files_no_gold.sh | 6 +- .../single_point_memory_model_runner.sh | 8 +- scripts/tiling/tile.sh | 4 +- scripts/tiling/tile_ext.sh | 14 ++- scripts/util/README.md | 2 +- scripts/util/__init__.py | 0 42 files changed, 267 insertions(+), 577 deletions(-) create mode 100644 scripts/run_onyx/README.md mode change 100644 => 100755 scripts/run_sam_sim/sam_frostt_runner.sh delete mode 100644 scripts/run_sam_sim/sam_suitesparse_runner_sddmmonly.sh create mode 100644 scripts/stats/README.md delete mode 100755 scripts/stats/ss_stats.sh create mode 100755 scripts/stats/suitesparse_stats.sh create mode 100644 scripts/tiling/README.md mode change 100644 => 100755 scripts/tiling/clean_memory_model.sh create mode 100644 scripts/util/__init__.py diff --git a/.gitignore b/.gitignore index 3c716691..a69400ea 100644 --- a/.gitignore +++ b/.gitignore @@ -32,7 +32,7 @@ build/ logs/ results/ results-cpu/ -suitesparse-bench/ +suitesparse-bench*/ sam-outputs/ compiler/benchmark/ diff --git a/scripts/README.md b/scripts/README.md index 561b5f0a..1207da54 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,21 +1,19 @@ # SAM Scripts ----------------------------------- -| Folder Name | Description | ------------------------------------ -| `artifact/` | Scripts used solely for The Sparse Abstract Machine ASPLOS 2023 AE | -| `formatting/` | Scripts used to format tensors from .mtx or .tns to other compressed formats | -| `gen_sam_apps/` | Scripts used to generate SAM apps from the compiler | -| `get_data/` | Scripts used to download and unpack datasets | -| `logs/` | Saved log files | -| `run_cpu/` | Scripts used to run the CPU baseline code | -| `run_onyx/` | Scripts used to run Onyx simulations | -| `run_sam_sim/` | Scripts used to run SAM simulations via Pytest | -| `stats/` | Scripts used to compute statistics on data (for DSE/development) | -| `tensor_names` | Scripts and files that have all the dataset tensor names | -| `tiling/` | Scripts used to generate, run, and check tiled simulations | -| `util/` | Utility code used by scripts under the `scripts/` directory | ------------------------------------ +| Folder Name | Description | +| ------------ | ----------------------- | +| `artifact/` | Scripts used solely for The Sparse Abstract Machine ASPLOS 2023 AE | +| `formatting/` | Scripts used to format tensors from .mtx or .tns to other compressed formats | +| `gen_sam_apps/` | Scripts used to generate SAM apps from the compiler | +| `get_data/` | Scripts used to download and unpack datasets | +| `logs/` | Saved log files | +| `run_cpu/` | Scripts used to run the CPU baseline code | +| `run_onyx/` | Scripts used to run Onyx simulations | +| `run_sam_sim/` | Scripts used to run SAM simulations via Pytest | +| `stats/` | Scripts used to compute statistics on data (for DSE/development) | +| `tensor_names` | Scripts and files that have all the dataset tensor names | +| `tiling/` | Scripts used to generate, run, and check tiled simulations | +| `util/` | Utility code used by scripts under the `scripts/` directory | Each folder has a README with a description of the corresponding scripts in diff --git a/scripts/formatting/datastructure_suitesparse.py b/scripts/formatting/datastructure_suitesparse.py index cb24ec39..502a8822 100644 --- a/scripts/formatting/datastructure_suitesparse.py +++ b/scripts/formatting/datastructure_suitesparse.py @@ -6,7 +6,7 @@ from pathlib import Path -from util import FormatWriter, SuiteSparseTensor, InputCacheSuiteSparse +from scripts.util.util import FormatWriter, SuiteSparseTensor, InputCacheSuiteSparse from sam.util import SUITESPARSE_FORMATTED_PATH, ScipyTensorShifter all_formats = ["coo", "cooT", "csr", "dcsr", "dcsc", "csc", "dense", "denseT"] diff --git a/scripts/formatting/datastructure_tns.py b/scripts/formatting/datastructure_tns.py index ccf60fae..aede2dbc 100644 --- a/scripts/formatting/datastructure_tns.py +++ b/scripts/formatting/datastructure_tns.py @@ -1,7 +1,7 @@ import argparse import os from pathlib import Path -from util import parse_taco_format +from sam.util import parse_taco_format cwd = os.getcwd() diff --git a/scripts/run_cpu/README.md b/scripts/run_cpu/README.md index 9cdf8ae5..2b05a73e 100644 --- a/scripts/run_cpu/README.md +++ b/scripts/run_cpu/README.md @@ -1,6 +1,10 @@ # CPU Baseline Scripts -The `scripts/run_cpu/` folder contains scripts used to run the CPU baseline tests. These are needed to compare against SAM and/or HW generated using SAM (e.g. Onyx). +The `scripts/run_cpu/` folder contains scripts used to run +the CPU baseline tests. These are needed to compare +against SAM and/or HW generated using SAM (e.g. Onyx). -1. `frostt_runner.sh` - Script that runs the frostt tests in taco on the CPU -2. `suitesparse_runner.sh` - Script that runs the SuiteSparse tests in taco on the CPU +1. `frostt_runner.sh` - Script that runs the frostt tests + in taco on the CPU +2. `suitesparse_runner.sh` - Script that runs the + SuiteSparse tests in taco on the CPU diff --git a/scripts/run_cpu/frostt_runner.sh b/scripts/run_cpu/frostt_runner.sh index fda1153c..e8d6dfac 100755 --- a/scripts/run_cpu/frostt_runner.sh +++ b/scripts/run_cpu/frostt_runner.sh @@ -4,8 +4,8 @@ #SBATCH -p lanka-v3 #SBATCH --exclusive -# ./frostt_runner.sh <0|1|2> -# where 0 us for local, 1 is for Lanka, and 2 is for Kiwi/Neva +# ./frostt_runner.sh +# Arg1 - Which machine is being used (0:local, 1:Lanka, 2:Kiwi/Neva) DATASET_NAMES=( fb1k diff --git a/scripts/run_cpu/suitesparse_runner.sh b/scripts/run_cpu/suitesparse_runner.sh index 01b74bbe..3bcc864f 100755 --- a/scripts/run_cpu/suitesparse_runner.sh +++ b/scripts/run_cpu/suitesparse_runner.sh @@ -4,9 +4,9 @@ #SBATCH -p lanka-v3 #SBATCH --exclusive -# ./suitesparse_runner.sh <0|1|2> -# First argument - Textfile with names of suitesparse tensors to run -# Second argument - Which machine to run on +# ./suitesparse_runner.sh +# Arg1 - Textfile with names of suitesparse tensors to run +# Arg2 - Which machine is being used (0:local, 1:Lanka, 2:Kiwi/Neva) set -u diff --git a/scripts/run_onyx/README.md b/scripts/run_onyx/README.md new file mode 100644 index 00000000..82634ba8 --- /dev/null +++ b/scripts/run_onyx/README.md @@ -0,0 +1,6 @@ +# Onyx Scripts + +The `scripts/run_onyx/` folder contains scripts used to +run Onyx test benches from the [`aha/`](https://github.com/StanfordAHA/aha) flow. + +1. `sam_hw_suitesparse_runner.sh` - Script that runs the SuiteSparse tests in Onyx (from the aha repository). diff --git a/scripts/run_onyx/sam_hw_suitesparse_runner.sh b/scripts/run_onyx/sam_hw_suitesparse_runner.sh index 22a731f8..e9748bf1 100755 --- a/scripts/run_onyx/sam_hw_suitesparse_runner.sh +++ b/scripts/run_onyx/sam_hw_suitesparse_runner.sh @@ -4,6 +4,16 @@ #SBATCH -p lanka-v3 #SBATCH --exclusive +# This should be run from the sam/ directory + +# ./sam_hw_suitesparse_runner.sh +# Arg1 - File with the SuiteSparse matrices to run +# Arg2 - Which machine is being used (0:local, 1:Lanka, 2:Kiwi/Neva) + +# This script: +# 1. Formats teh matrices +# 2. Then runs build_tb in garnet + set -u BENCHMARKS=( diff --git a/scripts/run_sam_sim/README.md b/scripts/run_sam_sim/README.md index 5aaa119c..2331a759 100644 --- a/scripts/run_sam_sim/README.md +++ b/scripts/run_sam_sim/README.md @@ -8,7 +8,29 @@ the `scripts/run_sam_sim/` folder contains scripts that run the sam simulator fo 2. FROSTT 3. Synthetically generated data -There are three types of scripts: -1. -2. -3. +1. `pytest_frostt.sh` - Script that runs ALL pytest tests beginning with the + name `test_tensor*` under `sam/sim/test/` with the FROSTT tensors. +2. `pytest_frostt_with_benchmarks.sh` - Script that runs only select pytest + benchmarks under `sam/sim/test/` with the FROSTT tensors. +3. `pytest_suitesparse.sh` - Script that runs ALL pytest tests in + `sam/sim/test/final-apps` with gold checking enabled for the SuiteSparse +matrices provided in `tensor_names.txt`. +4. `pytest_suitesparse_with_benchmarks.sh` - Script that runs runs select + SuiteSparse pytest benchmarks under `sam/sim/test/apps/`. This script has gold checking +disabled and aggregates results into a CSVs. +5. `run_suitesparse_final.sh` - Script that runs ALL SuiteSparse final tests in + `sam/sim/test/final-apps/` +6. `run_suitesparse_generated.sh` - Script that runs ALL SuiteSparse generated tests in + `sam/sim/test/apps/` +7. `run_suitesparse.sh` - Script that formats input SuiteSparse matrices and then runs + pytest on all SuiteSparse benchmarks in `sam/sim/test/apps` +8. `run_synthetics.sh` - Script that runs all of the synthetic benchmarks from + the ASPLOS 2023 SAM paper. +9. `sam_frostt_runner.sh` - Script that formats, runs, and generates CSVs for + all frostt benchmarks. +10. `sam_suitesparse_runner.sh` - Script that formats, runs, and generates CSVs + for all SuiteSparse benchmarks in `final-apps`. +11. `sam_suitesparse_runner_sddmmonly.sh` - Script that formats, runs, and + generates CSVs for the `final-apps` SDDMM SuiteSparse benchmark only. +12. `suitesparse_validator.sh` - Script that runs the CPU benchmarks and then + the SAM pytest benchmarks in `apps` on SuiteSparse data. diff --git a/scripts/run_sam_sim/pytest_frostt.sh b/scripts/run_sam_sim/pytest_frostt.sh index 39f4366d..ffc770a1 100755 --- a/scripts/run_sam_sim/pytest_frostt.sh +++ b/scripts/run_sam_sim/pytest_frostt.sh @@ -1,16 +1,13 @@ #!/bin/bash #SBATCH -N 1 #SBATCH -t 360 -outdir=/nobackup/owhsu/sparse-datasets/frostt-formatted -DATASET_NAMES=( - facebook - fb10k - fb1k - nell-1 - nell-2 - taco-tensor -) +# Run from sam/ repo +# ./scripts/run_sam_sim/pytest_frostt.sh + +# Script that runs ALL test_tensor* pytest tests under sam/sim/test + +outdir=/nobackup/owhsu/sparse-datasets/frostt-formatted errors=() RED='\033[0;31m' @@ -22,89 +19,18 @@ export FROSTT_FORMATTED_PATH=$outdir mkdir -p $outdir cd ./sam/sim -for i in ${!DATASET_NAMES[@]}; do - name=${DATASET_NAMES[$i]} +while read line; do + name=$line echo "Testing $name..." -# pytest -k test_mat_mul_ijk_csr_full_i --ssname $name -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} matmul_ijk_full") -# fi - -# pytest -k test_mat_identity_i --ssname $name -s -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} matmul_ijk") -# fi pytest -k test_tensor --frosttname $name -s -vv #--debug-sim status=$? if [ $status -gt 0 ] then - errors+=("${name} matmul_ijk") + errors+=("${name} test") fi - - -# -# pytest -k test_matmul_ijk_i --ssname $name -s #--debug-sim -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} matmul_ijk") -# fi - -# pytest -k test_mat_elemmul_i --ssname $name -s -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} matmul_ijk") -# fi - - -# pytest -k test_tensor3_elemmul_i --ssname $name -s -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} matmul_ijk") -# fi - -# pytest -k test_matmul_jik_i --ssname $name -s -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} matmul_ijk") -# fi - -# pytest -k test_matmul_jki_i --ssname $name -s -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} matmul_ijk") -# fi - - - - -# pytest -k test_mat_identity_i --ssname $name -s -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} mat_identity") -# fi - -# pytest -k test_mat_elemmul_i --ssname $name -s -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} mat_identity") -# fi - - - -done +done <$1 echo -e "${RED}Failed tests:" for i in ${!errors[@]}; do diff --git a/scripts/run_sam_sim/pytest_frostt_with_benchmarks.sh b/scripts/run_sam_sim/pytest_frostt_with_benchmarks.sh index 0ba9774d..da73cbb8 100755 --- a/scripts/run_sam_sim/pytest_frostt_with_benchmarks.sh +++ b/scripts/run_sam_sim/pytest_frostt_with_benchmarks.sh @@ -2,6 +2,7 @@ #SBATCH -N 1 #SBATCH -t 360 +# ./scripts/run_sam_sim/pytest_frostt_with_benchmarks.sh BENCHMARKS=( tensor3_elemmul @@ -13,15 +14,6 @@ BENCHMARKS=( tensor_mttkrp ) -DATASET_NAMES=( - facebook - fb10k - fb1k - nell-1 - nell-2 - taco-tensor -) - outdir=/nobackup/owhsu/sparse-datasets/frostt-formatted export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt @@ -33,7 +25,7 @@ RED='\033[0;31m' NC='\033[0m' # No Color -cwd=$(pwd) +basedir=$(pwd) resultdir=results @@ -41,27 +33,27 @@ cd ./sam/sim for b in ${!BENCHMARKS[@]}; do bench=${BENCHMARKS[$b]} - path=$cwd/$resultdir/$bench + path=$basedir/$resultdir/$bench - mkdir -p $cwd/$resultdir/$bench + mkdir -p $basedir/$resultdir/$bench echo "Testing $bench..." - for i in ${!DATASET_NAMES[@]}; do - name=${DATASET_NAMES[$i]} + while read line; do + name=$line echo "Testing $name..." pytest test/apps/test_$bench.py --ssname $name -s --benchmark-json=$path/$name.json - python $cwd/scripts/converter.py --json_name $path/$name.json + python $basedir/scripts/util/converter.py --json_name $path/$name.json status=$? if [ $status -gt 0 ] then errors+=("${name}, ${bench}") fi - done + done <$1 - python $cwd/scripts/bench_csv_aggregator.py $path $cwd/suitesparse_$bench.csv + python $basedir/scripts/util/bench_csv_aggregator.py $path $basedir/suitesparse_$bench.csv done diff --git a/scripts/run_sam_sim/pytest_suitesparse.sh b/scripts/run_sam_sim/pytest_suitesparse.sh index e040646c..1e440beb 100755 --- a/scripts/run_sam_sim/pytest_suitesparse.sh +++ b/scripts/run_sam_sim/pytest_suitesparse.sh @@ -1,22 +1,11 @@ #!/bin/bash #SBATCH -N 1 #SBATCH -t 360 -outdir=/nobackup/owhsu/sparse-datasets/suitesparse-formatted -DATASET_NAMES=( -# bcsstm04 - bcsstm02 - bcsstm03 - lpi_bgprtr - cage4 - klein-b1 - GD02_a - GD95_b - Hamrle1 - LF10 - lpi_itest2 - lp_scsd1 -) +# ./scripts/run_sam_sim/pytest_suitesparse.sh + + +outdir=$SUITESPARSE_FORMATTED_PATH errors=() RED='\033[0;31m' @@ -26,8 +15,8 @@ NC='\033[0m' # No Color mkdir -p $outdir cd ./sam/sim -for i in ${!DATASET_NAMES[@]}; do - name=${DATASET_NAMES[$i]} +while read line; do + name=$line echo "Testing $name..." @@ -37,65 +26,7 @@ for i in ${!DATASET_NAMES[@]}; do then errors+=("${name}") fi - - -# -# pytest -k test_matmul_ijk_i --ssname $name -s #--debug-sim -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} matmul_ijk") -# fi - -# pytest -k test_mat_elemmul_i --ssname $name -s -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} matmul_ijk") -# fi - - -# pytest -k test_tensor3_elemmul_i --ssname $name -s -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} matmul_ijk") -# fi - -# pytest -k test_matmul_jik_i --ssname $name -s -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} matmul_ijk") -# fi - -# pytest -k test_matmul_jki_i --ssname $name -s -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} matmul_ijk") -# fi - - - - -# pytest -k test_mat_identity_i --ssname $name -s -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} mat_identity") -# fi - -# pytest -k test_mat_elemmul_i --ssname $name -s -# status=$? -# if [ $status -gt 0 ] -# then -# errors+=("${name} mat_identity") -# fi - - - -done +done < $1 echo -e "${RED}Failed tests:" for i in ${!errors[@]}; do diff --git a/scripts/run_sam_sim/pytest_suitesparse_with_benchmarks.sh b/scripts/run_sam_sim/pytest_suitesparse_with_benchmarks.sh index 09cc2b67..e0e38f12 100755 --- a/scripts/run_sam_sim/pytest_suitesparse_with_benchmarks.sh +++ b/scripts/run_sam_sim/pytest_suitesparse_with_benchmarks.sh @@ -2,6 +2,8 @@ #SBATCH -N 1 #SBATCH -t 360 +# ./scripts/run_sam_sim/pytest_suitesparse_with_benchmarks.sh + BENCHMARKS=( matmul_kij matmul_kji @@ -22,27 +24,11 @@ BENCHMARKS=( ) -# FIXME: Need to change this to take in an input file as in taco side -DATASET_NAMES=( - bcsstm04 - bcsstm02 - bcsstm03 - lpi_bgprtr - cage4 - klein-b1 - GD02_a - GD95_b - Hamrle1 - LF10 -) - errors=() RED='\033[0;31m' NC='\033[0m' # No Color -export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse -export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted cwd=$(pwd) resultdir=results @@ -56,13 +42,13 @@ for b in ${!BENCHMARKS[@]}; do mkdir -p $cwd/$resultdir/$bench echo "Testing $bench..." - for i in ${!DATASET_NAMES[@]}; do - name=${DATASET_NAMES[$i]} + while read line; do + name=$line echo "Testing $name..." pytest test/apps/test_$bench.py --ssname $name -s --benchmark-json=$path/$name.json - python $cwd/scripts/converter.py --json_name $path/$name.json + python $cwd/scripts/util/converter.py --json_name $path/$name.json status=$? if [ $status -gt 0 ] @@ -71,9 +57,9 @@ for b in ${!BENCHMARKS[@]}; do fi done - python $cwd/scripts/bench_csv_aggregator.py $path $cwd/suitesparse_$bench.csv + python $cwd/scripts/util/bench_csv_aggregator.py $path $cwd/suitesparse_$bench.csv -done +done < $1 echo -e "${RED}Failed tests:" for i in ${!errors[@]}; do diff --git a/scripts/run_sam_sim/run_suitesparse.sh b/scripts/run_sam_sim/run_suitesparse.sh index cb7918ed..2b3da4ce 100755 --- a/scripts/run_sam_sim/run_suitesparse.sh +++ b/scripts/run_sam_sim/run_suitesparse.sh @@ -5,23 +5,12 @@ # 1. Formats input files # 2. Runs suitesparse sam sims in pytest +# ./scripts/run_sam_sim/run_suitesparse.sh + # THIS FILE MUST BE RUN FROM sam/ location outdir=/nobackup/owhsu/sparse-datasets/suitesparse-formatted basedir=$(pwd) -DATASET_NAMES=( - bcsstm04 - bcsstm02 - bcsstm03 - lpi_bgprtr - cage4 - klein-b1 - GD02_a - GD95_b - Hamrle1 - LF10 -) - errors=() RED='\033[0;31m' NC='\033[0m' # No Color @@ -31,8 +20,8 @@ export SUITESPARSE_FORMATTED_PATH=$outdir mkdir -p $outdir -for i in ${!DATASET_NAMES[@]}; do - name=${DATASET_NAMES[$i]} +while read line; do + name=$line cd $outdir echo "Generating input format files for $name..." @@ -53,7 +42,7 @@ for i in ${!DATASET_NAMES[@]}; do cd $outdir echo "Removing format files for $name..." rm ./$name*.txt -done +done < $1 echo -e "${RED}Failed tests:" for i in ${!errors[@]}; do diff --git a/scripts/run_sam_sim/run_suitesparse_final.sh b/scripts/run_sam_sim/run_suitesparse_final.sh index 886e58b5..d2480f74 100755 --- a/scripts/run_sam_sim/run_suitesparse_final.sh +++ b/scripts/run_sam_sim/run_suitesparse_final.sh @@ -4,6 +4,8 @@ #SBATCH -p lanka-v3 #SBATCH --exclusive +# ./scripts/run_sam_sim/run + pushd . cd sam/sim diff --git a/scripts/run_sam_sim/run_synthetics.sh b/scripts/run_sam_sim/run_synthetics.sh index 4b6a1c47..5e5b356a 100755 --- a/scripts/run_sam_sim/run_synthetics.sh +++ b/scripts/run_sam_sim/run_synthetics.sh @@ -2,15 +2,20 @@ #SBATCH -N 1 #SBATCH -t 360 +# ./scripts/run_sam_sim/run_synthetics.sh + # Req: Need to run this after synthetic/ is generated # 1. Runs all of the synthetic tests from the ASPLOS 2023 SAM paper +basedir=$(pwd) +resultdir=results + # Vars -if [ -z "$2" ] +if [ -z "$1" ] then - export SYNTHETIC_PATH="$(pwd)/synthetic/" + export SYNTHETIC_PATH="$basedir/synthetic/" else - export SYNTHETIC_PATH="$2" + export SYNTHETIC_PATH="$1" fi BENCHMARKS=( @@ -22,8 +27,6 @@ BENCHMARKS=( test_vec_elemmul_uncompressed ) -cwd=$(pwd) -resultdir=results for b in ${!BENCHMARKS[@]}; do bench=${BENCHMARKS[$b]} @@ -33,8 +36,8 @@ for b in ${!BENCHMARKS[@]}; do echo "Testing $bench..." pytest sam/sim/test/study-apps/$bench.py --synth --check-gold -k "random-40 or 0.2-blocks or 0.2-runs" --benchmark-json="$path/$bench.json" - python $cwd/scripts/converter.py --json_name $path/$bench.json - python $cwd/scripts/bench_csv_aggregator.py $path $cwd/SYNTH_OUT_ACCEL.csv + python $basedir/scripts/util/converter.py --json_name $path/$bench.json + python $basedir/scripts/util/bench_csv_aggregator.py $path $basedir/SYNTH_OUT_ACCEL.csv done @@ -47,7 +50,7 @@ BENCHMARKS=( test_reorder_matmul_kji ) -cwd=$(pwd) +basedir=$(pwd) resultdir=results_reorder for b in ${!BENCHMARKS[@]}; do @@ -58,8 +61,8 @@ for b in ${!BENCHMARKS[@]}; do echo "Testing $bench..." pytest sam/sim/test/reorder-study/$bench.py --synth --check-gold --benchmark-json="$path/$bench.json" - python $cwd/scripts/converter.py --json_name $path/$bench.json - python $cwd/scripts/bench_csv_aggregator.py $path $cwd/SYNTH_OUT_REORDER.csv + python $basedir/scripts/util/converter.py --json_name $path/$bench.json + python $basedir/scripts/util/bench_csv_aggregator.py $path $basedir/SYNTH_OUT_REORDER.csv done @@ -69,7 +72,7 @@ BENCHMARKS=( test_mat_sddmm_unfused ) -cwd=$(pwd) +basedir=$(pwd) resultdir=results_fusion for b in ${!BENCHMARKS[@]}; do @@ -80,8 +83,8 @@ for b in ${!BENCHMARKS[@]}; do echo "Testing $bench..." pytest sam/sim/test/fusion-study/$bench.py --synth --check-gold --benchmark-json="$path/$bench.json" - python $cwd/scripts/converter.py --json_name $path/$bench.json - python $cwd/scripts/bench_csv_aggregator.py $path $cwd/SYNTH_OUT_FUSION.csv + python $basedir/scripts/util/converter.py --json_name $path/$bench.json + python $basedir/scripts/util/bench_csv_aggregator.py $path $basedir/SYNTH_OUT_FUSION.csv done diff --git a/scripts/run_sam_sim/sam_frostt_runner.sh b/scripts/run_sam_sim/sam_frostt_runner.sh old mode 100644 new mode 100755 index 8df824cd..59a9119f --- a/scripts/run_sam_sim/sam_frostt_runner.sh +++ b/scripts/run_sam_sim/sam_frostt_runner.sh @@ -10,6 +10,8 @@ # 3. Converts data to CSV # 4. Aggregates CSV +# ./scripts/run_sam_sim/sam_frostt_runner.sh + set -u BENCHMARKS=( @@ -20,61 +22,15 @@ BENCHMARKS=( tensor3_mttkrp_FINAL ) -TENSORS=( - fb1k - fb10k - facebook - nell-2 - nell-1 -) - - errors=() RED='\033[0;31m' NC='\033[0m' # No Color -# LANKA -if [ $1 -eq 1 ]; then - export SUITESPARSE_PATH=/data/scratch/changwan/florida_all - export FROSTT_PATH=/data/scratch/owhsu/datasets/frostt - export TACO_TENSOR_PATH=/data/scratch/owhsu/datasets - export SUITESPARSE_FORMATTED_PATH=/data/scratch/owhsu/datasets/suitesparse-formatted - export FROSTT_FORMATTED_TACO_PATH=/data/scratch/owhsu/datasets/frostt-formatted/taco-tensor - export FROSTT_FORMATTED_PATH=/data/scratch/owhsu/datasets/frostt-formatted - - mkdir -p $TACO_TENSOR_PATH - mkdir -p $SUITESPARSE_FORMATTED_PATH - mkdir -p $FROSTT_FORMATTED_TACO_PATH - mkdir -p $FROSTT_FORMATTED_PATH - - lanka=ON - neva=OFF -elif [ $1 -eq 2 ]; then - lanka=OFF - neva=ON -else - lanka=OFF - neva=OFF -fi - format_outdir=${FROSTT_FORMATTED_PATH} basedir=$(pwd) frosttpath=$FROSTT_PATH benchout=frostt-bench/sam -__conda_setup="$('/data/scratch/owhsu/miniconda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" -if [ $? -eq 0 ]; then - eval "$__conda_setup" -else - if [ -f "/data/scratch/owhsu/miniconda/etc/profile.d/conda.sh" ]; then - . "/data/scratch/owhsu/miniconda/etc/profile.d/conda.sh" - else - export PATH="/data/scratch/owhsu/miniconda/bin:$PATH" - fi -fi -unset __conda_setup -conda activate aha - mkdir -p "$benchout" mkdir -p $format_outdir mkdir -p $TACO_TENSOR_PATH/other-formatted-taco @@ -87,8 +43,8 @@ for b in ${!BENCHMARKS[@]}; do mkdir -p $basedir/$benchout/$bench echo "Testing $bench..." - for t in ${!TENSORS[@]}; do - name=${TENSORS[$t]} + while read line; do + name=$line cd $format_outdir @@ -97,15 +53,15 @@ for b in ${!BENCHMARKS[@]}; do $basedir/compiler/taco/build/bin/taco-test sam.pack_sss012 $basedir/compiler/taco/build/bin/taco-test sam.pack_other_frostt - python $basedir/scripts/datastructure_tns.py -n $name -f sss012 - python $basedir/scripts/datastructure_tns.py -n $name -f sss012 --other + python $basedir/scripts/formatting/datastructure_tns.py -n $name -f sss012 + python $basedir/scripts/formatting/datastructure_tns.py -n $name -f sss012 --other chmod -R 775 $FROSTT_FORMATTED_PATH fi cd $basedir/sam/sim pytest test/final-apps/test_$bench.py --frosttname $name --benchmark-json=$path/$name.json - python $basedir/scripts/converter.py --json_name $path/$name.json + python $basedir/scripts/util/converter.py --json_name $path/$name.json status=$? if [ $status -gt 0 ] @@ -114,9 +70,9 @@ for b in ${!BENCHMARKS[@]}; do fi cd $basedir - done + done <$1 - python $basedir/scripts/bench_csv_aggregator.py $path $basedir/$benchout/frostt_$bench.csv + python $basedir/scripts/util/bench_csv_aggregator.py $path $basedir/$benchout/frostt_$bench.csv echo -e "${RED}Failed tests:" for i in ${!errors[@]}; do diff --git a/scripts/run_sam_sim/sam_suitesparse_runner.sh b/scripts/run_sam_sim/sam_suitesparse_runner.sh index 8c806381..5604f524 100755 --- a/scripts/run_sam_sim/sam_suitesparse_runner.sh +++ b/scripts/run_sam_sim/sam_suitesparse_runner.sh @@ -4,6 +4,8 @@ #SBATCH -p lanka-v3 #SBATCH --exclusive +# ./scripts/run_sam_sim/sam_suitesparse_runner.sh + set -u BENCHMARKS=( @@ -19,53 +21,17 @@ errors=() RED='\033[0;31m' NC='\033[0m' # No Color -# LANKA -if [ $2 -eq 1 ]; then - export SUITESPARSE_PATH=/data/scratch/changwan/florida_all - export FROSTT_PATH=/data/scratch/owhsu/datasets/frostt - export TACO_TENSOR_PATH=/data/scratch/owhsu/datasets - export SUITESPARSE_FORMATTED_PATH=/data/scratch/owhsu/datasets/suitesparse-formatted - export FROSTT_FORMATTED_TACO_PATH=/data/scratch/owhsu/datasets/frostt-formatted/taco-tensor - export FROSTT_FORMATTED_PATH=/data/scratch/owhsu/datasets/frostt-formatted - - mkdir -p $TACO_TENSOR_PATH - mkdir -p $SUITESPARSE_FORMATTED_PATH - mkdir -p $FROSTT_FORMATTED_TACO_PATH - mkdir -p $FROSTT_FORMATTED_PATH - - lanka=ON - neva=OFF -elif [ $2 -eq 2 ]; then - lanka=OFF - neva=ON -else - lanka=OFF - neva=OFF -fi - format_outdir=${SUITESPARSE_FORMATTED_PATH} basedir=$(pwd) sspath=$SUITESPARSE_PATH benchout=suitesparse-bench/sam -__conda_setup="$('/data/scratch/owhsu/miniconda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" -if [ $? -eq 0 ]; then - eval "$__conda_setup" -else - if [ -f "/data/scratch/owhsu/miniconda/etc/profile.d/conda.sh" ]; then - . "/data/scratch/owhsu/miniconda/etc/profile.d/conda.sh" - else - export PATH="/data/scratch/owhsu/miniconda/bin:$PATH" - fi -fi -unset __conda_setup -conda activate aha - mkdir -p "$benchout" mkdir -p $format_outdir mkdir -p $TACO_TENSOR_PATH/other-formatted-taco -make -j8 taco/build NEVA=$neva LANKA=$lanka GEN=ON +# make -j8 taco/build NEVA=$neva LANKA=$lanka GEN=ON +make -j8 taco/build GEN=ON for b in ${!BENCHMARKS[@]}; do bench=${BENCHMARKS[$b]} @@ -86,16 +52,16 @@ for b in ${!BENCHMARKS[@]}; do if [ "$bench" == "mat_vecmul_FINAL" ]; then echo "Generating input format files for $line..." - SUITESPARSE_TENSOR_PATH=$matrix python $basedir/scripts/datastructure_suitesparse.py -n $line + SUITESPARSE_TENSOR_PATH=$matrix python $basedir/scripts/formatting/datastructure_suitesparse.py -n $line SUITESPARSE_TENSOR_PATH=$matrix $basedir/compiler/taco/build/bin/taco-test sam.pack_other_ss - python $basedir/scripts/datastructure_tns.py -n $line -f ss01 --other -ss + python $basedir/scripts/formatting/datastructure_tns.py -n $line -f ss01 --other -ss fi cd $basedir/sam/sim pytest test/final-apps/test_$bench.py --ssname $line -s --report-stats --benchmark-json=$path/$line.json - python $basedir/scripts/converter.py --json_name $path/$line.json + python $basedir/scripts/util/converter.py --json_name $path/$line.json status=$? if [ $status -gt 0 ] @@ -106,7 +72,7 @@ for b in ${!BENCHMARKS[@]}; do cd $basedir done <$1 - python $basedir/scripts/bench_csv_aggregator.py $path $basedir/$benchout/suitesparse_$bench.csv + python $basedir/scripts/util/bench_csv_aggregator.py $path $basedir/$benchout/suitesparse_$bench.csv echo -e "${RED}Failed tests:" for i in ${!errors[@]}; do diff --git a/scripts/run_sam_sim/sam_suitesparse_runner_sddmmonly.sh b/scripts/run_sam_sim/sam_suitesparse_runner_sddmmonly.sh deleted file mode 100644 index 419e17dd..00000000 --- a/scripts/run_sam_sim/sam_suitesparse_runner_sddmmonly.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/bin/bash -#SBATCH -N 1 -#SBATCH --mem 120000 -#SBATCH -p lanka-v3 -#SBATCH --exclusive - -set -u - -BENCHMARKS=( - mat_sddmm_FINAL -) - -errors=() -RED='\033[0;31m' -NC='\033[0m' # No Color - -# LANKA -if [ $2 -eq 1 ]; then - export SUITESPARSE_PATH=/data/scratch/strange/tamu_sparse_unpacked - export FROSTT_PATH=/data/scratch/owhsu/datasets/frostt - export TACO_TENSOR_PATH=/data/scratch/owhsu/datasets - export SUITESPARSE_FORMATTED_PATH=/data/scratch/owhsu/datasets/suitesparse-formatted - export FROSTT_FORMATTED_TACO_PATH=/data/scratch/owhsu/datasets/frostt-formatted/taco-tensor - export FROSTT_FORMATTED_PATH=/data/scratch/owhsu/datasets/frostt-formatted - - mkdir -p $TACO_TENSOR_PATH - mkdir -p $SUITESPARSE_FORMATTED_PATH - mkdir -p $FROSTT_FORMATTED_TACO_PATH - mkdir -p $FROSTT_FORMATTED_PATH - - lanka=ON - neva=OFF -elif [ $2 -eq 2 ]; then - lanka=OFF - neva=ON -else - lanka=OFF - neva=OFF -fi - -format_outdir=${SUITESPARSE_FORMATTED_PATH} -basedir=$(pwd) -sspath=$SUITESPARSE_PATH -benchout=suitesparse-bench/sam - -__conda_setup="$('/data/scratch/owhsu/miniconda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" -if [ $? -eq 0 ]; then - eval "$__conda_setup" -else - if [ -f "/data/scratch/owhsu/miniconda/etc/profile.d/conda.sh" ]; then - . "/data/scratch/owhsu/miniconda/etc/profile.d/conda.sh" - else - export PATH="/data/scratch/owhsu/miniconda/bin:$PATH" - fi -fi -unset __conda_setup -conda activate aha - -mkdir -p "$benchout" -mkdir -p $format_outdir -mkdir -p $TACO_TENSOR_PATH/other-formatted-taco - -make -j8 taco/build NEVA=$neva LANKA=$lanka GEN=ON - -for b in ${!BENCHMARKS[@]}; do - bench=${BENCHMARKS[$b]} - path=$basedir/$benchout/$bench - mkdir -p $basedir/$benchout/$bench - echo "Testing $bench..." - - while read line; do -# cd $format_outdir - - if [ $2 -eq 1 ]; then - matrix="$sspath/$line/$line.mtx" - elif [ $2 -eq 2 ]; then - matrix="$sspath/$line.mtx" - else - matrix="$sspath/$line.mtx" - fi - -# if [ "$bench" == "mat_vecmul_FINAL" ]; then -# echo "Generating input format files for $line..." -# SUITESPARSE_TENSOR_PATH=$matrix python $basedir/scripts/datastructure_suitesparse.py -n $line --o -# -# SUITESPARSE_TENSOR_PATH=$matrix $basedir/compiler/taco/build/bin/taco-test sam.pack_other_ss -# python $basedir/scripts/datastructure_tns.py -n $line -f ss01 --other -ss -# fi - - cd $basedir/sam/sim - - pytest test/final-apps/test_$bench.py --ssname $line -s --benchmark-json=$path/$line.json - python $basedir/scripts/converter.py --json_name $path/$line.json - - status=$? - if [ $status -gt 0 ] - then - errors+=("${line}, ${bench}") - fi - - cd $basedir - done <$1 - - python $basedir/scripts/bench_csv_aggregator.py $path $basedir/$benchout/suitesparse_$bench.csv - - echo -e "${RED}Failed tests:" - for i in ${!errors[@]}; do - error=${errors[$i]} - echo -e "${RED}$error," - done - echo -e "${NC}" -done - diff --git a/scripts/run_sam_sim/suitesparse_validator.sh b/scripts/run_sam_sim/suitesparse_validator.sh index 8e554077..961dba79 100755 --- a/scripts/run_sam_sim/suitesparse_validator.sh +++ b/scripts/run_sam_sim/suitesparse_validator.sh @@ -3,6 +3,9 @@ #SBATCH --mem 120000 #SBATCH --exclusive +# ./scripts/run_sam_sim/suitesparse_validator.sh +# where out_path is optional + SAMNAME=( matmul_ikj vecmul_ij @@ -25,8 +28,13 @@ TACONAME=( set -u -sspath=/nobackup/owhsu/sparse-datasets/suitesparse -vout=/nobackup/owhsu/validate +sspath=$SUITESPARSE_PATH +if [ -z "$1" ] +then + vout=$basedir/validate/ +else + vout=$1 +fi mkdir -p "$vout" @@ -34,7 +42,7 @@ while read line; do matrix="$sspath/$line.mtx" # TACO - GEN=ON SUITESPARSE_TENSOR_PATH="$matrix" make -j8 validate-bench BENCHES="bench_suitesparse" VALIDATION_OUTPUT_PATH="$vout" NEVA=ON + GEN=ON SUITESPARSE_TENSOR_PATH="$matrix" make -j8 validate-bench BENCHES="bench_suitesparse" VALIDATION_OUTPUT_PATH="$vout" cd sam/sim # SAM diff --git a/scripts/stats/README.md b/scripts/stats/README.md new file mode 100644 index 00000000..dd1797d3 --- /dev/null +++ b/scripts/stats/README.md @@ -0,0 +1,8 @@ +# Statistics Scripts + +The `scripts/stats/` folder contains scripts used to get general sparse statistics about the datasets. This is useful for the designs + +1. `get_tensor_arrlen.py` - Script that gets the length of the datastructure arrays from the input datasets (to populate CSVs). +2. `suitesparse_stats.sh` - Script that calls `suitesparse_states.py` +3. `suitesparse_stats.py` - File that calcultes certain statistics (e.g size, + len, nnz) of the SuiteSparse data structure arrays (e.g. seg/crd) diff --git a/scripts/stats/get_tensor_arrlen.py b/scripts/stats/get_tensor_arrlen.py index 897738b2..0cc81fb9 100644 --- a/scripts/stats/get_tensor_arrlen.py +++ b/scripts/stats/get_tensor_arrlen.py @@ -1,8 +1,9 @@ +# python scripts/stats/get_tensor_arrlen.py + import argparse import os import csv - # This is using the old CSF file types def write_csv(path, outpath): with open(outpath, 'w+', newline='') as outcsv: diff --git a/scripts/stats/ss_stats.sh b/scripts/stats/ss_stats.sh deleted file mode 100755 index 6b8c3afe..00000000 --- a/scripts/stats/ss_stats.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -#SBATCH -N 1 -#SBATCH --exclusive -/home/owhsu/anaconda3/condabin/conda init bash -/home/owhsu/anaconda3/condabin/conda activate aha - -rm -rf /home/owhsu/aha/scadi_graph/scripts/logs - -python suitesparse_stats.py --overall -nstop 250 diff --git a/scripts/stats/suitesparse_stats.py b/scripts/stats/suitesparse_stats.py index 41947ade..bc4b49a0 100644 --- a/scripts/stats/suitesparse_stats.py +++ b/scripts/stats/suitesparse_stats.py @@ -8,7 +8,7 @@ from pathlib import Path -from util import TensorCollectionSuiteSparse, ScipyTensorShifter, \ +from sam.util import TensorCollectionSuiteSparse, ScipyTensorShifter, \ ScipyMatrixMarketTensorLoader, SuiteSparseTensor, safeCastPydataTensorToInts SS_PATH = os.getenv('SUITESPARSE_PATH') diff --git a/scripts/stats/suitesparse_stats.sh b/scripts/stats/suitesparse_stats.sh new file mode 100755 index 00000000..6b3760a0 --- /dev/null +++ b/scripts/stats/suitesparse_stats.sh @@ -0,0 +1,9 @@ +#!/bin/sh +#SBATCH -N 1 +#SBATCH --exclusive + +basedir=$(cwd) + +rm -rf $basedir/scripts/logs + +python suitesparse_stats.py --overall -nstop 250 diff --git a/scripts/tiling/README.md b/scripts/tiling/README.md new file mode 100644 index 00000000..47be7b1e --- /dev/null +++ b/scripts/tiling/README.md @@ -0,0 +1,33 @@ +# Tiling Scripts + +The `scripts/tiling/` folder contains scripts used to tile datasets and run tiling benchmarks. + +1. `advanced_simulator_runner.sh` - Script that formats, runs, and generates a + CSV for the tiled simulation (aka advanced simulator). +2. `clean_memory_model.sh` - Helper script to remove all generated files from + the tiled SAM flow +3. `ext_runner.sh` - Script that runs the Extensor configuration of for + inner-product matmul, used to recreate a graph in the ASPLOS 2023 SAM paper. +4. `few_points_memory_model_runner.sh` - Script that runs a restricted set of + experiments (8 points) from Figure 15 on pg. 12 of the SAM ASPLOS 2023 paper +(used in the ASPLOS 2023 artifact evaluation). +5. `full_ext_runner.sh` - Script that runs `ext_runner.sh` for all combinations + of NNZ and Dimension points. +6. `full_memory_model_runner.sh` - Script that runs the full set of experiments + to generate Figure 15 on pg. 12 of the SAM ASPLOS 2023 paper (used in the +ASPLOS 2023 artifact evaluation). +7. `generate_gold_matmul_tiled.py` - Script that generates the golden matmul + partial sums for each tile. +8. `generate_sparsity_sweep_mem_model.sh` - Script that generates pre-tiled + synthetic matrices. Used in the ASPLOS 2023 SAM artifact evaluation. +9. `prepare_files_no_gold.sh` - Script that runs `tile_ext.sh` for the extensor + configuration +10. `prepare_files.sh` - Script that runs `tile_ext.sh` and also prepares the + gold files using `generate_gold_matmul_tiled.py +11. `single_point_memory_model_runner.sh` - Script that runs a single point + from Figure 15 on pg. 12 of the SAM ASPLOS 2023 paper (Used in the ASPLOS +2023 artifact evaluation). +12. `tile_ext.sh` - Script that tiles the input matrices from a directory (like + extensor_mtx). +13. `tile.sh` - Script that tiles the input matrices from a tensor name (like + SuiteSparse matrices). diff --git a/scripts/tiling/advanced_simulator_runner.sh b/scripts/tiling/advanced_simulator_runner.sh index e7d772a0..2dd6edeb 100755 --- a/scripts/tiling/advanced_simulator_runner.sh +++ b/scripts/tiling/advanced_simulator_runner.sh @@ -4,10 +4,13 @@ #SBATCH -p lanka-v3 #SBATCH --exclusive +# ./scripts/tiling/advanced_simulator_runner.sh +# where machine is either 0(local), 1(Lanka), or 2(Kiwi/Neva/Lagos) + set -u BENCHMARKS=( -## mat_vecmul_FINAL +# mat_vecmul_FINAL # matmul_FINAL # mat_identity # mat_identity_back @@ -17,7 +20,7 @@ BENCHMARKS=( # matmul_ikj_glb_tile2 matmul_ikj_tile_pipeline_final # matmul_ikj_glb_tile_pipeline -# i matmul_ikj_glb_no_pipe +# matmul_ikj_glb_no_pipe # matmul_ikj_input_only # matmul_ikj_tiled_bcsstm02 # matmul_ikj_check @@ -36,64 +39,12 @@ NC='\033[0m' # No Color basedir=$(pwd) -# LANKA -if [ $2 -eq 1 ]; then - export SUITESPARSE_PATH=/data/scratch/changwan/florida_all - export FROSTT_PATH=/data/scratch/owhsu/datasets/frostt - export TACO_TENSOR_PATH=/data/scratch/owhsu/datasets - export SUITESPARSE_FORMATTED_PATH=/data/scratch/owhsu/datasets/suitesparse-formatted - export FROSTT_FORMATTED_TACO_PATH=/data/scratch/owhsu/datasets/frostt-formatted/taco-tensor - export FROSTT_FORMATTED_PATH=/data/scratch/owhsu/datasets/frostt-formatted - export SAM_HOME=$basedir - export TILED_SUITESPARSE_FORMATTED_PATH=${SAM_HOME}/tiles/matmul_ikj/formatted - export TILED_OUTPUT_PATH=${SAM_HOME}/tiles/matmul_ikj/output/ - - mkdir -p $TACO_TENSOR_PATH - mkdir -p $SUITESPARSE_FORMATTED_PATH - mkdir -p $FROSTT_FORMATTED_TACO_PATH - mkdir -p $FROSTT_FORMATTED_PATH - - lanka=ON - neva=OFF -elif [ $2 -eq 2 ]; then - export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse/ - export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt/ - export SUITESPARSE_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/suitesparse-formatted - export FROSTT_FORMATTED_TACO_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted/taco-tensor - export FROSTT_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted - export TACO_TENSOR_PATH=/nobackup/owhsu/sparse-datasets - export SAM_HOME=$basedir - export TILED_SUITESPARSE_FORMATTED_PATH=${SAM_HOME}/tiles/matmul_ikj/formatted - export TILED_OUTPUT_PATH=${SAM_HOME}/tiles/matmul_ikj/output/ - lanka=OFF - neva=ON -else - lanka=OFF - neva=OFF - export SAM_HOME=$basedir - export TILED_SUITESPARSE_FORMATTED_PATH=${SAM_HOME}/tiles/matmul_ikj/formatted - export TILED_OUTPUT_PATH=${SAM_HOME}/tiles/matmul_ikj/output/ -fi - sspath=$SUITESPARSE_PATH benchout=suitesparse-bench_simulator/sam format_outdir=${SUITESPARSE_FORMATTED_PATH} source $basedir/../venv/bin/activate -#__conda_setup="$('/data/scratch/owhsu/miniconda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" -#if [ $? -eq 0 ]; then -# eval "$__conda_setup" -#else -# if [ -f "/data/scratch/owhsu/miniconda/etc/profile.d/conda.sh" ]; then -# . "/data/scratch/owhsu/miniconda/etc/profile.d/conda.sh" -# else -# export PATH="/data/scratch/owhsu/miniconda/bin:$PATH" -# fi -#fi -#unset __conda_setup -#conda activate aha - mkdir -p "$benchout" mkdir -p $format_outdir mkdir -p $TACO_TENSOR_PATH/other-formatted-taco @@ -127,7 +78,7 @@ for b in ${!BENCHMARKS[@]}; do #python -m cProfile -o test/final-apps/test_$bench.py --ssname $line -s --benchmark-json=$path/$line.json pytest test/advanced-simulator/test_$bench.py --ssname $line -s --report-stats --check-gold --skip-empty --nbuffer --yaml_name=$3 --benchmark-json=$path/$line.json # pytest test/advanced-simulator/test_$bench.py --ssname $line -s --report-stats --back --depth=1 --debug-sim --check-gold --benchmark-json=$path/$line.json - # python $basedir/scripts/converter.py --json_name $path/$line.json + # python $basedir/scripts/util/converter.py --json_name $path/$line.json status=$? if [ $status -gt 0 ] @@ -138,7 +89,7 @@ for b in ${!BENCHMARKS[@]}; do cd $basedir done <$1 - python3 $basedir/scripts/bench_csv_aggregator.py $path $basedir/$benchout/suitesparse_$bench.csv + python $basedir/scripts/util/bench_csv_aggregator.py $path $basedir/$benchout/suitesparse_$bench.csv echo -e "${RED}Failed tests:" for i in ${!errors[@]}; do diff --git a/scripts/tiling/clean_memory_model.sh b/scripts/tiling/clean_memory_model.sh old mode 100644 new mode 100755 diff --git a/scripts/tiling/ext_runner.sh b/scripts/tiling/ext_runner.sh index 5ff01444..4965ace6 100755 --- a/scripts/tiling/ext_runner.sh +++ b/scripts/tiling/ext_runner.sh @@ -4,10 +4,13 @@ #SBATCH -p lanka-v3 #SBATCH --exclusive +# ./scripts/tiling/ext_runner.sh extensor__.mtx + +basedir=$(pwd) rm -rf $basedir/tiles/* -./scripts/tile_ext.sh $1 memory_config_extensor_17M_llb.yaml +./scripts/tiling/tile_ext.sh $1 memory_config_extensor_17M_llb.yaml -python scripts/generate_gold_matmul_tiled.py --yaml_name memory_config_extensor_17M_llb.yaml +python scripts/tiling/generate_gold_matmul_tiled.py --yaml_name memory_config_extensor_17M_llb.yaml -./scripts/advanced_simulator_runner.sh scripts/temp.txt 2 memory_config_extensor_17M_llb.yaml +./scripts/tiling/advanced_simulator_runner.sh scripts/temp.txt 2 memory_config_extensor_17M_llb.yaml diff --git a/scripts/tiling/few_points_memory_model_runner.sh b/scripts/tiling/few_points_memory_model_runner.sh index 79811385..02ba18e3 100755 --- a/scripts/tiling/few_points_memory_model_runner.sh +++ b/scripts/tiling/few_points_memory_model_runner.sh @@ -4,6 +4,9 @@ #SBATCH -p lanka-v3 #SBATCH --exclusive +# ./few_points_memory_model_runner.sh +# where gold is 0(no gold check) or 1(with gold check) + SECONDS=0 set -u @@ -49,9 +52,9 @@ for b in ${!BENCHMARKS[@]}; do for nnz in ${!NNZ[@]}; do for dim in ${!DIMENSIONS[@]}; do if [ $2 -eq 0 ]; then - ./scripts/prepare_files_no_gold.sh extensor_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.mtx + ./scripts/tiling/prepare_files_no_gold.sh extensor_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.mtx elif [ $2 -eq 1 ]; then - ./scripts/prepare_files.sh extensor_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.mtx + ./scripts/tiling/prepare_files.sh extensor_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.mtx fi bench=${BENCHMARKS[$b]} path=$basedir/$benchout @@ -65,7 +68,7 @@ for b in ${!BENCHMARKS[@]}; do else pytest test/advanced-simulator/test_$bench.py --ssname $line -s --skip-empty --nbuffer --yaml_name=$1 --nnz-value=${NNZ[$nnz]} --benchmark-json=$path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json fi - python $basedir/scripts/converter.py --json_name $path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json + python $basedir/scripts/util/converter.py --json_name $path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json status=$? if [ $status -gt 0 ] @@ -75,7 +78,7 @@ for b in ${!BENCHMARKS[@]}; do cd $basedir done done - python3 $basedir/scripts/bench_csv_aggregator.py $path $basedir/$benchout/$bench.csv + python3 $basedir/scripts/util/bench_csv_aggregator.py $path $basedir/$benchout/$bench.csv echo -e "${RED}Failed tests:" for i in ${!errors[@]}; do diff --git a/scripts/tiling/full_ext_runner.sh b/scripts/tiling/full_ext_runner.sh index aca5dd2e..411b2ecd 100755 --- a/scripts/tiling/full_ext_runner.sh +++ b/scripts/tiling/full_ext_runner.sh @@ -3,7 +3,8 @@ #SBATCH --mem 120000 #SBATCH -p lanka-v3 #SBATCH --exclusive -#SBATCH --mail-user=oliviahsu1107@gmail.com + +# ./scripts/tiling/full_ext_runner.sh NNZ=( 5000 @@ -27,6 +28,6 @@ DIMENSIONS=( for nnz in ${!NNZ[@]}; do for dim in ${!DIMENSIONS[@]}; do filename=${NNZ[$nnz]}_${DIMENSIONS[$dim]} - ./scripts/ext_runner.sh extensor_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.mtx + ./scripts/tiling/ext_runner.sh extensor_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.mtx done done diff --git a/scripts/tiling/full_memory_model_runner.sh b/scripts/tiling/full_memory_model_runner.sh index 447b7bc4..190239df 100755 --- a/scripts/tiling/full_memory_model_runner.sh +++ b/scripts/tiling/full_memory_model_runner.sh @@ -3,6 +3,10 @@ #SBATCH --mem 120000 #SBATCH -p lanka-v3 #SBATCH --exclusive + +# full_memory_model_runner.sh +# where gold is 0 (no gold check) or 1 (with gold check) + SECONDS=0 set -u @@ -49,9 +53,9 @@ for b in ${!BENCHMARKS[@]}; do for nnz in ${!NNZ[@]}; do for dim in ${!DIMENSIONS[@]}; do if [ $2 -eq 1 ]; then - ./scripts/prepare_files.sh extensor_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.mtx + ./scripts/tiling/prepare_files.sh extensor_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.mtx elif [ $2 -eq 0 ]; then - ./scripts/prepare_files_no_gold.sh extensor_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.mtx + ./scripts/tiling/prepare_files_no_gold.sh extensor_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.mtx fi bench=${BENCHMARKS[$b]} path=$basedir/$benchout @@ -65,7 +69,7 @@ for b in ${!BENCHMARKS[@]}; do else pytest test/advanced-simulator/test_$bench.py --ssname $line -s --skip-empty --nbuffer --yaml_name=$1 --nnz-value=${NNZ[$nnz]} --benchmark-json=$path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json fi - python $basedir/scripts/converter.py --json_name $path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json + python $basedir/scripts/util/converter.py --json_name $path/${line}_${NNZ[$nnz]}_${DIMENSIONS[$dim]}.json status=$? if [ $status -gt 0 ] @@ -75,7 +79,7 @@ for b in ${!BENCHMARKS[@]}; do cd $basedir done done - python3 $basedir/scripts/bench_csv_aggregator.py $path $basedir/$benchout/$bench.csv + python3 $basedir/scripts/util/bench_csv_aggregator.py $path $basedir/$benchout/$bench.csv echo -e "${RED}Failed tests:" for i in ${!errors[@]}; do diff --git a/scripts/tiling/generate_gold_matmul_tiled.py b/scripts/tiling/generate_gold_matmul_tiled.py index 64ff4946..55be3674 100644 --- a/scripts/tiling/generate_gold_matmul_tiled.py +++ b/scripts/tiling/generate_gold_matmul_tiled.py @@ -9,18 +9,7 @@ import argparse from pathlib import Path - - -# FIXME: (owhsu) this should be imported from util -def round_sparse(x): - if 0.0 <= x < 1: - return 1 - elif 0.0 > x > -1: - return -1 - elif x >= 0.0: - return math.floor(x + 0.5) - else: - return math.ceil(x - 0.5) +from scripts.util.util import round_sparse def generate_gold_matmul_tiled(tile_crd_b, tile_crd_c, dirname, out_format="ss01"): diff --git a/scripts/tiling/generate_sparsity_sweep_mem_model.sh b/scripts/tiling/generate_sparsity_sweep_mem_model.sh index 4ac85ed3..35bb6d8a 100755 --- a/scripts/tiling/generate_sparsity_sweep_mem_model.sh +++ b/scripts/tiling/generate_sparsity_sweep_mem_model.sh @@ -1,3 +1,5 @@ +# ./scripts/tiling/generate_sparsity_sweep_mem_model.sh + SECONDS=0 mkdir extensor_mtx diff --git a/scripts/tiling/prepare_files.sh b/scripts/tiling/prepare_files.sh index bed6796c..5aece84f 100755 --- a/scripts/tiling/prepare_files.sh +++ b/scripts/tiling/prepare_files.sh @@ -3,12 +3,13 @@ #SBATCH --mem 120000 #SBATCH -p lanka-v3 #SBATCH --exclusive -#SBATCH --mail-user=oliviahsu1107@gmail.com + +# ./scripts/tiling/prepare_files.sh extensor__.mtx basedir=$(pwd) rm -rf $basedir/tiles/* -./scripts/tile_ext.sh $1 memory_config_extensor_17M_llb.yaml +./scripts/tiling/tile_ext.sh $1 memory_config_extensor_17M_llb.yaml -python scripts/generate_gold_matmul_tiled.py --yaml_name memory_config_extensor_17M_llb.yaml +python scripts/tiling/generate_gold_matmul_tiled.py --yaml_name memory_config_extensor_17M_llb.yaml diff --git a/scripts/tiling/prepare_files_no_gold.sh b/scripts/tiling/prepare_files_no_gold.sh index 13e3de8c..719d668c 100755 --- a/scripts/tiling/prepare_files_no_gold.sh +++ b/scripts/tiling/prepare_files_no_gold.sh @@ -3,8 +3,10 @@ #SBATCH --mem 120000 #SBATCH -p lanka-v3 #SBATCH --exclusive -#SBATCH --mail-user=oliviahsu1107@gmail.com +# ./scripts/tiling/prepare_files_no_gold.sh extensor__.mtx + +basedir=$(pwd) rm -rf $basedir/tiles/* -./scripts/tile_ext.sh $1 memory_config_extensor_17M_llb.yaml +$basedir/scripts/tiling/tile_ext.sh $1 memory_config_extensor_17M_llb.yaml diff --git a/scripts/tiling/single_point_memory_model_runner.sh b/scripts/tiling/single_point_memory_model_runner.sh index e666769d..a21b2d30 100755 --- a/scripts/tiling/single_point_memory_model_runner.sh +++ b/scripts/tiling/single_point_memory_model_runner.sh @@ -4,6 +4,8 @@ #SBATCH -p lanka-v3 #SBATCH --exclusive +# ./scripts/tiling/single_point_memory_model_runner.sh extensor__.mtx + benchout=memory_model_out basedir=$(pwd) @@ -31,13 +33,13 @@ mkdir -p $path mkdir -p $basedir/tiles/ rm -rf $basedir/tiles/* -./scripts/prepare_files.sh $fname +./scripts/tiling/prepare_files.sh $fname cd $basedir/sam/sim pytest test/advanced-simulator/test_$bench.py --ssname $line -s --check-gold --skip-empty --nbuffer --yaml_name=$yaml_fname --nnz-value=$nnz --benchmark-json=$path/${line}_${nnz}_${dim}.json -python $basedir/scripts/converter.py --json_name $path/${line}_${nnz}_${dim}.json +python $basedir/scripts/util/converter.py --json_name $path/${line}_${nnz}_${dim}.json -python3 $basedir/scripts/bench_csv_aggregator.py $path $basedir/$benchout/$bench.csv +python3 $basedir/scripts/util/bench_csv_aggregator.py $path $basedir/$benchout/$bench.csv popd diff --git a/scripts/tiling/tile.sh b/scripts/tiling/tile.sh index 8b735289..9f71c94a 100755 --- a/scripts/tiling/tile.sh +++ b/scripts/tiling/tile.sh @@ -1,5 +1,7 @@ #!/bin/bash +# ./scripts/tiling/tile.sh + BENCHMARKS=( matmul_ikj ) @@ -22,7 +24,7 @@ for b in ${!BENCHMARKS[@]}; do python $basedir/sam/sim/src/tiling/tile.py --input_tensor $line --cotile $bench --multilevel --hw_config $basedir/sam/sim/src/tiling/$2 echo "Generating input format files for $line..." - python $basedir/scripts/datastructure_suitesparse.py -n $line -hw -b $bench --input $basedir/tiles/$bench/mtx/ --output_dir_path $basedir/tiles/$bench/formatted --tiles + python $basedir/scripts/formatting/datastructure_suitesparse.py -n $line -hw -b $bench --input $basedir/tiles/$bench/mtx/ --output_dir_path $basedir/tiles/$bench/formatted --tiles done <$1 done diff --git a/scripts/tiling/tile_ext.sh b/scripts/tiling/tile_ext.sh index 2c8a54e3..4548f466 100755 --- a/scripts/tiling/tile_ext.sh +++ b/scripts/tiling/tile_ext.sh @@ -1,17 +1,19 @@ #!/bin/bash +# THIS FILE MUST BE RUN FROM sam/ location +# ./scripts/tiling/tile_ext.sh + BENCHMARKS=( matmul_ikj ) -# THIS FILE MUST BE RUN FROM sam/ location sspath=$SUITESPARSE_PATH basedir=$(pwd) -ext_path=$basedir/extensor_mtx/$1 +tiles_path=$basedir/extensor_mtx/$1 -echo "$ext_path" +echo "$tiles_path" for b in ${!BENCHMARKS[@]}; do bench=${BENCHMARKS[$b]} @@ -22,10 +24,10 @@ for b in ${!BENCHMARKS[@]}; do rm -rf $basedir/tiles/* echo "Tiling mtx file" - python $basedir/sam/sim/src/tiling/tile.py --extensor --input_path $ext_path --cotile $bench --multilevel --hw_config $basedir/sam/sim/src/tiling/$2 + python $basedir/sam/sim/src/tiling/tile.py --extensor --input_path $tiles_path --cotile $bench --multilevel --hw_config $basedir/sam/sim/src/tiling/$2 - echo "Generating input format files for $ext_path..." - python $basedir/scripts/datastructure_suitesparse.py -n temp -hw -b $bench --input $basedir/tiles/$bench/mtx/ --output_dir_path $basedir/tiles/$bench/formatted --tiles + echo "Generating input format files for $tiles_path..." + python $basedir/scripts/formatting/datastructure_suitesparse.py -n temp -hw -b $bench --input $basedir/tiles/$bench/mtx/ --output_dir_path $basedir/tiles/$bench/formatted --tiles done diff --git a/scripts/util/README.md b/scripts/util/README.md index cbad7835..21f3936f 100644 --- a/scripts/util/README.md +++ b/scripts/util/README.md @@ -3,7 +3,7 @@ The `scripts/util` folder contains util.py (shared utility functions) and shared utility scripts used to aggregate and format csv data. -1. `util.py` - +1. `util.py` - List of python util code needed by the Python scripts under `sam/scripts` 2. `bench_csv_aggregator.py` - Script that aggregates all of the output CSVs. This is useful since CPU tests are run using googlebench potentially one tensor at a time (to run tests in parallel), which will produce one CSV per tensor. diff --git a/scripts/util/__init__.py b/scripts/util/__init__.py new file mode 100644 index 00000000..e69de29b From 9dae11474ae564b3a1cbfa23a7b4e8c796b9f5c1 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Mon, 17 Jul 2023 16:49:48 -0700 Subject: [PATCH 32/76] Fix pycodestyle --- scripts/stats/get_tensor_arrlen.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/stats/get_tensor_arrlen.py b/scripts/stats/get_tensor_arrlen.py index 0cc81fb9..0d2df62d 100644 --- a/scripts/stats/get_tensor_arrlen.py +++ b/scripts/stats/get_tensor_arrlen.py @@ -4,6 +4,7 @@ import os import csv + # This is using the old CSF file types def write_csv(path, outpath): with open(outpath, 'w+', newline='') as outcsv: From 95562954d327b44ed6b90978ecf4c03de1eebf7b Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Wed, 19 Jul 2023 10:34:16 -0700 Subject: [PATCH 33/76] tiling for apps --- sam/sim/src/tiling/tile.py | 29 ++++++++++++++++++---- scripts/prepare_files.sh | 2 +- scripts/suitesparse_memory_model_runner.sh | 16 ++++++++---- scripts/tile_ext.sh | 9 ++++--- setup_tiling_mat.py | 25 +++++++++++++++++++ 5 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 setup_tiling_mat.py diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 79d773d5..7674afeb 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -6,15 +6,24 @@ import yaml import copy import pickle +import random from itertools import compress from pathlib import Path + +import sys +custom_path = '/home/avb03/sam' +sys.path.append(custom_path) + from sam.util import SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter from sam.sim.src.tiling.process_expr import parse_all, update_dict SAM_STRS = {"matmul_kij": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)", "matmul_ikj": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss -s=reorder(i,k,j)", - "matmul_ijk": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)"} + "matmul_ijk": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", + "mat_elemadd": "X(i,j)=B(i,j)+C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", + "mat_elemmul": "X(i,j)=B(i,j)*C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", + "mat_mattransmul": "X(i,j)=B(i,j)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss -f=d:ss -s=reorder(i,j,k)"} def print_dict(dd): for k, v in dd.items(): @@ -186,8 +195,17 @@ def get_other_tensors(app_str, tensor): elif "mat_sddmm" in app_str: pass - elif "mat_mattransmul" in app_str or "mat_residual" in app_str: - pass + elif "mat_mattransmul" in app_str: + print("Writing other tensors...") + rows, cols = tensor.shape # i,j + tensor_c = scipy.sparse.random(cols, 1) + tensor_d = scipy.sparse.random(rows, 1) + + tensors.append(tensor_c) + tensors.append(tensor_d) + + elif "mat_residual" in app_str: + pass elif "mat_vecmul" in app_str: pass else: @@ -202,6 +220,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): tensors = get_other_tensors(app_str, tensors[0]) names, format_permutations, ivars = parse_sam_input(args.cotile) + print(ivars) sizes_dict = {} for i, name in enumerate(names): @@ -275,8 +294,8 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): if __name__ == "__main__": parser = argparse.ArgumentParser(description='Tile matrices') parser.add_argument("--input_tensor", type=str, default=None) - parser.add_argument("--gen_tensor", action="store_true") - parser.add_argument("--cotile", type=str, default=None, description="Name of kernel if it needs to be cotiled") + parser.add_argument("--gen_tensor", action="store_false") + parser.add_argument("--cotile", type=str, default=None) parser.add_argument("--output_dir_path", type=str, default="./tiles") parser.add_argument("--hw_config", type=str, default=None) parser.add_argument("--multilevel", action="store_true") diff --git a/scripts/prepare_files.sh b/scripts/prepare_files.sh index f14f0380..4e3c82ed 100755 --- a/scripts/prepare_files.sh +++ b/scripts/prepare_files.sh @@ -11,4 +11,4 @@ rm -rf $basedir/tiles/* ./scripts/tile_ext.sh $1 $2 -python scripts/generate_gold_matmul_tiled.py --yaml_name $2 +python3 scripts/generate_gold_matmul_tiled.py --yaml_name $2 diff --git a/scripts/suitesparse_memory_model_runner.sh b/scripts/suitesparse_memory_model_runner.sh index 0e9c2dd0..ccea10e6 100755 --- a/scripts/suitesparse_memory_model_runner.sh +++ b/scripts/suitesparse_memory_model_runner.sh @@ -7,17 +7,22 @@ benchout=memory_model_out basedir=$(pwd) -bench=matmul_ikj_tile_pipeline_final +# bench=matmul_ijk_tile_pipeline_final yaml_fname=memory_config_onyx.yaml path=$basedir/$benchout fname=$1 +appname=$2 + echo "Running for suitesparse $fname" export SAM_HOME=$basedir -export TILED_SUITESPARSE_FORMATTED_PATH=${SAM_HOME}/tiles/matmul_ikj/formatted -export TILED_OUTPUT_PATH=${SAM_HOME}/tiles/matmul_ikj/output/ +# export TILED_SUITESPARSE_FORMATTED_PATH=${SAM_HOME}/tiles/matmul_ijk/formatted +# export TILED_OUTPUT_PATH=${SAM_HOME}/tiles/matmul_ijk/output/ + +export TILED_SUITESPARSE_FORMATTED_PATH=${SAM_HOME}/tiles/${appname}/formatted +export TILED_OUTPUT_PATH=${SAM_HOME}/tiles/${appname}/output/ pushd . @@ -29,9 +34,10 @@ rm -rf $basedir/tiles/* ./scripts/prepare_files.sh $fname.mtx $yaml_fname cd $basedir/sam/sim -pytest test/advanced-simulator/test_$bench.py --ssname $fname -s --check-gold --skip-empty --nbuffer --yaml_name=$yaml_fname --benchmark-json=$path/mem_model_$fname.json +# python3 -m pytest test/advanced-simulator/test_$bench.py --ssname $fname -s --check-gold --skip-empty --nbuffer --yaml_name=$yaml_fname --benchmark-json=$path/mem_model_$fname.json +# pytest test/advanced-simulator/test_$bench.py --ssname $fname -s --check-gold --skip-empty --nbuffer --yaml_name=$yaml_fname --benchmark-json=$path/mem_model_$fname.json -python $basedir/scripts/converter.py --json_name $path/mem_model_$fname.json +# python3 $basedir/scripts/converter.py --json_name $path/mem_model_$fname.json python3 $basedir/scripts/bench_csv_aggregator.py $path $basedir/$benchout/$bench.csv diff --git a/scripts/tile_ext.sh b/scripts/tile_ext.sh index 2c8a54e3..46c56e70 100755 --- a/scripts/tile_ext.sh +++ b/scripts/tile_ext.sh @@ -1,7 +1,10 @@ #!/bin/bash BENCHMARKS=( - matmul_ikj +# matmul_ijk +# mat_elemadd + # mat_elemmul + mat_mattransmul ) # THIS FILE MUST BE RUN FROM sam/ location @@ -22,10 +25,10 @@ for b in ${!BENCHMARKS[@]}; do rm -rf $basedir/tiles/* echo "Tiling mtx file" - python $basedir/sam/sim/src/tiling/tile.py --extensor --input_path $ext_path --cotile $bench --multilevel --hw_config $basedir/sam/sim/src/tiling/$2 + python3 $basedir/sam/sim/src/tiling/tile.py --extensor --input_path $ext_path --cotile $bench --multilevel --hw_config $basedir/sam/sim/src/tiling/$2 echo "Generating input format files for $ext_path..." - python $basedir/scripts/datastructure_suitesparse.py -n temp -hw -b $bench --input $basedir/tiles/$bench/mtx/ --output_dir_path $basedir/tiles/$bench/formatted --tiles + python3 $basedir/scripts/datastructure_suitesparse.py -n temp -hw -b $bench --input $basedir/tiles/$bench/mtx/ --output_dir_path $basedir/tiles/$bench/formatted --tiles done diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py new file mode 100644 index 00000000..580dedcf --- /dev/null +++ b/setup_tiling_mat.py @@ -0,0 +1,25 @@ +import subprocess +import glob +import shutil +import os + +data = ['rel5'] +# app_name = "mat_elemadd" +app_name = "mat_elemmul" +# data_file = open("scripts/tensor_names/suitesparse_valid_mid50.txt") +# data_file_lines = data_file.readlines() +# for line in data_file_lines: +# data.append(line[:-1]) + +for datum in data: + mtx_file = glob.glob(f"/nobackup/owhsu/sparse-datasets/suitesparse/{datum}.mtx")[0] + shutil.copy(mtx_file,f"extensor_mtx/{datum}.mtx") + + command = f"./scripts/suitesparse_memory_model_runner.sh {datum} {app_name}" + os.system(command) + + copy_rename = f"cp -r tiles/{app_name} tiles_compiled/{app_name}_{datum}" + os.system(copy_rename) + + docker_copy_command = f"docker cp tiles_compiled/{app_name}_{datum} avb03-sparse-tiling:/aha/garnet/tiles_{app_name}_{datum}" + os.system(docker_copy_command) \ No newline at end of file From 3074adeaba1aab09f237e278fdb22af3f114ae82 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Wed, 19 Jul 2023 16:31:51 -0700 Subject: [PATCH 34/76] mat_mattransmul prob --- sam/sim/src/tiling/tile.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 7674afeb..942035b2 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -23,12 +23,17 @@ "matmul_ijk": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemadd": "X(i,j)=B(i,j)+C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemmul": "X(i,j)=B(i,j)*C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", - "mat_mattransmul": "X(i,j)=B(i,j)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss -f=d:ss -s=reorder(i,j,k)"} + "mat_mattransmul": "X(i,j)=B(j,i)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss:0 -f=d:ss:0 -s=reorder(i,j)"} def print_dict(dd): for k, v in dd.items(): print(k, ":", v) +def print_ast(node): + for child in ast.iter_child_nodes(node): + print_ast(child) + print(node) + def get_ivars(names, expr): [lhs, rhs] = expr.split("=") @@ -95,7 +100,12 @@ def tile_coo(tensor, ivar_map, split_map, new_ivar_order=None): tile_sizes = dict() order = len(tensor.shape) - tensor_points = tensor.todok() + tensor_coo = scipy.sparse.coo_matrix(tensor) + tensor_points = tensor_coo.todok() + + print("ivar_map: ", ivar_map) + print("split_map: ", split_map) + print("order = ", order) new_shape = [] for lvl in range(order): @@ -158,10 +168,15 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map): tensor_format = permutation_strs[i] ivar_map = dict() order = len(tensor.shape) + print("order is ", order) for dim in range(order): + print("tensor format: ", tensor_format) + print("dim is ", dim) + print("tensor_format[dim:dim+1] is ", tensor_format[dim:dim+1]) lvl_permutation = tensor_format[dim:dim + 1][0] ivar = ivar_strs[i][dim] ivar_map[lvl_permutation] = ivar + print("ivar_map is ", ivar_map) tiles, tile_sizes = tile_coo(tensor, ivar_map, split_map) tiled_tensors[tensor_name] = tiles @@ -198,8 +213,8 @@ def get_other_tensors(app_str, tensor): elif "mat_mattransmul" in app_str: print("Writing other tensors...") rows, cols = tensor.shape # i,j - tensor_c = scipy.sparse.random(cols, 1) - tensor_d = scipy.sparse.random(rows, 1) + tensor_c = scipy.sparse.random(cols, 1).toarray().flatten() + tensor_d = scipy.sparse.random(rows, 1).toarray().flatten() tensors.append(tensor_c) tensors.append(tensor_d) @@ -220,8 +235,8 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): tensors = get_other_tensors(app_str, tensors[0]) names, format_permutations, ivars = parse_sam_input(args.cotile) - print(ivars) + import pdb; pdb.set_trace(); sizes_dict = {} for i, name in enumerate(names): tensor = tensors[i] @@ -257,6 +272,8 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): if cotiled is None: # First iteration of tiling + print("tensor shapes: ", tensors[0].shape, " ", tensors[1].shape, " ", tensors[2].shape) + print("format_permutations: ", format_permutations) cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map) else: # recursively tile the blocks From 5df6eacaebb0589b12f9d713890149ab93f6a145 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Wed, 19 Jul 2023 16:36:50 -0700 Subject: [PATCH 35/76] setup script added --- setup_tiling_mat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py index 580dedcf..4d156366 100644 --- a/setup_tiling_mat.py +++ b/setup_tiling_mat.py @@ -5,7 +5,7 @@ data = ['rel5'] # app_name = "mat_elemadd" -app_name = "mat_elemmul" +app_name = "mat_mattransmul" # data_file = open("scripts/tensor_names/suitesparse_valid_mid50.txt") # data_file_lines = data_file.readlines() # for line in data_file_lines: From ceb4ff17b6a44ece7c16ed707a3c7a2d5b12d49b Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Wed, 26 Jul 2023 17:29:33 -0700 Subject: [PATCH 36/76] Add in tiling script to tile tensors for mattransmul. Frostt tensors are IP --- sam/sim/src/tiling/tile.py | 182 ++++++++++++++++++++++++++++++------- sam/util.py | 31 ++++--- scripts/tile_ext.sh | 2 +- setup_tiling_mat.py | 8 +- 4 files changed, 173 insertions(+), 50 deletions(-) diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 942035b2..462da75d 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -7,6 +7,7 @@ import copy import pickle import random +import sparse from itertools import compress from pathlib import Path @@ -15,7 +16,7 @@ custom_path = '/home/avb03/sam' sys.path.append(custom_path) -from sam.util import SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter +from sam.util import SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter, PydataSparseTensorDumper, SUITESPARSE_PATH, FROSTT_PATH from sam.sim.src.tiling.process_expr import parse_all, update_dict SAM_STRS = {"matmul_kij": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)", @@ -88,6 +89,72 @@ def parse_sam_input(string): ivars = [ivars[tensor] for tensor in tensors] return tensors, permutations, ivars +# Outputs Pydata/sparse tensor tiles, given a pydata/sparse tensor (DOK or COO) +# ASSUME: tensor is a scipy.sparse.coo_matrix +# TODO: new_ivar_order right now is assumed to be one fixed order +# In the future, will have to take into acocunt all reorderings +def tile_tensor(tensor, ivar_map, split_map, new_ivar_order=None): + human_readable = False + + tiles = dict() + tile_sizes = dict() + order = len(tensor.shape) + + tensor_coo = sparse.COO(tensor) + tensor_points = sparse.DOK.from_coo(tensor_coo) + + print("ivar_map: ", ivar_map) + print("split_map: ", split_map) + print("order = ", order) + + new_shape = [] + for lvl in range(order): + ivar = ivar_map[lvl] + sf = split_map[ivar] + new_shape.append(sf) + + for crds, val in tensor_points.data.items(): + point = list(crds) + + new_point = [] + tile_id = [] + for lvl in range(order): + ivar = ivar_map[lvl] + sf = split_map[ivar] + + new_point.append(point[lvl] % sf) + tile_id.append(int(point[lvl] / sf)) + + # Add in value to the new_point as well + new_point.append(val) + tile_id = tuple(tile_id) + + if tile_id in tiles: + tiles[tile_id].append(new_point) + else: + tiles[tile_id] = [new_point] + + # sort the new coo lists + for key, val in tiles.items(): + if human_readable: + dok = sorted(val) + else: + dok = sparse.DOK(tuple(new_shape)) + for point in val: + dok[tuple(point[0:-1])] = point[-1] + + tiles[key] = dok + + for tile_id, tile_dok in tiles.items(): + tile = tile_dok.to_coo() + # FIXME: This size number isn't correct for tensor tiles + nonempty_rows = tile.nnz + nonempty_row_ind = np.where(nonempty_rows > 0)[0] + tile_sizes[tile_id] = tile.nnz * 2 + 2 * len(nonempty_row_ind) + 3 + + return tiles, tile_sizes + + # Outputs COO tiles, given a COO tensor # ASSUME: tensor is a scipy.sparse.coo_matrix @@ -159,7 +226,7 @@ def tile_coo(tensor, ivar_map, split_map, new_ivar_order=None): # permutation_strs: list of permutation_strs [ss01, ss10] following tensor_names (from SAM) # ivar_strs: list of ivar_strs ["ik", "kj"] following tensor_names (from SAM) # split_map: dictionary of split factors (from hardware) -def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map): +def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map, higher_order=False): tiled_tensors = dict() tiled_tensor_sizes = dict() @@ -178,7 +245,11 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map): ivar_map[lvl_permutation] = ivar print("ivar_map is ", ivar_map) - tiles, tile_sizes = tile_coo(tensor, ivar_map, split_map) + if higher_order: + tiles, tile_sizes = tile_tensor(tensor, ivar_map, split_map) + else: + tiles, tile_sizes = tile_coo(tensor, ivar_map, split_map) + tiled_tensors[tensor_name] = tiles tiled_tensor_sizes[tensor_name] = tile_sizes @@ -231,7 +302,7 @@ def get_other_tensors(app_str, tensor): return tensors -def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): +def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, higher_order=False): tensors = get_other_tensors(app_str, tensors[0]) names, format_permutations, ivars = parse_sam_input(args.cotile) @@ -274,7 +345,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): # First iteration of tiling print("tensor shapes: ", tensors[0].shape, " ", tensors[1].shape, " ", tensors[2].shape) print("format_permutations: ", format_permutations) - cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map) + cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map, higher_order) else: # recursively tile the blocks new_cotiled = {} @@ -284,9 +355,13 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): new_cotiled[name] = {} new_cotiled_sizes[name] = {} for tile_id, tile in cotiled[name].items(): - new_cotiled_temp, new_cotiled_sizes_temp = cotile_coo(name, [tile.tocoo()], + if higher_order: + tile_in_coo = tile.to_coo() + else: + tile_in_coo = tile.tocoo() + new_cotiled_temp, new_cotiled_sizes_temp = cotile_coo(name, [tile_in_coo], [format_permutations[i]], [ivars[i]], - split_map) + split_map, higher_order) for kk, vv in copy.deepcopy(new_cotiled_temp)[name].items(): new_tile_id = tuple(list(tile_id) + list(kk)) @@ -309,31 +384,66 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): inputCache = InputCacheSuiteSparse() if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Tile matrices') - parser.add_argument("--input_tensor", type=str, default=None) - parser.add_argument("--gen_tensor", action="store_false") - parser.add_argument("--cotile", type=str, default=None) - parser.add_argument("--output_dir_path", type=str, default="./tiles") - parser.add_argument("--hw_config", type=str, default=None) - parser.add_argument("--multilevel", action="store_true") - parser.add_argument("--input_path", type=str, default=None) - parser.add_argument("--extensor", action="store_true") + parser = argparse.ArgumentParser(description='script that tiles tensors') + parser.add_argument("--tensor_type", choices=['ex', 'gen', 'file', 'ss', 'frostt'], help='The \ + tiles, tile_sizes = tile_coo(tensor, ivar_map, split_map) \ + type of tensor to tile: extensor(ex), generated (gen), \ + SuiteSparse (ss), FROSTT (frostt), or input file (file)') + parser.add_argument("--higher_order", action="store_true", help="If \ + true then we want to process a higher-order tensor. With higher-order set to true, if \ + 'tensor_type' is: \ + \n 'gen' then a 3-tensor is generated instead of matrix. \ + \n 'file' then a .tns file is read instead of a .mtx file. \ + \n 'ss' then other matrices used with SuiteSparse are .tns instead of .mtx files. \ + \n 'frostt' should always have 'higher_order' set as true.") + + parser.add_argument("--input_tensor", type=str, default=None, + help="Input tensor NAME if tensor_type is set to 'file'. \ + This is for use with SuiteSparse or FROSTT") + parser.add_argument("--input_path", type=str, default=None, help="Input tensor path") + parser.add_argument("--output_dir_path", type=str, default="./tiles", + help='Output path, directory where tiles get written to') + parser.add_argument("--hw_config", type=str, default=None, + help='Path to the hardware config yaml') + + parser.add_argument("--cotile", type=str, default=None, help='If \ + this is true cotile multiple tensors, else tile one tensor only') + parser.add_argument("--multilevel", action="store_true", help='If \ + multilevel is true there will exist more than one level of tiles, \ + else only tile once') + parser.add_argument("--seed", type=int, default=0, help="Random seed") args = parser.parse_args() + random.seed(args.seed) + np.random.seed(args.seed) + tensor = None cwd = os.getcwd() - if args.gen_tensor: - tensor = scipy.sparse.random(16, 16) - elif args.extensor: + if args.tensor_type == "gen": + if args.higher_order: + tensor = sparse.COO(sparse.random((16, 16, 16))) + else: + tensor = scipy.sparse.random(16, 16) + elif args.tensor_type == "ex": tensor = scipy.io.mmread(args.input_path) + elif args.tensor_type == "ss": + assert args.input_tensor is not None + tensor_path = os.path.join(SUITESPARSE_PATH, args.input_tensor + ".mtx") + ss_tensor = SuiteSparseTensor(tensor_path) + tensor = inputCache.load(ss_tensor, False) + elif args.tensor_type == "frostt": + assert args.input_tensor is not None + assert args.higher_order + + tensor_path = os.path.join(FROSTT_PATH, args.input_tensor + ".tns") + + # FIXME: This is broken + frostt_tensor = FrosttTensor(tensor_path) + tensor = inputCache.load(ss_tensor, False) + else: - assert args.input_tensor is not None - SS_PATH = os.getenv('SUITESPARSE_PATH', default=os.path.join(cwd, 'suitesparse')) - # print("PATH:", SS_PATH) - tensor_path = os.path.join(SS_PATH, args.input_tensor + ".mtx") - ss_tensor = SuiteSparseTensor(tensor_path) - tensor = inputCache.load(ss_tensor, False) + raise ValueError("This choice of 'tensor_type' is unreachable") split_map = {"i": 16, "j": 16, "k": 16} @@ -345,7 +455,6 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): print("TILES:") print_dict(tiles) else: - output_mtx_name = os.path.join(args.output_dir_path, args.cotile, "mtx") output_mtx_path = Path(output_mtx_name) output_mtx_path.mkdir(parents=True, exist_ok=True) @@ -354,21 +463,30 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): if args.multilevel: assert args.cotile is not None cotiled_tensors = cotile_multilevel_coo(args.cotile, args.hw_config, [tensor], - os.path.join(args.output_dir_path, args.cotile)) + os.path.join(args.output_dir_path, + args.cotile), + args.higher_order) elif args.cotile is not None: tensor2 = scipy.sparse.random(tensor.shape[0], tensor.shape[1]) names, format_permutations, ivars = parse_sam_input(args.cotile) - cotiled_tensors = cotile_coo(names, [tensor, tensor2], format_permutations, ivars, split_map) + cotiled_tensors = cotile_coo(names, [tensor, tensor2], + format_permutations, ivars, split_map, args.higher_order) # print(cotiled_tensors) names = cotiled_tensors.keys() for name in names: for tile_id, tile in cotiled_tensors[name].items(): [str(item) for item in tile_id] - filename = "tensor_" + name + "_tile_" + "_".join([str(item) for item in tile_id]) + ".mtx" + filename = "tensor_" + name + "_tile_" + "_".join([str(item) for item in tile_id]) + filename += ".tns" if args.higher_order else ".mtx" mtx_path_name = os.path.join(output_mtx_name, filename) print(tile) - print(mtx_path_name, cwd) - scipy.io.mmwrite(mtx_path_name, tile) - print(os.path.exists(mtx_path_name)) + print("Output path:", mtx_path_name) + + if args.higher_order: + tns_dumper = PydataSparseTensorDumper() + print(tile.shape) + tns_dumper.dump(tile, mtx_path_name) + else: + scipy.io.mmwrite(mtx_path_name, tile) diff --git a/sam/util.py b/sam/util.py index 7044e94d..1d7588a4 100644 --- a/sam/util.py +++ b/sam/util.py @@ -143,21 +143,22 @@ def load(self, path): # PydataSparseTensorLoader loads a sparse tensor from a file into # a pydata.sparse tensor. -# class PydataSparseTensorLoader: -# def __init__(self): -# self.loader = TnsFileLoader() -# -# def load(self, path): -# dims, coords, values = self.loader.load(path) -# return sparse.COO(coords, values, tuple(dims)) -# -# # PydataSparseTensorDumper dumps a sparse tensor to a the desired file. -# class PydataSparseTensorDumper: -# def __init__(self): -# self.dumper = TnsFileDumper() -# -# def dump(self, tensor, path): -# self.dumper.dump_dict_to_file(tensor.shape, sparse.DOK(tensor).data, path) +class PydataSparseTensorLoader: + def __init__(self): + self.loader = TnsFileLoader() + + def load(self, path): + dims, coords, values = self.loader.load(path) + return sparse.COO(coords, values, tuple(dims)) + +# PydataSparseTensorDumper dumps a sparse tensor to a the desired file. +class PydataSparseTensorDumper: + def __init__(self): + self.dumper = TnsFileDumper() + + def dump(self, tensor, path): + assert isinstance(tensor, sparse.DOK), "The tensor needs to be a pydata/sparse DOK format" + self.dumper.dump_dict_to_file(tensor.shape, tensor.data, path) # # # diff --git a/scripts/tile_ext.sh b/scripts/tile_ext.sh index 46c56e70..1df28a71 100755 --- a/scripts/tile_ext.sh +++ b/scripts/tile_ext.sh @@ -25,7 +25,7 @@ for b in ${!BENCHMARKS[@]}; do rm -rf $basedir/tiles/* echo "Tiling mtx file" - python3 $basedir/sam/sim/src/tiling/tile.py --extensor --input_path $ext_path --cotile $bench --multilevel --hw_config $basedir/sam/sim/src/tiling/$2 + python3 $basedir/sam/sim/src/tiling/tile.py --tensor_type dataset --input_path $ext_path --cotile $bench --multilevel --hw_config $basedir/sam/sim/src/tiling/$2 echo "Generating input format files for $ext_path..." python3 $basedir/scripts/datastructure_suitesparse.py -n temp -hw -b $bench --input $basedir/tiles/$bench/mtx/ --output_dir_path $basedir/tiles/$bench/formatted --tiles diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py index 4d156366..0c646b2d 100644 --- a/setup_tiling_mat.py +++ b/setup_tiling_mat.py @@ -3,6 +3,8 @@ import shutil import os +from sam.util import SUITESPARSE_PATH + data = ['rel5'] # app_name = "mat_elemadd" app_name = "mat_mattransmul" @@ -12,14 +14,16 @@ # data.append(line[:-1]) for datum in data: - mtx_file = glob.glob(f"/nobackup/owhsu/sparse-datasets/suitesparse/{datum}.mtx")[0] + mtx_file = glob.glob(f"{SUITESPARSE_PATH}/{datum}.mtx")[0] + os.makedirs("extensor_mtx", exist_ok=True) shutil.copy(mtx_file,f"extensor_mtx/{datum}.mtx") command = f"./scripts/suitesparse_memory_model_runner.sh {datum} {app_name}" os.system(command) + os.makedirs("tiles_compiled", exist_ok=True) copy_rename = f"cp -r tiles/{app_name} tiles_compiled/{app_name}_{datum}" os.system(copy_rename) docker_copy_command = f"docker cp tiles_compiled/{app_name}_{datum} avb03-sparse-tiling:/aha/garnet/tiles_{app_name}_{datum}" - os.system(docker_copy_command) \ No newline at end of file + os.system(docker_copy_command) From 9e1b84d1c21d0e2868e319c08fda5de8057da6c9 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Wed, 26 Jul 2023 17:46:14 -0700 Subject: [PATCH 37/76] Add pydata/sparse to requirements for CI --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 1b7cab3d..8671a953 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,5 +25,6 @@ PyYAML==6.0 requests==2.28.2 scipy==1.10.0 six==1.16.0 +sparse==0.13.0 tomli==2.0.1 tqdm==4.64.1 From 7a06b1f9a5830456e24629e0db7a17a71e2abd5e Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Wed, 26 Jul 2023 17:54:45 -0700 Subject: [PATCH 38/76] Update gitignore --- .gitignore | 12 ++++--- sam/sim/src/tiling/tile.py | 73 ++++++++++++++++++++------------------ sam/util.py | 23 ++++++------ 3 files changed, 57 insertions(+), 51 deletions(-) diff --git a/.gitignore b/.gitignore index 82490b68..74d80687 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ __pycache__/ *.txt *.out +# Generated Python Package files +*.egg-info/ + # Files for MacOS and IDEs .DS_store .idea/ @@ -38,13 +41,14 @@ compiler/benchmark/ # Generated SAM simulator tests */sim/test/apps/test_*.py -*.gv - +# Tensor files *.mtx *.tns -# Temporary matrices +# Temporary or generated tensor directories tmp_mat*/ +tiles/ +synthetic/ # Jupyter notebook checkpoints .ipynb_checkpoints/ @@ -52,5 +56,3 @@ tmp_mat*/ # Generated formatted tensor files tensor_*_mode_* -# Tensor files -tiles/ diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 462da75d..f278baf7 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -1,35 +1,38 @@ -import numpy as np -import scipy.sparse -import os import argparse import ast -import yaml import copy +import os import pickle import random +import sys +from pathlib import Path + +import numpy as np +import scipy.sparse import sparse +import yaml -from itertools import compress -from pathlib import Path +from sam.util import SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter, PydataSparseTensorDumper, \ + SUITESPARSE_PATH, FROSTT_PATH +from sam.sim.src.tiling.process_expr import parse_all -import sys +# FIXME: This should not be here... Set your SAM_HOME directory custom_path = '/home/avb03/sam' sys.path.append(custom_path) -from sam.util import SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter, PydataSparseTensorDumper, SUITESPARSE_PATH, FROSTT_PATH -from sam.sim.src.tiling.process_expr import parse_all, update_dict - -SAM_STRS = {"matmul_kij": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)", +SAM_STRS = {"matmul_kij": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)", "matmul_ikj": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss -s=reorder(i,k,j)", "matmul_ijk": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemadd": "X(i,j)=B(i,j)+C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemmul": "X(i,j)=B(i,j)*C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_mattransmul": "X(i,j)=B(j,i)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss:0 -f=d:ss:0 -s=reorder(i,j)"} + def print_dict(dd): for k, v in dd.items(): print(k, ":", v) + def print_ast(node): for child in ast.iter_child_nodes(node): print_ast(child) @@ -89,6 +92,7 @@ def parse_sam_input(string): ivars = [ivars[tensor] for tensor in tensors] return tensors, permutations, ivars + # Outputs Pydata/sparse tensor tiles, given a pydata/sparse tensor (DOK or COO) # ASSUME: tensor is a scipy.sparse.coo_matrix # TODO: new_ivar_order right now is assumed to be one fixed order @@ -155,7 +159,6 @@ def tile_tensor(tensor, ivar_map, split_map, new_ivar_order=None): return tiles, tile_sizes - # Outputs COO tiles, given a COO tensor # ASSUME: tensor is a scipy.sparse.coo_matrix # TODO: new_ivar_order right now is assumed to be one fixed order @@ -239,7 +242,7 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map, hi for dim in range(order): print("tensor format: ", tensor_format) print("dim is ", dim) - print("tensor_format[dim:dim+1] is ", tensor_format[dim:dim+1]) + print("tensor_format[dim:dim+1] is ", tensor_format[dim:dim + 1]) lvl_permutation = tensor_format[dim:dim + 1][0] ivar = ivar_strs[i][dim] ivar_map[lvl_permutation] = ivar @@ -249,7 +252,7 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map, hi tiles, tile_sizes = tile_tensor(tensor, ivar_map, split_map) else: tiles, tile_sizes = tile_coo(tensor, ivar_map, split_map) - + tiled_tensors[tensor_name] = tiles tiled_tensor_sizes[tensor_name] = tile_sizes @@ -283,7 +286,7 @@ def get_other_tensors(app_str, tensor): pass elif "mat_mattransmul" in app_str: print("Writing other tensors...") - rows, cols = tensor.shape # i,j + rows, cols = tensor.shape # i,j tensor_c = scipy.sparse.random(cols, 1).toarray().flatten() tensor_d = scipy.sparse.random(rows, 1).toarray().flatten() @@ -291,7 +294,7 @@ def get_other_tensors(app_str, tensor): tensors.append(tensor_d) elif "mat_residual" in app_str: - pass + pass elif "mat_vecmul" in app_str: pass else: @@ -307,7 +310,8 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi names, format_permutations, ivars = parse_sam_input(args.cotile) - import pdb; pdb.set_trace(); + import pdb + pdb.set_trace() sizes_dict = {} for i, name in enumerate(names): tensor = tensors[i] @@ -345,7 +349,8 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi # First iteration of tiling print("tensor shapes: ", tensors[0].shape, " ", tensors[1].shape, " ", tensors[2].shape) print("format_permutations: ", format_permutations) - cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map, higher_order) + cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map, + higher_order) else: # recursively tile the blocks new_cotiled = {} @@ -398,13 +403,13 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi \n 'frostt' should always have 'higher_order' set as true.") parser.add_argument("--input_tensor", type=str, default=None, - help="Input tensor NAME if tensor_type is set to 'file'. \ + help="Input tensor NAME if tensor_type is set to 'file'. \ This is for use with SuiteSparse or FROSTT") parser.add_argument("--input_path", type=str, default=None, help="Input tensor path") parser.add_argument("--output_dir_path", type=str, default="./tiles", - help='Output path, directory where tiles get written to') + help='Output path, directory where tiles get written to') parser.add_argument("--hw_config", type=str, default=None, - help='Path to the hardware config yaml') + help='Path to the hardware config yaml') parser.add_argument("--cotile", type=str, default=None, help='If \ this is true cotile multiple tensors, else tile one tensor only') @@ -428,22 +433,22 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi elif args.tensor_type == "ex": tensor = scipy.io.mmread(args.input_path) elif args.tensor_type == "ss": - assert args.input_tensor is not None - tensor_path = os.path.join(SUITESPARSE_PATH, args.input_tensor + ".mtx") - ss_tensor = SuiteSparseTensor(tensor_path) - tensor = inputCache.load(ss_tensor, False) + assert args.input_tensor is not None + tensor_path = os.path.join(SUITESPARSE_PATH, args.input_tensor + ".mtx") + ss_tensor = SuiteSparseTensor(tensor_path) + tensor = inputCache.load(ss_tensor, False) elif args.tensor_type == "frostt": - assert args.input_tensor is not None - assert args.higher_order + assert args.input_tensor is not None + assert args.higher_order - tensor_path = os.path.join(FROSTT_PATH, args.input_tensor + ".tns") + tensor_path = os.path.join(FROSTT_PATH, args.input_tensor + ".tns") - # FIXME: This is broken - frostt_tensor = FrosttTensor(tensor_path) - tensor = inputCache.load(ss_tensor, False) + # FIXME: This is broken + frostt_tensor = FrosttTensor(tensor_path) + tensor = inputCache.load(frostt_tensor, False) else: - raise ValueError("This choice of 'tensor_type' is unreachable") + raise ValueError("This choice of 'tensor_type' is unreachable") split_map = {"i": 16, "j": 16, "k": 16} @@ -464,14 +469,14 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi assert args.cotile is not None cotiled_tensors = cotile_multilevel_coo(args.cotile, args.hw_config, [tensor], os.path.join(args.output_dir_path, - args.cotile), + args.cotile), args.higher_order) elif args.cotile is not None: tensor2 = scipy.sparse.random(tensor.shape[0], tensor.shape[1]) names, format_permutations, ivars = parse_sam_input(args.cotile) cotiled_tensors = cotile_coo(names, [tensor, tensor2], - format_permutations, ivars, split_map, args.higher_order) + format_permutations, ivars, split_map, args.higher_order) # print(cotiled_tensors) names = cotiled_tensors.keys() diff --git a/sam/util.py b/sam/util.py index 1d7588a4..ff3d29bf 100644 --- a/sam/util.py +++ b/sam/util.py @@ -1,24 +1,20 @@ -import scipy.sparse -import scipy.io -import os import glob -import numpy import itertools -import shutil -import numpy as np import math -import sparse - -from pathlib import Path +import os +import shutil from dataclasses import dataclass +from pathlib import Path -import os -import math import numpy +import numpy as np +import scipy.io +import scipy.sparse +import sparse # All environment variables for SAM should live here or in make file cwd = os.getcwd() -SAM_HOME = os.getenv('HOSTNAME', default=cwd) +SAM_HOME = os.getenv('SAM_HOME', default=cwd) HOSTNAME = os.getenv('HOSTNAME', default="local") SUITESPARSE_PATH = os.getenv('SUITESPARSE_PATH', default=os.path.join(SAM_HOME, "data", "suitesparse")) SUITESPARSE_FORMATTED_PATH = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(SAM_HOME, "data", @@ -151,6 +147,7 @@ def load(self, path): dims, coords, values = self.loader.load(path) return sparse.COO(coords, values, tuple(dims)) + # PydataSparseTensorDumper dumps a sparse tensor to a the desired file. class PydataSparseTensorDumper: def __init__(self): @@ -159,6 +156,8 @@ def __init__(self): def dump(self, tensor, path): assert isinstance(tensor, sparse.DOK), "The tensor needs to be a pydata/sparse DOK format" self.dumper.dump_dict_to_file(tensor.shape, tensor.data, path) + + # # # From 1678d58c44c9df15d4bd411c1c39e1a203e5e853 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Wed, 26 Jul 2023 17:58:18 -0700 Subject: [PATCH 39/76] Add in updated gitignore --- .gitignore | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index a69400ea..40366917 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,9 @@ __pycache__/ *.swo *.txt *.out -download_suitesparse_partial.sh + +# Generated Python Package files +*.egg-info/ # Files for MacOS and IDEs .DS_store @@ -27,37 +29,29 @@ cmake-build-*/ *.csv *.json +# Tensor files +*.mtx +*.tns + +# Generated formatted tensor files +tensor_*_mode_* + # Generated folders build/ logs/ results/ results-cpu/ -suitesparse-bench*/ +suitesparse-bench/ sam-outputs/ compiler/benchmark/ -# Generated SAM simulator tests -*/sim/test/apps/test_*.py - -# Generated SAM graphs -*.gv - -# Downloaded data -*.mtx -*.tns - -# Temporary matrices +# Temporary or generated tensor directories tmp_mat*/ - -# Jupyter notebook checkpoints -.ipynb_checkpoints/ - -# Generated formatted tensor files -tensor_*_mode_* - -# Tiling files tiles/ +synthetic/ -# sam package info -sam.egg-info/ +# Generated SAM simulator tests +*/sim/test/apps/test_*.py +# Temporary scripts +download_suitesparse_partial.sh From 1b45a01e952656b52034005dfab5e2361850773f Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Wed, 26 Jul 2023 18:13:48 -0700 Subject: [PATCH 40/76] Fix pycodestyle for CI --- sam/sim/src/tiling/tile.py | 7 ++++--- sam/util.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index f278baf7..73ee06fd 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -12,8 +12,8 @@ import sparse import yaml -from sam.util import SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter, PydataSparseTensorDumper, \ - SUITESPARSE_PATH, FROSTT_PATH +from sam.util import SUITESPARSE_PATH, SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter, \ + FROSTT_PATH, FrosttTensor, PydataSparseTensorDumper, InputCacheTensor from sam.sim.src.tiling.process_expr import parse_all # FIXME: This should not be here... Set your SAM_HOME directory @@ -387,6 +387,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi inputCache = InputCacheSuiteSparse() +inputCacheTensor = InputCacheTensor() if __name__ == "__main__": parser = argparse.ArgumentParser(description='script that tiles tensors') @@ -445,7 +446,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi # FIXME: This is broken frostt_tensor = FrosttTensor(tensor_path) - tensor = inputCache.load(frostt_tensor, False) + tensor = inputCacheTensor.load(frostt_tensor, False) else: raise ValueError("This choice of 'tensor_type' is unreachable") diff --git a/sam/util.py b/sam/util.py index ff3d29bf..480b4101 100644 --- a/sam/util.py +++ b/sam/util.py @@ -546,6 +546,20 @@ def load(self, tensor, suiteSparse, cast, format_str): return self.tensor +# FrosttTensor represents a tensor in the FROSTT dataset. +class FrosttTensor: + def __init__(self, path): + self.path = path + self.__name__ = self.__str__() + + def __str__(self): + f = os.path.split(self.path)[1] + return f.replace(".tns", "") + + def load(self): + return PydataSparseTensorLoader().load(self.path) + + # PydataMatrixMarketTensorLoader loads tensors in the matrix market format # into pydata.sparse matrices. # class PydataMatrixMarketTensorLoader: From 875569dca8578277e0e24167a4f566076d91891f Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Wed, 26 Jul 2023 18:22:06 -0700 Subject: [PATCH 41/76] spmv sparsity sweep stuff --- generate_spmv_sparsity_sweep.py | 164 +++++++++++++++++++ sam/sim/src/tiling/memory_config_onyx.yaml | 2 +- sam/sim/src/tiling/tile.py | 99 ++++++++++-- sam/util.py | 13 +- scripts/datastructure_suitesparse.py | 7 +- scripts/datastructure_tns.py | 180 ++++++++++++++++----- scripts/datastructure_tns_old.py | 127 +++++++++++++++ scripts/generate_gold_matmul_tiled.py | 17 +- scripts/generate_suitesparse_formats.sh | 20 +-- scripts/prepare_files.sh | 2 +- setup_tiling_mat.py | 6 + spmv_sparsity_sweep.py | 42 +++++ 12 files changed, 605 insertions(+), 74 deletions(-) create mode 100644 generate_spmv_sparsity_sweep.py create mode 100644 scripts/datastructure_tns_old.py create mode 100644 spmv_sparsity_sweep.py diff --git a/generate_spmv_sparsity_sweep.py b/generate_spmv_sparsity_sweep.py new file mode 100644 index 00000000..3d2f00e0 --- /dev/null +++ b/generate_spmv_sparsity_sweep.py @@ -0,0 +1,164 @@ +#script to generate 50 random 3D tensors (seeded, produces same 50 each time) +import numpy as np +import random +import os +import scipy.io as sio +import scipy.sparse as sps +# from scipy.io import mmread + +# Set the seed value +#previously used to be this: seed_value = 42 +seed_value = 100 +random.seed(seed_value) +np.random.seed(seed_value) + +#generating matrix dimensions and storing results in an array, array size is 2, 1 matrix and 2 dimensions per matrix + +#conditions which need to be met for each set of 3 tensor dimensions: no dimension can't be 0, and can't have a tensor with more than 900 elements (meaning dimension1*dimension2*dimension3 <= 900) +#note try to make it so no dimension is 1 or 2 (gives slight issues later, esp 2nd and 3rd dimensions) +dimensions = [0] * 2 +dimensions_onematrix = [0] * 2 + +# x goes from 0 to __ (before 0 to 49) +for x in range(1): + # dimensions_onematrix[0] = random.randint(1,60) + # dimensions_onematrix[1] = random.randint(3,60) + + # while((dimensions_onetensor[0]*dimensions_onetensor[1]*dimensions_onetensor[2])>901): + # dimensions_onematrix[0] = random.randint(1,60) + # dimensions_onematrix[1] = random.randint(3,60) + # dimensions_onematrix[2] = random.randint(3,60) + dimensions_onematrix[0] = 10 + dimensions_onematrix[1] = 10 + + dimensions[x*3] = dimensions_onematrix[0] + dimensions[(x*3)+1] = dimensions_onematrix[1] + + dimensions_onematrix[0] = 0 + dimensions_onematrix[1] = 0 + #print('\n') + + +#Generating matrix values based on the dimensions now stored in the dimensions (2 elem) array +#i goes from 0 to __ (before 0 to 49) +matrix_num = 1 +randomNumber = 0 +numToInsert = 0 +countnnz = 0 +#can add in as many sparsity numbers here (num elements in the sparsities array = num matrices being generated) +sparsities = [0.5] +# NEED TO CHANGE suitesparse_path for this to work: frostt_path = os.environ['FROSTT_PATH'] +ss_path = '' +for i in range(1): + filename = os.path.join(ss_path, "rand_matrix"+str(matrix_num)+".mtx") + sparsity = sparsities[i] + f = open(filename, "w") + f.write('\n') + lineToAddInFile = "" + arr = np.zeros([dimensions[i*3],dimensions[(i*3)+1]], dtype=int) + for x in range(len(arr)): + for y in range(len(arr[x])): + #TO CHANGE SPARSITY: generate random number from 1 to 9; if 1,2,3,7,8,9 don't add a num in, only add if 4,5,6 + # randomNumber = random.randint(1,9) + randomNumber = random.random() + if(randomNumber>sparsity): + numToInsert = random.randint(1,100) + arr[x][y] = numToInsert + numToInsert = 0 + randomNumber = 0 + #print(arr[x][y][z]) + if(arr[x][y]!=0): + #tensor files are not 0 indexed - say want to insert a point at (0,0,0), then need to feed in (1,1,1) to the tensor file to insert at the (0,0,0) location + lineToAddInFile="" + str(x+1) + " " + str(y+1) + " " + str(arr[x][y]) + countnnz += 1 + f.write(lineToAddInFile + '\n') + # writing in first line in file: + with open(filename, 'r') as f: + content = f.read() + updated_content = ""+str(dimensions[i*3]) + " " + str(dimensions[i*3+1]) + " " + str(countnnz) + content + with open(filename, 'w') as f: + f.write(updated_content) + + with open(filename, 'r') as file: + data = file.readlines() + + header = data.pop(0) + num_rows, num_cols, num_nonzeros = map(int, header.strip().split()) + matrix_data = [] + row_indices = [] + col_indices = [] + for line in data: + row, col, value = map(float, line.strip().split()) + row_indices.append(int(row) - 1) # Convert to 0-based indexing + col_indices.append(int(col) - 1) # Convert to 0-based indexing + matrix_data.append(value) + matrix = sps.coo_matrix((matrix_data, (row_indices, col_indices)), shape=(num_rows, num_cols)) + output_file = os.path.join(ss_path, "rand_matrix"+str(matrix_num)+".mat") + sio.savemat(output_file, {'matrix': matrix}, do_compression=True) + + # vec = sps.random(dimensions[i*3+1], 1, 0, data_rvs=np.ones) + vec = np.ones(dimensions[i*3+1]) + output_file1 = os.path.join(ss_path, "rand_vector"+str(matrix_num)+".mat") + sio.savemat(output_file1, {'vector': vec}, do_compression=True) + + + # f.close() + # a = mmread(filename) + # a.toarray() + # scipy.io.savemat("rand_matrix"+str(matrix_num)+".mat", {'mydata': a}) + + # f.write(""+str(dimensions[i*3]) + " " + str(dimensions[i*3+1]) + " " + str(countnnz)) + # f.write("\n") + matrix_num = matrix_num + 1 + + +#first step: one randomly generated 3D tensor given first set dimensions +#Note: generally if 2/3 elems in a tensor is 0, it can be considered sparse +#approach: 2/3 of the time add in a 0, 1/3 of the time add in an integer from 0 to 100 (use randint to generate num from 1 to 9 inclusive, and depending on where the num is, insert number or not) +#print('dimensions:') +#print(dimensions[0]) +#print(dimensions[1]) +#print(dimensions[2]) +#print('tensor vals') + +""" +arr = np.zeros([dimensions[0],dimensions[1],dimensions[2]], dtype=int) +randomNumber = 0 +numToInsert = 0 +for x in range(len(arr)): + for y in range(len(arr[x])): + for z in range(len(arr[x][y])): + #generate random number from 1 to 9; if 1,2,3,7,8,9 don't add a num in, only add if 4,5,6 + randomNumber = random.randint(1,9) + if(randomNumber==4 or randomNumber==5 or randomNumber==6): + numToInsert = random.randint(1,100) + arr[x][y][z] = numToInsert + numToInsert = 0 + print(arr[x][y][z]) + + #lineToAddInFile="" + str(x) + " " + str(y) + " " + str(z) + " " + str(arr[x][y][z]) + #f.write(lineToAddInFile + '\n') + +print('dimensions:') +print(dimensions[3]) +print(dimensions[4]) +print(dimensions[5]) +print('tensor vals') +arr = np.zeros([dimensions[3],dimensions[4],dimensions[5]], dtype=int) +randomNumber = 0 +numToInsert = 0 +for x in range(len(arr)): + for y in range(len(arr[x])): + for z in range(len(arr[x][y])): + #generate random number from 1 to 9; if 1,2,3,7,8,9 don't add a num in, only add if 4,5,6 + randomNumber = random.randint(1,9) + if(randomNumber==4 or randomNumber==5 or randomNumber==6): + numToInsert = random.randint(1,100) + arr[x][y][z] = numToInsert + numToInsert = 0 + randomNumber = 0 + print(arr[x][y][z]) + + #lineToAddInFile="" + str(x) + " " + str(y) + " " + str(z) + " " + str(arr[x][y][z]) + #f.write(lineToAddInFile + '\n') +""" diff --git a/sam/sim/src/tiling/memory_config_onyx.yaml b/sam/sim/src/tiling/memory_config_onyx.yaml index 74c80c27..b565bce0 100644 --- a/sam/sim/src/tiling/memory_config_onyx.yaml +++ b/sam/sim/src/tiling/memory_config_onyx.yaml @@ -16,4 +16,4 @@ n_levels: 3 level_names: ["Main", "Glb", "Mem"] Main_tile_size: None Glb_tile_size: 8 # 8 = (8x8) = 64 elements -Mem_tile_size: 45 # Size of one dense dimension. 45 = (45*45) = 2025 +Mem_tile_size: 30 #45 # Size of one dense dimension. 45 = (45*45) = 2025 diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 942035b2..9360f3e0 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -7,11 +7,16 @@ import copy import pickle import random +import sys from itertools import compress from pathlib import Path -import sys +custom_path = '/home/avb03/sam/scripts' +sys.path.append(custom_path) + +from util import FormatWriter, SuiteSparseTensor, InputCacheSuiteSparse + custom_path = '/home/avb03/sam' sys.path.append(custom_path) @@ -153,6 +158,68 @@ def tile_coo(tensor, ivar_map, split_map, new_ivar_order=None): return tiles, tile_sizes +def tile_coo_tensor_named(tensor_name, tensor, ivar_map, split_map, new_ivar_order=None): + human_readable = False + + tiles = dict() + tile_sizes = dict() + order = len(tensor.shape) + # if tensor_name == 'd' or tensor_name == 'c': + # order = 1 + + tensor_coo = scipy.sparse.coo_matrix(tensor) + tensor_points = tensor_coo.todok() + + print("ivar_map: ", ivar_map) + print("split_map: ", split_map) + print("order: ", order) + + new_shape = [] + for lvl in range(order): + ivar = ivar_map[lvl] + sf = split_map[ivar] + new_shape.append(sf) + + print("new_shape: ", new_shape) + for crds, val in tensor_points.items(): + point = list(crds) + + new_point = [] + tile_id = [] + for lvl in range(order): + ivar = ivar_map[lvl] + sf = split_map[ivar] + + new_point.append(point[lvl] % sf) + tile_id.append(int(point[lvl] / sf)) + + # Add in value to the new_point as well + new_point.append(val) + tile_id = tuple(tile_id) + + if tile_id in tiles: + tiles[tile_id].append(new_point) + else: + tiles[tile_id] = [new_point] + + # sort the new coo lists + for key, val in tiles.items(): + if human_readable: + dok = sorted(val) + else: + dok = scipy.sparse.dok_matrix(tuple(new_shape)) + for point in val: + dok[tuple(point[0:-1])] = point[-1] + + tiles[key] = dok + + for tile_id, tile_dok in tiles.items(): + tile = tile_dok.tocoo() + nonempty_rows = tile.getnnz(axis=1) + nonempty_row_ind = np.where(nonempty_rows > 0)[0] + tile_sizes[tile_id] = tile.nnz * 2 + 2 * len(nonempty_row_ind) + 3 + + return tiles, tile_sizes # tensor_names: list of tensor names [B,C,D] (from SAM) # tensors: list of scipy.sparse.coo_matrix following tensor_names (from SAM) @@ -168,7 +235,10 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map): tensor_format = permutation_strs[i] ivar_map = dict() order = len(tensor.shape) - print("order is ", order) + # if tensor_name == 'd' or tensor_name == 'c': + # order = 1 + print("tensor name = ", tensor_name) + print("order in cotile_coo = ", order) for dim in range(order): print("tensor format: ", tensor_format) print("dim is ", dim) @@ -178,7 +248,7 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map): ivar_map[lvl_permutation] = ivar print("ivar_map is ", ivar_map) - tiles, tile_sizes = tile_coo(tensor, ivar_map, split_map) + tiles, tile_sizes = tile_coo_tensor_named(tensor_name, tensor, ivar_map, split_map) tiled_tensors[tensor_name] = tiles tiled_tensor_sizes[tensor_name] = tile_sizes @@ -189,6 +259,8 @@ def get_other_tensors(app_str, tensor): tensors = [] tensors.append(tensor) + # formatWriter = FormatWriter(cast_int=True) + if "matmul" in app_str: print("Writing shifted...") shifted = ScipyTensorShifter().shiftLastMode(tensor) @@ -213,9 +285,13 @@ def get_other_tensors(app_str, tensor): elif "mat_mattransmul" in app_str: print("Writing other tensors...") rows, cols = tensor.shape # i,j - tensor_c = scipy.sparse.random(cols, 1).toarray().flatten() - tensor_d = scipy.sparse.random(rows, 1).toarray().flatten() + tensor_c = scipy.sparse.random(cols, 1, data_rvs=np.ones).toarray().flatten() + tensor_d = scipy.sparse.random(rows, 1, data_rvs=np.ones).toarray().flatten() + # # import pdb; pdb.set_trace() + + # tensor_c_coo = formatWriter.convert_format(tensor_c, "coo") + # tensor_d_coo = formatWriter.convert_format(tensor_d, "coo") tensors.append(tensor_c) tensors.append(tensor_d) @@ -236,7 +312,9 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): names, format_permutations, ivars = parse_sam_input(args.cotile) - import pdb; pdb.set_trace(); + print("cotile_multilevel_coo tensors: ", tensors) + + # import pdb; pdb.set_trace(); sizes_dict = {} for i, name in enumerate(names): tensor = tensors[i] @@ -275,12 +353,13 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): print("tensor shapes: ", tensors[0].shape, " ", tensors[1].shape, " ", tensors[2].shape) print("format_permutations: ", format_permutations) cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map) + print("cotiled is ", cotiled) else: # recursively tile the blocks new_cotiled = {} new_cotiled_sizes = {} for i, name in enumerate(names): - + # import pdb; pdb.set_trace() new_cotiled[name] = {} new_cotiled_sizes[name] = {} for tile_id, tile in cotiled[name].items(): @@ -295,6 +374,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): for kk, vv in copy.deepcopy(new_cotiled_sizes_temp)[name].items(): new_tile_id = tuple(list(tile_id) + list(kk)) new_cotiled_sizes[name][new_tile_id] = vv + print(new_cotiled_temp) cotiled = copy.deepcopy(new_cotiled) cotiled_sizes = copy.deepcopy(new_cotiled_sizes) @@ -311,7 +391,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): if __name__ == "__main__": parser = argparse.ArgumentParser(description='Tile matrices') parser.add_argument("--input_tensor", type=str, default=None) - parser.add_argument("--gen_tensor", action="store_false") + parser.add_argument("--gen_tensor", action="store_true") parser.add_argument("--cotile", type=str, default=None) parser.add_argument("--output_dir_path", type=str, default="./tiles") parser.add_argument("--hw_config", type=str, default=None) @@ -345,7 +425,6 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): print("TILES:") print_dict(tiles) else: - output_mtx_name = os.path.join(args.output_dir_path, args.cotile, "mtx") output_mtx_path = Path(output_mtx_name) output_mtx_path.mkdir(parents=True, exist_ok=True) @@ -363,6 +442,8 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): # print(cotiled_tensors) names = cotiled_tensors.keys() + print("cotiled_tensors.keys(): ", names) + print("cotiled_tensors: ", cotiled_tensors) for name in names: for tile_id, tile in cotiled_tensors[name].items(): [str(item) for item in tile_id] diff --git a/sam/util.py b/sam/util.py index 7044e94d..f2382f16 100644 --- a/sam/util.py +++ b/sam/util.py @@ -207,12 +207,13 @@ def shiftLastMode(self, tensor): @dataclass class DoublyCompressedMatrix: - shape: (int) - seg0: [int] - crd0: [int] - seg1: [int] - crd1: [int] - data: [float] + # shape: (int) + shape = [int] + seg0 = [int] + crd0 = [int] + seg1 = [int] + crd1 = [int] + data = [float] # ScipyMatrixMarketTensorLoader loads tensors in the matrix market format diff --git a/scripts/datastructure_suitesparse.py b/scripts/datastructure_suitesparse.py index cb24ec39..6c4bace4 100644 --- a/scripts/datastructure_suitesparse.py +++ b/scripts/datastructure_suitesparse.py @@ -37,6 +37,7 @@ def write_datastructure_bench(args, tensor, out_path, tiles=None): print("Writing " + args.name + " for test " + args.benchname + "...") dirname = args.output_dir_path if args.output_dir_path is not None else os.path.join(out_path, args.name, args.benchname) + print("dirname: " + dirname) if tiles is not None: dirname = os.path.join(dirname, tiles) dirpath = Path(dirname) @@ -128,7 +129,8 @@ def write_datastructure_bench(args, tensor, out_path, tiles=None): elif "mat_mattransmul" in args.benchname: formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") - if not args.no_gen_other: + # if not args.no_gen_other: + if False: tensorname = 'd' vec = scipy.sparse.random(shape[0], 1, density=args.density, data_rvs=np.ones) vec = vec.toarray().flatten() @@ -184,7 +186,7 @@ def write_datastructure_bench(args, tensor, out_path, tiles=None): parser.add_argument('--output_dir_path', type=str, default=None) parser.add_argument('--tiles', action='store_true') parser.add_argument('--no_gen_other', action='store_true', help="Whether this" - "script should generate the randmo 'other' tensors") + "script should generate the random 'other' tensors") parser.add_argument('--seed', type=int, default=0, help='Random seed needed for gen_other') parser.add_argument('--density', type=int, default=0.25, help='If gen_other, used for density of "other" tensor') args = parser.parse_args() @@ -249,6 +251,7 @@ def write_datastructure_bench(args, tensor, out_path, tiles=None): formatWriter.writeout(trans_shifted, format_str, trans_filename) elif args.hw: if args.tiles and tensor is not None: + print("tensor lengths = ", len(tensor)) for i, ten in enumerate(tensor): tile_name = os.path.split(mtx_files[i])[1].split(".")[0] write_datastructure_tiles(args, ten, out_path, tile_name) diff --git a/scripts/datastructure_tns.py b/scripts/datastructure_tns.py index ccf60fae..16e00afc 100644 --- a/scripts/datastructure_tns.py +++ b/scripts/datastructure_tns.py @@ -1,10 +1,21 @@ import argparse import os +import shutil +import scipy.sparse +import numpy as np +import sys +import random +import shutil + from pathlib import Path from util import parse_taco_format -cwd = os.getcwd() +from util import FormatWriter, SuiteSparseTensor, InputCacheSuiteSparse +# custom_path = '/nobackup/jadivara/sam/sam/util.py' +# sys.path.append(custom_path) +# from import SUITESPARSE_FORMATTED_PATH, ScipyTensorShifter +cwd = os.getcwd() formats = ["sss012", "ss01", "dss", "dds", "ddd", "dsd", "sdd", "sds", "ssd"] @@ -21,9 +32,10 @@ help='Format filenames as in AHA SCGRA _mode_') parser.add_argument('-np', '--numpy', action='store_true', default=False, help='Format numpy tensors') parser.add_argument('-b', '--bench', type=str, default=None, help='Name of benchmark') +parser.add_argument('--density', type=int, default=0.25, help='If gen_other, used for density of "other" tensor') +parser.add_argument('-cast', '--cast', action='store_true', default=False, help='Safe sparsity cast to int for values') args = parser.parse_args() - if args.other: if args.suitesparse: outdir_name = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) @@ -44,70 +56,158 @@ out_path = Path(outdir_name) out_path.mkdir(parents=True, exist_ok=True) +formatWriter = FormatWriter(args.cast) + if args.name is None: print("Please enter a tensor name") exit() - +#breakpoint() if args.format is not None: assert args.format in formats levels = args.format[:-3] - if args.other: + + if os.path.exists('sam/FROST_FORMATTED/rand_tensor*'): + shutil.rmtree('sam/FROST_FORMATTED/rand_tensor*') + + if args.bench != "tensor3_elemadd" and args.bench != "tensor3_innerprod": assert args.bench is not None + #$FROSTT_FORMATTED_TACO_PATH + taco_format_orig_filename = "/home/avb03/sam/FROST_FORMATTED_TACO" + outdir_other_name = os.path.join(outdir_name, args.name, args.bench) + # outdir_other_name = os.path.join(outdir_name, args.name, 'other', otherfile[:-4]) + outdir_orig_path = Path(outdir_other_name) + outdir_orig_path.mkdir(parents=True, exist_ok=True) + + name = None + taco_format_orig_filename = os.path.join(taco_format_dirname, args.name + "_" + levels + '.txt') + + inputCache = InputCacheSuiteSparse() - otherfileNames = [f for f in os.listdir(taco_format_dirname) if - os.path.isfile(os.path.join(taco_format_dirname, f)) and args.name in f] + if args.bench == "tensor3_ttv": + outdir_orig_name = os.path.join(outdir_name, args.name, args.bench, args.format) + outdir_orig_path = Path(outdir_orig_name) + outdir_orig_path.mkdir(parents=True, exist_ok=True) + + taco_format_orig_filename = "/home/avb03/sam/FROST_FORMATTED_TACO/" + args.name + "_" + levels + '.txt' + parse_taco_format(taco_format_orig_filename, outdir_orig_name, 'B', args.format, hw_filename=args.hw) + #Need this line? formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + file_path_name = os.path.join(outdir_orig_name, "tensor_B_mode_shape") + file1 = open(file_path_name, 'r') + shape = [0]*3 + lines = file1.readlines() + count = 0 + + # Strips the newline character + for line in lines: + shape[count] = int(line) + count += 1 + # coo = inputCache.load(tensor, False) + + # formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + tensorname = 'c' + vec = scipy.sparse.random(shape[2], 1, density=args.density, data_rvs=np.ones) + vec = vec.toarray().flatten() + tensor_out_path = os.path.join(out_path, args.name, args.bench, args.format) + formatWriter.writeout_separate_vec(vec, tensor_out_path, tensorname) + + # vec = scipy.sparse.random(shape[2], 1, data_rvs=np.ones) + # vec = vec.toarray().flatten() + # formatWriter.writeout_separate_vec(vec, out_path, tensorname) + #FormatWriter.writeout_separate_vec(vec, out_path, tensorname, tensorname) + #formatWriter.writeout_separate_sparse_only() + elif args.bench == "tensor3_ttm": + outdir_orig_name = os.path.join(outdir_name, args.name, args.bench, args.format) + outdir_orig_path = Path(outdir_orig_name) + outdir_orig_path.mkdir(parents=True, exist_ok=True) - for otherfile in otherfileNames: - taco_format_orig_filename = os.path.join(taco_format_dirname, otherfile) - outdir_other_name = os.path.join(outdir_name, args.name, args.bench) - # outdir_other_name = os.path.join(outdir_name, args.name, 'other', otherfile[:-4]) - outdir_orig_path = Path(outdir_other_name) + taco_format_orig_filename = "/home/avb03/sam/FROST_FORMATTED_TACO/" + args.name + "_" + levels + '.txt' + parse_taco_format(taco_format_orig_filename, outdir_orig_name, 'B', args.format, hw_filename=args.hw) + #Need this line? formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + file_path_name = os.path.join(outdir_orig_name, "tensor_B_mode_shape") + file1 = open(file_path_name, 'r') + shape = [0]*3 + lines = file1.readlines() + count = 0 + + # Strips the newline character + for line in lines: + shape[count] = int(line) + count += 1 + # coo = inputCache.load(tensor, False) + dimension_k = random.randint(min(shape), 10) + dimension_l = shape[2] + dimension_j = shape[1] + + # formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + tensorname = 'C' + matrix = scipy.sparse.random(dimension_k, dimension_l, density=args.density, data_rvs=np.ones).toarray() + tensor_out_path = os.path.join(out_path, args.name, args.bench, args.format) + formatWriter.writeout_separate_sparse_only(matrix, tensor_out_path, tensorname) + + # vec = scipy.sparse.random(shape[2], 1, data_rvs=np.ones) + # vec = vec.toarray().flatten() + # formatWriter.writeout_separate_vec(vec, out_path, tensorname) + #FormatWriter.writeout_separate_vec(vec, out_path, tensorname, tensorname) + #formatWriter.writeout_separate_sparse_only() + elif args.bench == "tensor3_mttkrp": + outdir_orig_name = os.path.join(outdir_name, args.name, args.bench, args.format) + outdir_orig_path = Path(outdir_orig_name) outdir_orig_path.mkdir(parents=True, exist_ok=True) - name = None - if args.bench == "mat_residual": - if "mode0" in otherfile: - name = 'b' - elif "mode1" in otherfile: - name = 'd' - else: - raise NotImplementedError - elif args.bench == "mat_mattransmul": - if "mode0" in otherfile: - name = 'd' - elif "mode1" in otherfile: - name = 'f' - else: - raise NotImplementedError - elif "mat_vecmul" in args.bench: - if "mode1" in otherfile: - name = 'c' - elif "mode0" in otherfile: - continue - else: - raise NotImplementedError - else: - raise NotImplementedError - - assert name is not None, "Other tensor name was not set properly and is None" - parse_taco_format(taco_format_orig_filename, outdir_other_name, name, args.format, hw_filename=args.hw) + taco_format_orig_filename = "/home/avb03/sam/FROST_FORMATTED_TACO/" + args.name + "_" + levels + '.txt' + parse_taco_format(taco_format_orig_filename, outdir_orig_name, 'B', args.format, hw_filename=args.hw) + + file_path_name = os.path.join(outdir_orig_name, "tensor_B_mode_shape") + file1 = open(file_path_name, 'r') + shape = [0]*3 + lines = file1.readlines() + count = 0 + + # Strips the newline character + for line in lines: + shape[count] = int(line) + count += 1 + + dimension_i = shape[0] + dimension_k = shape[1] + dimension_l = shape[2] + dimension_j = random.randint(min(shape), 10) + + # formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + tensorname = 'C' + matrix = scipy.sparse.random(dimension_j, dimension_k, density=args.density, data_rvs=np.ones).toarray() + tensor_out_path = os.path.join(out_path, args.name, args.bench, args.format) + formatWriter.writeout_separate_sparse_only(matrix, tensor_out_path, tensorname) + + tensorname = 'D' + matrix = scipy.sparse.random(dimension_j, dimension_l, density=args.density, data_rvs=np.ones).toarray() + tensor_out_path = os.path.join(out_path, args.name, args.bench, args.format) + formatWriter.writeout_separate_sparse_only(matrix, tensor_out_path, tensorname) + else: + raise NotImplementedError + + assert tensorname is not None, "Other tensor name was not set properly and is None" + # parse_taco_format(taco_format_orig_filename, outdir_other_name, tensorname, args.format, hw_filename=args.hw) else: + #this code is used for: tensor3_elemadd, tensor3_innerprod taco_format_orig_filename = os.path.join(taco_format_dirname, args.name + "_" + levels + '.txt') taco_format_shift_filename = os.path.join(taco_format_dirname, args.name + '_shift_' + levels + '.txt') # Original - outdir_orig_name = os.path.join(outdir_name, args.name, 'orig', args.format) + outdir_orig_name = os.path.join(outdir_name, args.name, args.bench, args.format) outdir_orig_path = Path(outdir_orig_name) outdir_orig_path.mkdir(parents=True, exist_ok=True) + taco_format_orig_filename = "/home/avb03/sam/FROST_FORMATTED_TACO/" + args.name + "_" + levels + '.txt' parse_taco_format(taco_format_orig_filename, outdir_orig_name, 'B', args.format, hw_filename=args.hw) # Shifted if args.shift: - outdir_shift_name = os.path.join(outdir_name, args.name, 'shift', args.format) + outdir_shift_name = os.path.join(outdir_name, args.name, args.bench, args.format) outdir_shift_path = Path(outdir_shift_name) outdir_shift_path.mkdir(parents=True, exist_ok=True) + taco_format_shift_filename = "/home/avb03/sam/FROST_FORMATTED_TACO/" + args.name + "_shift_" + levels + '.txt' parse_taco_format(taco_format_shift_filename, outdir_shift_name, 'C', args.format, hw_filename=args.hw) diff --git a/scripts/datastructure_tns_old.py b/scripts/datastructure_tns_old.py new file mode 100644 index 00000000..863f1d0b --- /dev/null +++ b/scripts/datastructure_tns_old.py @@ -0,0 +1,127 @@ +import argparse +import os +from pathlib import Path +from util import parse_taco_format + +cwd = os.getcwd() + + +formats = ["sss012", "ss01", "dss", "dds", "ddd", "dsd", "sdd", "sds", "ssd"] + +parser = argparse.ArgumentParser(description="Process some Frostt tensors into per-level datastructures") +parser.add_argument('-n', '--name', metavar='fname', type=str, action='store', + help='tensor name to run format conversion on one frostt tensor') +parser.add_argument('-f', '--format', metavar='fformat', type=str, action='store', + help='The format that the tensor should be converted to') +parser.add_argument('-i', '--int', action='store_false', default=True, help='Safe sparsity cast to int for values') +parser.add_argument('-s', '--shift', action='store_false', default=True, help='Also format shifted tensor') +parser.add_argument('-o', '--other', action='store_true', default=False, help='Format other tensor') +parser.add_argument('-ss', '--suitesparse', action='store_true', default=False, help='Format suitesparse other tensor') +parser.add_argument('-hw', '--hw', action='store_true', default=False, + help='Format filenames as in AHA SCGRA _mode_') +parser.add_argument('-np', '--numpy', action='store_true', default=False, help='Format numpy tensors') +parser.add_argument('-b', '--bench', type=str, default=None, help='Name of benchmark') + +args = parser.parse_args() + +if args.other: + if args.suitesparse: + outdir_name = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) + else: + outdir_name = os.getenv('FROSTT_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) + taco_format_dirname = os.getenv('TACO_TENSOR_PATH') + if taco_format_dirname is None: + print("Please set the TACO_TENSOR_PATH environment variable") + exit() + taco_format_dirname = os.path.join(taco_format_dirname, "other") + # taco_format_dirname = os.path.join(taco_format_dirname, "other-formatted-taco") +else: + outdir_name = os.getenv('FROSTT_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) + taco_format_dirname = os.getenv('FROSTT_FORMATTED_TACO_PATH') + if taco_format_dirname is None: + print("Please set the FROSTT_FORMATTED_TACO_PATH environment variable") + exit() + +out_path = Path(outdir_name) +out_path.mkdir(parents=True, exist_ok=True) + +print("args.name is ", args.name) + +if args.name is None: + print("Please enter a tensor name") + exit() + +print("\nhere after Please enter tensor name\n") + +if args.format is not None: + assert args.format in formats + levels = args.format[:-3] + if args.other: + assert args.bench is not None + + print("here to get other file names\n") + + otherfileNames = [f for f in os.listdir(taco_format_dirname) if + os.path.isfile(os.path.join(taco_format_dirname, f)) and args.name in f] + + print("have otherfileNames\n") + print(os.listdir(outdir_name)) + print("length of otherfilenames is: ", len(otherfileNames), "\n") + + for otherfile in otherfileNames: + print("iterate thru otherfileNames\n") + taco_format_orig_filename = os.path.join(taco_format_dirname, otherfile) + # outdir_other_name = os.path.join(outdir_name, args.name, args.bench) + outdir_other_name = os.path.join(outdir_name, args.name, 'other', otherfile[:-4]) + outdir_orig_path = Path(outdir_other_name) + outdir_orig_path.mkdir(parents=True, exist_ok=True) + + name = None + if args.bench == "mat_residual": + if "mode0" in otherfile: + name = 'b' + elif "mode1" in otherfile: + name = 'd' + else: + raise NotImplementedError + elif args.bench == "mat_mattransmul": + if "mode0" in otherfile: + name = 'd' + elif "mode1" in otherfile: + name = 'f' + else: + raise NotImplementedError + elif "mat_vecmul" in args.bench: + if "mode1" in otherfile: + name = 'c' + elif "mode0" in otherfile: + continue + else: + raise NotImplementedError + else: + raise NotImplementedError + + assert name is not None, "Other tensor name was not set properly and is None" + parse_taco_format(taco_format_orig_filename, outdir_other_name, name, args.format, hw_filename=args.hw) + + else: + print("in else statement\n") + taco_format_orig_filename = os.path.join(taco_format_dirname, args.name + "_" + levels + '.txt') + taco_format_shift_filename = os.path.join(taco_format_dirname, args.name + '_shift_' + levels + '.txt') + + # Original + outdir_orig_name = os.path.join(outdir_name, args.name, 'orig', args.format) + outdir_orig_path = Path(outdir_orig_name) + outdir_orig_path.mkdir(parents=True, exist_ok=True) + + print("parse taco format\n") + + parse_taco_format(taco_format_orig_filename, outdir_orig_name, 'B', args.format, hw_filename=args.hw) + + # Shifted + if args.shift: + outdir_shift_name = os.path.join(outdir_name, args.name, 'shift', args.format) + outdir_shift_path = Path(outdir_shift_name) + outdir_shift_path.mkdir(parents=True, exist_ok=True) + + parse_taco_format(taco_format_shift_filename, outdir_shift_name, 'C', args.format, hw_filename=args.hw) diff --git a/scripts/generate_gold_matmul_tiled.py b/scripts/generate_gold_matmul_tiled.py index 64ff4946..0112a4e7 100644 --- a/scripts/generate_gold_matmul_tiled.py +++ b/scripts/generate_gold_matmul_tiled.py @@ -10,6 +10,9 @@ from pathlib import Path +# app_name = "mat_elemadd" +# app_name = "mat_elemmul" +app_name = "mat_mattransmul" # FIXME: (owhsu) this should be imported from util def round_sparse(x): @@ -25,7 +28,7 @@ def round_sparse(x): def generate_gold_matmul_tiled(tile_crd_b, tile_crd_c, dirname, out_format="ss01"): # CSR - formatted_dir = "./tiles/matmul_ikj/mtx" + formatted_dir = f"./tiles/{app_name}/mtx" B_dir = "tensor_B_tile_" for a in tile_crd_b: B_dir += str(a) + "_" @@ -69,6 +72,7 @@ def generate_gold_matmul_tiled(tile_crd_b, tile_crd_c, dirname, out_format="ss01 itr += 1 C_scipy = C_scipy.tocsc() gold_nd = (B_scipy @ C_scipy) + # gold_nd = B_scipy.dot(C_scipy) gold_out = gold_nd.tocoo() assert tile_crd_b[1] == tile_crd_c[0] and tile_crd_b[3] == tile_crd_c[2] scipy.io.mmwrite( @@ -80,25 +84,26 @@ def generate_gold_matmul_tiled(tile_crd_b, tile_crd_c, dirname, out_format="ss01 parser = argparse.ArgumentParser(description="Generate tiled output gold") parser.add_argument("--yaml_name", type=str, default="memory_config_real.yaml") args = parser.parse_args() - outdir = "./tiles/matmul_ikj/output/" + outdir = f"./tiles/{app_name}/output/" outpath = Path(outdir) - outpath.mkdir(parents=True, exist_ok=True) + outpath.mkdir(parents=True) # generate_gold_matmul_tiled([0, 1, 2, 9], [1, 0, 9, 0], outdir) # generate_gold_matmul_tiled([0, 1, 0, 7], [1, 0, 7, 0], outdir) # quit() with open("/nobackup/rsharma3/Sparsity/simulator/old_sam/sam/tiles/matmul_ikj/tensor_sizes", "rb") as ff: - with open("./tiles/matmul_ikj/tensor_sizes", "rb") as ff: + with open(f"./tiles/{app_name}/tensor_sizes", "rb") as ff: sizes_dict_level_full = pickle.load(ff) with open("./sam/sim/src/tiling/" + args.yaml_name, "r") as stream: loop_config = yaml.safe_load(stream) + print("sizes_dict_level_full", sizes_dict_level_full) struct = { "i00": 1 + int(sizes_dict_level_full["B"][0]) // (loop_config["Glb_tile_size"] * loop_config["Mem_tile_size"]), - "k00": 1 + int(sizes_dict_level_full["B"][1]) // (loop_config["Glb_tile_size"] * loop_config["Mem_tile_size"]), - "j00": 1 + int(sizes_dict_level_full["C"][1]) // (loop_config["Glb_tile_size"] * loop_config["Mem_tile_size"]), + "k00": 1 + int(sizes_dict_level_full["c"][0]) // (loop_config["Glb_tile_size"] * loop_config["Mem_tile_size"]), + "j00": 1 + int(sizes_dict_level_full["d"][0]) // (loop_config["Glb_tile_size"] * loop_config["Mem_tile_size"]), "i0": loop_config["Glb_tile_size"], "k0": loop_config["Glb_tile_size"], "j0": loop_config["Glb_tile_size"]} print(struct) # quit() diff --git a/scripts/generate_suitesparse_formats.sh b/scripts/generate_suitesparse_formats.sh index a12d9eea..d335bd18 100755 --- a/scripts/generate_suitesparse_formats.sh +++ b/scripts/generate_suitesparse_formats.sh @@ -3,15 +3,17 @@ #SBATCH -t 360 BENCHMARKS=( - matmul_ikj - matmul_ijk - matmul_kij - mat_elemmul - mat_elemadd - mat_elemadd3 +# matmul_ikj +# matmul_ijk +# matmul_kij +# mat_elemmul +# mat_elemadd +# mat_elemadd3 mat_residual mat_mattransmul - mat_identity + mat_vecmul +# mat_identity +# mat_sddmm ) # This is a list of benchmarks that have "other" tensors that are generated @@ -32,10 +34,10 @@ for b in ${!BENCHMARKS[@]}; do sspath=${SUITESPARSE_PATH}/$name echo "Generating input format files for $name..." - SUITESPARSE_TENSOR_PATH=$sspath python $basedir/scripts/datastructure_suitesparse.py -n $name -hw -b $bench + SUITESPARSE_TENSOR_PATH=$sspath python3 $basedir/scripts/datastructure_suitesparse.py -n $name -hw -b $bench if [[ $OTHERBENCHES =~ "$bench" ]]; then echo "Generating format of 'other' tensor" - python $basedir/scripts/datastructure_tns.py -n $line -f ss01 --other -ss -b $bench -hw + python3 $basedir/scripts/datastructure_tns.py -n $line -f ss01 --other -ss -b $bench -hw fi done <$textfile diff --git a/scripts/prepare_files.sh b/scripts/prepare_files.sh index 4e3c82ed..5f8cb587 100755 --- a/scripts/prepare_files.sh +++ b/scripts/prepare_files.sh @@ -11,4 +11,4 @@ rm -rf $basedir/tiles/* ./scripts/tile_ext.sh $1 $2 -python3 scripts/generate_gold_matmul_tiled.py --yaml_name $2 +# python3 scripts/generate_gold_matmul_tiled.py --yaml_name $2 diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py index 4d156366..fd944c71 100644 --- a/setup_tiling_mat.py +++ b/setup_tiling_mat.py @@ -11,6 +11,12 @@ # for line in data_file_lines: # data.append(line[:-1]) +if not os.path.exists("extensor_mtx"): + os.mkdir("extensor_mtx") + +if not os.path.exists("tiles_compiled"): + os.mkdir("tiles_compiled") + for datum in data: mtx_file = glob.glob(f"/nobackup/owhsu/sparse-datasets/suitesparse/{datum}.mtx")[0] shutil.copy(mtx_file,f"extensor_mtx/{datum}.mtx") diff --git a/spmv_sparsity_sweep.py b/spmv_sparsity_sweep.py new file mode 100644 index 00000000..8847e00b --- /dev/null +++ b/spmv_sparsity_sweep.py @@ -0,0 +1,42 @@ +import numpy as np +import scipy.io as sio +import scipy.sparse as sp +import os +import random + +num_rows = 10 +num_cols = 10 +density = 0.1 + +seed_value = 100 +random.seed(seed_value) +np.random.seed(seed_value) + +if not os.path.exists('spmv_sparsity_sweep'): + os.makedirs('spmv_sparsity_sweep') +else: + os.system("rm -rf spmv_sparsity_sweep/*") + +if not os.path.exists('spmv_sparsity_sweep/MAT_FILES'): + os.makedirs('spmv_sparsity_sweep/MAT_FILES') +else: + os.system("rm -rf spmv_sparsity_sweep/MAT_FILES/*") + os.makedirs('spmv_sparsity_sweep/MAT_FILES') + +if not os.path.exists('spmv_sparsity_sweep/MTX_FILES'): + os.makedirs('spmv_sparsity_sweep/MTX_FILES') +else: + os.system("rm -rf spmv_sparsity_sweep/MTX_FILES/*") + os.makedirs('spmv_sparsity_sweep/MTX_FILES') + +matrix = sp.random(num_rows, num_cols, density, data_rvs=np.ones, random_state=seed_value) +print(matrix) + +probability = 0.7 # Adjust this value to control the ratio of 1s to 0s in vector +vector = np.random.choice([0, 1], size=num_cols, p=[1 - probability, probability]) +print(vector) + +sio.mmwrite('spmv_sparsity_sweep/MTX_FILES/matrix.mtx', matrix) + +sio.savemat('spmv_sparsity_sweep/MAT_FILES/matrix.mat', {'matrix': matrix}) +sio.savemat('spmv_sparsity_sweep/MAT_FILES/vector.mat', {'vector': vector}) From 68f05676f22d069c3a2f3b054de6a835c5aa46a5 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Thu, 27 Jul 2023 16:07:46 -0700 Subject: [PATCH 42/76] pushing all fixed merge conflicts --- sam/sim/src/tiling/tile.py | 195 ++++-------------- .../formatting/datastructure_suitesparse.py | 3 +- scripts/suitesparse_memory_model_runner.sh | 4 +- scripts/tile_ext.sh | 34 --- scripts/tiling/generate_gold_matmul_tiled.py | 1 + scripts/tiling/prepare_files.sh | 2 +- scripts/tiling/tile_ext.sh | 8 +- setup_tiling_mat.py | 11 +- 8 files changed, 52 insertions(+), 206 deletions(-) delete mode 100755 scripts/tile_ext.sh diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 971bfbbb..b4982c7c 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -1,50 +1,35 @@ +import numpy as np +import scipy.sparse +import os import argparse import ast +import yaml import copy -import os import pickle import random -import sys -<<<<<<< HEAD +import sparse from itertools import compress from pathlib import Path -custom_path = '/home/avb03/sam/scripts' -sys.path.append(custom_path) - -from util import FormatWriter, SuiteSparseTensor, InputCacheSuiteSparse - -======= -from pathlib import Path - -import numpy as np -import scipy.sparse -import sparse -import yaml - -from sam.util import SUITESPARSE_PATH, SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter, \ - FROSTT_PATH, FrosttTensor, PydataSparseTensorDumper, InputCacheTensor -from sam.sim.src.tiling.process_expr import parse_all - -# FIXME: This should not be here... Set your SAM_HOME directory ->>>>>>> 1b45a01e952656b52034005dfab5e2361850773f +import sys custom_path = '/home/avb03/sam' sys.path.append(custom_path) -SAM_STRS = {"matmul_kij": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)", +from sam.util import SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter, PydataSparseTensorDumper, SUITESPARSE_PATH, FROSTT_PATH +from sam.sim.src.tiling.process_expr import parse_all, update_dict + +SAM_STRS = {"matmul_kij": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)", "matmul_ikj": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss -s=reorder(i,k,j)", "matmul_ijk": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemadd": "X(i,j)=B(i,j)+C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemmul": "X(i,j)=B(i,j)*C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_mattransmul": "X(i,j)=B(j,i)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss:0 -f=d:ss:0 -s=reorder(i,j)"} - def print_dict(dd): for k, v in dd.items(): print(k, ":", v) - def print_ast(node): for child in ast.iter_child_nodes(node): print_ast(child) @@ -104,7 +89,6 @@ def parse_sam_input(string): ivars = [ivars[tensor] for tensor in tensors] return tensors, permutations, ivars - # Outputs Pydata/sparse tensor tiles, given a pydata/sparse tensor (DOK or COO) # ASSUME: tensor is a scipy.sparse.coo_matrix # TODO: new_ivar_order right now is assumed to be one fixed order @@ -171,6 +155,7 @@ def tile_tensor(tensor, ivar_map, split_map, new_ivar_order=None): return tiles, tile_sizes + # Outputs COO tiles, given a COO tensor # ASSUME: tensor is a scipy.sparse.coo_matrix # TODO: new_ivar_order right now is assumed to be one fixed order @@ -235,68 +220,6 @@ def tile_coo(tensor, ivar_map, split_map, new_ivar_order=None): return tiles, tile_sizes -def tile_coo_tensor_named(tensor_name, tensor, ivar_map, split_map, new_ivar_order=None): - human_readable = False - - tiles = dict() - tile_sizes = dict() - order = len(tensor.shape) - # if tensor_name == 'd' or tensor_name == 'c': - # order = 1 - - tensor_coo = scipy.sparse.coo_matrix(tensor) - tensor_points = tensor_coo.todok() - - print("ivar_map: ", ivar_map) - print("split_map: ", split_map) - print("order: ", order) - - new_shape = [] - for lvl in range(order): - ivar = ivar_map[lvl] - sf = split_map[ivar] - new_shape.append(sf) - - print("new_shape: ", new_shape) - for crds, val in tensor_points.items(): - point = list(crds) - - new_point = [] - tile_id = [] - for lvl in range(order): - ivar = ivar_map[lvl] - sf = split_map[ivar] - - new_point.append(point[lvl] % sf) - tile_id.append(int(point[lvl] / sf)) - - # Add in value to the new_point as well - new_point.append(val) - tile_id = tuple(tile_id) - - if tile_id in tiles: - tiles[tile_id].append(new_point) - else: - tiles[tile_id] = [new_point] - - # sort the new coo lists - for key, val in tiles.items(): - if human_readable: - dok = sorted(val) - else: - dok = scipy.sparse.dok_matrix(tuple(new_shape)) - for point in val: - dok[tuple(point[0:-1])] = point[-1] - - tiles[key] = dok - - for tile_id, tile_dok in tiles.items(): - tile = tile_dok.tocoo() - nonempty_rows = tile.getnnz(axis=1) - nonempty_row_ind = np.where(nonempty_rows > 0)[0] - tile_sizes[tile_id] = tile.nnz * 2 + 2 * len(nonempty_row_ind) + 3 - - return tiles, tile_sizes # tensor_names: list of tensor names [B,C,D] (from SAM) # tensors: list of scipy.sparse.coo_matrix following tensor_names (from SAM) @@ -312,28 +235,21 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map, hi tensor_format = permutation_strs[i] ivar_map = dict() order = len(tensor.shape) - # if tensor_name == 'd' or tensor_name == 'c': - # order = 1 - print("tensor name = ", tensor_name) - print("order in cotile_coo = ", order) + print("order is ", order) for dim in range(order): print("tensor format: ", tensor_format) print("dim is ", dim) - print("tensor_format[dim:dim+1] is ", tensor_format[dim:dim + 1]) + print("tensor_format[dim:dim+1] is ", tensor_format[dim:dim+1]) lvl_permutation = tensor_format[dim:dim + 1][0] ivar = ivar_strs[i][dim] ivar_map[lvl_permutation] = ivar print("ivar_map is ", ivar_map) -<<<<<<< HEAD - tiles, tile_sizes = tile_coo_tensor_named(tensor_name, tensor, ivar_map, split_map) -======= if higher_order: tiles, tile_sizes = tile_tensor(tensor, ivar_map, split_map) else: tiles, tile_sizes = tile_coo(tensor, ivar_map, split_map) - ->>>>>>> 1b45a01e952656b52034005dfab5e2361850773f + tiled_tensors[tensor_name] = tiles tiled_tensor_sizes[tensor_name] = tile_sizes @@ -344,8 +260,6 @@ def get_other_tensors(app_str, tensor): tensors = [] tensors.append(tensor) - # formatWriter = FormatWriter(cast_int=True) - if "matmul" in app_str: print("Writing shifted...") shifted = ScipyTensorShifter().shiftLastMode(tensor) @@ -369,25 +283,15 @@ def get_other_tensors(app_str, tensor): pass elif "mat_mattransmul" in app_str: print("Writing other tensors...") -<<<<<<< HEAD rows, cols = tensor.shape # i,j - tensor_c = scipy.sparse.random(cols, 1, data_rvs=np.ones).toarray().flatten() - tensor_d = scipy.sparse.random(rows, 1, data_rvs=np.ones).toarray().flatten() -======= - rows, cols = tensor.shape # i,j tensor_c = scipy.sparse.random(cols, 1).toarray().flatten() tensor_d = scipy.sparse.random(rows, 1).toarray().flatten() ->>>>>>> 1b45a01e952656b52034005dfab5e2361850773f - - # # import pdb; pdb.set_trace() - # tensor_c_coo = formatWriter.convert_format(tensor_c, "coo") - # tensor_d_coo = formatWriter.convert_format(tensor_d, "coo") tensors.append(tensor_c) tensors.append(tensor_d) elif "mat_residual" in app_str: - pass + pass elif "mat_vecmul" in app_str: pass else: @@ -403,14 +307,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi names, format_permutations, ivars = parse_sam_input(args.cotile) -<<<<<<< HEAD - print("cotile_multilevel_coo tensors: ", tensors) - - # import pdb; pdb.set_trace(); -======= - import pdb - pdb.set_trace() ->>>>>>> 1b45a01e952656b52034005dfab5e2361850773f + import pdb; pdb.set_trace(); sizes_dict = {} for i, name in enumerate(names): tensor = tensors[i] @@ -448,19 +345,13 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi # First iteration of tiling print("tensor shapes: ", tensors[0].shape, " ", tensors[1].shape, " ", tensors[2].shape) print("format_permutations: ", format_permutations) -<<<<<<< HEAD - cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map) - print("cotiled is ", cotiled) -======= - cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map, - higher_order) ->>>>>>> 1b45a01e952656b52034005dfab5e2361850773f + cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map, higher_order) else: # recursively tile the blocks new_cotiled = {} new_cotiled_sizes = {} for i, name in enumerate(names): - # import pdb; pdb.set_trace() + new_cotiled[name] = {} new_cotiled_sizes[name] = {} for tile_id, tile in cotiled[name].items(): @@ -479,7 +370,6 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi for kk, vv in copy.deepcopy(new_cotiled_sizes_temp)[name].items(): new_tile_id = tuple(list(tile_id) + list(kk)) new_cotiled_sizes[name][new_tile_id] = vv - print(new_cotiled_temp) cotiled = copy.deepcopy(new_cotiled) cotiled_sizes = copy.deepcopy(new_cotiled_sizes) @@ -492,20 +382,8 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi inputCache = InputCacheSuiteSparse() -inputCacheTensor = InputCacheTensor() if __name__ == "__main__": -<<<<<<< HEAD - parser = argparse.ArgumentParser(description='Tile matrices') - parser.add_argument("--input_tensor", type=str, default=None) - parser.add_argument("--gen_tensor", action="store_true") - parser.add_argument("--cotile", type=str, default=None) - parser.add_argument("--output_dir_path", type=str, default="./tiles") - parser.add_argument("--hw_config", type=str, default=None) - parser.add_argument("--multilevel", action="store_true") - parser.add_argument("--input_path", type=str, default=None) - parser.add_argument("--extensor", action="store_true") -======= parser = argparse.ArgumentParser(description='script that tiles tensors') parser.add_argument("--tensor_type", choices=['ex', 'gen', 'file', 'ss', 'frostt'], help='The \ tiles, tile_sizes = tile_coo(tensor, ivar_map, split_map) \ @@ -520,13 +398,13 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi \n 'frostt' should always have 'higher_order' set as true.") parser.add_argument("--input_tensor", type=str, default=None, - help="Input tensor NAME if tensor_type is set to 'file'. \ + help="Input tensor NAME if tensor_type is set to 'file'. \ This is for use with SuiteSparse or FROSTT") parser.add_argument("--input_path", type=str, default=None, help="Input tensor path") parser.add_argument("--output_dir_path", type=str, default="./tiles", - help='Output path, directory where tiles get written to') + help='Output path, directory where tiles get written to') parser.add_argument("--hw_config", type=str, default=None, - help='Path to the hardware config yaml') + help='Path to the hardware config yaml') parser.add_argument("--cotile", type=str, default=None, help='If \ this is true cotile multiple tensors, else tile one tensor only') @@ -534,7 +412,6 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi multilevel is true there will exist more than one level of tiles, \ else only tile once') parser.add_argument("--seed", type=int, default=0, help="Random seed") ->>>>>>> 1b45a01e952656b52034005dfab5e2361850773f args = parser.parse_args() @@ -551,22 +428,22 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi elif args.tensor_type == "ex": tensor = scipy.io.mmread(args.input_path) elif args.tensor_type == "ss": - assert args.input_tensor is not None - tensor_path = os.path.join(SUITESPARSE_PATH, args.input_tensor + ".mtx") - ss_tensor = SuiteSparseTensor(tensor_path) - tensor = inputCache.load(ss_tensor, False) + assert args.input_tensor is not None + tensor_path = os.path.join(SUITESPARSE_PATH, args.input_tensor + ".mtx") + ss_tensor = SuiteSparseTensor(tensor_path) + tensor = inputCache.load(ss_tensor, False) elif args.tensor_type == "frostt": - assert args.input_tensor is not None - assert args.higher_order + assert args.input_tensor is not None + assert args.higher_order - tensor_path = os.path.join(FROSTT_PATH, args.input_tensor + ".tns") + tensor_path = os.path.join(FROSTT_PATH, args.input_tensor + ".tns") - # FIXME: This is broken - frostt_tensor = FrosttTensor(tensor_path) - tensor = inputCacheTensor.load(frostt_tensor, False) + # FIXME: This is broken + frostt_tensor = FrosttTensor(tensor_path) + tensor = inputCache.load(ss_tensor, False) else: - raise ValueError("This choice of 'tensor_type' is unreachable") + raise ValueError("This choice of 'tensor_type' is unreachable") split_map = {"i": 16, "j": 16, "k": 16} @@ -587,19 +464,17 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi assert args.cotile is not None cotiled_tensors = cotile_multilevel_coo(args.cotile, args.hw_config, [tensor], os.path.join(args.output_dir_path, - args.cotile), + args.cotile), args.higher_order) elif args.cotile is not None: tensor2 = scipy.sparse.random(tensor.shape[0], tensor.shape[1]) names, format_permutations, ivars = parse_sam_input(args.cotile) cotiled_tensors = cotile_coo(names, [tensor, tensor2], - format_permutations, ivars, split_map, args.higher_order) + format_permutations, ivars, split_map, args.higher_order) # print(cotiled_tensors) names = cotiled_tensors.keys() - print("cotiled_tensors.keys(): ", names) - print("cotiled_tensors: ", cotiled_tensors) for name in names: for tile_id, tile in cotiled_tensors[name].items(): [str(item) for item in tile_id] @@ -614,4 +489,4 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi print(tile.shape) tns_dumper.dump(tile, mtx_path_name) else: - scipy.io.mmwrite(mtx_path_name, tile) + scipy.io.mmwrite(mtx_path_name, tile) \ No newline at end of file diff --git a/scripts/formatting/datastructure_suitesparse.py b/scripts/formatting/datastructure_suitesparse.py index f9aeb3ae..823e8e13 100644 --- a/scripts/formatting/datastructure_suitesparse.py +++ b/scripts/formatting/datastructure_suitesparse.py @@ -219,7 +219,8 @@ def write_datastructure_bench(args, tensor, out_path, tiles=None): mtx_files = None if args.tiles: # get all mtx tile files from args.input_path - mtx_files = [os.path.join(args.input_path, fname) for fname in os.listdir(args.input_path) if fname.endswith(".mtx")] + # mtx_files = [os.path.join(args.input_path, fname) for fname in os.listdir(args.input_path) if fname.endswith(".mtx")] + mtx_files = [os.path.join(args.input_path, fname) for fname in os.listdir(args.input_path)] tensor = [SuiteSparseTensor(mtx_file) for mtx_file in mtx_files] elif args.input_path is not None: diff --git a/scripts/suitesparse_memory_model_runner.sh b/scripts/suitesparse_memory_model_runner.sh index ccea10e6..d2873266 100755 --- a/scripts/suitesparse_memory_model_runner.sh +++ b/scripts/suitesparse_memory_model_runner.sh @@ -31,7 +31,7 @@ mkdir -p $path mkdir -p $basedir/tiles/ rm -rf $basedir/tiles/* -./scripts/prepare_files.sh $fname.mtx $yaml_fname +./scripts/tiling/prepare_files.sh $fname.mtx $yaml_fname cd $basedir/sam/sim # python3 -m pytest test/advanced-simulator/test_$bench.py --ssname $fname -s --check-gold --skip-empty --nbuffer --yaml_name=$yaml_fname --benchmark-json=$path/mem_model_$fname.json @@ -39,6 +39,6 @@ cd $basedir/sam/sim # python3 $basedir/scripts/converter.py --json_name $path/mem_model_$fname.json -python3 $basedir/scripts/bench_csv_aggregator.py $path $basedir/$benchout/$bench.csv +python3 $basedir/scripts/util/bench_csv_aggregator.py $path $basedir/$benchout/$bench.csv popd diff --git a/scripts/tile_ext.sh b/scripts/tile_ext.sh deleted file mode 100755 index 1df28a71..00000000 --- a/scripts/tile_ext.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -BENCHMARKS=( -# matmul_ijk -# mat_elemadd - # mat_elemmul - mat_mattransmul -) - -# THIS FILE MUST BE RUN FROM sam/ location -sspath=$SUITESPARSE_PATH - -basedir=$(pwd) - -ext_path=$basedir/extensor_mtx/$1 - -echo "$ext_path" - -for b in ${!BENCHMARKS[@]}; do - bench=${BENCHMARKS[$b]} - path=$basedir/$benchout/$bench - mkdir -p $basedir/$benchout/$bench - echo "Testing $bench..." - - rm -rf $basedir/tiles/* - - echo "Tiling mtx file" - python3 $basedir/sam/sim/src/tiling/tile.py --tensor_type dataset --input_path $ext_path --cotile $bench --multilevel --hw_config $basedir/sam/sim/src/tiling/$2 - - echo "Generating input format files for $ext_path..." - python3 $basedir/scripts/datastructure_suitesparse.py -n temp -hw -b $bench --input $basedir/tiles/$bench/mtx/ --output_dir_path $basedir/tiles/$bench/formatted --tiles - -done - diff --git a/scripts/tiling/generate_gold_matmul_tiled.py b/scripts/tiling/generate_gold_matmul_tiled.py index cd90cb33..2a069a0c 100644 --- a/scripts/tiling/generate_gold_matmul_tiled.py +++ b/scripts/tiling/generate_gold_matmul_tiled.py @@ -11,6 +11,7 @@ from pathlib import Path from scripts.util.util import round_sparse +app_name = "mat_mattransmul" def generate_gold_matmul_tiled(tile_crd_b, tile_crd_c, dirname, out_format="ss01"): # CSR diff --git a/scripts/tiling/prepare_files.sh b/scripts/tiling/prepare_files.sh index 5aece84f..3d24d037 100755 --- a/scripts/tiling/prepare_files.sh +++ b/scripts/tiling/prepare_files.sh @@ -12,4 +12,4 @@ rm -rf $basedir/tiles/* ./scripts/tiling/tile_ext.sh $1 memory_config_extensor_17M_llb.yaml -python scripts/tiling/generate_gold_matmul_tiled.py --yaml_name memory_config_extensor_17M_llb.yaml +python3 scripts/tiling/generate_gold_matmul_tiled.py --yaml_name memory_config_extensor_17M_llb.yaml diff --git a/scripts/tiling/tile_ext.sh b/scripts/tiling/tile_ext.sh index 4548f466..16126e12 100755 --- a/scripts/tiling/tile_ext.sh +++ b/scripts/tiling/tile_ext.sh @@ -4,7 +4,8 @@ # ./scripts/tiling/tile_ext.sh BENCHMARKS=( - matmul_ikj +# matmul_ikj + mat_mattransmul ) sspath=$SUITESPARSE_PATH @@ -24,10 +25,11 @@ for b in ${!BENCHMARKS[@]}; do rm -rf $basedir/tiles/* echo "Tiling mtx file" - python $basedir/sam/sim/src/tiling/tile.py --extensor --input_path $tiles_path --cotile $bench --multilevel --hw_config $basedir/sam/sim/src/tiling/$2 + # python $basedir/sam/sim/src/tiling/tile.py --extensor --input_path $tiles_path --cotile $bench --multilevel --hw_config $basedir/sam/sim/src/tiling/$2 + python3 ./sam/sim/src/tiling/tile.py --tensor_type ss --input_tensor rel5 --cotile mat_mattransmul --multilevel --hw_config ./sam/sim/src/tiling/memory_config_onyx.yaml --higher_order echo "Generating input format files for $tiles_path..." - python $basedir/scripts/formatting/datastructure_suitesparse.py -n temp -hw -b $bench --input $basedir/tiles/$bench/mtx/ --output_dir_path $basedir/tiles/$bench/formatted --tiles + python3 $basedir/scripts/formatting/datastructure_suitesparse.py -n temp -hw -b $bench --input $basedir/tiles/$bench/mtx/ --output_dir_path $basedir/tiles/$bench/formatted --tiles done diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py index d20cb49a..e7195c99 100644 --- a/setup_tiling_mat.py +++ b/setup_tiling_mat.py @@ -13,11 +13,12 @@ # for line in data_file_lines: # data.append(line[:-1]) -if not os.path.exists("extensor_mtx"): - os.mkdir("extensor_mtx") - -if not os.path.exists("tiles_compiled"): - os.mkdir("tiles_compiled") +os.environ["SUITESPARSE_PATH"] = "/nobackup/owhsu/sparse-datasets/suitesparse/" +os.environ["FROSTT_PATH"] = "/nobackup/owhsu/sparse-datasets/frostt/" +os.environ["SUITESPARSE_FORMATTED_PATH"] = "/home/avb03/sam/SUITESPARSE_FORMATTED" +os.environ["FROSTT_FORMATTED_TACO_PATH"] = "/home/avb03/sam/FROST_FORMATTED_TACO" +os.environ["FROSTT_FORMATTED_PATH"] = "/home/avb03/sam/FROST_FORMATTED" +os.environ["TACO_TENSOR_PATH"] = "/home/avb03/sam/TACO_TENSOR" for datum in data: mtx_file = glob.glob(f"{SUITESPARSE_PATH}/{datum}.mtx")[0] From 09fb1b0bf7ac2c249c949335b0755eb008bcd753 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Thu, 27 Jul 2023 16:32:26 -0700 Subject: [PATCH 43/76] Add in fixes to tile.py that broke during merge --- sam/sim/src/tiling/tile.py | 97 +++++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 39 deletions(-) diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index b4982c7c..bae03922 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -1,5 +1,6 @@ import numpy as np import scipy.sparse +import scipy.io import os import argparse import ast @@ -8,28 +9,31 @@ import pickle import random import sparse +import sys -from itertools import compress from pathlib import Path -import sys +from sam.util import SUITESPARSE_PATH, SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter, \ + FROSTT_PATH, FrosttTensor, PydataSparseTensorDumper, InputCacheTensor +from sam.sim.src.tiling.process_expr import parse_all + +# FIXME: This should not be here... Set your SAM_HOME directory custom_path = '/home/avb03/sam' sys.path.append(custom_path) -from sam.util import SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter, PydataSparseTensorDumper, SUITESPARSE_PATH, FROSTT_PATH -from sam.sim.src.tiling.process_expr import parse_all, update_dict - -SAM_STRS = {"matmul_kij": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)", +SAM_STRS = {"matmul_kij": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)", "matmul_ikj": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss -s=reorder(i,k,j)", "matmul_ijk": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemadd": "X(i,j)=B(i,j)+C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemmul": "X(i,j)=B(i,j)*C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_mattransmul": "X(i,j)=B(j,i)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss:0 -f=d:ss:0 -s=reorder(i,j)"} + def print_dict(dd): for k, v in dd.items(): print(k, ":", v) + def print_ast(node): for child in ast.iter_child_nodes(node): print_ast(child) @@ -87,13 +91,16 @@ def parse_sam_input(string): permutations = [list(map(int, dictionary[tensor]["perm"])) for tensor in tensors] ivars = get_ivars(tensors, str_arr[0]) ivars = [ivars[tensor] for tensor in tensors] + + print("PARSE SAM INPUTS", tensors) return tensors, permutations, ivars + # Outputs Pydata/sparse tensor tiles, given a pydata/sparse tensor (DOK or COO) # ASSUME: tensor is a scipy.sparse.coo_matrix # TODO: new_ivar_order right now is assumed to be one fixed order # In the future, will have to take into acocunt all reorderings -def tile_tensor(tensor, ivar_map, split_map, new_ivar_order=None): +def tile_tensor(tensor, ivar_map, split_map, new_ivar_order=None, tensor_name=""): human_readable = False tiles = dict() @@ -155,12 +162,11 @@ def tile_tensor(tensor, ivar_map, split_map, new_ivar_order=None): return tiles, tile_sizes - # Outputs COO tiles, given a COO tensor # ASSUME: tensor is a scipy.sparse.coo_matrix # TODO: new_ivar_order right now is assumed to be one fixed order # In the future, will have to take into acocunt all reorderings -def tile_coo(tensor, ivar_map, split_map, new_ivar_order=None): +def tile_coo(tensor, ivar_map, split_map, new_ivar_order=None, tensor_name=""): human_readable = False tiles = dict() @@ -239,26 +245,25 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map, hi for dim in range(order): print("tensor format: ", tensor_format) print("dim is ", dim) - print("tensor_format[dim:dim+1] is ", tensor_format[dim:dim+1]) + print("tensor_format[dim:dim+1] is ", tensor_format[dim:dim + 1]) lvl_permutation = tensor_format[dim:dim + 1][0] ivar = ivar_strs[i][dim] ivar_map[lvl_permutation] = ivar print("ivar_map is ", ivar_map) if higher_order: - tiles, tile_sizes = tile_tensor(tensor, ivar_map, split_map) + tiles, tile_sizes = tile_tensor(tensor, ivar_map, split_map, tensor_name=tensor_name) else: - tiles, tile_sizes = tile_coo(tensor, ivar_map, split_map) - + tiles, tile_sizes = tile_coo(tensor, tensor_name, ivar_map, split_map, tensor_name=tensor_name) + tiled_tensors[tensor_name] = tiles tiled_tensor_sizes[tensor_name] = tile_sizes return tiled_tensors, tiled_tensor_sizes -def get_other_tensors(app_str, tensor): - tensors = [] - tensors.append(tensor) +def get_other_tensors(app_str, tensor, other_nonempty=True): + tensors = [tensor] if "matmul" in app_str: print("Writing shifted...") @@ -283,15 +288,21 @@ def get_other_tensors(app_str, tensor): pass elif "mat_mattransmul" in app_str: print("Writing other tensors...") - rows, cols = tensor.shape # i,j - tensor_c = scipy.sparse.random(cols, 1).toarray().flatten() - tensor_d = scipy.sparse.random(rows, 1).toarray().flatten() + rows, cols = tensor.shape # i,j + tensor_c = scipy.sparse.random(cols, 1, data_rvs=np.ones).toarray().flatten() + tensor_d = scipy.sparse.random(rows, 1, data_rvs=np.ones).toarray().flatten() + + if other_nonempty: + tensor_c[0] = 1 + tensor_d[0] = 1 + + # import pdb; pdb.set_trace() tensors.append(tensor_c) tensors.append(tensor_d) elif "mat_residual" in app_str: - pass + pass elif "mat_vecmul" in app_str: pass else: @@ -307,7 +318,11 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi names, format_permutations, ivars = parse_sam_input(args.cotile) - import pdb; pdb.set_trace(); + print("cotile_multilevel_coo tensors: ", names, "\n", tensors) + + # import pdb + # pdb.set_trace() + sizes_dict = {} for i, name in enumerate(names): tensor = tensors[i] @@ -345,7 +360,9 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi # First iteration of tiling print("tensor shapes: ", tensors[0].shape, " ", tensors[1].shape, " ", tensors[2].shape) print("format_permutations: ", format_permutations) - cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map, higher_order) + cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map, + higher_order) + print("cotiled is ", cotiled) else: # recursively tile the blocks new_cotiled = {} @@ -398,13 +415,13 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi \n 'frostt' should always have 'higher_order' set as true.") parser.add_argument("--input_tensor", type=str, default=None, - help="Input tensor NAME if tensor_type is set to 'file'. \ + help="Input tensor NAME if tensor_type is set to 'file'. \ This is for use with SuiteSparse or FROSTT") parser.add_argument("--input_path", type=str, default=None, help="Input tensor path") parser.add_argument("--output_dir_path", type=str, default="./tiles", - help='Output path, directory where tiles get written to') + help='Output path, directory where tiles get written to') parser.add_argument("--hw_config", type=str, default=None, - help='Path to the hardware config yaml') + help='Path to the hardware config yaml') parser.add_argument("--cotile", type=str, default=None, help='If \ this is true cotile multiple tensors, else tile one tensor only') @@ -412,6 +429,8 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi multilevel is true there will exist more than one level of tiles, \ else only tile once') parser.add_argument("--seed", type=int, default=0, help="Random seed") + parser.add_argument("--other_nonempty", action="store_true", + help="If this is enabled, the 'other' tensors will have at least one nonzero value") args = parser.parse_args() @@ -428,22 +447,22 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi elif args.tensor_type == "ex": tensor = scipy.io.mmread(args.input_path) elif args.tensor_type == "ss": - assert args.input_tensor is not None - tensor_path = os.path.join(SUITESPARSE_PATH, args.input_tensor + ".mtx") - ss_tensor = SuiteSparseTensor(tensor_path) - tensor = inputCache.load(ss_tensor, False) + assert args.input_tensor is not None + tensor_path = os.path.join(SUITESPARSE_PATH, args.input_tensor + ".mtx") + ss_tensor = SuiteSparseTensor(tensor_path) + tensor = inputCache.load(ss_tensor, False) elif args.tensor_type == "frostt": - assert args.input_tensor is not None - assert args.higher_order + assert args.input_tensor is not None + assert args.higher_order - tensor_path = os.path.join(FROSTT_PATH, args.input_tensor + ".tns") + tensor_path = os.path.join(FROSTT_PATH, args.input_tensor + ".tns") - # FIXME: This is broken - frostt_tensor = FrosttTensor(tensor_path) - tensor = inputCache.load(ss_tensor, False) + # FIXME: This is broken + frostt_tensor = FrosttTensor(tensor_path) + tensor = inputCache.load(frostt_tensor, False) else: - raise ValueError("This choice of 'tensor_type' is unreachable") + raise ValueError("This choice of 'tensor_type' is unreachable") split_map = {"i": 16, "j": 16, "k": 16} @@ -464,14 +483,14 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi assert args.cotile is not None cotiled_tensors = cotile_multilevel_coo(args.cotile, args.hw_config, [tensor], os.path.join(args.output_dir_path, - args.cotile), + args.cotile), args.higher_order) elif args.cotile is not None: tensor2 = scipy.sparse.random(tensor.shape[0], tensor.shape[1]) names, format_permutations, ivars = parse_sam_input(args.cotile) cotiled_tensors = cotile_coo(names, [tensor, tensor2], - format_permutations, ivars, split_map, args.higher_order) + format_permutations, ivars, split_map, args.higher_order) # print(cotiled_tensors) names = cotiled_tensors.keys() @@ -489,4 +508,4 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi print(tile.shape) tns_dumper.dump(tile, mtx_path_name) else: - scipy.io.mmwrite(mtx_path_name, tile) \ No newline at end of file + scipy.io.mmwrite(mtx_path_name, tile) From 479a566cf0abb4e80396c010172833c5810269ab Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Sat, 29 Jul 2023 10:54:44 -0700 Subject: [PATCH 44/76] formatting scripts mod --- sam/sim/src/tiling/tile.py | 8 +++++--- scripts/tiling/tile_ext.sh | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index bae03922..3f259de6 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -504,8 +504,10 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi print("Output path:", mtx_path_name) if args.higher_order: - tns_dumper = PydataSparseTensorDumper() + # tns_dumper = PydataSparseTensorDumper() print(tile.shape) - tns_dumper.dump(tile, mtx_path_name) + # tns_dumper.dump(tile, mtx_path_name) + # print(np.array(tile.todense()).reshape(1,-1)) + scipy.io.mmwrite(mtx_path_name, np.array(tile.todense()).reshape(1,-1)) else: - scipy.io.mmwrite(mtx_path_name, tile) + scipy.io.mmwrite(mtx_path_name, tile) \ No newline at end of file diff --git a/scripts/tiling/tile_ext.sh b/scripts/tiling/tile_ext.sh index 16126e12..36ce32ee 100755 --- a/scripts/tiling/tile_ext.sh +++ b/scripts/tiling/tile_ext.sh @@ -31,5 +31,7 @@ for b in ${!BENCHMARKS[@]}; do echo "Generating input format files for $tiles_path..." python3 $basedir/scripts/formatting/datastructure_suitesparse.py -n temp -hw -b $bench --input $basedir/tiles/$bench/mtx/ --output_dir_path $basedir/tiles/$bench/formatted --tiles + # $basedir/compiler/taco/build/bin/taco-test sam.pack_ss01 + # python3 $basedir/scripts/formatting/datastructure_tns.py -n rel5 -f ss01 -b $bench -hw done From 8846e91316b1e6f14bbad4b6c676e0d6a61a82bf Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Sat, 29 Jul 2023 11:05:39 -0700 Subject: [PATCH 45/76] mtx vs tns file for vector tiling --- sam/sim/src/tiling/tile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 3f259de6..bd964ab0 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -498,7 +498,8 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi for tile_id, tile in cotiled_tensors[name].items(): [str(item) for item in tile_id] filename = "tensor_" + name + "_tile_" + "_".join([str(item) for item in tile_id]) - filename += ".tns" if args.higher_order else ".mtx" + # filename += ".tns" if args.higher_order else ".mtx" + filename += ".mtx" mtx_path_name = os.path.join(output_mtx_name, filename) print(tile) print("Output path:", mtx_path_name) From 5a0998f6c1acbd1915d5cd20f53dd73739f51501 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Sat, 29 Jul 2023 11:47:41 -0700 Subject: [PATCH 46/76] correct tile.py --- sam/sim/src/tiling/tile.py | 230 ++++++++----------------------------- 1 file changed, 45 insertions(+), 185 deletions(-) diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index bd964ab0..88be95f2 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -1,6 +1,5 @@ import numpy as np import scipy.sparse -import scipy.io import os import argparse import ast @@ -8,32 +7,28 @@ import copy import pickle import random -import sparse -import sys +from itertools import compress from pathlib import Path -from sam.util import SUITESPARSE_PATH, SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter, \ - FROSTT_PATH, FrosttTensor, PydataSparseTensorDumper, InputCacheTensor -from sam.sim.src.tiling.process_expr import parse_all - -# FIXME: This should not be here... Set your SAM_HOME directory +import sys custom_path = '/home/avb03/sam' sys.path.append(custom_path) -SAM_STRS = {"matmul_kij": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)", +from sam.util import SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter +from sam.sim.src.tiling.process_expr import parse_all, update_dict + +SAM_STRS = {"matmul_kij": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)", "matmul_ikj": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss -s=reorder(i,k,j)", "matmul_ijk": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemadd": "X(i,j)=B(i,j)+C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemmul": "X(i,j)=B(i,j)*C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_mattransmul": "X(i,j)=B(j,i)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss:0 -f=d:ss:0 -s=reorder(i,j)"} - def print_dict(dd): for k, v in dd.items(): print(k, ":", v) - def print_ast(node): for child in ast.iter_child_nodes(node): print_ast(child) @@ -91,82 +86,14 @@ def parse_sam_input(string): permutations = [list(map(int, dictionary[tensor]["perm"])) for tensor in tensors] ivars = get_ivars(tensors, str_arr[0]) ivars = [ivars[tensor] for tensor in tensors] - - print("PARSE SAM INPUTS", tensors) return tensors, permutations, ivars -# Outputs Pydata/sparse tensor tiles, given a pydata/sparse tensor (DOK or COO) -# ASSUME: tensor is a scipy.sparse.coo_matrix -# TODO: new_ivar_order right now is assumed to be one fixed order -# In the future, will have to take into acocunt all reorderings -def tile_tensor(tensor, ivar_map, split_map, new_ivar_order=None, tensor_name=""): - human_readable = False - - tiles = dict() - tile_sizes = dict() - order = len(tensor.shape) - - tensor_coo = sparse.COO(tensor) - tensor_points = sparse.DOK.from_coo(tensor_coo) - - print("ivar_map: ", ivar_map) - print("split_map: ", split_map) - print("order = ", order) - - new_shape = [] - for lvl in range(order): - ivar = ivar_map[lvl] - sf = split_map[ivar] - new_shape.append(sf) - - for crds, val in tensor_points.data.items(): - point = list(crds) - - new_point = [] - tile_id = [] - for lvl in range(order): - ivar = ivar_map[lvl] - sf = split_map[ivar] - - new_point.append(point[lvl] % sf) - tile_id.append(int(point[lvl] / sf)) - - # Add in value to the new_point as well - new_point.append(val) - tile_id = tuple(tile_id) - - if tile_id in tiles: - tiles[tile_id].append(new_point) - else: - tiles[tile_id] = [new_point] - - # sort the new coo lists - for key, val in tiles.items(): - if human_readable: - dok = sorted(val) - else: - dok = sparse.DOK(tuple(new_shape)) - for point in val: - dok[tuple(point[0:-1])] = point[-1] - - tiles[key] = dok - - for tile_id, tile_dok in tiles.items(): - tile = tile_dok.to_coo() - # FIXME: This size number isn't correct for tensor tiles - nonempty_rows = tile.nnz - nonempty_row_ind = np.where(nonempty_rows > 0)[0] - tile_sizes[tile_id] = tile.nnz * 2 + 2 * len(nonempty_row_ind) + 3 - - return tiles, tile_sizes - - # Outputs COO tiles, given a COO tensor # ASSUME: tensor is a scipy.sparse.coo_matrix # TODO: new_ivar_order right now is assumed to be one fixed order # In the future, will have to take into acocunt all reorderings -def tile_coo(tensor, ivar_map, split_map, new_ivar_order=None, tensor_name=""): +def tile_coo(tensor, ivar_map, split_map, new_ivar_order=None): human_readable = False tiles = dict() @@ -232,7 +159,7 @@ def tile_coo(tensor, ivar_map, split_map, new_ivar_order=None, tensor_name=""): # permutation_strs: list of permutation_strs [ss01, ss10] following tensor_names (from SAM) # ivar_strs: list of ivar_strs ["ik", "kj"] following tensor_names (from SAM) # split_map: dictionary of split factors (from hardware) -def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map, higher_order=False): +def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map): tiled_tensors = dict() tiled_tensor_sizes = dict() @@ -245,25 +172,22 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map, hi for dim in range(order): print("tensor format: ", tensor_format) print("dim is ", dim) - print("tensor_format[dim:dim+1] is ", tensor_format[dim:dim + 1]) + print("tensor_format[dim:dim+1] is ", tensor_format[dim:dim+1]) lvl_permutation = tensor_format[dim:dim + 1][0] ivar = ivar_strs[i][dim] ivar_map[lvl_permutation] = ivar print("ivar_map is ", ivar_map) - if higher_order: - tiles, tile_sizes = tile_tensor(tensor, ivar_map, split_map, tensor_name=tensor_name) - else: - tiles, tile_sizes = tile_coo(tensor, tensor_name, ivar_map, split_map, tensor_name=tensor_name) - + tiles, tile_sizes = tile_coo(tensor, ivar_map, split_map) tiled_tensors[tensor_name] = tiles tiled_tensor_sizes[tensor_name] = tile_sizes return tiled_tensors, tiled_tensor_sizes -def get_other_tensors(app_str, tensor, other_nonempty=True): - tensors = [tensor] +def get_other_tensors(app_str, tensor): + tensors = [] + tensors.append(tensor) if "matmul" in app_str: print("Writing shifted...") @@ -288,21 +212,15 @@ def get_other_tensors(app_str, tensor, other_nonempty=True): pass elif "mat_mattransmul" in app_str: print("Writing other tensors...") - rows, cols = tensor.shape # i,j - tensor_c = scipy.sparse.random(cols, 1, data_rvs=np.ones).toarray().flatten() - tensor_d = scipy.sparse.random(rows, 1, data_rvs=np.ones).toarray().flatten() - - if other_nonempty: - tensor_c[0] = 1 - tensor_d[0] = 1 - - # import pdb; pdb.set_trace() + rows, cols = tensor.shape # i,j + tensor_c = scipy.sparse.random(cols, 1).toarray().flatten() + tensor_d = scipy.sparse.random(rows, 1).toarray().flatten() tensors.append(tensor_c) tensors.append(tensor_d) elif "mat_residual" in app_str: - pass + pass elif "mat_vecmul" in app_str: pass else: @@ -313,16 +231,12 @@ def get_other_tensors(app_str, tensor, other_nonempty=True): return tensors -def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, higher_order=False): +def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): tensors = get_other_tensors(app_str, tensors[0]) names, format_permutations, ivars = parse_sam_input(args.cotile) - print("cotile_multilevel_coo tensors: ", names, "\n", tensors) - - # import pdb - # pdb.set_trace() - + import pdb; pdb.set_trace(); sizes_dict = {} for i, name in enumerate(names): tensor = tensors[i] @@ -360,9 +274,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi # First iteration of tiling print("tensor shapes: ", tensors[0].shape, " ", tensors[1].shape, " ", tensors[2].shape) print("format_permutations: ", format_permutations) - cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map, - higher_order) - print("cotiled is ", cotiled) + cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map) else: # recursively tile the blocks new_cotiled = {} @@ -372,13 +284,9 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi new_cotiled[name] = {} new_cotiled_sizes[name] = {} for tile_id, tile in cotiled[name].items(): - if higher_order: - tile_in_coo = tile.to_coo() - else: - tile_in_coo = tile.tocoo() - new_cotiled_temp, new_cotiled_sizes_temp = cotile_coo(name, [tile_in_coo], + new_cotiled_temp, new_cotiled_sizes_temp = cotile_coo(name, [tile.tocoo()], [format_permutations[i]], [ivars[i]], - split_map, higher_order) + split_map) for kk, vv in copy.deepcopy(new_cotiled_temp)[name].items(): new_tile_id = tuple(list(tile_id) + list(kk)) @@ -401,68 +309,31 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi inputCache = InputCacheSuiteSparse() if __name__ == "__main__": - parser = argparse.ArgumentParser(description='script that tiles tensors') - parser.add_argument("--tensor_type", choices=['ex', 'gen', 'file', 'ss', 'frostt'], help='The \ - tiles, tile_sizes = tile_coo(tensor, ivar_map, split_map) \ - type of tensor to tile: extensor(ex), generated (gen), \ - SuiteSparse (ss), FROSTT (frostt), or input file (file)') - parser.add_argument("--higher_order", action="store_true", help="If \ - true then we want to process a higher-order tensor. With higher-order set to true, if \ - 'tensor_type' is: \ - \n 'gen' then a 3-tensor is generated instead of matrix. \ - \n 'file' then a .tns file is read instead of a .mtx file. \ - \n 'ss' then other matrices used with SuiteSparse are .tns instead of .mtx files. \ - \n 'frostt' should always have 'higher_order' set as true.") - - parser.add_argument("--input_tensor", type=str, default=None, - help="Input tensor NAME if tensor_type is set to 'file'. \ - This is for use with SuiteSparse or FROSTT") - parser.add_argument("--input_path", type=str, default=None, help="Input tensor path") - parser.add_argument("--output_dir_path", type=str, default="./tiles", - help='Output path, directory where tiles get written to') - parser.add_argument("--hw_config", type=str, default=None, - help='Path to the hardware config yaml') - - parser.add_argument("--cotile", type=str, default=None, help='If \ - this is true cotile multiple tensors, else tile one tensor only') - parser.add_argument("--multilevel", action="store_true", help='If \ - multilevel is true there will exist more than one level of tiles, \ - else only tile once') - parser.add_argument("--seed", type=int, default=0, help="Random seed") - parser.add_argument("--other_nonempty", action="store_true", - help="If this is enabled, the 'other' tensors will have at least one nonzero value") + parser = argparse.ArgumentParser(description='Tile matrices') + parser.add_argument("--input_tensor", type=str, default=None) + parser.add_argument("--gen_tensor", action="store_false") + parser.add_argument("--cotile", type=str, default=None) + parser.add_argument("--output_dir_path", type=str, default="./tiles") + parser.add_argument("--hw_config", type=str, default=None) + parser.add_argument("--multilevel", action="store_true") + parser.add_argument("--input_path", type=str, default=None) + parser.add_argument("--extensor", action="store_true") args = parser.parse_args() - random.seed(args.seed) - np.random.seed(args.seed) - tensor = None cwd = os.getcwd() - if args.tensor_type == "gen": - if args.higher_order: - tensor = sparse.COO(sparse.random((16, 16, 16))) - else: - tensor = scipy.sparse.random(16, 16) - elif args.tensor_type == "ex": + if args.gen_tensor: + tensor = scipy.sparse.random(16, 16) + elif args.extensor: tensor = scipy.io.mmread(args.input_path) - elif args.tensor_type == "ss": + else: assert args.input_tensor is not None - tensor_path = os.path.join(SUITESPARSE_PATH, args.input_tensor + ".mtx") + SS_PATH = os.getenv('SUITESPARSE_PATH', default=os.path.join(cwd, 'suitesparse')) + # print("PATH:", SS_PATH) + tensor_path = os.path.join(SS_PATH, args.input_tensor + ".mtx") ss_tensor = SuiteSparseTensor(tensor_path) tensor = inputCache.load(ss_tensor, False) - elif args.tensor_type == "frostt": - assert args.input_tensor is not None - assert args.higher_order - - tensor_path = os.path.join(FROSTT_PATH, args.input_tensor + ".tns") - - # FIXME: This is broken - frostt_tensor = FrosttTensor(tensor_path) - tensor = inputCache.load(frostt_tensor, False) - - else: - raise ValueError("This choice of 'tensor_type' is unreachable") split_map = {"i": 16, "j": 16, "k": 16} @@ -474,6 +345,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi print("TILES:") print_dict(tiles) else: + output_mtx_name = os.path.join(args.output_dir_path, args.cotile, "mtx") output_mtx_path = Path(output_mtx_name) output_mtx_path.mkdir(parents=True, exist_ok=True) @@ -482,33 +354,21 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi if args.multilevel: assert args.cotile is not None cotiled_tensors = cotile_multilevel_coo(args.cotile, args.hw_config, [tensor], - os.path.join(args.output_dir_path, - args.cotile), - args.higher_order) + os.path.join(args.output_dir_path, args.cotile)) elif args.cotile is not None: tensor2 = scipy.sparse.random(tensor.shape[0], tensor.shape[1]) names, format_permutations, ivars = parse_sam_input(args.cotile) - cotiled_tensors = cotile_coo(names, [tensor, tensor2], - format_permutations, ivars, split_map, args.higher_order) + cotiled_tensors = cotile_coo(names, [tensor, tensor2], format_permutations, ivars, split_map) # print(cotiled_tensors) names = cotiled_tensors.keys() for name in names: for tile_id, tile in cotiled_tensors[name].items(): [str(item) for item in tile_id] - filename = "tensor_" + name + "_tile_" + "_".join([str(item) for item in tile_id]) - # filename += ".tns" if args.higher_order else ".mtx" - filename += ".mtx" + filename = "tensor_" + name + "_tile_" + "_".join([str(item) for item in tile_id]) + ".mtx" mtx_path_name = os.path.join(output_mtx_name, filename) print(tile) - print("Output path:", mtx_path_name) - - if args.higher_order: - # tns_dumper = PydataSparseTensorDumper() - print(tile.shape) - # tns_dumper.dump(tile, mtx_path_name) - # print(np.array(tile.todense()).reshape(1,-1)) - scipy.io.mmwrite(mtx_path_name, np.array(tile.todense()).reshape(1,-1)) - else: - scipy.io.mmwrite(mtx_path_name, tile) \ No newline at end of file + print(mtx_path_name, cwd) + scipy.io.mmwrite(mtx_path_name, tile) + print(os.path.exists(mtx_path_name)) \ No newline at end of file From 91ad37f88f71a0633e641192d4e87e9392f94498 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Mon, 31 Jul 2023 13:37:25 -0700 Subject: [PATCH 47/76] orig tile files --- sam/sim/src/tiling/tile.py | 252 +++++++++++++++++++----- scripts/formatting/datastructure_tns.py | 2 +- 2 files changed, 204 insertions(+), 50 deletions(-) diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 88be95f2..10cf469c 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -1,5 +1,6 @@ import numpy as np import scipy.sparse +import scipy.io import os import argparse import ast @@ -7,28 +8,33 @@ import copy import pickle import random +import sparse +import sys -from itertools import compress from pathlib import Path -import sys +from sam.util import SUITESPARSE_PATH, SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter, \ + FROSTT_PATH, FrosttTensor, PydataSparseTensorDumper, InputCacheTensor +from sam.sim.src.tiling.process_expr import parse_all + +# FIXME: This should not be here... Set your SAM_HOME directory custom_path = '/home/avb03/sam' sys.path.append(custom_path) -from sam.util import SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter -from sam.sim.src.tiling.process_expr import parse_all, update_dict - -SAM_STRS = {"matmul_kij": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)", +SAM_STRS = {"matmul_kij": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss:1,0 -f=C:ss -s=reorder(k,i,j)", "matmul_ikj": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss -s=reorder(i,k,j)", "matmul_ijk": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemadd": "X(i,j)=B(i,j)+C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemmul": "X(i,j)=B(i,j)*C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", - "mat_mattransmul": "X(i,j)=B(j,i)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss:0 -f=d:ss:0 -s=reorder(i,j)"} + "mat_mattransmul": "X(i,j)=C(j,i)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss:0 -f=d:ss:0 -s=reorder(i,j)", + "mat_vecmul_ij" : "X(i,j)=B(i,j)*c(j) -f=X:ss -f=B:ss -f=c:ss:0 -s=reorder(i,j)"} + def print_dict(dd): for k, v in dd.items(): print(k, ":", v) + def print_ast(node): for child in ast.iter_child_nodes(node): print_ast(child) @@ -86,14 +92,82 @@ def parse_sam_input(string): permutations = [list(map(int, dictionary[tensor]["perm"])) for tensor in tensors] ivars = get_ivars(tensors, str_arr[0]) ivars = [ivars[tensor] for tensor in tensors] + + print("PARSE SAM INPUTS", tensors) return tensors, permutations, ivars +# Outputs Pydata/sparse tensor tiles, given a pydata/sparse tensor (DOK or COO) +# ASSUME: tensor is a scipy.sparse.coo_matrix +# TODO: new_ivar_order right now is assumed to be one fixed order +# In the future, will have to take into acocunt all reorderings +def tile_tensor(tensor, ivar_map, split_map, new_ivar_order=None, tensor_name=""): + human_readable = False + + tiles = dict() + tile_sizes = dict() + order = len(tensor.shape) + + tensor_coo = sparse.COO(tensor) + tensor_points = sparse.DOK.from_coo(tensor_coo) + + print("ivar_map: ", ivar_map) + print("split_map: ", split_map) + print("order = ", order) + + new_shape = [] + for lvl in range(order): + ivar = ivar_map[lvl] + sf = split_map[ivar] + new_shape.append(sf) + + for crds, val in tensor_points.data.items(): + point = list(crds) + + new_point = [] + tile_id = [] + for lvl in range(order): + ivar = ivar_map[lvl] + sf = split_map[ivar] + + new_point.append(point[lvl] % sf) + tile_id.append(int(point[lvl] / sf)) + + # Add in value to the new_point as well + new_point.append(val) + tile_id = tuple(tile_id) + + if tile_id in tiles: + tiles[tile_id].append(new_point) + else: + tiles[tile_id] = [new_point] + + # sort the new coo lists + for key, val in tiles.items(): + if human_readable: + dok = sorted(val) + else: + dok = sparse.DOK(tuple(new_shape)) + for point in val: + dok[tuple(point[0:-1])] = point[-1] + + tiles[key] = dok + + for tile_id, tile_dok in tiles.items(): + tile = tile_dok.to_coo() + # FIXME: This size number isn't correct for tensor tiles + nonempty_rows = tile.nnz + nonempty_row_ind = np.where(nonempty_rows > 0)[0] + tile_sizes[tile_id] = tile.nnz * 2 + 2 * len(nonempty_row_ind) + 3 + + return tiles, tile_sizes + + # Outputs COO tiles, given a COO tensor # ASSUME: tensor is a scipy.sparse.coo_matrix # TODO: new_ivar_order right now is assumed to be one fixed order # In the future, will have to take into acocunt all reorderings -def tile_coo(tensor, ivar_map, split_map, new_ivar_order=None): +def tile_coo(tensor, ivar_map, split_map, new_ivar_order=None, tensor_name=""): human_readable = False tiles = dict() @@ -159,7 +233,7 @@ def tile_coo(tensor, ivar_map, split_map, new_ivar_order=None): # permutation_strs: list of permutation_strs [ss01, ss10] following tensor_names (from SAM) # ivar_strs: list of ivar_strs ["ik", "kj"] following tensor_names (from SAM) # split_map: dictionary of split factors (from hardware) -def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map): +def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map, higher_order=False): tiled_tensors = dict() tiled_tensor_sizes = dict() @@ -172,22 +246,25 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map): for dim in range(order): print("tensor format: ", tensor_format) print("dim is ", dim) - print("tensor_format[dim:dim+1] is ", tensor_format[dim:dim+1]) + print("tensor_format[dim:dim+1] is ", tensor_format[dim:dim + 1]) lvl_permutation = tensor_format[dim:dim + 1][0] ivar = ivar_strs[i][dim] ivar_map[lvl_permutation] = ivar print("ivar_map is ", ivar_map) - tiles, tile_sizes = tile_coo(tensor, ivar_map, split_map) + if higher_order: + tiles, tile_sizes = tile_tensor(tensor, ivar_map, split_map, tensor_name=tensor_name) + else: + tiles, tile_sizes = tile_coo(tensor, tensor_name, ivar_map, split_map, tensor_name=tensor_name) + tiled_tensors[tensor_name] = tiles tiled_tensor_sizes[tensor_name] = tile_sizes return tiled_tensors, tiled_tensor_sizes -def get_other_tensors(app_str, tensor): - tensors = [] - tensors.append(tensor) +def get_other_tensors(app_str, tensor, other_nonempty=True): + tensors = [tensor] if "matmul" in app_str: print("Writing shifted...") @@ -212,17 +289,32 @@ def get_other_tensors(app_str, tensor): pass elif "mat_mattransmul" in app_str: print("Writing other tensors...") - rows, cols = tensor.shape # i,j - tensor_c = scipy.sparse.random(cols, 1).toarray().flatten() - tensor_d = scipy.sparse.random(rows, 1).toarray().flatten() + rows, cols = tensor.shape # i,j + tensor_c = scipy.sparse.random(cols, 1, data_rvs=np.ones).toarray().flatten() + # tensor_d = scipy.sparse.random(rows, 1, density=1.0, data_rvs=np.ones).toarray().flatten() + tensor_d = scipy.sparse.random(rows, 1, data_rvs=np.ones).toarray().flatten() + + if other_nonempty: + tensor_c[0] = 1 + tensor_d[0] = 1 + + # import pdb; pdb.set_trace() tensors.append(tensor_c) tensors.append(tensor_d) elif "mat_residual" in app_str: - pass - elif "mat_vecmul" in app_str: pass + elif "mat_vecmul" in app_str: + print("Writing other tensors...") + rows, cols = tensor.shape + tensor_c = scipy.sparse.random(cols, 1, data_rvs=np.ones).toarray().flatten() + + if other_nonempty: + tensor_c[0] = 1 + + tensors.append(tensor_c) + else: tensor2 = scipy.sparse.random(tensor.shape[0], tensor.shape[1]) tensors.append(tensor2) @@ -231,12 +323,16 @@ def get_other_tensors(app_str, tensor): return tensors -def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): +def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, higher_order=False): tensors = get_other_tensors(app_str, tensors[0]) names, format_permutations, ivars = parse_sam_input(args.cotile) - import pdb; pdb.set_trace(); + print("cotile_multilevel_coo tensors: ", names, "\n", tensors) + + # import pdb + # pdb.set_trace() + sizes_dict = {} for i, name in enumerate(names): tensor = tensors[i] @@ -272,9 +368,8 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): if cotiled is None: # First iteration of tiling - print("tensor shapes: ", tensors[0].shape, " ", tensors[1].shape, " ", tensors[2].shape) - print("format_permutations: ", format_permutations) - cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map) + cotiled, cotiled_sizes = cotile_coo(names, tensors, format_permutations, ivars, split_map, + higher_order) else: # recursively tile the blocks new_cotiled = {} @@ -284,9 +379,13 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): new_cotiled[name] = {} new_cotiled_sizes[name] = {} for tile_id, tile in cotiled[name].items(): - new_cotiled_temp, new_cotiled_sizes_temp = cotile_coo(name, [tile.tocoo()], + if higher_order: + tile_in_coo = tile.to_coo() + else: + tile_in_coo = tile.tocoo() + new_cotiled_temp, new_cotiled_sizes_temp = cotile_coo(name, [tile_in_coo], [format_permutations[i]], [ivars[i]], - split_map) + split_map, higher_order) for kk, vv in copy.deepcopy(new_cotiled_temp)[name].items(): new_tile_id = tuple(list(tile_id) + list(kk)) @@ -309,31 +408,68 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): inputCache = InputCacheSuiteSparse() if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Tile matrices') - parser.add_argument("--input_tensor", type=str, default=None) - parser.add_argument("--gen_tensor", action="store_false") - parser.add_argument("--cotile", type=str, default=None) - parser.add_argument("--output_dir_path", type=str, default="./tiles") - parser.add_argument("--hw_config", type=str, default=None) - parser.add_argument("--multilevel", action="store_true") - parser.add_argument("--input_path", type=str, default=None) - parser.add_argument("--extensor", action="store_true") + parser = argparse.ArgumentParser(description='script that tiles tensors') + parser.add_argument("--tensor_type", choices=['ex', 'gen', 'file', 'ss', 'frostt'], help='The \ + tiles, tile_sizes = tile_coo(tensor, ivar_map, split_map) \ + type of tensor to tile: extensor(ex), generated (gen), \ + SuiteSparse (ss), FROSTT (frostt), or input file (file)') + parser.add_argument("--higher_order", action="store_true", help="If \ + true then we want to process a higher-order tensor. With higher-order set to true, if \ + 'tensor_type' is: \ + \n 'gen' then a 3-tensor is generated instead of matrix. \ + \n 'file' then a .tns file is read instead of a .mtx file. \ + \n 'ss' then other matrices used with SuiteSparse are .tns instead of .mtx files. \ + \n 'frostt' should always have 'higher_order' set as true.") + + parser.add_argument("--input_tensor", type=str, default=None, + help="Input tensor NAME if tensor_type is set to 'file'. \ + This is for use with SuiteSparse or FROSTT") + parser.add_argument("--input_path", type=str, default=None, help="Input tensor path") + parser.add_argument("--output_dir_path", type=str, default="./tiles", + help='Output path, directory where tiles get written to') + parser.add_argument("--hw_config", type=str, default=None, + help='Path to the hardware config yaml') + + parser.add_argument("--cotile", type=str, default=None, help='If \ + this is true cotile multiple tensors, else tile one tensor only') + parser.add_argument("--multilevel", action="store_true", help='If \ + multilevel is true there will exist more than one level of tiles, \ + else only tile once') + parser.add_argument("--seed", type=int, default=0, help="Random seed") + parser.add_argument("--other_nonempty", action="store_true", + help="If this is enabled, the 'other' tensors will have at least one nonzero value") args = parser.parse_args() + random.seed(args.seed) + np.random.seed(args.seed) + tensor = None cwd = os.getcwd() - if args.gen_tensor: - tensor = scipy.sparse.random(16, 16) - elif args.extensor: + if args.tensor_type == "gen": + if args.higher_order: + tensor = sparse.COO(sparse.random((16, 16, 16))) + else: + tensor = scipy.sparse.random(16, 16) + elif args.tensor_type == "ex": tensor = scipy.io.mmread(args.input_path) - else: + elif args.tensor_type == "ss": assert args.input_tensor is not None - SS_PATH = os.getenv('SUITESPARSE_PATH', default=os.path.join(cwd, 'suitesparse')) - # print("PATH:", SS_PATH) - tensor_path = os.path.join(SS_PATH, args.input_tensor + ".mtx") + tensor_path = os.path.join(SUITESPARSE_PATH, args.input_tensor + ".mtx") ss_tensor = SuiteSparseTensor(tensor_path) tensor = inputCache.load(ss_tensor, False) + elif args.tensor_type == "frostt": + assert args.input_tensor is not None + assert args.higher_order + + tensor_path = os.path.join(FROSTT_PATH, args.input_tensor + ".tns") + + # FIXME: This is broken + frostt_tensor = FrosttTensor(tensor_path) + tensor = inputCache.load(frostt_tensor, False) + + else: + raise ValueError("This choice of 'tensor_type' is unreachable") split_map = {"i": 16, "j": 16, "k": 16} @@ -345,7 +481,6 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): print("TILES:") print_dict(tiles) else: - output_mtx_name = os.path.join(args.output_dir_path, args.cotile, "mtx") output_mtx_path = Path(output_mtx_name) output_mtx_path.mkdir(parents=True, exist_ok=True) @@ -354,21 +489,40 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path): if args.multilevel: assert args.cotile is not None cotiled_tensors = cotile_multilevel_coo(args.cotile, args.hw_config, [tensor], - os.path.join(args.output_dir_path, args.cotile)) + os.path.join(args.output_dir_path, + args.cotile), + args.higher_order) elif args.cotile is not None: tensor2 = scipy.sparse.random(tensor.shape[0], tensor.shape[1]) names, format_permutations, ivars = parse_sam_input(args.cotile) - cotiled_tensors = cotile_coo(names, [tensor, tensor2], format_permutations, ivars, split_map) + cotiled_tensors = cotile_coo(names, [tensor, tensor2], + format_permutations, ivars, split_map, args.higher_order) # print(cotiled_tensors) names = cotiled_tensors.keys() for name in names: for tile_id, tile in cotiled_tensors[name].items(): [str(item) for item in tile_id] - filename = "tensor_" + name + "_tile_" + "_".join([str(item) for item in tile_id]) + ".mtx" + filename = "tensor_" + name + "_tile_" + "_".join([str(item) for item in tile_id]) + # filename += ".tns" if args.higher_order else ".mtx" + filename += ".mtx" mtx_path_name = os.path.join(output_mtx_name, filename) print(tile) - print(mtx_path_name, cwd) - scipy.io.mmwrite(mtx_path_name, tile) - print(os.path.exists(mtx_path_name)) \ No newline at end of file + print("Output path:", mtx_path_name) + + if args.higher_order: + # tns_dumper = PydataSparseTensorDumper() + print(tile.shape) + # print(tile) + # tns_dumper.dump(tile, mtx_path_name) + + if len(tile.shape) == 1: + # print(np.array(tile.todense()).reshape(1,-1)) + scipy.io.mmwrite(mtx_path_name, scipy.sparse.coo_matrix(tile.todense())) + else: + # print(tile.todense()) + scipy.io.mmwrite(mtx_path_name, scipy.sparse.coo_matrix(tile.todense())) + + else: + scipy.io.mmwrite(mtx_path_name, tile) \ No newline at end of file diff --git a/scripts/formatting/datastructure_tns.py b/scripts/formatting/datastructure_tns.py index be0fa6c8..db9e1951 100644 --- a/scripts/formatting/datastructure_tns.py +++ b/scripts/formatting/datastructure_tns.py @@ -10,7 +10,7 @@ from pathlib import Path from sam.util import parse_taco_format -from util import FormatWriter, SuiteSparseTensor, InputCacheSuiteSparse +from scripts.util.util import FormatWriter, SuiteSparseTensor, InputCacheSuiteSparse # custom_path = '/nobackup/jadivara/sam/sam/util.py' # sys.path.append(custom_path) # from import SUITESPARSE_FORMATTED_PATH, ScipyTensorShifter From 3947620230754b7a5c1fd20e546a9efd20e88d07 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Mon, 31 Jul 2023 14:39:39 -0700 Subject: [PATCH 48/76] Add in fixes to get tensor apps working --- sam/sim/src/tiling/tile.py | 49 +++++++++++++++++++++++++++----------- sam/util.py | 2 +- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 10cf469c..ad430463 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -27,7 +27,8 @@ "mat_elemadd": "X(i,j)=B(i,j)+C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemmul": "X(i,j)=B(i,j)*C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_mattransmul": "X(i,j)=C(j,i)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss:0 -f=d:ss:0 -s=reorder(i,j)", - "mat_vecmul_ij" : "X(i,j)=B(i,j)*c(j) -f=X:ss -f=B:ss -f=c:ss:0 -s=reorder(i,j)"} + "mat_vecmul_ij": "X(i,j)=B(i,j)*c(j) -f=X:ss -f=B:ss -f=c:ss:0 -s=reorder(i,j)", + "tensor3_ttv": "X(i,j)=B(i,j,k)*c(k) -f=X:ss -f=B:sss -f=c:s"} def print_dict(dd): @@ -229,7 +230,7 @@ def tile_coo(tensor, ivar_map, split_map, new_ivar_order=None, tensor_name=""): # tensor_names: list of tensor names [B,C,D] (from SAM) -# tensors: list of scipy.sparse.coo_matrix following tensor_names (from SAM) +# tensors: list of sparse COO tensors (either Scipy or Pydata/Sparse) following tensor_names (from SAM) # permutation_strs: list of permutation_strs [ss01, ss10] following tensor_names (from SAM) # ivar_strs: list of ivar_strs ["ik", "kj"] following tensor_names (from SAM) # split_map: dictionary of split factors (from hardware) @@ -237,6 +238,7 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map, hi tiled_tensors = dict() tiled_tensor_sizes = dict() + print(tensor_names, tensors, permutation_strs, ivar_strs, split_map) for i, tensor in enumerate(tensors): tensor_name = tensor_names[i] tensor_format = permutation_strs[i] @@ -245,6 +247,7 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map, hi print("order is ", order) for dim in range(order): print("tensor format: ", tensor_format) + print("dim is ", dim) print("tensor_format[dim:dim+1] is ", tensor_format[dim:dim + 1]) lvl_permutation = tensor_format[dim:dim + 1][0] @@ -266,6 +269,7 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map, hi def get_other_tensors(app_str, tensor, other_nonempty=True): tensors = [tensor] + if "matmul" in app_str: print("Writing shifted...") shifted = ScipyTensorShifter().shiftLastMode(tensor) @@ -312,13 +316,22 @@ def get_other_tensors(app_str, tensor, other_nonempty=True): if other_nonempty: tensor_c[0] = 1 - + tensors.append(tensor_c) + elif "tensor3_ttv" in app_str: + print("Writing other tensors...") + size_i, size_j, size_k = tensor.shape # i,j,k + tensor_c = scipy.sparse.random(size_k, 1, data_rvs=np.ones).toarray().flatten() + + if other_nonempty: + tensor_c[0] = 1 + + tensors.append(tensor_c) else: - tensor2 = scipy.sparse.random(tensor.shape[0], tensor.shape[1]) - tensors.append(tensor2) - # raise NotImplementedError + # tensor2 = scipy.sparse.random(tensor.shape[0], tensor.shape[1]) + # tensors.append(tensor2) + raise NotImplementedError return tensors @@ -405,7 +418,8 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi print(exc) -inputCache = InputCacheSuiteSparse() +inputCacheSuiteSparse = InputCacheSuiteSparse() +inputCacheTensor = InputCacheTensor() if __name__ == "__main__": parser = argparse.ArgumentParser(description='script that tiles tensors') @@ -446,6 +460,8 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi tensor = None cwd = os.getcwd() + inputCache = None + if args.tensor_type == "gen": if args.higher_order: tensor = sparse.COO(sparse.random((16, 16, 16))) @@ -455,6 +471,8 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi tensor = scipy.io.mmread(args.input_path) elif args.tensor_type == "ss": assert args.input_tensor is not None + + inputCache = inputCacheSuiteSparse tensor_path = os.path.join(SUITESPARSE_PATH, args.input_tensor + ".mtx") ss_tensor = SuiteSparseTensor(tensor_path) tensor = inputCache.load(ss_tensor, False) @@ -462,6 +480,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi assert args.input_tensor is not None assert args.higher_order + inputCache = inputCacheTensor tensor_path = os.path.join(FROSTT_PATH, args.input_tensor + ".tns") # FIXME: This is broken @@ -512,12 +531,14 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi print("Output path:", mtx_path_name) if args.higher_order: - # tns_dumper = PydataSparseTensorDumper() - print(tile.shape) - # print(tile) - # tns_dumper.dump(tile, mtx_path_name) - - if len(tile.shape) == 1: + if args.tensor_type == "frostt": + tns_dumper = PydataSparseTensorDumper() + print(tile.shape) + print(tile) + tns_dumper.dump(tile, mtx_path_name) + + # FIXME: (owhsu) Why did avb03 add this in? + elif len(tile.shape) == 1: # print(np.array(tile.todense()).reshape(1,-1)) scipy.io.mmwrite(mtx_path_name, scipy.sparse.coo_matrix(tile.todense())) else: @@ -525,4 +546,4 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi scipy.io.mmwrite(mtx_path_name, scipy.sparse.coo_matrix(tile.todense())) else: - scipy.io.mmwrite(mtx_path_name, tile) \ No newline at end of file + scipy.io.mmwrite(mtx_path_name, tile) diff --git a/sam/util.py b/sam/util.py index b92f8052..fbe308c9 100644 --- a/sam/util.py +++ b/sam/util.py @@ -534,7 +534,7 @@ def __init__(self): self.lastName = None self.tensor = None - def load(self, tensor, suiteSparse, cast, format_str): + def load(self, tensor, cast): if self.lastName == str(tensor): return self.tensor else: From 588a1c0eb0f86601a6c76856e6c0eb3662073468 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 4 Aug 2023 10:00:32 -0700 Subject: [PATCH 49/76] Update pydata sparse import --- sam/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sam/util.py b/sam/util.py index 96cc15c5..67d3fcf4 100644 --- a/sam/util.py +++ b/sam/util.py @@ -7,7 +7,7 @@ import shutil import numpy as np import math -import pydata +import sparse from pathlib import Path from dataclasses import dataclass From 6aa9f6fcc1e0b3344d0949e723d76fd528d89c07 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Tue, 8 Aug 2023 14:48:56 -0700 Subject: [PATCH 50/76] Add in pydata/sparse and update gitignore --- .gitignore | 5 +++++ requirements.txt | 1 + 2 files changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index 40366917..e3c498b9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,10 @@ __pycache__/ # Temporary output files *.swp *.swo +*.swn *.txt *.out +*.log # Generated Python Package files *.egg-info/ @@ -55,3 +57,6 @@ synthetic/ # Temporary scripts download_suitesparse_partial.sh + +# Network Filesystem +.nfs* diff --git a/requirements.txt b/requirements.txt index 1b7cab3d..8671a953 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,5 +25,6 @@ PyYAML==6.0 requests==2.28.2 scipy==1.10.0 six==1.16.0 +sparse==0.13.0 tomli==2.0.1 tqdm==4.64.1 From 11502cbcd9312247aa38e1ba600265dfb2453ee6 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Tue, 8 Aug 2023 15:07:31 -0700 Subject: [PATCH 51/76] Update util.py to pass codestyle --- sam/util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sam/util.py b/sam/util.py index 67d3fcf4..0658de93 100644 --- a/sam/util.py +++ b/sam/util.py @@ -142,7 +142,7 @@ def load(self, path): # PydataSparseTensorLoader loads a sparse tensor from a file into -# a pydata.sparse tensor. +# a sparse tensor. # class PydataSparseTensorLoader: # def __init__(self): # self.loader = TnsFileLoader() @@ -547,7 +547,7 @@ def load(self, tensor, suiteSparse, cast, format_str): # PydataMatrixMarketTensorLoader loads tensors in the matrix market format -# into pydata.sparse matrices. +# into sparse matrices. # class PydataMatrixMarketTensorLoader: # def __init__(self): # pass @@ -601,7 +601,7 @@ def safeCastPydataTensorToInts(tensor): # else: # data[i] = int(tensor.data[i]) data[i] = round_sparse(tensor.data[i]) - return pydata.sparse.COO(tensor.coords, data, tensor.shape) + return sparse.COO(tensor.coords, data, tensor.shape) def parse_taco_format(infilename, outdir, tensorname, format_str): From 870205dcbaa3d7216ccefc26070a05782ea4c507 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Wed, 9 Aug 2023 13:59:14 -0700 Subject: [PATCH 52/76] Change suitesparse file formatting --- scripts/datastructure_suitesparse.py | 281 ++++++++++++++++++ .../formatting/datastructure_suitesparse.py | 2 +- 2 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 scripts/datastructure_suitesparse.py diff --git a/scripts/datastructure_suitesparse.py b/scripts/datastructure_suitesparse.py new file mode 100644 index 00000000..cb24ec39 --- /dev/null +++ b/scripts/datastructure_suitesparse.py @@ -0,0 +1,281 @@ +import argparse +import os +import shutil +import scipy.sparse +import numpy as np + +from pathlib import Path + +from util import FormatWriter, SuiteSparseTensor, InputCacheSuiteSparse +from sam.util import SUITESPARSE_FORMATTED_PATH, ScipyTensorShifter + +all_formats = ["coo", "cooT", "csr", "dcsr", "dcsc", "csc", "dense", "denseT"] +formats = ["coo", "cooT", "csr", "dcsr", "dcsc", "csc", "dense"] +scipy_formats = ["coo", "csr", "csc"] + + +def write_datastructure_tiles(args, tensor, out_path, tile_name): + print("Writing " + args.name + " for test " + args.benchname + "...") + + dirname = args.output_dir_path if args.output_dir_path is not None else os.path.join(out_path, args.name, args.benchname) + dirname = os.path.join(dirname, tile_name) + dirpath = Path(dirname) + if os.path.exists(dirpath): + shutil.rmtree(dirpath) + dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) + + print(tile_name) + tensorname = tile_name.split("_")[1] + + coo = inputCache.load(tensor, False) + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss01", hw=False) + + +def write_datastructure_bench(args, tensor, out_path, tiles=None): + shifter = ScipyTensorShifter() + + print("Writing " + args.name + " for test " + args.benchname + "...") + + dirname = args.output_dir_path if args.output_dir_path is not None else os.path.join(out_path, args.name, args.benchname) + if tiles is not None: + dirname = os.path.join(dirname, tiles) + dirpath = Path(dirname) + if os.path.exists(dirpath): + shutil.rmtree(dirpath) + dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) + + if "mat_mattransmul" in args.benchname or "mat_residual" in args.benchname: + tensorname = "C" + else: + tensorname = "B" + + coo = inputCache.load(tensor, False) + shape = coo.shape + + # These benchmarks need format_str == "ss10" + if args.benchname not in ["matmul_kij", "matmul_kji", "matmul_jki", "mat_vecmul", "mat_vecmul_ji", "mat_mattransmul"]: + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss01") + + if "matmul_ijk" in args.benchname: + shifted = shifter.shiftLastMode(coo) + + print("Writing " + args.name + " shifted and transposed...") + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss10") + + elif "matmul_jik" in args.benchname: + shifted = shifter.shiftLastMode(coo) + + print("Writing " + args.name + " shifted and transposed...") + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss10") + elif "matmul_ikj" in args.benchname: + shifted = shifter.shiftLastMode(coo) + + print("Writing " + args.name + " shifted and transposed...") + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss01") + + elif "matmul_jki" in args.benchname: + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + + shifted = shifter.shiftLastMode(coo) + + print("Writing " + args.name + " shifted and transposed...") + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss10") + + elif "matmul_kij" in args.benchname: + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + + shifted = shifter.shiftLastMode(coo) + + print("Writing " + args.name + " shifted and transposed...") + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss01") + + elif "matmul_kji" in args.benchname: + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + + shifted = shifter.shiftLastMode(coo) + + print("Writing " + args.name + " shifted and transposed...") + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss01") + + elif "mat_elemadd3" in args.benchname: + print("Writing " + args.name + " shifted...") + tensorname = "C" + shifted = shifter.shiftLastMode(coo) + formatWriter.writeout_separate_sparse_only(shifted, dirname, tensorname, format_str="ss01") + + print("Writing " + args.name + " shifted2...") + tensorname = "D" + shifted2 = shifter.shiftLastMode(shifted) + formatWriter.writeout_separate_sparse_only(shifted2, dirname, tensorname, format_str="ss01") + + elif "mat_elemadd" in args.benchname or "mat_elemmul" in args.benchname: + print("Writing " + args.name + " shifted...") + tensorname = "C" + shifted = shifter.shiftLastMode(coo) + formatWriter.writeout_separate_sparse_only(shifted, dirname, tensorname, format_str="ss01") + + elif "mat_mattransmul" in args.benchname: + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + if not args.no_gen_other: + tensorname = 'd' + vec = scipy.sparse.random(shape[0], 1, density=args.density, data_rvs=np.ones) + vec = vec.toarray().flatten() + formatWriter.writeout_separate_vec(vec, dirname, tensorname) + + tensorname = 'f' + vec = scipy.sparse.random(shape[1], 1, density=args.density, data_rvs=np.ones) + vec = vec.toarray().flatten() + formatWriter.writeout_separate_vec(vec, dirname, tensorname) + elif "mat_vecmul" == args.benchname or "mat_vecmul_ji" in args.benchname: + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + if not args.no_gen_other: + tensorname = 'c' + vec = scipy.sparse.random(shape[1], 1, density=args.density, data_rvs=np.ones) + vec = vec.toarray().flatten() + formatWriter.writeout_separate_vec(vec, dirname, tensorname) + elif "mat_vecmul_ij" in args.benchname: + pass + elif "mat_sddmm" in args.benchname: + pass + elif "mat_residual" in args.benchname: + if not args.no_gen_other: + tensorname = 'b' + vec = scipy.sparse.random(shape[0], 1, density=args.density, data_rvs=np.ones) + vec = vec.toarray().flatten() + formatWriter.writeout_separate_vec(vec, dirname, tensorname) + + tensorname = 'd' + vec = scipy.sparse.random(shape[1], 1, density=args.density, data_rvs=np.ones) + vec = vec.toarray().flatten() + formatWriter.writeout_separate_vec(vec, dirname, tensorname) + elif "mat_identity" in args.benchname: + pass + else: + raise NotImplementedError + + +parser = argparse.ArgumentParser(description="Process some suitesparse matrices into per-level datastructures") +parser.add_argument('-n', '--name', metavar='ssname', type=str, action='store', help='tensor name to run format ' + 'conversion on one SS tensor') +parser.add_argument('-f', '--format', metavar='ssformat', type=str, action='store', help='The format that the tensor ' + 'should be converted to') +parser.add_argument('-comb', '--combined', action='store_true', default=False, help='Whether the formatted datastructures ' + 'should be in separate files') +parser.add_argument('-o', '--omit-dense', action='store_true', default=False, help='Do not create fully dense format') +parser.add_argument('-cast', '--cast', action='store_true', default=False, help='Safe sparsity cast to int for values') +parser.add_argument('-hw', '--hw', action='store_true', default=False, + help='Only generate formats used for hardware testing (all sparse' + 'levels, concordant)') +parser.add_argument('-b', '--benchname', type=str, default=None, help='test name to run format ' + 'conversion on') +parser.add_argument('--input_path', type=str, default=None) +parser.add_argument('--output_dir_path', type=str, default=None) +parser.add_argument('--tiles', action='store_true') +parser.add_argument('--no_gen_other', action='store_true', help="Whether this" + "script should generate the randmo 'other' tensors") +parser.add_argument('--seed', type=int, default=0, help='Random seed needed for gen_other') +parser.add_argument('--density', type=int, default=0.25, help='If gen_other, used for density of "other" tensor') +args = parser.parse_args() + +np.random.seed(args.seed) + +inputCache = InputCacheSuiteSparse() +formatWriter = FormatWriter(args.cast) + +cwd = os.getcwd() +if args.output_dir_path is None: + out_dirname = SUITESPARSE_FORMATTED_PATH +else: + out_dirname = args.output_dir_path + +out_path = Path(out_dirname) +out_path.mkdir(parents=True, exist_ok=True, mode=0o777) + +if args.name is None: + print("Please enter a matrix name") + exit() + +if args.input_path is None: + SS_PATH = os.getenv('SUITESPARSE_TENSOR_PATH', default=os.path.join(cwd, 'suitesparse')) + +else: + SS_PATH = args.input_path + +tensor = None +mtx_files = None +if args.tiles: + # get all mtx tile files from args.input_path + mtx_files = [os.path.join(args.input_path, fname) for fname in os.listdir(args.input_path) if fname.endswith(".mtx")] + + tensor = [SuiteSparseTensor(mtx_file) for mtx_file in mtx_files] +elif args.input_path is not None: + tensor = SuiteSparseTensor(args.input_path) +else: + print(SS_PATH) + tensor = SuiteSparseTensor(SS_PATH) + +if args.format is not None: + assert args.format in formats + filename = os.path.join(out_path, args.name + "_" + args.format + ".txt") + + coo = inputCache.load(tensor, False) + formatWriter.writeout(coo, args.format, filename) +elif args.combined: + for format_str in formats: + filename = os.path.join(out_path, args.name + "_" + format_str + ".txt") + print("Writing " + args.name + " " + format_str + "...") + + coo = inputCache.load(tensor, False) + formatWriter.writeout(coo, format_str, filename) + + shifted_filename = os.path.join(out_path, args.name + "_shifted_" + format_str + ".txt") + shifted = ScipyTensorShifter().shiftLastMode(coo) + formatWriter.writeout(shifted, format_str, shifted_filename) + + trans_filename = os.path.join(out_path, args.name + "_trans_shifted_" + format_str + ".txt") + trans_shifted = shifted.transpose() + formatWriter.writeout(trans_shifted, format_str, trans_filename) +elif args.hw: + if args.tiles and tensor is not None: + for i, ten in enumerate(tensor): + tile_name = os.path.split(mtx_files[i])[1].split(".")[0] + write_datastructure_tiles(args, ten, out_path, tile_name) + else: + write_datastructure_bench(args, tensor, out_path) + +else: + print("Writing " + args.name + " original...") + dirname = os.path.join(out_path, args.name, "orig") + dirpath = Path(dirname) + dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) + tensorname = "B" + coo = inputCache.load(tensor, False) + formatWriter.writeout_separate(coo, dirname, tensorname, omit_dense=args.omit_dense) + + print("Writing " + args.name + " shifted...") + dirname = os.path.join(out_path, args.name, "shift") + dirpath = Path(dirname) + dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) + tensorname = "C" + shifted = ScipyTensorShifter().shiftLastMode(coo) + formatWriter.writeout_separate(shifted, dirname, tensorname, omit_dense=args.omit_dense) + + print("Writing " + args.name + " shifted and transposed...") + dirname = os.path.join(out_path, args.name, "shift-trans") + dirpath = Path(dirname) + dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) + tensorname = "C" + trans_shifted = shifted.transpose() + formatWriter.writeout_separate(trans_shifted, dirname, tensorname, omit_dense=args.omit_dense) diff --git a/scripts/formatting/datastructure_suitesparse.py b/scripts/formatting/datastructure_suitesparse.py index 823e8e13..9a703034 100644 --- a/scripts/formatting/datastructure_suitesparse.py +++ b/scripts/formatting/datastructure_suitesparse.py @@ -28,7 +28,7 @@ def write_datastructure_tiles(args, tensor, out_path, tile_name): tensorname = tile_name.split("_")[1] coo = inputCache.load(tensor, False) - formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss01", hw=False) + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss01", args.hw) def write_datastructure_bench(args, tensor, out_path, tiles=None): From c3eb5382bc76d36d30b6d03ba884b77f3bb377cc Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Fri, 18 Aug 2023 18:14:44 -0700 Subject: [PATCH 53/76] current matrix tiling flow --- count_nnz_tiling.py | 42 ++ find_max_tilesize.py | 75 +++ sam/sim/src/tiling/tile.py | 36 +- .../formatting/datastructure_suitesparse.py | 2 + scripts/formatting/datastructure_tns.py | 10 +- scripts/generate_frostt_formats_onyx.sh | 59 +++ scripts/suitesparse_memory_model_runner.sh | 2 +- scripts/tiling/generate_gold_mattransmul.py | 174 +++++++ scripts/tiling/prepare_files.sh | 6 +- scripts/tiling/tile_ext.sh | 8 +- setup_tiling_mat.py | 175 ++++++- setup_tiling_tensors.py | 23 + tile_pairing.py | 437 ++++++++++++++++++ 13 files changed, 1020 insertions(+), 29 deletions(-) create mode 100644 count_nnz_tiling.py create mode 100644 find_max_tilesize.py create mode 100755 scripts/generate_frostt_formats_onyx.sh create mode 100644 scripts/tiling/generate_gold_mattransmul.py create mode 100644 setup_tiling_tensors.py create mode 100644 tile_pairing.py diff --git a/count_nnz_tiling.py b/count_nnz_tiling.py new file mode 100644 index 00000000..c98bdd3a --- /dev/null +++ b/count_nnz_tiling.py @@ -0,0 +1,42 @@ +import glob +def count_nonzeros(matrix_values_file): + with open(matrix_values_file, 'r') as values_file: + matrix_values = [float(val) for val in values_file.readlines()] + + nonzeros = sum(1 for val in matrix_values if val != 0) + + return nonzeros + + +tile_dirs = glob.glob("SPARSE_TESTS/MAT_TMP_DIR/tile*") +num_tiles = len(tile_dirs) +print("there are ", num_tiles, "tiles") +limit = 1000 + +tot_num_nonzeros = 0 +for tile_num in range(0,num_tiles): + tensor_C_values_file = f'SPARSE_TESTS/MAT_TMP_DIR/tile{tile_num}/tensor_C_mode_vals' + + num_nonzeros = count_nonzeros(tensor_C_values_file) + if num_nonzeros >= limit: + print("error! too many nonzeros in tensorC, tile", tile_num) + # raise Exception + +# tot_num_nonzeros += num_nonzeros + +# average_num_nonzeros = tot_num_nonzeros / 9 +# print("for matrix C, the average number of non-zero values is", average_num_nonzeros) + +tot_num_nonzeros = 0 + +for tile_num in range(0,num_tiles): + tensor_C_values_file = f'SPARSE_TESTS/MAT_TMP_DIR/tile{tile_num}/tensor_B_mode_vals' + + num_nonzeros = count_nonzeros(tensor_C_values_file) + if num_nonzeros >= limit: + print("error! too many nonzeros in tensorB, tile", tile_num) + # raise Exception +# tot_num_nonzeros += num_nonzeros + +# average_num_nonzeros = tot_num_nonzeros / 6 +# print("for matrix B, the average number of non-zero values is", average_num_nonzeros) diff --git a/find_max_tilesize.py b/find_max_tilesize.py new file mode 100644 index 00000000..8eb96038 --- /dev/null +++ b/find_max_tilesize.py @@ -0,0 +1,75 @@ +import os +import sys +import glob + +def write_to_line(file_path, line_number, new_content): + with open(file_path, 'r') as file: + lines = file.readlines() + + if line_number > len(lines) or line_number < 1: + # Line number is out of range + return + + lines[line_number - 1] = new_content + '\n' + + with open(file_path, 'w') as file: + file.writelines(lines) + +def check_keyword_in_output(command, keyword): + # Run the command and redirect the output to a file + os.system(f'{command} > output.txt') + + # Read the contents of the file + with open('output.txt', 'r') as file: + output = file.read() + + # Check if the keyword is present in the output + if keyword in output: + # Optionally, you can delete the output file + os.remove('output.txt') + return True + else: + # Optionally, you can delete the output file + os.remove('output.txt') + return False + + +tile_size = 450 +step = 10 + +for _ in range(20): + print("********************") + print("tile size: ", tile_size) + print("step: ", step) + + yaml_file = "sam/sim/src/tiling/memory_config_onyx.yaml" + mem_tile_line = f"Mem_tile_size: {tile_size}" + print(mem_tile_line) + write_to_line(yaml_file, 19, mem_tile_line) + + run_setup_script = "python3 setup_tiling_mat.py > temp.txt" + os.system(run_setup_script) + print(run_setup_script) + + run_tile_pairing = "python3 tile_pairing.py > temp.txt" + os.system(run_tile_pairing) + print(run_tile_pairing) + + run_count = "python3 count_nnz_tiling.py" + print(run_count) + + if (check_keyword_in_output(run_count, "error")) == False: + tile_size += step + step *= 2 + else: + print("****************Tile broken!") + tile_size -= step + step //= 2 + + if step == 0: + if _ >= 15: + step = 10 + else: + break + +print("max tile size: ", tile_size) diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index ad430463..76dc1dde 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -26,9 +26,10 @@ "matmul_ijk": "X(i,j)=B(i,k)*C(k,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemadd": "X(i,j)=B(i,j)+C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", "mat_elemmul": "X(i,j)=B(i,j)*C(i,j) -f=X:ss -f=B:ss -f=C:ss:1,0 -s=reorder(i,j,k)", - "mat_mattransmul": "X(i,j)=C(j,i)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss:0 -f=d:ss:0 -s=reorder(i,j)", - "mat_vecmul_ij": "X(i,j)=B(i,j)*c(j) -f=X:ss -f=B:ss -f=c:ss:0 -s=reorder(i,j)", - "tensor3_ttv": "X(i,j)=B(i,j,k)*c(k) -f=X:ss -f=B:sss -f=c:s"} + "mat_mattransmul": "X(i,j)=B(j,i)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss:0 -f=d:ss:0 -s=reorder(i,j)", + "mat_vecmul_ij" : "X(i,j)=B(i,j)*c(j) -f=X:ss -f=B:ss -f=c:ss:0 -s=reorder(i,j)", + "mat_residual": "X(i,j)=b(i)-C(i,j)*d(j) -f=X:ss -f=C:ss -f=b:ss:0 -f=d:ss:0 -s=reorder(i,j)", + "mat_sddmm": "X(i,j)=B(i,j)*C(i,k)*D(k,j) -f=X:ss -f=B:ss -f=C:ss -f=D:ss -s=reorder(i,j,k)"} def print_dict(dd): @@ -87,9 +88,11 @@ def parse_sam_input(string): str_arr = sam_str.split(" ") dictionary = parse_all(str_arr, has_quotes=False) + print("dictionary is: ", dictionary) # Assume there are no repeat tensors... tensors = dictionary["rhs_tensors"] + print("tensors are: ", tensors) permutations = [list(map(int, dictionary[tensor]["perm"])) for tensor in tensors] ivars = get_ivars(tensors, str_arr[0]) ivars = [ivars[tensor] for tensor in tensors] @@ -250,6 +253,7 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map, hi print("dim is ", dim) print("tensor_format[dim:dim+1] is ", tensor_format[dim:dim + 1]) + print("tensor name is ", tensor_name) lvl_permutation = tensor_format[dim:dim + 1][0] ivar = ivar_strs[i][dim] ivar_map[lvl_permutation] = ivar @@ -290,7 +294,15 @@ def get_other_tensors(app_str, tensor, other_nonempty=True): tensors.append(shifted) elif "mat_sddmm" in app_str: - pass + print("Writing other tensors, shifted...") + print("Writing shifted...") + shifted = ScipyTensorShifter().shiftLastMode(tensor) + tensors.append(shifted) + + print("Writing shifted2...") + shifted2 = ScipyTensorShifter().shiftLastMode(shifted) + tensors.append(shifted2) + elif "mat_mattransmul" in app_str: print("Writing other tensors...") rows, cols = tensor.shape # i,j @@ -308,7 +320,18 @@ def get_other_tensors(app_str, tensor, other_nonempty=True): tensors.append(tensor_d) elif "mat_residual" in app_str: - pass + print("Writing other tensors...") + rows, cols = tensor.shape + tensor_b = scipy.sparse.random(rows, 1, data_rvs=np.ones).toarray().flatten() + tensor_d = scipy.sparse.random(cols, 1, data_rvs=np.ones).toarray().flatten() + + if other_nonempty: + tensor_b[0] = 1 + tensor_d[0] = 1 + + tensors.insert(0, tensor_b) + tensors.append(tensor_d) + elif "mat_vecmul" in app_str: print("Writing other tensors...") rows, cols = tensor.shape @@ -536,10 +559,11 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi print(tile.shape) print(tile) tns_dumper.dump(tile, mtx_path_name) - # FIXME: (owhsu) Why did avb03 add this in? elif len(tile.shape) == 1: + real_shape = tile.shape[0] # print(np.array(tile.todense()).reshape(1,-1)) + # scipy.io.mmwrite(mtx_path_name, scipy.sparse.coo_matrix(tile.todense()).reshape((real_shape,1))) scipy.io.mmwrite(mtx_path_name, scipy.sparse.coo_matrix(tile.todense())) else: # print(tile.todense()) diff --git a/scripts/formatting/datastructure_suitesparse.py b/scripts/formatting/datastructure_suitesparse.py index 823e8e13..373bf81e 100644 --- a/scripts/formatting/datastructure_suitesparse.py +++ b/scripts/formatting/datastructure_suitesparse.py @@ -29,6 +29,8 @@ def write_datastructure_tiles(args, tensor, out_path, tile_name): coo = inputCache.load(tensor, False) formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss01", hw=False) + # formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss01", hw=args.hw) + def write_datastructure_bench(args, tensor, out_path, tiles=None): diff --git a/scripts/formatting/datastructure_tns.py b/scripts/formatting/datastructure_tns.py index db9e1951..cb335f9b 100644 --- a/scripts/formatting/datastructure_tns.py +++ b/scripts/formatting/datastructure_tns.py @@ -90,7 +90,7 @@ outdir_orig_path.mkdir(parents=True, exist_ok=True) taco_format_orig_filename = "/home/avb03/sam/FROST_FORMATTED_TACO/" + args.name + "_" + levels + '.txt' - parse_taco_format(taco_format_orig_filename, outdir_orig_name, 'B', args.format, hw_filename=args.hw) + parse_taco_format(taco_format_orig_filename, outdir_orig_name, 'B', args.format) #Need this line? formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") file_path_name = os.path.join(outdir_orig_name, "tensor_B_mode_shape") file1 = open(file_path_name, 'r') @@ -122,7 +122,7 @@ outdir_orig_path.mkdir(parents=True, exist_ok=True) taco_format_orig_filename = "/home/avb03/sam/FROST_FORMATTED_TACO/" + args.name + "_" + levels + '.txt' - parse_taco_format(taco_format_orig_filename, outdir_orig_name, 'B', args.format, hw_filename=args.hw) + parse_taco_format(taco_format_orig_filename, outdir_orig_name, 'B', args.format) #Need this line? formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") file_path_name = os.path.join(outdir_orig_name, "tensor_B_mode_shape") file1 = open(file_path_name, 'r') @@ -156,7 +156,7 @@ outdir_orig_path.mkdir(parents=True, exist_ok=True) taco_format_orig_filename = "/home/avb03/sam/FROST_FORMATTED_TACO/" + args.name + "_" + levels + '.txt' - parse_taco_format(taco_format_orig_filename, outdir_orig_name, 'B', args.format, hw_filename=args.hw) + parse_taco_format(taco_format_orig_filename, outdir_orig_name, 'B', args.format) file_path_name = os.path.join(outdir_orig_name, "tensor_B_mode_shape") file1 = open(file_path_name, 'r') @@ -201,7 +201,7 @@ outdir_orig_path.mkdir(parents=True, exist_ok=True) taco_format_orig_filename = "/home/avb03/sam/FROST_FORMATTED_TACO/" + args.name + "_" + levels + '.txt' - parse_taco_format(taco_format_orig_filename, outdir_orig_name, 'B', args.format, hw_filename=args.hw) + parse_taco_format(taco_format_orig_filename, outdir_orig_name, 'B', args.format) # Shifted if args.shift: @@ -210,4 +210,4 @@ outdir_shift_path.mkdir(parents=True, exist_ok=True) taco_format_shift_filename = "/home/avb03/sam/FROST_FORMATTED_TACO/" + args.name + "_shift_" + levels + '.txt' - parse_taco_format(taco_format_shift_filename, outdir_shift_name, 'C', args.format, hw_filename=args.hw) + parse_taco_format(taco_format_shift_filename, outdir_shift_name, 'C', args.format) diff --git a/scripts/generate_frostt_formats_onyx.sh b/scripts/generate_frostt_formats_onyx.sh new file mode 100755 index 00000000..9a84bde2 --- /dev/null +++ b/scripts/generate_frostt_formats_onyx.sh @@ -0,0 +1,59 @@ +#!/bin/bash +#SBATCH -N 1 +#SBATCH -t 360 + +# ./scripts/generate_frostt_formats_onyx.sh + +FORMATS=( + sss012 +) + +BENCHMARKS=( + #using all tensor apps except elemmul here** + # tensor3_elemadd + # tensor3_innerprod + tensor3_ttv + # tensor3_elemmul + # tensor3_mttkrp + # tensor3_ttm + # using tensor3_ttm +) + +# OTHERBENCHES='["tensor3_ttv"]' +# export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse/ +# export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt/ +# export SUITESPARSE_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/suitesparse-formatted +# export FROSTT_FORMATTED_TACO_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted/taco-tensor +# export FROSTT_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted + +export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse/ +export FROSTT_PATH=/home/avb03/sparse-datasets/tensors +export SUITESPARSE_FORMATTED_PATH=/home/avb03/sam/SUITESPARSE_FORMATTED +export FROSTT_FORMATTED_TACO_PATH=/home/avb03/sam/FROST_FORMATTED_TACO +export FROSTT_FORMATTED_PATH=/home/avb03/sam/FROST_FORMATTED +export TACO_TENSOR_PATH=/home/avb03/sam/TACO_TENSOR + +basedir=$(pwd) + +for i in ${!FORMATS[@]}; do + format=${FORMATS[@]}; + echo "Generating files for format $format..." + + $basedir/compiler/taco/build/bin/taco-test sam.pack_$format + $basedir/compiler/taco/build/bin/taco-test sam.pack_other_frostt + for b in ${!BENCHMARKS[@]}; do + bench=${BENCHMARKS[$b]} + while read line; do + + name=$line + echo "Generating input format files for $name..." + python3 $basedir/scripts/formatting/datastructure_tns.py -n $name -f $format -b $bench -hw + python3 $basedir/scripts/formatting/datastructure_tns.py -n $name -f $format --other -b $bench -hw + # if [[ $OTHERBENCHES =~ "$bench" ]]; then + # echo "Generating format of 'other' tensor" + # python3 $basedir/scripts/datastructure_tns_old.py -n $line -f ss01 --other -ss -b $bench -hw + # fi + chmod -R 775 $FROSTT_FORMATTED_PATH + done <$1 + done +done diff --git a/scripts/suitesparse_memory_model_runner.sh b/scripts/suitesparse_memory_model_runner.sh index d2873266..e715a508 100755 --- a/scripts/suitesparse_memory_model_runner.sh +++ b/scripts/suitesparse_memory_model_runner.sh @@ -31,7 +31,7 @@ mkdir -p $path mkdir -p $basedir/tiles/ rm -rf $basedir/tiles/* -./scripts/tiling/prepare_files.sh $fname.mtx $yaml_fname +./scripts/tiling/prepare_files.sh $fname.mtx $yaml_fname $fname cd $basedir/sam/sim # python3 -m pytest test/advanced-simulator/test_$bench.py --ssname $fname -s --check-gold --skip-empty --nbuffer --yaml_name=$yaml_fname --benchmark-json=$path/mem_model_$fname.json diff --git a/scripts/tiling/generate_gold_mattransmul.py b/scripts/tiling/generate_gold_mattransmul.py new file mode 100644 index 00000000..b044a949 --- /dev/null +++ b/scripts/tiling/generate_gold_mattransmul.py @@ -0,0 +1,174 @@ +import scipy +import scipy.sparse +import os +import scipy.io +import numpy as np +import yaml +import math +import pickle +import argparse + +from pathlib import Path +from scripts.util.util import round_sparse + +def generate_gold_mattransmul_tiled(tile_crd_b, tile_crd_c, tile_crd_d, dirname, out_format="ss01"): + # CSR + formatted_dir = f"./tiles/mat_mattransmul/mtx" + + B_dir = "tensor_B_tile_" + for a in tile_crd_b: + B_dir += str(a) + "_" + C_dir = "tensor_c_tile_" + for a in tile_crd_c: + C_dir += str(a) + "_" + d_dir = "tensor_d_tile_" + for a in tile_crd_d: + d_dir += str(a) + "_" + + B_dir = B_dir[0:-1] + ".mtx" + C_dir = C_dir[0:-1] + ".mtx" + d_dir = d_dir[0:-1] + ".mtx" + # print(B_dir, " ", C_dir) + B_filename = os.path.join(formatted_dir, B_dir) + C_filename = os.path.join(formatted_dir, C_dir) + d_filename = os.path.join(formatted_dir, d_dir) + # print() + # print(B_filename) + # print(C_filename) + # print(d_filename) + # print() + if os.path.exists(B_filename) and os.path.exists(C_filename) and os.path.exists(d_filename): + B_scipy = scipy.io.mmread(B_filename) + itr = 0 + # print("\nB_scipy: ", B_scipy) + for i, j, v in zip(B_scipy.row, B_scipy.col, B_scipy.data): + # print(B_scipy.data) + # print(i, " ", j, " ", v) + B_scipy.data[itr] = round_sparse(B_scipy.data[itr]) + # if B_scipy.data[itr] < 1 and B_scipy.data[itr] > 0: + # B_scipy.data[itr] = 1 + # elif B_scipy.data[itr] < 0 and B_scipy.data[itr] > -1: + # B_scipy.data[itr] = -1 + # else: + # B_scipy.data[itr] = int(B_scipy.data[itr]) + itr += 1 + B_scipy = B_scipy.tocsr() + + + C_scipy = scipy.io.mmread(C_filename) + # print(C_filename) + # print("\nC_scipy: ", C_scipy) + # print("___________________") + # print(B_scipy) + itr = 0 + for i, j, v in zip(C_scipy.row, C_scipy.col, C_scipy.data): + C_scipy.data[itr] = round_sparse(C_scipy.data[itr]) + itr += 1 + C_scipy = C_scipy.tocsr() + C_scipy = np.transpose(C_scipy) + + d_scipy = scipy.io.mmread(d_filename) + # print("\nd_scipy: ", d_scipy) + + itr = 0 + for i, j, v in zip(d_scipy.row, d_scipy.col, d_scipy.data): + d_scipy.data[itr] = round_sparse(d_scipy.data[itr]) + + itr += 1 + d_scipy = d_scipy.tocsr() + d_scipy = np.transpose(d_scipy) + + # gold_nd = (B_scipy @ C_scipy) + # gold_nd = B_scipy.dot(C_scipy) + + #constants + alpha = 2 + beta = 2 + + print("B_scipy.shape: ", B_scipy.shape) + print("C_scipy.shape: ", C_scipy.shape) + print("d_scipy.shape: ", d_scipy.shape) + + gold_nd = alpha*(B_scipy @ C_scipy) + beta * d_scipy + # print(gold_nd) + + gold_out = gold_nd.tocoo() + assert tile_crd_b[1] == tile_crd_c[0] and tile_crd_b[3] == tile_crd_c[1] and tile_crd_b[0] == tile_crd_d[0] and tile_crd_b[2] == tile_crd_d[1] + # assert tile_crd_b[1] == tile_crd_c[0] and tile_crd_b[3] == tile_crd_c[2] + scipy.io.mmwrite( + dirname + "out_" + str(tile_crd_b[0]) + "_" + str(tile_crd_b[1]) + "_" + str(tile_crd_b[3]) + "_" + str(tile_crd_b[2]) + "_" + str( + tile_crd_c[0]) + "_" + str(tile_crd_c[1]) + "_" + str(tile_crd_d[0]) + "_" + str(tile_crd_d[1]) + ".mtx", gold_out) + elif os.path.exists(d_filename): + d_scipy = scipy.io.mmread(d_filename) + # print("\nd_scipy: ", d_scipy) + + itr = 0 + for i, j, v in zip(d_scipy.row, d_scipy.col, d_scipy.data): + d_scipy.data[itr] = d_scipy.data[itr] + + itr += 1 + d_scipy = d_scipy.tocsr() + # d_scipy = np.transpose(d_scipy) + + # gold_nd = (B_scipy @ C_scipy) + # gold_nd = B_scipy.dot(C_scipy) + + #constants + alpha = 2 + beta = 2 + + # print(d_scipy.todense()) + gold_nd = beta * d_scipy + # print(gold_nd) + if(np.count_nonzero(gold_nd.todense()) == 0): + print("output is all zero") + return + + gold_out = gold_nd.tocoo() + # assert tile_crd_b[1] == tile_crd_c[0] and tile_crd_b[3] == tile_crd_c[1] and tile_crd_b[0] == tile_crd_d[0] and tile_crd_b[2] == tile_crd_d[1] + # assert tile_crd_b[1] == tile_crd_c[0] and tile_crd_b[3] == tile_crd_c[2] + scipy.io.mmwrite( + dirname + "out_" + str(tile_crd_b[0]) + "_" + str(tile_crd_b[1]) + "_" + str(tile_crd_b[3]) + "_" + str(tile_crd_b[2]) + "_" + str( + tile_crd_c[0]) + "_" + str(tile_crd_c[1]) + "_" + str(tile_crd_d[0]) + "_" + str(tile_crd_d[1]) + ".mtx", gold_out) + + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Generate tiled output gold") + parser.add_argument("--yaml_name", type=str, default="memory_config_real.yaml") + args = parser.parse_args() + outdir = f"./tiles/mat_mattransmul/output/" + outpath = Path(outdir) + outpath.mkdir(parents=True) + + # generate_gold_matmul_tiled([0, 1, 2, 9], [1, 0, 9, 0], outdir) + + # generate_gold_matmul_tiled([0, 1, 0, 7], [1, 0, 7, 0], outdir) + # quit() with open("/nobackup/rsharma3/Sparsity/simulator/old_sam/sam/tiles/matmul_ikj/tensor_sizes", "rb") as ff: + + with open(f"./tiles/mat_mattransmul/tensor_sizes", "rb") as ff: + sizes_dict_level_full = pickle.load(ff) + + with open("./sam/sim/src/tiling/" + args.yaml_name, "r") as stream: + loop_config = yaml.safe_load(stream) + + print() + print("sizes_dict_level_full", sizes_dict_level_full) + print() + print("loop_config", loop_config) + + struct = { + "j00": 1 + int(sizes_dict_level_full["B"][0]) // (loop_config["Glb_tile_size"] * loop_config["Mem_tile_size"]), + "i00": 1 + int(sizes_dict_level_full["c"][0]) // (loop_config["Glb_tile_size"] * loop_config["Mem_tile_size"]), + "i0": loop_config["Glb_tile_size"], "j0": loop_config["Glb_tile_size"]} + + print() + print(struct) + + # print(struct) + # # quit() + for i00 in range(struct["i00"]): + for j00 in range(struct["j00"]): + for i0 in range(struct["i0"]): + for j0 in range(struct["j0"]): + generate_gold_mattransmul_tiled([j00, i00, j0, i0], [i00, i0], [j00, j0], outdir) diff --git a/scripts/tiling/prepare_files.sh b/scripts/tiling/prepare_files.sh index 3d24d037..d255f317 100755 --- a/scripts/tiling/prepare_files.sh +++ b/scripts/tiling/prepare_files.sh @@ -6,10 +6,12 @@ # ./scripts/tiling/prepare_files.sh extensor__.mtx +appname=$3 + basedir=$(pwd) rm -rf $basedir/tiles/* -./scripts/tiling/tile_ext.sh $1 memory_config_extensor_17M_llb.yaml +./scripts/tiling/tile_ext.sh $1 memory_config_extensor_17M_llb.yaml $appname -python3 scripts/tiling/generate_gold_matmul_tiled.py --yaml_name memory_config_extensor_17M_llb.yaml +# python3 scripts/tiling/generate_gold_matmul_tiled.py --yaml_name memory_config_extensor_17M_llb.yaml diff --git a/scripts/tiling/tile_ext.sh b/scripts/tiling/tile_ext.sh index 36ce32ee..5acaeab7 100755 --- a/scripts/tiling/tile_ext.sh +++ b/scripts/tiling/tile_ext.sh @@ -5,9 +5,13 @@ BENCHMARKS=( # matmul_ikj - mat_mattransmul + # mat_mattransmul + # mat_vecmul_ij + mat_residual ) +appname=$3 + sspath=$SUITESPARSE_PATH basedir=$(pwd) @@ -26,7 +30,7 @@ for b in ${!BENCHMARKS[@]}; do echo "Tiling mtx file" # python $basedir/sam/sim/src/tiling/tile.py --extensor --input_path $tiles_path --cotile $bench --multilevel --hw_config $basedir/sam/sim/src/tiling/$2 - python3 ./sam/sim/src/tiling/tile.py --tensor_type ss --input_tensor rel5 --cotile mat_mattransmul --multilevel --hw_config ./sam/sim/src/tiling/memory_config_onyx.yaml --higher_order + python3 ./sam/sim/src/tiling/tile.py --tensor_type ss --input_tensor $appname --cotile $bench --multilevel --hw_config ./sam/sim/src/tiling/memory_config_onyx.yaml --higher_order echo "Generating input format files for $tiles_path..." python3 $basedir/scripts/formatting/datastructure_suitesparse.py -n temp -hw -b $bench --input $basedir/tiles/$bench/mtx/ --output_dir_path $basedir/tiles/$bench/formatted --tiles diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py index e7195c99..bd12c015 100644 --- a/setup_tiling_mat.py +++ b/setup_tiling_mat.py @@ -2,16 +2,35 @@ import glob import shutil import os +import re from sam.util import SUITESPARSE_PATH +## PARAMS ###################################################################### + +# 'rel5', 'mk9-b1', data = ['rel5'] # app_name = "mat_elemadd" -app_name = "mat_mattransmul" +# app_name = "mat_elemmul" +app_name = "mat_sddmm" +# app_name = "matmul_ijk" +# app_name = "mat_elemmul" +# app_name = "mat_vecmul_ij" +# app_name = "mat_residual" # data_file = open("scripts/tensor_names/suitesparse_valid_mid50.txt") # data_file_lines = data_file.readlines() # for line in data_file_lines: # data.append(line[:-1]) +mode_to_exclude = 0 +addition_vector_name = "d" #mattransmul (d) and residual (b) only + +other_tensors = ["c"] +samples_directory = f"samples/{app_name}" +docker_path = f"avb03-sparse-tiling" +use_dataset_files = False +matrix_app=True + +############################################################################### os.environ["SUITESPARSE_PATH"] = "/nobackup/owhsu/sparse-datasets/suitesparse/" os.environ["FROSTT_PATH"] = "/nobackup/owhsu/sparse-datasets/frostt/" @@ -20,17 +39,147 @@ os.environ["FROSTT_FORMATTED_PATH"] = "/home/avb03/sam/FROST_FORMATTED" os.environ["TACO_TENSOR_PATH"] = "/home/avb03/sam/TACO_TENSOR" -for datum in data: - mtx_file = glob.glob(f"{SUITESPARSE_PATH}/{datum}.mtx")[0] - os.makedirs("extensor_mtx", exist_ok=True) - shutil.copy(mtx_file,f"extensor_mtx/{datum}.mtx") - - command = f"./scripts/suitesparse_memory_model_runner.sh {datum} {app_name}" - os.system(command) +def replace_ones_with_zeros(mtx_file): + with open(mtx_file, 'r') as file: + lines = file.readlines() + + new_lines = [] + for line in lines: + values = line.split() + if len(values) >= 3: + values[2] = '0' + new_lines.append(' '.join(values)) + + with open(mtx_file, 'w') as file: + file.writelines(new_lines) + + +if(matrix_app): + for datum in data: + rmdir = f"rm -rf tiles/{app_name}" + os.system(rmdir) + + mtx_file = glob.glob(f"{SUITESPARSE_PATH}/{datum}.mtx")[0] + os.makedirs("extensor_mtx", exist_ok=True) + shutil.copy(mtx_file,f"extensor_mtx/{datum}.mtx") + + command = f"./scripts/suitesparse_memory_model_runner.sh {datum} {app_name}" + os.system(command) + + directories = glob.glob(f'tiles/{app_name}/formatted/tensor_[a-z]*') + + #for vectors, do cleanup + for directory in directories: + print(directory) + match = re.search(r'tensor_([a-z])', directory) + if match: + lowercase_letter = match.group(1) + + crd_file = os.path.join(directory, f"{lowercase_letter}{mode_to_exclude}_crd.txt") + seg_file = os.path.join(directory, f"{lowercase_letter}{mode_to_exclude}_seg.txt") + + # if os.path.exists(crd_file): + # os.remove(crd_file) + + # if os.path.exists(seg_file): + # os.remove(seg_file) + + samples_with_addition_vector = None + + # dense tile replacement for addition + if app_name == "mat_mattransmul" or app_name == "mat_residual": + # samples_with_addition_vector = glob.glob(f"{samples_directory}/*[{addition_vector_name}]*") + # samples_with_addition_vector = glob.glob(f"{samples_directory}/mtm_w_0_1/tensor_d_tile_0_0") + samples_with_addition_vector = glob.glob(f"{samples_directory}/mtm_w_0_1_BAK") + + + print(samples_with_addition_vector) + #fill in missing tiles with blanks + for sample in samples_with_addition_vector: + file_path = os.path.join(sample, f"{addition_vector_name}_vals.txt") + + with open(file_path, "r") as file: + file_contents = file.read() + + file_contents = file_contents.replace("1", "0") - os.makedirs("tiles_compiled", exist_ok=True) - copy_rename = f"cp -r tiles/{app_name} tiles_compiled/{app_name}_{datum}" - os.system(copy_rename) + with open(file_path, "w") as file: + file.write(file_contents) - docker_copy_command = f"docker cp tiles_compiled/{app_name}_{datum} avb03-sparse-tiling:/aha/garnet/tiles_{app_name}_{datum}" - os.system(docker_copy_command) + tile_range = [(0,i) for i in range(8)] + [(1,i) for i in range(4)] + + for i,j in tile_range: + tile_dir = f"tiles/{app_name}/formatted/tensor_{addition_vector_name}_tile_{i}_{j}" + + if not os.path.exists(tile_dir): + # replace_ones_with_zeros("samples/mat_mattransmul/tensor_d_dense_mtx.mtx") + + # copy_over_to_mtx_dir = f"cp samples/mat_mattransmul/tensor_d_dense_gold_stash.mtx tiles/{app_name}/mtx/tensor_{addition_vector_name}_tile_{i}_{j}.mtx" + # os.system(copy_over_to_mtx_dir) + + sample_tile_dir = samples_with_addition_vector[0] + + if os.path.exists(sample_tile_dir): + shutil.copytree(sample_tile_dir, tile_dir) + + if(use_dataset_files): + assert os.path.exists("SUITESPARSE_FORMATTED") + + temp_name = app_name + if app_name == "mat_vecmul_ij": + temp_name = "mat_vecmul" + + app_path_additional = f"SUITESPARSE_FORMATTED/{datum}/{temp_name}/" + + for tens in other_tensors: + valid_dirs = glob.glob(f"tiles/{app_name}/formatted/tensor_{tens}*") + for d in valid_dirs: + remove_tens = f"rm {d}/*" + print(remove_tens) + os.system(remove_tens) + + files_to_cp = glob.glob(f"{app_path_additional}tensor_{tens}*") + + for file in files_to_cp: + if "mode_0_crd" in file: + copy_rename = f"cp {file} {d}/{tens}0_crd.txt" + print(copy_rename) + os.system(copy_rename) + elif "mode_1_crd" in file: + copy_rename = f"cp {file} {d}/{tens}1_crd.txt" + print(copy_rename) + os.system(copy_rename) + elif "mode_0_seg" in file: + copy_rename = f"cp {file} {d}/{tens}0_seg.txt" + print(copy_rename) + os.system(copy_rename) + elif "mode_1_seg" in file: + copy_rename = f"cp {file} {d}/{tens}1_seg.txt" + print(copy_rename) + os.system(copy_rename) + elif "vals" in file: + copy_rename = f"cp {file} {d}/{tens}_vals.txt" + print(copy_rename) + os.system(copy_rename) + elif "shape" in file: + copy_rename = f"cp {file} {d}/{tens}_shape.txt" + print(copy_rename) + os.system(copy_rename) + + + dump_gold_tiles = f"python3 scripts/tiling/generate_gold_mattransmul.py --yaml_name memory_config_extensor_17M_llb.yaml" + os.system(dump_gold_tiles) + + # os.makedirs("tiles_compiled", exist_ok=True) + # copy_rename = f"cp -r tiles/{app_name} tiles_compiled/{app_name}_{datum}" + # print(copy_rename) + # os.system(copy_rename) + + docker_clean = f"docker exec {docker_path} rm -r /aha/garnet/tiles_{app_name}_{datum}" + print(docker_clean) + os.system(docker_clean) + + docker_copy_command = f"docker cp tiles {docker_path}:/aha/garnet/tiles_{app_name}_{datum}" + print(docker_copy_command) + os.system(docker_copy_command) + diff --git a/setup_tiling_tensors.py b/setup_tiling_tensors.py new file mode 100644 index 00000000..15d73c98 --- /dev/null +++ b/setup_tiling_tensors.py @@ -0,0 +1,23 @@ +import numpy as np +import os +import glob +import shutil +from scripts.util.util import FormatWriter, InputCacheSuiteSparse + +#### PARAMS #### +tile = True +app_name = "tensor3_ttv" +vector_names = ['c'] +############## + +tiled_tensors = glob.glob(f"tiles/{app_name}/mtx/*.tns") +formatwriter = FormatWriter() +inputCache = InputCacheSuiteSparse() + +for tensor in tiled_tensors: + if any(x in tensor for x in vector_names): + #vector + inputCache.load(tensor) + formatwriter.writeout_separate_sparse_only() + else: + print("regular 3d tensors can be packed and tiled") \ No newline at end of file diff --git a/tile_pairing.py b/tile_pairing.py new file mode 100644 index 00000000..5e171464 --- /dev/null +++ b/tile_pairing.py @@ -0,0 +1,437 @@ +import shutil +import glob +import subprocess +import os +import json + +# test = "bcsstm26" +# test = "rel5" +test = "qiulp" +# test = "adder_dcop_30" +# test = "n4c6-b1" +# app_name = "mat_residual" +# app_name = "matmul_ijk" +# app_name = "matmul_ijk" +# app_name = "mat_mattransmul" +app_name = "mat_elemmul" +const_val = 2 # only for mat_mattransmul + + +tiles_accumulation = {} + +b_tensors = glob.glob(f"/home/avb03/sam/tiles/{app_name}/formatted/tensor_B*") +c_tensors = glob.glob(f"/home/avb03/sam/tiles/{app_name}/formatted/tensor_C*") +d_tensors = glob.glob(f"/aha/garnet/tiles_{app_name}_{test}/{app_name}/formatted/tensor_D*") + +print("b_tensors: ", b_tensors) +print("c_tensors: ", c_tensors) +print("d_tensors: ", d_tensors) + +# b_tensors = glob.glob(f"/aha/garnet/tiles_{app_name}_{test}/formatted/tensor_B*") +# c_tensors = glob.glob(f"/aha/garnet/tiles_{app_name}_{test}/formatted/tensor_C*") + +b_vec_tensors = glob.glob(f"/aha/garnet/tiles_{app_name}_{test}/{app_name}/formatted/tensor_b*") +c_vec_tensors = glob.glob(f"/aha/garnet/tiles_{app_name}_{test}/{app_name}/formatted/tensor_c*") +d_vec_tensors = glob.glob(f"/aha/garnet/tiles_{app_name}_{test}/{app_name}/formatted/tensor_d*") + +d_loc_paired = [] +b_loc_paired = [] + +if not os.path.exists("SPARSE_TESTS/MAT_TMP_DIR"): + os.makedirs("SPARSE_TESTS/MAT_TMP_DIR") + +os.system(f"rm -rf SPARSE_TESTS/{app_name}*") +os.system(f"rm -rf SPARSE_TESTS/MAT_TMP_DIR/tile*") + +tile = 0 + +os.chdir("SPARSE_TESTS") + +if app_name == "matmul_ijk": + for b in b_tensors: + for c in c_tensors: + tile_str = "tile" + str(tile) + b_loc = b[-7:] + c_loc = c[-7:] + b_loc = b_loc.split("_") + c_loc = c_loc.split("_") + if(b_loc[1] == c_loc[0] and b_loc[3] == c_loc[2]): + print(b, c) + + if b_loc[2] not in tiles_accumulation: + tiles_accumulation[b_loc[2]] = [] + + tiles_accumulation[b_loc[2]].append(tile_str) + + if not os.path.exists(f"./MAT_TMP_DIR/{tile_str}"): + os.mkdir(f"./MAT_TMP_DIR/{tile_str}") + + shutil.copy(f"{b}/B0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_0_crd") + shutil.copy(f"{b}/B0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_0_seg") + + shutil.copy(f"{b}/B1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_1_crd") + shutil.copy(f"{b}/B1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_1_seg") + + shutil.copy(f"{b}/B_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_vals") + + shutil.copy(f"{b}/B_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_shape") + + shutil.copy(f"{c}/C0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_crd") + shutil.copy(f"{c}/C0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_seg") + + shutil.copy(f"{c}/C1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_crd") + shutil.copy(f"{c}/C1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_seg") + + shutil.copy(f"{c}/C_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_vals") + + shutil.copy(f"{c}/C_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_shape") + + tile = tile + 1 +elif app_name == "mat_elemadd" or app_name == "mat_elemmul": + for b in b_tensors: + for c in c_tensors: + tile_str = "tile" + str(tile) + b_loc = b[-7:] + c_loc = c[-7:] + b_loc = b_loc.split("_") + c_loc = c_loc.split("_") + if(b_loc == c_loc): + print(b, c) + if not os.path.exists(f"./MAT_TMP_DIR/{tile_str}"): + os.mkdir(f"./MAT_TMP_DIR/{tile_str}") + shutil.copy(f"{b}/B0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_0_crd") + shutil.copy(f"{b}/B0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_0_seg") + + shutil.copy(f"{b}/B1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_1_crd") + shutil.copy(f"{b}/B1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_1_seg") + + shutil.copy(f"{b}/B_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_vals") + + shutil.copy(f"{b}/B_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_shape") + + shutil.copy(f"{c}/C0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_crd") + shutil.copy(f"{c}/C0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_seg") + + shutil.copy(f"{c}/C1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_crd") + shutil.copy(f"{c}/C1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_seg") + + shutil.copy(f"{c}/C_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_vals") + + shutil.copy(f"{c}/C_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_shape") + + # subprocess.call(["aha", + # "regress", + # "fast"], + # text=True) + + # shutil.copy("/aha/garnet/SPARSE_TESTS/GLB_DIR/matmul_ijk_combined_seed_tile1/output_gold.npy", "/aha/garnet/SPARSE_TESTS/GLB_DIR/matmul_ijk_combined_seed_tile1/bin") + # shutil.copytree("/aha/garnet/SPARSE_TESTS/GLB_DIR/matmul_ijk_combined_seed_tile1/bin", f"/aha/garnet/SPARSE_TESTS/{tile_str}") + tile = tile + 1 + # print("we are on tile ", tile) +elif app_name == "mat_mattransmul": + for b in b_tensors: + for c in c_vec_tensors: + for d in d_vec_tensors: + tile_str = "tile" + str(tile) + b_loc = b[-7:] + c_loc = c[-3:] + d_loc = d[-3:] + + b_loc = b_loc.split("_") + c_loc = c_loc.split("_") + d_loc = d_loc.split("_") + + if(b_loc[1] == c_loc[0] and b_loc[3] == c_loc[1] and b_loc[0] == d_loc[0] and b_loc[2] == d_loc[1]): + # if(b_loc[1] == d_loc[0] and b_loc[3] == d_loc[1] and b_loc[0] == c_loc[0] and b_loc[2] == c_loc[1]): + d_loc_paired.append(d_loc) + + print(f"\n ----- TILE {tile} ----- \n") + print("B is: ", b) #in build_tb, B == C, c == d, d == f. (#FIXME: change build_tb) + print("C is: ", c) + print("d is: ", d) + print(f"\n ----- TILE {tile} ----- \n") + if not os.path.exists(f"./MAT_TMP_DIR/{tile_str}"): + os.mkdir(f"./MAT_TMP_DIR/{tile_str}") + + shutil.copy(f"{b}/B0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_crd") + shutil.copy(f"{b}/B0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_seg") + + shutil.copy(f"{b}/B1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_crd") + shutil.copy(f"{b}/B1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_seg") + + shutil.copy(f"{b}/B_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_vals") + + shutil.copy(f"{b}/B_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_shape") + + shutil.copy(f"{c}/c1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_1_crd") + shutil.copy(f"{c}/c1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_1_seg") + + shutil.copy(f"{c}/c0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_0_crd") + shutil.copy(f"{c}/c0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_0_seg") + + shutil.copy(f"{d}/d1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_f_mode_1_crd") + shutil.copy(f"{d}/d1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_f_mode_1_seg") + + shutil.copy(f"{d}/d0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_f_mode_0_crd") + shutil.copy(f"{d}/d0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_f_mode_0_seg") + + shutil.copy(f"{c}/c_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_vals") + shutil.copy(f"{c}/c_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_shape") + + shutil.copy(f"{d}/d_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_f_mode_vals") + shutil.copy(f"{d}/d_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_f_mode_shape") + + with open(f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_vals", 'w') as file: + file.write(str(const_val)) + + with open(f"./MAT_TMP_DIR/{tile_str}/tensor_e_mode_vals", 'w') as file: + file.write(str(const_val)) + + tile = tile + 1 + elif d_loc not in d_loc_paired: + # case: B and c tiles are zero but d is nonzero. We have all d tiles. Just take a B and c tile, copy it and make it zero.' + d_loc_paired.append(d_loc) + print(f"\n ----- TILE D-unpaired {tile} ----- \n") + print("B (zero tile) is: ", b) #in build_tb, B == C, c == d, d == f. (#FIXME: change build_tb) + print("C (zero tile) is: ", c) + print("d is: ", d) + print(f"\n ----- TILE D-unpaired {tile} ----- \n") + + if not os.path.exists(f"./MAT_TMP_DIR/{tile_str}"): + os.mkdir(f"./MAT_TMP_DIR/{tile_str}") + + shutil.copy(f"{b}/B0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_crd") + shutil.copy(f"{b}/B0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_seg") + + shutil.copy(f"{b}/B1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_crd") + shutil.copy(f"{b}/B1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_seg") + + shutil.copy(f"{b}/B_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_vals") + + # clear out C vals + with open(f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_vals", 'r+') as file: + contents = file.read() + contents = contents.replace(contents, str(0)) + file.seek(0) + file.write(contents) + + shutil.copy(f"{b}/B_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_shape") + + shutil.copy(f"{c}/c1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_1_crd") + shutil.copy(f"{c}/c1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_1_seg") + + shutil.copy(f"{c}/c0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_0_crd") + shutil.copy(f"{c}/c0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_0_seg") + + shutil.copy(f"{d}/d1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_f_mode_1_crd") + shutil.copy(f"{d}/d1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_f_mode_1_seg") + + shutil.copy(f"{d}/d0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_f_mode_0_crd") + shutil.copy(f"{d}/d0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_f_mode_0_seg") + + shutil.copy(f"{c}/c_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_vals") + + # clear out d vals + with open(f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_vals", 'r+') as file: + contents = file.read() + contents = contents.replace(contents, str(0)) + file.seek(0) + file.write(contents) + + shutil.copy(f"{c}/c_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_shape") + + shutil.copy(f"{d}/d_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_f_mode_vals") + shutil.copy(f"{d}/d_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_f_mode_shape") + + with open(f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_vals", 'w') as file: + file.write(str(const_val)) + + with open(f"./MAT_TMP_DIR/{tile_str}/tensor_e_mode_vals", 'w') as file: + file.write(str(const_val)) + + tile = tile + 1 + print("d_loc_paired: ", d_loc_paired) +elif app_name == "mat_vecmul_ij": + for b in b_tensors: + for c in c_vec_tensors: + tile_str = "tile" + str(tile) + b_loc = b[-7:] + c_loc = c[-3:] + + b_loc = b_loc.split("_") + c_loc = c_loc.split("_") + + # if(b_loc[1] == c_loc[0] and b_loc[3] == c_loc[1] and b_loc[0] == d_loc[0] and b_loc[2] == d_loc[1]): + if(b_loc[1] == c_loc[0] and b_loc[3] == c_loc[1]): + print(b,c) + if not os.path.exists(f"./MAT_TMP_DIR/{tile_str}"): + os.mkdir(f"./MAT_TMP_DIR/{tile_str}") + + shutil.copy(f"{b}/B0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_0_crd") + shutil.copy(f"{b}/B0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_0_seg") + + shutil.copy(f"{b}/B1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_1_crd") + shutil.copy(f"{b}/B1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_1_seg") + + shutil.copy(f"{b}/B_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_vals") + + shutil.copy(f"{b}/B_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_shape") + + # shutil.copy(f"{c}/c1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_c_mode_1_crd") + # shutil.copy(f"{c}/c1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_c_mode_1_seg") + + shutil.copy(f"{c}/c0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_c_mode_0_crd") + shutil.copy(f"{c}/c0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_c_mode_0_seg") + + shutil.copy(f"{c}/c_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_c_mode_vals") + shutil.copy(f"{c}/c_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_c_mode_shape") + + tile = tile + 1 +elif app_name == "mat_residual": + for b in b_vec_tensors: + for c in c_tensors: + for d in d_vec_tensors: + tile_str = "tile" + str(tile) + b_loc = b[-3:] + c_loc = c[-7:] + d_loc = d[-3:] + + b_loc = b_loc.split("_") + c_loc = c_loc.split("_") + d_loc = d_loc.split("_") + + # if(b_loc[1] == c_loc[0] and b_loc[3] == c_loc[1] and b_loc[0] == d_loc[0] and b_loc[2] == d_loc[1]): + if(c_loc[0] == b_loc[0] and c_loc[2] == b_loc[1] and c_loc[1] == d_loc[0] and c_loc[3] == d_loc[1]): + print(b, c, d) + b_loc_paired.append(b_loc) + + if not os.path.exists(f"./MAT_TMP_DIR/{tile_str}"): + os.mkdir(f"./MAT_TMP_DIR/{tile_str}") + + shutil.copy(f"{c}/C0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_crd") + shutil.copy(f"{c}/C0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_seg") + + shutil.copy(f"{c}/C1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_crd") + shutil.copy(f"{c}/C1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_seg") + + shutil.copy(f"{c}/C_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_vals") + + shutil.copy(f"{c}/C_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_shape") + + shutil.copy(f"{b}/b1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_1_crd") + shutil.copy(f"{b}/b1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_1_seg") + + shutil.copy(f"{b}/b0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_0_crd") + shutil.copy(f"{b}/b0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_0_seg") + + shutil.copy(f"{d}/d1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_1_crd") + shutil.copy(f"{d}/d1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_1_seg") + + shutil.copy(f"{d}/d0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_0_crd") + shutil.copy(f"{d}/d0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_0_seg") + + shutil.copy(f"{b}/b_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_vals") + shutil.copy(f"{b}/b_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_shape") + + shutil.copy(f"{d}/d_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_vals") + shutil.copy(f"{d}/d_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_shape") + + tile = tile + 1 + elif b_loc not in b_loc_paired: + b_loc_paired.append(b_loc) + + if not os.path.exists(f"./MAT_TMP_DIR/{tile_str}"): + os.mkdir(f"./MAT_TMP_DIR/{tile_str}") + + shutil.copy(f"{c}/C0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_crd") + shutil.copy(f"{c}/C0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_seg") + + shutil.copy(f"{c}/C1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_crd") + shutil.copy(f"{c}/C1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_seg") + + shutil.copy(f"{c}/C_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_vals") + + # clear out C vals + with open(f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_vals", 'r+') as file: + contents = file.read() + contents = contents.replace(contents, str(0)) + file.seek(0) + file.write(contents) + + shutil.copy(f"{c}/C_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_shape") + + shutil.copy(f"{b}/b1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_1_crd") + shutil.copy(f"{b}/b1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_1_seg") + + shutil.copy(f"{b}/b0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_0_crd") + shutil.copy(f"{b}/b0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_0_seg") + + shutil.copy(f"{d}/d1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_1_crd") + shutil.copy(f"{d}/d1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_1_seg") + + shutil.copy(f"{d}/d0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_0_crd") + shutil.copy(f"{d}/d0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_0_seg") + + shutil.copy(f"{b}/b_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_vals") + shutil.copy(f"{b}/b_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_b_mode_shape") + + shutil.copy(f"{d}/d_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_vals") + shutil.copy(f"{d}/d_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_shape") + + # clear out d vals + with open(f"./MAT_TMP_DIR/{tile_str}/tensor_d_mode_vals", 'r+') as file: + contents = file.read() + contents = contents.replace(contents, str(0)) + file.seek(0) + file.write(contents) + + tile = tile + 1 + +elif app_name == "mat_sddmm": + for b in b_tensors: + for c in c_tensors: + for d in d_tensors: + tile_str = "tile" + str(tile) + + b_loc = b[-7:] + c_loc = c[-7:] + d_loc = d[-7:] + + b_loc = b_loc.split("_") + c_loc = c_loc.split("_") + d_loc = d_loc.split("_") + + # first j, then i (k is a free coordinate) + if(b_loc[0] == d_loc[1] and b_loc[2] == d_loc[3] and b_loc[1] == c_loc[0] and b_loc[3] == c_loc[2]): + print(b, c, d) + if not os.path.exists(f"./MAT_TMP_DIR/{tile_str}"): + os.mkdir(f"./MAT_TMP_DIR/{tile_str}") + + shutil.copy(f"{b}/B0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_0_crd") + shutil.copy(f"{b}/B0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_0_seg") + + shutil.copy(f"{b}/B1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_1_crd") + shutil.copy(f"{b}/B1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_1_seg") + + shutil.copy(f"{b}/B_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_vals") + + shutil.copy(f"{b}/B_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_shape") + + shutil.copy(f"{c}/C0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_crd") + shutil.copy(f"{c}/C0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_seg") + + shutil.copy(f"{c}/C1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_crd") + shutil.copy(f"{c}/C1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_seg") + + shutil.copy(f"{c}/C_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_vals") + + shutil.copy(f"{c}/C_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_shape") + + tile = tile + 1 + +print("tiles_accumulation: ", tiles_accumulation) + +with open("../tiles_accumulation.json", "w") as file: + json.dump(tiles_accumulation, file) + +print("there are ", tile_str, " tiles") \ No newline at end of file From 9c6443322baca43e466c68e1f186a1e397196171 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Sun, 20 Aug 2023 10:33:22 -0700 Subject: [PATCH 54/76] updated matrix tiling flow --- sam/sim/src/tiling/tile.py | 2 +- scripts/tiling/tile_ext.sh | 4 ++-- tile_pairing.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 76dc1dde..637aa71d 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -29,7 +29,7 @@ "mat_mattransmul": "X(i,j)=B(j,i)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss:0 -f=d:ss:0 -s=reorder(i,j)", "mat_vecmul_ij" : "X(i,j)=B(i,j)*c(j) -f=X:ss -f=B:ss -f=c:ss:0 -s=reorder(i,j)", "mat_residual": "X(i,j)=b(i)-C(i,j)*d(j) -f=X:ss -f=C:ss -f=b:ss:0 -f=d:ss:0 -s=reorder(i,j)", - "mat_sddmm": "X(i,j)=B(i,j)*C(i,k)*D(k,j) -f=X:ss -f=B:ss -f=C:ss -f=D:ss -s=reorder(i,j,k)"} + "mat_sddmm": "X(i,j)=B(i,j)*C(i,k)*D(k,j) -f=X:ss -f=B:ss -f=C:dd -f=D:dd:1,0 -s=reorder(i,j,k)"} def print_dict(dd): diff --git a/scripts/tiling/tile_ext.sh b/scripts/tiling/tile_ext.sh index 5acaeab7..e43b9c87 100755 --- a/scripts/tiling/tile_ext.sh +++ b/scripts/tiling/tile_ext.sh @@ -6,8 +6,8 @@ BENCHMARKS=( # matmul_ikj # mat_mattransmul - # mat_vecmul_ij - mat_residual + mat_sddmm + # mat_residual ) appname=$3 diff --git a/tile_pairing.py b/tile_pairing.py index 5e171464..e5e1dc5d 100644 --- a/tile_pairing.py +++ b/tile_pairing.py @@ -13,7 +13,7 @@ # app_name = "matmul_ijk" # app_name = "matmul_ijk" # app_name = "mat_mattransmul" -app_name = "mat_elemmul" +app_name = "mat_vecmul_ij" const_val = 2 # only for mat_mattransmul @@ -434,4 +434,4 @@ with open("../tiles_accumulation.json", "w") as file: json.dump(tiles_accumulation, file) -print("there are ", tile_str, " tiles") \ No newline at end of file +print("there are ", tile, " tiles") \ No newline at end of file From 5be8b8f8b3e25ba31a086f25a9e217d0ef532369 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Sun, 20 Aug 2023 11:54:21 -0700 Subject: [PATCH 55/76] minor matrix tiling updates --- scripts/tiling/tile_ext.sh | 3 ++- setup_tiling_mat.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/tiling/tile_ext.sh b/scripts/tiling/tile_ext.sh index e43b9c87..e9d7b146 100755 --- a/scripts/tiling/tile_ext.sh +++ b/scripts/tiling/tile_ext.sh @@ -6,7 +6,8 @@ BENCHMARKS=( # matmul_ikj # mat_mattransmul - mat_sddmm + # mat_sddmm + mat_vecmul_ij # mat_residual ) diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py index bd12c015..e9739d24 100644 --- a/setup_tiling_mat.py +++ b/setup_tiling_mat.py @@ -9,13 +9,13 @@ ## PARAMS ###################################################################### # 'rel5', 'mk9-b1', -data = ['rel5'] +data = ['west2021'] # app_name = "mat_elemadd" # app_name = "mat_elemmul" -app_name = "mat_sddmm" +# app_name = "mat_sddmm" # app_name = "matmul_ijk" # app_name = "mat_elemmul" -# app_name = "mat_vecmul_ij" +app_name = "mat_vecmul_ij" # app_name = "mat_residual" # data_file = open("scripts/tensor_names/suitesparse_valid_mid50.txt") # data_file_lines = data_file.readlines() From 887b0a57db99fbfcd59aaafb8e0ce87d260e2683 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Mon, 21 Aug 2023 18:10:27 -0700 Subject: [PATCH 56/76] all matrix apps tiling flow --- find_max_tilesize.py | 5 ++++- sam/sim/src/tiling/tile.py | 3 ++- scripts/tiling/tile_ext.sh | 1 + setup_tiling_mat.py | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/find_max_tilesize.py b/find_max_tilesize.py index 8eb96038..bab4549a 100644 --- a/find_max_tilesize.py +++ b/find_max_tilesize.py @@ -34,7 +34,7 @@ def check_keyword_in_output(command, keyword): return False -tile_size = 450 +tile_size = 300 step = 10 for _ in range(20): @@ -66,6 +66,9 @@ def check_keyword_in_output(command, keyword): tile_size -= step step //= 2 + if tile_size == 450: + break + if step == 0: if _ >= 15: step = 10 diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 637aa71d..35822d5e 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -29,7 +29,8 @@ "mat_mattransmul": "X(i,j)=B(j,i)*c(j)+d(i) -f=X:ss -f=B:ss -f=c:ss:0 -f=d:ss:0 -s=reorder(i,j)", "mat_vecmul_ij" : "X(i,j)=B(i,j)*c(j) -f=X:ss -f=B:ss -f=c:ss:0 -s=reorder(i,j)", "mat_residual": "X(i,j)=b(i)-C(i,j)*d(j) -f=X:ss -f=C:ss -f=b:ss:0 -f=d:ss:0 -s=reorder(i,j)", - "mat_sddmm": "X(i,j)=B(i,j)*C(i,k)*D(k,j) -f=X:ss -f=B:ss -f=C:dd -f=D:dd:1,0 -s=reorder(i,j,k)"} + "mat_sddmm": "X(i,j)=B(i,j)*C(i,k)*D(k,j) -f=X:ss -f=B:ss -f=C:dd -f=D:dd:1,0 -s=reorder(i,j,k)", + "mat_elemadd3": "X(i,j)=B(i,j)+C(i,j)+D(i,j) -f=X:ss -f=B:ss -f=C:ss -f=D:ss"} def print_dict(dd): diff --git a/scripts/tiling/tile_ext.sh b/scripts/tiling/tile_ext.sh index e9d7b146..234e588f 100755 --- a/scripts/tiling/tile_ext.sh +++ b/scripts/tiling/tile_ext.sh @@ -7,6 +7,7 @@ BENCHMARKS=( # matmul_ikj # mat_mattransmul # mat_sddmm + # mat_vecmul_ij mat_vecmul_ij # mat_residual ) diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py index e9739d24..6fa553dc 100644 --- a/setup_tiling_mat.py +++ b/setup_tiling_mat.py @@ -9,7 +9,7 @@ ## PARAMS ###################################################################### # 'rel5', 'mk9-b1', -data = ['west2021'] +data = ['adder_trans_02'] # app_name = "mat_elemadd" # app_name = "mat_elemmul" # app_name = "mat_sddmm" From 0f0b87efc95e80858ff850b447f4c5de2b4846c7 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Wed, 23 Aug 2023 20:27:32 -0700 Subject: [PATCH 57/76] loading in same vectors as CPU --- count_nnz_tiling.py | 34 +++--- sam/sim/src/tiling/tile.py | 17 ++- sam/util.py | 7 ++ scripts/tiling/tile_ext.sh | 4 +- setup_tiling_mat.py | 244 +++++++++++++++++-------------------- tile_pairing.py | 70 ++++++++++- 6 files changed, 217 insertions(+), 159 deletions(-) diff --git a/count_nnz_tiling.py b/count_nnz_tiling.py index c98bdd3a..c05b054b 100644 --- a/count_nnz_tiling.py +++ b/count_nnz_tiling.py @@ -10,33 +10,29 @@ def count_nonzeros(matrix_values_file): tile_dirs = glob.glob("SPARSE_TESTS/MAT_TMP_DIR/tile*") num_tiles = len(tile_dirs) +limit = 900 print("there are ", num_tiles, "tiles") -limit = 1000 -tot_num_nonzeros = 0 + for tile_num in range(0,num_tiles): + tot_num_nonzeros = 0 + tensor_C_values_file = f'SPARSE_TESTS/MAT_TMP_DIR/tile{tile_num}/tensor_C_mode_vals' num_nonzeros = count_nonzeros(tensor_C_values_file) - if num_nonzeros >= limit: - print("error! too many nonzeros in tensorC, tile", tile_num) - # raise Exception - -# tot_num_nonzeros += num_nonzeros - -# average_num_nonzeros = tot_num_nonzeros / 9 -# print("for matrix C, the average number of non-zero values is", average_num_nonzeros) + tot_num_nonzeros += num_nonzeros -tot_num_nonzeros = 0 - -for tile_num in range(0,num_tiles): tensor_C_values_file = f'SPARSE_TESTS/MAT_TMP_DIR/tile{tile_num}/tensor_B_mode_vals' num_nonzeros = count_nonzeros(tensor_C_values_file) - if num_nonzeros >= limit: - print("error! too many nonzeros in tensorB, tile", tile_num) - # raise Exception -# tot_num_nonzeros += num_nonzeros + tot_num_nonzeros += num_nonzeros -# average_num_nonzeros = tot_num_nonzeros / 6 -# print("for matrix B, the average number of non-zero values is", average_num_nonzeros) + tensor_C_values_file = f'SPARSE_TESTS/MAT_TMP_DIR/tile{tile_num}/tensor_D_mode_vals' + + num_nonzeros = count_nonzeros(tensor_C_values_file) + tot_num_nonzeros += tot_num_nonzeros + + if tot_num_nonzeros >= limit: + print("tot_num_nonzeros: ", tot_num_nonzeros) + print("error! too many nonzeros in matrices") + raise Exception \ No newline at end of file diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 35822d5e..bf71a7bb 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -14,7 +14,7 @@ from pathlib import Path from sam.util import SUITESPARSE_PATH, SuiteSparseTensor, InputCacheSuiteSparse, ScipyTensorShifter, \ - FROSTT_PATH, FrosttTensor, PydataSparseTensorDumper, InputCacheTensor + FROSTT_PATH, FrosttTensor, PydataSparseTensorDumper, InputCacheTensor, constructOtherMatKey, constructOtherVecKey from sam.sim.src.tiling.process_expr import parse_all # FIXME: This should not be here... Set your SAM_HOME directory @@ -274,7 +274,6 @@ def cotile_coo(tensor_names, tensors, permutation_strs, ivar_strs, split_map, hi def get_other_tensors(app_str, tensor, other_nonempty=True): tensors = [tensor] - if "matmul" in app_str: print("Writing shifted...") shifted = ScipyTensorShifter().shiftLastMode(tensor) @@ -335,8 +334,18 @@ def get_other_tensors(app_str, tensor, other_nonempty=True): elif "mat_vecmul" in app_str: print("Writing other tensors...") - rows, cols = tensor.shape - tensor_c = scipy.sparse.random(cols, 1, data_rvs=np.ones).toarray().flatten() + tensorName = args.input_tensor + # c(j) use mode1 + variant = "mode1" + path = constructOtherVecKey(tensorName,variant) + tensor_c_from_path = FrosttTensor(path) + tensor_c = tensor_c_from_path.load().todense() + + print("TENSOR SHAPE: ", tensor.shape) + print("TENSOR_C SHAPE: ", tensor_c.shape) + + # rows, cols = tensor.shape + # tensor_c = scipy.sparse.random(cols, 1, data_rvs=np.ones).toarray().flatten() if other_nonempty: tensor_c[0] = 1 diff --git a/sam/util.py b/sam/util.py index fbe308c9..85ab59a3 100644 --- a/sam/util.py +++ b/sam/util.py @@ -35,6 +35,13 @@ def safeCastScipyTensorToInts(tensor): data[i] = round_sparse(tensor.data[i]) return scipy.sparse.coo_matrix(tensor.coords, data, tensor.shape) +def constructOtherVecKey(tensorName, variant, sparsity=0.001): + path = os.getenv('TACO_TENSOR_PATH') + return f"{path}/{tensorName}-vec_{variant}-{sparsity}.tns" + +def constructOtherMatKey(tensorName, variant, sparsity=0.001): + path = os.getenv('TACO_TENSOR_PATH') + return f"{path}/../suitesparse/{tensorName}_{variant}.mtx" # ScipyTensorShifter shifts all elements in the last mode # of the input scipy/sparse tensor by one. diff --git a/scripts/tiling/tile_ext.sh b/scripts/tiling/tile_ext.sh index 234e588f..e0dba099 100755 --- a/scripts/tiling/tile_ext.sh +++ b/scripts/tiling/tile_ext.sh @@ -8,8 +8,10 @@ BENCHMARKS=( # mat_mattransmul # mat_sddmm # mat_vecmul_ij - mat_vecmul_ij + # mat_vecmul_ij # mat_residual + mat_elemadd3 + # matmul_ijk ) appname=$3 diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py index 6fa553dc..c68b3fb3 100644 --- a/setup_tiling_mat.py +++ b/setup_tiling_mat.py @@ -8,19 +8,31 @@ ## PARAMS ###################################################################### -# 'rel5', 'mk9-b1', +# data = ['rajat12'] + data = ['adder_trans_02'] +tilesizes = [30] # app_name = "mat_elemadd" # app_name = "mat_elemmul" # app_name = "mat_sddmm" -# app_name = "matmul_ijk" +# app_name = "matmul_ijk" +app_name = "mat_elemadd3" # app_name = "mat_elemmul" -app_name = "mat_vecmul_ij" # app_name = "mat_residual" -# data_file = open("scripts/tensor_names/suitesparse_valid_mid50.txt") + +# data = [] +# data_file = open("onyx_final_eval_mid50_tensor_names.txt") # data_file_lines = data_file.readlines() # for line in data_file_lines: # data.append(line[:-1]) + +# with open('matmul_tilesize_list.txt', 'r') as file: +# lines = file.readlines() + +# tilesizes = [int(line.strip()) for line in lines] +print("TILESIZES: ", tilesizes) +print("DATA: ", data) + mode_to_exclude = 0 addition_vector_name = "d" #mattransmul (d) and residual (b) only @@ -28,16 +40,21 @@ samples_directory = f"samples/{app_name}" docker_path = f"avb03-sparse-tiling" use_dataset_files = False -matrix_app=True ############################################################################### -os.environ["SUITESPARSE_PATH"] = "/nobackup/owhsu/sparse-datasets/suitesparse/" -os.environ["FROSTT_PATH"] = "/nobackup/owhsu/sparse-datasets/frostt/" -os.environ["SUITESPARSE_FORMATTED_PATH"] = "/home/avb03/sam/SUITESPARSE_FORMATTED" -os.environ["FROSTT_FORMATTED_TACO_PATH"] = "/home/avb03/sam/FROST_FORMATTED_TACO" -os.environ["FROSTT_FORMATTED_PATH"] = "/home/avb03/sam/FROST_FORMATTED" -os.environ["TACO_TENSOR_PATH"] = "/home/avb03/sam/TACO_TENSOR" +def write_to_line(file_path, line_number, new_content): + with open(file_path, 'r') as file: + lines = file.readlines() + + if line_number > len(lines) or line_number < 1: + # Line number is out of range + return + + lines[line_number - 1] = new_content + '\n' + + with open(file_path, 'w') as file: + file.writelines(lines) def replace_ones_with_zeros(mtx_file): with open(mtx_file, 'r') as file: @@ -54,132 +71,95 @@ def replace_ones_with_zeros(mtx_file): file.writelines(new_lines) -if(matrix_app): - for datum in data: - rmdir = f"rm -rf tiles/{app_name}" - os.system(rmdir) +i = 0 +for datum in data: + tilesize = tilesizes[i] + + yaml_file = "sam/sim/src/tiling/memory_config_onyx.yaml" + mem_tile_line = f"Mem_tile_size: {tilesize}" + print(mem_tile_line) + write_to_line(yaml_file, 19, mem_tile_line) + + rmdir = f"rm -rf tiles/{app_name}" + os.system(rmdir) - mtx_file = glob.glob(f"{SUITESPARSE_PATH}/{datum}.mtx")[0] - os.makedirs("extensor_mtx", exist_ok=True) - shutil.copy(mtx_file,f"extensor_mtx/{datum}.mtx") + mtx_file = glob.glob(f"{SUITESPARSE_PATH}/{datum}.mtx")[0] + os.makedirs("extensor_mtx", exist_ok=True) + shutil.copy(mtx_file,f"extensor_mtx/{datum}.mtx") + + command = f"./scripts/suitesparse_memory_model_runner.sh {datum} {app_name}" + os.system(command) + + directories = glob.glob(f'tiles/{app_name}/formatted/tensor_[a-z]*') + + #for vectors, do cleanup + for directory in directories: + print(directory) + match = re.search(r'tensor_([a-z])', directory) + if match: + lowercase_letter = match.group(1) - command = f"./scripts/suitesparse_memory_model_runner.sh {datum} {app_name}" - os.system(command) + crd_file = os.path.join(directory, f"{lowercase_letter}{mode_to_exclude}_crd.txt") + seg_file = os.path.join(directory, f"{lowercase_letter}{mode_to_exclude}_seg.txt") + + # if os.path.exists(crd_file): + # os.remove(crd_file) - directories = glob.glob(f'tiles/{app_name}/formatted/tensor_[a-z]*') + # if os.path.exists(seg_file): + # os.remove(seg_file) - #for vectors, do cleanup - for directory in directories: - print(directory) - match = re.search(r'tensor_([a-z])', directory) - if match: - lowercase_letter = match.group(1) + samples_with_addition_vector = None + + # dense tile replacement for addition + if app_name == "mat_mattransmul" or app_name == "mat_residual": + # samples_with_addition_vector = glob.glob(f"{samples_directory}/*[{addition_vector_name}]*") + # samples_with_addition_vector = glob.glob(f"{samples_directory}/mtm_w_0_1/tensor_d_tile_0_0") + samples_with_addition_vector = glob.glob(f"{samples_directory}/mtm_w_0_1_BAK") + + + print(samples_with_addition_vector) + #fill in missing tiles with blanks + for sample in samples_with_addition_vector: + file_path = os.path.join(sample, f"{addition_vector_name}_vals.txt") + + with open(file_path, "r") as file: + file_contents = file.read() - crd_file = os.path.join(directory, f"{lowercase_letter}{mode_to_exclude}_crd.txt") - seg_file = os.path.join(directory, f"{lowercase_letter}{mode_to_exclude}_seg.txt") + file_contents = file_contents.replace("1", "0") - # if os.path.exists(crd_file): - # os.remove(crd_file) + with open(file_path, "w") as file: + file.write(file_contents) - # if os.path.exists(seg_file): - # os.remove(seg_file) + tile_range = [(0,i) for i in range(8)] + [(1,i) for i in range(4)] - samples_with_addition_vector = None - - # dense tile replacement for addition - if app_name == "mat_mattransmul" or app_name == "mat_residual": - # samples_with_addition_vector = glob.glob(f"{samples_directory}/*[{addition_vector_name}]*") - # samples_with_addition_vector = glob.glob(f"{samples_directory}/mtm_w_0_1/tensor_d_tile_0_0") - samples_with_addition_vector = glob.glob(f"{samples_directory}/mtm_w_0_1_BAK") - - - print(samples_with_addition_vector) - #fill in missing tiles with blanks - for sample in samples_with_addition_vector: - file_path = os.path.join(sample, f"{addition_vector_name}_vals.txt") - - with open(file_path, "r") as file: - file_contents = file.read() - - file_contents = file_contents.replace("1", "0") - - with open(file_path, "w") as file: - file.write(file_contents) - - tile_range = [(0,i) for i in range(8)] + [(1,i) for i in range(4)] - - for i,j in tile_range: - tile_dir = f"tiles/{app_name}/formatted/tensor_{addition_vector_name}_tile_{i}_{j}" - - if not os.path.exists(tile_dir): - # replace_ones_with_zeros("samples/mat_mattransmul/tensor_d_dense_mtx.mtx") - - # copy_over_to_mtx_dir = f"cp samples/mat_mattransmul/tensor_d_dense_gold_stash.mtx tiles/{app_name}/mtx/tensor_{addition_vector_name}_tile_{i}_{j}.mtx" - # os.system(copy_over_to_mtx_dir) - - sample_tile_dir = samples_with_addition_vector[0] - - if os.path.exists(sample_tile_dir): - shutil.copytree(sample_tile_dir, tile_dir) - - if(use_dataset_files): - assert os.path.exists("SUITESPARSE_FORMATTED") - - temp_name = app_name - if app_name == "mat_vecmul_ij": - temp_name = "mat_vecmul" - - app_path_additional = f"SUITESPARSE_FORMATTED/{datum}/{temp_name}/" - - for tens in other_tensors: - valid_dirs = glob.glob(f"tiles/{app_name}/formatted/tensor_{tens}*") - for d in valid_dirs: - remove_tens = f"rm {d}/*" - print(remove_tens) - os.system(remove_tens) - - files_to_cp = glob.glob(f"{app_path_additional}tensor_{tens}*") - - for file in files_to_cp: - if "mode_0_crd" in file: - copy_rename = f"cp {file} {d}/{tens}0_crd.txt" - print(copy_rename) - os.system(copy_rename) - elif "mode_1_crd" in file: - copy_rename = f"cp {file} {d}/{tens}1_crd.txt" - print(copy_rename) - os.system(copy_rename) - elif "mode_0_seg" in file: - copy_rename = f"cp {file} {d}/{tens}0_seg.txt" - print(copy_rename) - os.system(copy_rename) - elif "mode_1_seg" in file: - copy_rename = f"cp {file} {d}/{tens}1_seg.txt" - print(copy_rename) - os.system(copy_rename) - elif "vals" in file: - copy_rename = f"cp {file} {d}/{tens}_vals.txt" - print(copy_rename) - os.system(copy_rename) - elif "shape" in file: - copy_rename = f"cp {file} {d}/{tens}_shape.txt" - print(copy_rename) - os.system(copy_rename) - - - dump_gold_tiles = f"python3 scripts/tiling/generate_gold_mattransmul.py --yaml_name memory_config_extensor_17M_llb.yaml" - os.system(dump_gold_tiles) - - # os.makedirs("tiles_compiled", exist_ok=True) - # copy_rename = f"cp -r tiles/{app_name} tiles_compiled/{app_name}_{datum}" - # print(copy_rename) - # os.system(copy_rename) - - docker_clean = f"docker exec {docker_path} rm -r /aha/garnet/tiles_{app_name}_{datum}" - print(docker_clean) - os.system(docker_clean) - - docker_copy_command = f"docker cp tiles {docker_path}:/aha/garnet/tiles_{app_name}_{datum}" - print(docker_copy_command) - os.system(docker_copy_command) - + for i,j in tile_range: + tile_dir = f"tiles/{app_name}/formatted/tensor_{addition_vector_name}_tile_{i}_{j}" + + if not os.path.exists(tile_dir): + # replace_ones_with_zeros("samples/mat_mattransmul/tensor_d_dense_mtx.mtx") + + # copy_over_to_mtx_dir = f"cp samples/mat_mattransmul/tensor_d_dense_gold_stash.mtx tiles/{app_name}/mtx/tensor_{addition_vector_name}_tile_{i}_{j}.mtx" + # os.system(copy_over_to_mtx_dir) + + sample_tile_dir = samples_with_addition_vector[0] + + if os.path.exists(sample_tile_dir): + shutil.copytree(sample_tile_dir, tile_dir) + + dump_gold_tiles = f"python3 scripts/tiling/generate_gold_mattransmul.py --yaml_name memory_config_extensor_17M_llb.yaml" + os.system(dump_gold_tiles) + + # os.makedirs("tiles_compiled", exist_ok=True) + # copy_rename = f"cp -r tiles/{app_name} tiles_compiled/{app_name}_{datum}" + # print(copy_rename) + # os.system(copy_rename) + + docker_clean = f"docker exec {docker_path} rm -r /aha/garnet/tiles_{app_name}_{datum}" + print(docker_clean) + os.system(docker_clean) + + docker_copy_command = f"docker cp tiles {docker_path}:/aha/garnet/tiles_{app_name}_{datum}" + print(docker_copy_command) + os.system(docker_copy_command) + + i = i+1 diff --git a/tile_pairing.py b/tile_pairing.py index e5e1dc5d..638df2da 100644 --- a/tile_pairing.py +++ b/tile_pairing.py @@ -13,7 +13,7 @@ # app_name = "matmul_ijk" # app_name = "matmul_ijk" # app_name = "mat_mattransmul" -app_name = "mat_vecmul_ij" +app_name = "mat_elemadd3" const_val = 2 # only for mat_mattransmul @@ -21,7 +21,7 @@ b_tensors = glob.glob(f"/home/avb03/sam/tiles/{app_name}/formatted/tensor_B*") c_tensors = glob.glob(f"/home/avb03/sam/tiles/{app_name}/formatted/tensor_C*") -d_tensors = glob.glob(f"/aha/garnet/tiles_{app_name}_{test}/{app_name}/formatted/tensor_D*") +d_tensors = glob.glob(f"/home/avb03/sam/tiles/{app_name}/formatted/tensor_D*") print("b_tensors: ", b_tensors) print("c_tensors: ", c_tensors) @@ -31,7 +31,8 @@ # c_tensors = glob.glob(f"/aha/garnet/tiles_{app_name}_{test}/formatted/tensor_C*") b_vec_tensors = glob.glob(f"/aha/garnet/tiles_{app_name}_{test}/{app_name}/formatted/tensor_b*") -c_vec_tensors = glob.glob(f"/aha/garnet/tiles_{app_name}_{test}/{app_name}/formatted/tensor_c*") +c_vec_tensors = glob.glob(f"/home/avb03/sam/tiles/{app_name}/formatted/tensor_c*") +print("c_vec_tensors: ", c_vec_tensors) d_vec_tensors = glob.glob(f"/aha/garnet/tiles_{app_name}_{test}/{app_name}/formatted/tensor_d*") d_loc_paired = [] @@ -429,6 +430,69 @@ tile = tile + 1 +elif app_name == "mat_elemadd3": + for b in b_tensors: + for c in c_tensors: + for d in d_tensors: + tile_str = "tile" + str(tile) + b_loc = b[-7:] + c_loc = c[-7:] + b_loc = b_loc.split("_") + c_loc = c_loc.split("_") + d_loc = d[-7:] + d_loc = d_loc.split("_") + + # if(b_loc == c_loc and b_loc != d_loc): + # b_equal_c_no_d += 1 + # if(c_loc == d_loc and b_loc != c_loc): + # c_equal_d_no_b += 1 + # if(b_loc == d_loc and b_loc != c_loc): + # b_equal_d_no_c += 1 + + if(b_loc == c_loc and b_loc == d_loc): + print(b, c, d) + if not os.path.exists(f"./MAT_TMP_DIR/{tile_str}"): + os.mkdir(f"./MAT_TMP_DIR/{tile_str}") + shutil.copy(f"{b}/B0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_0_crd") + shutil.copy(f"{b}/B0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_0_seg") + + shutil.copy(f"{b}/B1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_1_crd") + shutil.copy(f"{b}/B1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_1_seg") + + shutil.copy(f"{b}/B_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_vals") + + shutil.copy(f"{b}/B_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_B_mode_shape") + + shutil.copy(f"{c}/C0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_crd") + shutil.copy(f"{c}/C0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_0_seg") + + shutil.copy(f"{c}/C1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_crd") + shutil.copy(f"{c}/C1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_1_seg") + + shutil.copy(f"{c}/C_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_vals") + + shutil.copy(f"{c}/C_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_C_mode_shape") + + shutil.copy(f"{d}/D0_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_D_mode_0_crd") + shutil.copy(f"{d}/D0_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_D_mode_0_seg") + + shutil.copy(f"{d}/D1_crd.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_D_mode_1_crd") + shutil.copy(f"{d}/D1_seg.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_D_mode_1_seg") + + shutil.copy(f"{d}/D_vals.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_D_mode_vals") + + shutil.copy(f"{d}/D_shape.txt", f"./MAT_TMP_DIR/{tile_str}/tensor_D_mode_shape") + + # subprocess.call(["aha", + # "regress", + # "fast"], + # text=True) + + # shutil.copy("/aha/garnet/SPARSE_TESTS/GLB_DIR/matmul_ijk_combined_seed_tile1/output_gold.npy", "/aha/garnet/SPARSE_TESTS/GLB_DIR/matmul_ijk_combined_seed_tile1/bin") + # shutil.copytree("/aha/garnet/SPARSE_TESTS/GLB_DIR/matmul_ijk_combined_seed_tile1/bin", f"/aha/garnet/SPARSE_TESTS/{tile_str}") + tile = tile + 1 + # print("we are on tile ", tile) + print("tiles_accumulation: ", tiles_accumulation) with open("../tiles_accumulation.json", "w") as file: From 60f4ad7bb7c26ea490e71ecfd634621f4fb6e655 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Fri, 1 Sep 2023 20:07:07 -0700 Subject: [PATCH 58/76] input arg setup --- setup_tiling_mat.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py index c68b3fb3..0ae6cde8 100644 --- a/setup_tiling_mat.py +++ b/setup_tiling_mat.py @@ -3,6 +3,7 @@ import shutil import os import re +import sys from sam.util import SUITESPARSE_PATH @@ -10,13 +11,13 @@ # data = ['rajat12'] -data = ['adder_trans_02'] -tilesizes = [30] +data = [sys.argv[2]] +tilesizes = [int(sys.argv[3])] # app_name = "mat_elemadd" # app_name = "mat_elemmul" # app_name = "mat_sddmm" # app_name = "matmul_ijk" -app_name = "mat_elemadd3" +app_name = sys.argv[1] # app_name = "mat_elemmul" # app_name = "mat_residual" From 19080a3f2e9a1c6b8a42d34ce4537889089c39e1 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Sat, 2 Sep 2023 13:29:22 -0700 Subject: [PATCH 59/76] latest update tiling --- maximum_tiling.py | 105 +++++++++++++++++++++++++++++++------ scripts/tiling/tile_ext.sh | 5 +- setup_tiling_mat.py | 4 +- 3 files changed, 94 insertions(+), 20 deletions(-) diff --git a/maximum_tiling.py b/maximum_tiling.py index 3be52642..317ea607 100644 --- a/maximum_tiling.py +++ b/maximum_tiling.py @@ -41,6 +41,40 @@ def pair_tiles(app_name): if (b_loc[1] == c_loc[0] and b_loc[3] == c_loc[2]): tile_pairing[tile] = [b, c] tile += 1 + elif "elemmul" in app_name: + operands = ["B", "C"] + operand_files = get_files_from_dir(path, operands) + b_tensors = operand_files["B"] + c_tensors = operand_files["C"] + + tile = 0 + for b in b_tensors: + for c in c_tensors: + b_loc = get_tile_id(b) + c_loc = get_tile_id(c) + if (b_loc == c_loc): + tile_pairing[tile] = [b, c] + tile += 1 + elif "elemadd3" in app_name: + operands = ["B", "C", "D"] + operand_files = get_files_from_dir(path, operands) + b_tensors = operand_files["B"] + c_tensors = operand_files["C"] + d_tensors = operand_files["D"] + + tile = 0 + for b in b_tensors: + for c in c_tensors: + b_loc = get_tile_id(b) + c_loc = get_tile_id(c) + if (b_loc != c_loc): + continue + + for d in d_tensors: + d_loc = get_tile_id(d) + if (b_loc == c_loc and c_loc == d_loc): + tile_pairing[tile] = [b, c, d] + tile += 1 return tile_pairing @@ -56,16 +90,44 @@ def compute_outputs(tile_pairing, app_name, limit=900): C_mat = read_mtx(value[1]) C_mat = np.transpose(C_mat) out = np.matmul(B_mat, C_mat) - # if np.count_nonzero(out) > limit: - if np.any(out): + if np.count_nonzero(out) > limit or np.count_nonzero(B_mat) > limit or np.count_nonzero(C_mat) > limit: + # if np.any(out): print("tile = ", key) print("B_tile_ID = ", value[0]) print("C_tile_ID = ", value[1]) print("out = ", out) print("count = ", np.count_nonzero(out)) - # return EarlyReturn() - breakpoint() - break + return EarlyReturn() + elif "elemmul" in app_name: + B_mat = read_mtx(value[0]) + C_mat = read_mtx(value[1]) + out = np.multiply(B_mat, C_mat) + # if np.any(out): + if np.count_nonzero(out) > limit or np.count_nonzero(B_mat) > limit or np.count_nonzero(C_mat) > limit: + # if np.count_nonzero(out) > limit or (np.count_nonzero(B_mat) + np.count_nonzero(C_mat)) > limit: + print("tile = ", key) + print("B_tile_ID = ", value[0]) + print("C_tile_ID = ", value[1]) + print("out = ", out) + print("count = ", np.count_nonzero(out)) + return EarlyReturn() + elif "elemadd3" in app_name: + B_mat = read_mtx(value[0]) + C_mat = read_mtx(value[1]) + D_mat = read_mtx(value[2]) + + out = np.add(np.add(B_mat, C_mat), D_mat) + # if np.any(out): + if np.count_nonzero(out) > limit or np.count_nonzero(B_mat) > limit or np.count_nonzero(C_mat) > limit or np.count_nonzero(D_mat) > limit: + # if np.count_nonzero(out) > limit or (np.count_nonzero(B_mat) + np.count_nonzero(C_mat)) > limit: + print("tile = ", key) + print("B_tile_ID = ", value[0]) + print("C_tile_ID = ", value[1]) + print("D_tile_ID = ", value[2]) + print("out = ", out) + print("count = ", np.count_nonzero(out)) + return EarlyReturn() + return None def find_optimal_tilesize(app_name, datum, initial=30, step_size=10): @@ -73,7 +135,8 @@ def find_optimal_tilesize(app_name, datum, initial=30, step_size=10): max_tile_size = initial prev_tile_pairing = None - for _ in range(10): + # while True: + for _ in range(50): call_tiling = f"python3 setup_tiling_mat.py {app_name} {datum} {tile_size} > temp.txt" os.system(call_tiling) print(call_tiling) @@ -90,18 +153,28 @@ def find_optimal_tilesize(app_name, datum, initial=30, step_size=10): print("***********************") prev_tile_pairing = tile_pairing - return None + return tile_size, prev_tile_pairing if __name__ == "__main__": - app_name = "matmul_ijk" - datum = "qiulp" + max_list = {} + for i in range(1, 11): + app_name = "matmul_ijk" + datum = f"matrix_sp80_sm_{i}" - tile_pairing = pair_tiles(app_name) - compute_outputs(tile_pairing, app_name) + # tile_pairing = pair_tiles(app_name) + # compute_outputs(tile_pairing, app_name) + + max_tile_size, tile_pairing = find_optimal_tilesize(app_name, datum, initial=30, step_size=10) + print("-"*20) + print(f"MAX TILESIZE for {app_name}, {datum}: {max_tile_size}") + print(f"NUMBER OF TILES: {len(tile_pairing.keys())}") + print("-"*20) + + max_list[datum] = [max_tile_size, len(tile_pairing.keys())] + + call_tiling = f"python3 setup_tiling_mat.py {app_name} {datum} {max_tile_size} > temp.txt" + os.system(call_tiling) + print(call_tiling) - # max_tile_size, tile_pairing = find_optimal_tilesize(app_name, datum) - # print("-"*20) - # print(f"MAX TILESIZE for {app_name}, {datum}: {max_tile_size}") - # print(f"NUMBER OF TILES: {len(tile_pairing.keys())}") - # print("-"*20) \ No newline at end of file + print(max_list) \ No newline at end of file diff --git a/scripts/tiling/tile_ext.sh b/scripts/tiling/tile_ext.sh index e0dba099..3483df89 100755 --- a/scripts/tiling/tile_ext.sh +++ b/scripts/tiling/tile_ext.sh @@ -10,8 +10,9 @@ BENCHMARKS=( # mat_vecmul_ij # mat_vecmul_ij # mat_residual - mat_elemadd3 - # matmul_ijk + # mat_elemadd3 + matmul_ijk + # mat_elemmul ) appname=$3 diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py index 0ae6cde8..84ff2051 100644 --- a/setup_tiling_mat.py +++ b/setup_tiling_mat.py @@ -31,8 +31,8 @@ # lines = file.readlines() # tilesizes = [int(line.strip()) for line in lines] -print("TILESIZES: ", tilesizes) -print("DATA: ", data) +# print("TILESIZES: ", tilesizes) +# print("DATA: ", data) mode_to_exclude = 0 addition_vector_name = "d" #mattransmul (d) and residual (b) only From a80b449bd503649942e8bbacf269aaf42e247227 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Sat, 2 Sep 2023 13:30:17 -0700 Subject: [PATCH 60/76] helper scripts (need cleanup) --- count_nnz_tiling.py | 26 ++++++++++++++++++++------ tile_pairing.py | 4 ++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/count_nnz_tiling.py b/count_nnz_tiling.py index c05b054b..c013fa4f 100644 --- a/count_nnz_tiling.py +++ b/count_nnz_tiling.py @@ -1,4 +1,5 @@ import glob +import sys def count_nonzeros(matrix_values_file): with open(matrix_values_file, 'r') as values_file: matrix_values = [float(val) for val in values_file.readlines()] @@ -13,7 +14,10 @@ def count_nonzeros(matrix_values_file): limit = 900 print("there are ", num_tiles, "tiles") - +sparsity_B = 0 +sparsity_C = 0 +# tilesize=int(sys.argv[1])**2 +tot_num_nonzeros = 0 for tile_num in range(0,num_tiles): tot_num_nonzeros = 0 @@ -21,18 +25,28 @@ def count_nonzeros(matrix_values_file): num_nonzeros = count_nonzeros(tensor_C_values_file) tot_num_nonzeros += num_nonzeros + if num_nonzeros >= limit: + print("num_nonzeros: ", num_nonzeros) + print("error! too many nonzeros in INPUT matrices") + raise Exception tensor_C_values_file = f'SPARSE_TESTS/MAT_TMP_DIR/tile{tile_num}/tensor_B_mode_vals' num_nonzeros = count_nonzeros(tensor_C_values_file) tot_num_nonzeros += num_nonzeros + if num_nonzeros >= limit: + print("num_nonzeros: ", num_nonzeros) + print("error! too many nonzeros in INPUT matrices") + raise Exception - tensor_C_values_file = f'SPARSE_TESTS/MAT_TMP_DIR/tile{tile_num}/tensor_D_mode_vals' - - num_nonzeros = count_nonzeros(tensor_C_values_file) - tot_num_nonzeros += tot_num_nonzeros if tot_num_nonzeros >= limit: print("tot_num_nonzeros: ", tot_num_nonzeros) print("error! too many nonzeros in matrices") - raise Exception \ No newline at end of file + raise Exception + +sparsity_B /= num_tiles +sparsity_C /= num_tiles + +print("sparsity_B: ", sparsity_B) +print("sparsity_C: ", sparsity_C) \ No newline at end of file diff --git a/tile_pairing.py b/tile_pairing.py index 638df2da..8af7000b 100644 --- a/tile_pairing.py +++ b/tile_pairing.py @@ -12,8 +12,8 @@ # app_name = "mat_residual" # app_name = "matmul_ijk" # app_name = "matmul_ijk" -# app_name = "mat_mattransmul" -app_name = "mat_elemadd3" +# app_name = "mat_mattrpython3ansmul" +app_name = "mat_elemmul" const_val = 2 # only for mat_mattransmul From 9f73f16c07b243444b8facab14b7138b4a9efc72 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Sat, 2 Sep 2023 23:08:37 -0700 Subject: [PATCH 61/76] square matrices for vecmul iter --- spmv_iter_matrices.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 spmv_iter_matrices.txt diff --git a/spmv_iter_matrices.txt b/spmv_iter_matrices.txt new file mode 100644 index 00000000..f113329a --- /dev/null +++ b/spmv_iter_matrices.txt @@ -0,0 +1,9 @@ +bcsstm26 +tols2000 +west2021 +adder_dcop_30 +adder_trans_02 +watt_2 +rajat12 +G42 +G30 From a1925123acadee034c7505fb03855f0cca8cbcbd Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Sun, 3 Sep 2023 00:05:19 -0700 Subject: [PATCH 62/76] moved to right place --- scripts/tensor_names/spmv_iter_matrices.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 scripts/tensor_names/spmv_iter_matrices.txt diff --git a/scripts/tensor_names/spmv_iter_matrices.txt b/scripts/tensor_names/spmv_iter_matrices.txt new file mode 100644 index 00000000..f113329a --- /dev/null +++ b/scripts/tensor_names/spmv_iter_matrices.txt @@ -0,0 +1,9 @@ +bcsstm26 +tols2000 +west2021 +adder_dcop_30 +adder_trans_02 +watt_2 +rajat12 +G42 +G30 From 6c9dbd730bfdf301718afbb3f5e207f46184b174 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Sun, 3 Sep 2023 12:26:59 -0700 Subject: [PATCH 63/76] changes for new complex apps --- maximum_tiling.py | 122 ++++++++++++++++++--- sam/sim/src/tiling/memory_config_onyx.yaml | 2 +- sam/sim/src/tiling/tile.py | 28 ++++- scripts/tiling/tile_ext.sh | 4 +- setup_tiling_mat.py | 24 ++-- 5 files changed, 149 insertions(+), 31 deletions(-) diff --git a/maximum_tiling.py b/maximum_tiling.py index 317ea607..e9a41415 100644 --- a/maximum_tiling.py +++ b/maximum_tiling.py @@ -76,6 +76,62 @@ def pair_tiles(app_name): tile_pairing[tile] = [b, c, d] tile += 1 + elif "mat_mask_tri" in app_name: + operands = ["B", "C", "D"] + operand_files = get_files_from_dir(path, operands) + b_tensors = operand_files["B"] + c_tensors = operand_files["C"] + d_tensors = operand_files["D"] + + tile = 0 + for b in b_tensors: + for c in c_tensors: + b_loc = get_tile_id(b) + c_loc = get_tile_id(c) + if not (b_loc[0] == c_loc[0] and b_loc[2] == c_loc[2]): + continue + + for d in d_tensors: + d_loc = get_tile_id(d) + if(c_loc[1] == d_loc[0] and c_loc[3] == d_loc[2] and b_loc[1] == d_loc[1] and b_loc[3] == d_loc[3] and b_loc[0] == c_loc[0] and b_loc[2] == c_loc[2]): + tile_pairing[tile] = [b, c, d] + tile += 1 + elif "mat_vecmul_iter" in app_name: + operands = ["B", "C", "D", "E", "f"] + operand_files = get_files_from_dir(path, operands) + b_tensors = operand_files["B"] + c_tensors = operand_files["C"] + d_tensors = operand_files["D"] + e_tensors = operand_files["E"] + f_tensors = operand_files["f"] + + tile = 0 + + for b in b_tensors: + for c in c_tensors: + b_loc = get_tile_id(b) + c_loc = get_tile_id(c) + if not (b_loc[1] == c_loc[0] and b_loc[3] == c_loc[2]): + continue + for d in d_tensors: + d_loc = get_tile_id(d) + # check k coord + if not (c_loc[1] == d_loc[0] and c_loc[3] == d_loc[2]): + continue + for e in e_tensors: + e_loc = get_tile_id(e) + # check l coord + if not (d_loc[1] == e_loc[0] and d_loc[3] == e_loc[2]): + continue + for f in f_tensors: + f_loc = get_tile_id(f) + if (d_loc[1] == e_loc[0] and d_loc[3] == e_loc[2] and c_loc[1] == d_loc[0] and c_loc[3] == d_loc[2] and b_loc[1] == c_loc[0] and b_loc[3] == c_loc[2] and e_loc[1] == f_loc[0] and e_loc[3] == f_loc[1]): + tile_pairing[tile] = [b, c, d, e, f] + tile += 1 + + + + return tile_pairing def read_mtx(mtx_path): @@ -127,7 +183,41 @@ def compute_outputs(tile_pairing, app_name, limit=900): print("out = ", out) print("count = ", np.count_nonzero(out)) return EarlyReturn() - + elif "mat_mask_tri" in app_name: + B_mat = read_mtx(value[0]) + C_mat = read_mtx(value[1]) + D_mat = read_mtx(value[2]) + D_mat = np.transpose(D_mat) + out = np.sum(np.multiply(np.matmul(C_mat, D_mat), B_mat)) + if np.count_nonzero(out) > limit or np.count_nonzero(B_mat) > limit or np.count_nonzero(C_mat) > limit or np.count_nonzero(D_mat) > limit: + print("tile = ", key) + print("B_tile_ID = ", value[0]) + print("C_tile_ID = ", value[1]) + print("D_tile_ID = ", value[2]) + print("out = ", out) + print("count = ", np.count_nonzero(out)) + return EarlyReturn() + elif "mat_vecmul_iter" in app_name: + B_mat = read_mtx(value[0]) + C_mat = read_mtx(value[1]) + D_mat = read_mtx(value[2]) + E_mat = read_mtx(value[3]) + f_mat = read_mtx(value[4]) + # we transpose bc we swap in copy formatted + f_mat = np.transpose(f_mat) + out = np.matmul(np.matmul(np.matmul(np.matmul(B_mat, C_mat), D_mat), E_mat), f_mat) + if np.any(out): + # if np.count_nonzero(out) > limit or np.count_nonzero(B_mat) > limit or np.count_nonzero(C_mat) > limit or np.count_nonzero(D_mat) > limit or np.count_nonzero(E_mat) > limit or np.count_nonzero(f_mat) > limit: + print("tile = ", key) + print("B_tile_ID = ", value[0]) + print("C_tile_ID = ", value[1]) + print("D_tile_ID = ", value[2]) + print("E_tile_ID = ", value[3]) + print("f_tile_ID = ", value[4]) + print("out = ", out) + print("count = ", np.count_nonzero(out)) + breakpoint() + return EarlyReturn() return None def find_optimal_tilesize(app_name, datum, initial=30, step_size=10): @@ -158,23 +248,23 @@ def find_optimal_tilesize(app_name, datum, initial=30, step_size=10): if __name__ == "__main__": max_list = {} - for i in range(1, 11): - app_name = "matmul_ijk" - datum = f"matrix_sp80_sm_{i}" + # for i in range(1, 11): + app_name = "mat_vecmul_iter" + datum = "qiulp" - # tile_pairing = pair_tiles(app_name) - # compute_outputs(tile_pairing, app_name) + tile_pairing = pair_tiles(app_name) + compute_outputs(tile_pairing, app_name) - max_tile_size, tile_pairing = find_optimal_tilesize(app_name, datum, initial=30, step_size=10) - print("-"*20) - print(f"MAX TILESIZE for {app_name}, {datum}: {max_tile_size}") - print(f"NUMBER OF TILES: {len(tile_pairing.keys())}") - print("-"*20) + # max_tile_size, tile_pairing = find_optimal_tilesize(app_name, datum, initial=20, step_size=10) + # print("-"*20) + # print(f"MAX TILESIZE for {app_name}, {datum}: {max_tile_size}") + # print(f"NUMBER OF TILES: {len(tile_pairing.keys())}") + # print("-"*20) - max_list[datum] = [max_tile_size, len(tile_pairing.keys())] + # # max_list[datum] = [max_tile_size, len(tile_pairing.keys())] - call_tiling = f"python3 setup_tiling_mat.py {app_name} {datum} {max_tile_size} > temp.txt" - os.system(call_tiling) - print(call_tiling) + # call_tiling = f"python3 setup_tiling_mat.py {app_name} {datum} {max_tile_size} > temp.txt" + # os.system(call_tiling) + # print(call_tiling) - print(max_list) \ No newline at end of file + # print(max_list) \ No newline at end of file diff --git a/sam/sim/src/tiling/memory_config_onyx.yaml b/sam/sim/src/tiling/memory_config_onyx.yaml index b565bce0..a6fa9d35 100644 --- a/sam/sim/src/tiling/memory_config_onyx.yaml +++ b/sam/sim/src/tiling/memory_config_onyx.yaml @@ -16,4 +16,4 @@ n_levels: 3 level_names: ["Main", "Glb", "Mem"] Main_tile_size: None Glb_tile_size: 8 # 8 = (8x8) = 64 elements -Mem_tile_size: 30 #45 # Size of one dense dimension. 45 = (45*45) = 2025 +Mem_tile_size: 30 diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index bf71a7bb..c6ef86b7 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -30,7 +30,9 @@ "mat_vecmul_ij" : "X(i,j)=B(i,j)*c(j) -f=X:ss -f=B:ss -f=c:ss:0 -s=reorder(i,j)", "mat_residual": "X(i,j)=b(i)-C(i,j)*d(j) -f=X:ss -f=C:ss -f=b:ss:0 -f=d:ss:0 -s=reorder(i,j)", "mat_sddmm": "X(i,j)=B(i,j)*C(i,k)*D(k,j) -f=X:ss -f=B:ss -f=C:dd -f=D:dd:1,0 -s=reorder(i,j,k)", - "mat_elemadd3": "X(i,j)=B(i,j)+C(i,j)+D(i,j) -f=X:ss -f=B:ss -f=C:ss -f=D:ss"} + "mat_elemadd3": "X(i,j)=B(i,j)+C(i,j)+D(i,j) -f=X:ss -f=B:ss -f=C:ss -f=D:ss", + "mat_mask_tri": "X(i,j)=B(i,j)*C(i,k)*D(k,j) -f=X:ss -f=B:ss -f=C:ss -f=D:ss:1,0 -s=reorder(i,j,k)", + "mat_vecmul_iter": "X(i,j)=B(i,j)*C(j,k)*D(k,l)*E(l,m)*f(m) -f=X:ss -f=B:ss -f=C:ss -f=D:ss -f=E:ss -f=f:s -s=reorder(i,j,k,l,m)"} def print_dict(dd): @@ -303,6 +305,30 @@ def get_other_tensors(app_str, tensor, other_nonempty=True): shifted2 = ScipyTensorShifter().shiftLastMode(shifted) tensors.append(shifted2) + elif "mat_mask_tri" in app_str: + print("Writing other tensor 1...") + shifted = ScipyTensorShifter().shiftLastMode(tensor) + tensors.append(shifted) + + print("Writing shifted2...") + shifted2 = ScipyTensorShifter().shiftLastMode(shifted) + tensors.append(shifted2) + elif "mat_vecmul_iter" in app_str: + print("Writing other tensor 1...") + tensors.append(tensor) + tensors.append(tensor) + tensors.append(tensor) + + print("writing other vector...") + tensorName = args.input_tensor + variant = "mode1" + path = constructOtherVecKey(tensorName,variant) + tensor_c_from_path = FrosttTensor(path) + tensor_c = tensor_c_from_path.load().todense() + + # breakpoint() + tensors.append(tensor_c) + elif "mat_mattransmul" in app_str: print("Writing other tensors...") rows, cols = tensor.shape # i,j diff --git a/scripts/tiling/tile_ext.sh b/scripts/tiling/tile_ext.sh index 3483df89..7fc23251 100755 --- a/scripts/tiling/tile_ext.sh +++ b/scripts/tiling/tile_ext.sh @@ -11,7 +11,9 @@ BENCHMARKS=( # mat_vecmul_ij # mat_residual # mat_elemadd3 - matmul_ijk + # matmul_ijk + # mat_mask_tri + mat_vecmul_iter # mat_elemmul ) diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py index 84ff2051..1202ac81 100644 --- a/setup_tiling_mat.py +++ b/setup_tiling_mat.py @@ -11,8 +11,8 @@ # data = ['rajat12'] -data = [sys.argv[2]] -tilesizes = [int(sys.argv[3])] +# data = [sys.argv[2]] +# tilesizes = [int(sys.argv[3])] # app_name = "mat_elemadd" # app_name = "mat_elemmul" # app_name = "mat_sddmm" @@ -21,18 +21,18 @@ # app_name = "mat_elemmul" # app_name = "mat_residual" -# data = [] -# data_file = open("onyx_final_eval_mid50_tensor_names.txt") -# data_file_lines = data_file.readlines() -# for line in data_file_lines: -# data.append(line[:-1]) +data = [] +data_file = open("onyx_final_eval_mid50_tensor_names.txt") +data_file_lines = data_file.readlines() +for line in data_file_lines: + data.append(line[:-1]) -# with open('matmul_tilesize_list.txt', 'r') as file: -# lines = file.readlines() +with open('matmul_tilesize_list.txt', 'r') as file: + lines = file.readlines() -# tilesizes = [int(line.strip()) for line in lines] -# print("TILESIZES: ", tilesizes) -# print("DATA: ", data) +tilesizes = [int(line.strip()) for line in lines] +print("TILESIZES: ", tilesizes) +print("DATA: ", data) mode_to_exclude = 0 addition_vector_name = "d" #mattransmul (d) and residual (b) only From 46ce2681056855ad3839eb77edebb9e729b86cc6 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 29 Sep 2023 17:39:01 -0700 Subject: [PATCH 64/76] Add in fixes to scripts --- sam/util.py | 51 ------------------- scripts/formatting/datastructure_tns.py | 2 +- .../generate_suitesparse_formats.sh | 2 +- 3 files changed, 2 insertions(+), 53 deletions(-) diff --git a/sam/util.py b/sam/util.py index 0658de93..b023147d 100644 --- a/sam/util.py +++ b/sam/util.py @@ -602,54 +602,3 @@ def safeCastPydataTensorToInts(tensor): # data[i] = int(tensor.data[i]) data[i] = round_sparse(tensor.data[i]) return sparse.COO(tensor.coords, data, tensor.shape) - - -def parse_taco_format(infilename, outdir, tensorname, format_str): - with open(infilename, 'r') as inf: - level = -1 - count = 0 - seg = True - level_done = False - for line in inf: - if count == 0: - dim_start = line.find('(') + 1 - dim_end = line.find(')') - dims = line[dim_start: dim_end] - dims = dims.split('x') - - shapefile = os.path.join(outdir, tensorname + '_shape.txt') - with open(shapefile, 'w+') as shapef: - shapef.write(array_newline_str(dims)) - else: - if line.find(':') > -1: - level += 1 - seg = True - level_done = False - else: - start = line.find('[') + 1 - end = line.find(']') - line = line[start: end] - line = line.split(', ') - - if level_done: - # This is a values array - valfile = os.path.join(outdir, tensorname + '_vals.txt') - with open(valfile, 'w+') as valf: - valf.write(array_newline_str(line)) - else: - level_format = format_str[level] - if level_format == 's': - if seg: - segfile = os.path.join(outdir, tensorname + str(level) + - '_seg.txt') - with open(segfile, 'w+') as segf: - segf.write(array_newline_str(line)) - seg = False - else: - crdfile = os.path.join(outdir, tensorname + str(level) + - '_crd.txt') - with open(crdfile, 'w+') as crdf: - crdf.write(array_newline_str(line)) - level_done = True - - count += 1 diff --git a/scripts/formatting/datastructure_tns.py b/scripts/formatting/datastructure_tns.py index aede2dbc..7ff46056 100644 --- a/scripts/formatting/datastructure_tns.py +++ b/scripts/formatting/datastructure_tns.py @@ -1,7 +1,7 @@ import argparse import os from pathlib import Path -from sam.util import parse_taco_format +from scripts.util.util import parse_taco_format cwd = os.getcwd() diff --git a/scripts/formatting/generate_suitesparse_formats.sh b/scripts/formatting/generate_suitesparse_formats.sh index 8e74b9a1..3776800c 100755 --- a/scripts/formatting/generate_suitesparse_formats.sh +++ b/scripts/formatting/generate_suitesparse_formats.sh @@ -22,7 +22,7 @@ OTHERBENCHES='["mat_residual", "mat_mattransmul", "mat_vecmul"]' # THIS FILE MUST BE RUN FROM sam/ location outdir=${SUITESPARSE_FORMATTED_PATH} basedir=$(pwd) -textfile=$basedir/scripts/tensor_names/$1 +textfile=$basedir/$1 mkdir -p $outdir cd $outdir From d19e7da150cc39024ccf3fc84c68607a70b4ce6f Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Fri, 29 Sep 2023 17:42:06 -0700 Subject: [PATCH 65/76] Remove gantt reorder study to get CI passing --- .../test_matmul_kij_FINAL.py | 249 ----------------- .../test_reorder_matmul_ijk_GINA.py | 262 ------------------ 2 files changed, 511 deletions(-) delete mode 100644 sam/sim/test/reorder-study-gina/test_matmul_kij_FINAL.py delete mode 100644 sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py diff --git a/sam/sim/test/reorder-study-gina/test_matmul_kij_FINAL.py b/sam/sim/test/reorder-study-gina/test_matmul_kij_FINAL.py deleted file mode 100644 index 57390a62..00000000 --- a/sam/sim/test/reorder-study-gina/test_matmul_kij_FINAL.py +++ /dev/null @@ -1,249 +0,0 @@ -import pytest -import time -import scipy.sparse -from sam.sim.src.rd_scanner import UncompressCrdRdScan, CompressedCrdRdScan -from sam.sim.src.wr_scanner import ValsWrScan -from sam.sim.src.joiner import Intersect2, Union2 -from sam.sim.src.compute import Multiply2, Add2 -from sam.sim.src.crd_manager import CrdDrop, CrdHold -from sam.sim.src.repeater import Repeat, RepeatSigGen -from sam.sim.src.accumulator import Reduce -from sam.sim.src.accumulator import SparseAccumulator1, SparseAccumulator2 -from sam.sim.src.token import * -from sam.sim.test.test import * -from sam.sim.test.gold import * -import os -import csv -from sam.sim.test.gen_gantt import gen_gantt - -cwd = os.getcwd() -formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) - - -@pytest.mark.suitesparse -def test_matmul_kij_FINAL(samBench, ssname, check_gold, report_stats, debug_sim, cast, backpressure, depth, fill=0): - B_dirname = os.path.join(formatted_dir, ssname, "matmul_kij") - B_shape_filename = os.path.join(B_dirname, "tensor_B_mode_shape") - B_shape = read_inputs(B_shape_filename) - - B0_seg_filename = os.path.join(B_dirname, "tensor_B_mode_0_seg") - B_seg0 = read_inputs(B0_seg_filename) - B0_crd_filename = os.path.join(B_dirname, "tensor_B_mode_0_crd") - B_crd0 = read_inputs(B0_crd_filename) - - B1_seg_filename = os.path.join(B_dirname, "tensor_B_mode_1_seg") - B_seg1 = read_inputs(B1_seg_filename) - B1_crd_filename = os.path.join(B_dirname, "tensor_B_mode_1_crd") - B_crd1 = read_inputs(B1_crd_filename) - - B_vals_filename = os.path.join(B_dirname, "tensor_B_mode_vals") - B_vals = read_inputs(B_vals_filename, float) - - C_dirname = B_dirname - C_shape_filename = os.path.join(C_dirname, "tensor_C_mode_shape") - C_shape = read_inputs(C_shape_filename) - - C0_seg_filename = os.path.join(C_dirname, "tensor_C_mode_0_seg") - C_seg0 = read_inputs(C0_seg_filename) - C0_crd_filename = os.path.join(C_dirname, "tensor_C_mode_0_crd") - C_crd0 = read_inputs(C0_crd_filename) - - C1_seg_filename = os.path.join(C_dirname, "tensor_C_mode_1_seg") - C_seg1 = read_inputs(C1_seg_filename) - C1_crd_filename = os.path.join(C_dirname, "tensor_C_mode_1_crd") - C_crd1 = read_inputs(C1_crd_filename) - - C_vals_filename = os.path.join(C_dirname, "tensor_C_mode_vals") - C_vals = read_inputs(C_vals_filename, float) - - # THIS IS FOR SIZE INFO - Bs_dirname = B_dirname - Bs_seg = read_inputs(os.path.join(Bs_dirname, "tensor_B_mode_0_seg")) - - fiberlookup_Bk_17 = CompressedCrdRdScan(crd_arr=B_crd1, seg_arr=B_seg1, debug=debug_sim, statistics=report_stats, - back_en=backpressure, depth=int(depth)) - fiberlookup_Ck_18 = CompressedCrdRdScan(crd_arr=C_crd0, seg_arr=C_seg0, debug=debug_sim, statistics=report_stats, - back_en=backpressure, depth=int(depth)) - intersectk_16 = Intersect2(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - fiberlookup_Bi_15 = CompressedCrdRdScan(crd_arr=B_crd0, seg_arr=B_seg0, debug=debug_sim, statistics=report_stats, - back_en=backpressure, depth=int(depth)) - repsiggen_i_13 = RepeatSigGen(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - repeat_Ci_12 = Repeat(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - fiberlookup_Cj_11 = CompressedCrdRdScan(crd_arr=C_crd1, seg_arr=C_seg1, debug=debug_sim, statistics=report_stats, - back_en=backpressure, depth=int(depth)) - arrayvals_C_7 = Array(init_arr=C_vals, debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - crdhold_4 = CrdHold(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - repsiggen_j_9 = RepeatSigGen(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - repeat_Bj_8 = Repeat(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - arrayvals_B_6 = Array(init_arr=B_vals, debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - mul_5 = Multiply2(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - spaccumulator2_3 = SparseAccumulator2(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - spaccumulator2_3_drop_crd_inner = StknDrop(debug=debug_sim, statistics=report_stats, - back_en=backpressure, depth=int(depth)) - spaccumulator2_3_drop_crd_outer = StknDrop(debug=debug_sim, statistics=report_stats, - back_en=backpressure, depth=int(depth)) - spaccumulator2_3_drop_val = StknDrop(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - fiberwrite_Xvals_0 = ValsWrScan(size=1 * Bs_seg[-1] * Bs_seg[-1], fill=fill, debug=debug_sim, statistics=report_stats, - back_en=backpressure, depth=int(depth)) - fiberwrite_X1_1 = CompressWrScan(seg_size=Bs_seg[-1] + 1, size=Bs_seg[-1] * Bs_seg[-1], fill=fill, - debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - fiberwrite_X0_2 = CompressWrScan(seg_size=2, size=Bs_seg[-1], fill=fill, debug=debug_sim, statistics=report_stats, - back_en=backpressure, depth=int(depth)) - in_ref_B = [0, 'D'] - in_ref_C = [0, 'D'] - done = False - time_cnt = 0 - while not done and time_cnt < TIMEOUT: - if len(in_ref_B) > 0: - fiberlookup_Bk_17.set_in_ref(in_ref_B.pop(0), "") - - if len(in_ref_C) > 0: - fiberlookup_Ck_18.set_in_ref(in_ref_C.pop(0), "") - - intersectk_16.set_in1(fiberlookup_Bk_17.out_ref(), fiberlookup_Bk_17.out_crd(), fiberlookup_Bk_17) - intersectk_16.set_in2(fiberlookup_Ck_18.out_ref(), fiberlookup_Ck_18.out_crd(), fiberlookup_Ck_18) - - fiberlookup_Bi_15.set_in_ref(intersectk_16.out_ref1(), intersectk_16) - - repsiggen_i_13.set_istream(fiberlookup_Bi_15.out_crd(), fiberlookup_Bi_15) - - repeat_Ci_12.set_in_ref(intersectk_16.out_ref2(), intersectk_16) - repeat_Ci_12.set_in_repsig(repsiggen_i_13.out_repsig(), repsiggen_i_13) - - fiberlookup_Cj_11.set_in_ref(repeat_Ci_12.out_ref(), repeat_Ci_12) - - arrayvals_C_7.set_load(fiberlookup_Cj_11.out_ref(), fiberlookup_Cj_11) - - crdhold_4.set_outer_crd(fiberlookup_Bi_15.out_crd(), fiberlookup_Bi_15) - crdhold_4.set_inner_crd(fiberlookup_Cj_11.out_crd(), fiberlookup_Cj_11) - repsiggen_j_9.set_istream(fiberlookup_Cj_11.out_crd(), fiberlookup_Cj_11) - - repeat_Bj_8.set_in_ref(fiberlookup_Bi_15.out_ref(), fiberlookup_Bi_15) - repeat_Bj_8.set_in_repsig(repsiggen_j_9.out_repsig(), repsiggen_j_9) - - arrayvals_B_6.set_load(repeat_Bj_8.out_ref(), repeat_Bj_8) - - mul_5.set_in1(arrayvals_B_6.out_val(), arrayvals_B_6) - mul_5.set_in2(arrayvals_C_7.out_val(), arrayvals_C_7) - - spaccumulator2_3_drop_crd_outer.set_in_stream(crdhold_4.out_crd_outer(), crdhold_4) - spaccumulator2_3_drop_crd_inner.set_in_stream(crdhold_4.out_crd_inner(), crdhold_4) - spaccumulator2_3_drop_val.set_in_stream(mul_5.out_val(), mul_5) - spaccumulator2_3.set_crd_outer(spaccumulator2_3_drop_crd_outer.out_val(), spaccumulator2_3_drop_crd_outer) - spaccumulator2_3.set_crd_inner(spaccumulator2_3_drop_crd_inner.out_val(), spaccumulator2_3_drop_crd_inner) - spaccumulator2_3.set_val(spaccumulator2_3_drop_val.out_val(), spaccumulator2_3_drop_val) - - fiberwrite_Xvals_0.set_input(spaccumulator2_3.out_val(), spaccumulator2_3) - - fiberwrite_X1_1.set_input(spaccumulator2_3.out_crd_inner(), spaccumulator2_3) - - fiberwrite_X0_2.set_input(spaccumulator2_3.out_crd_outer(), spaccumulator2_3) - - fiberlookup_Bk_17.update() - fiberlookup_Ck_18.update() - intersectk_16.update() - fiberlookup_Bi_15.update() - repsiggen_i_13.update() - repeat_Ci_12.update() - fiberlookup_Cj_11.update() - arrayvals_C_7.update() - crdhold_4.update() - repsiggen_j_9.update() - repeat_Bj_8.update() - arrayvals_B_6.update() - mul_5.update() - spaccumulator2_3_drop_crd_outer.update() - spaccumulator2_3_drop_crd_inner.update() - spaccumulator2_3_drop_val.update() - spaccumulator2_3.update() - fiberwrite_Xvals_0.update() - fiberwrite_X1_1.update() - fiberwrite_X0_2.update() - - done = fiberwrite_X0_2.out_done() and fiberwrite_X1_1.out_done() and fiberwrite_Xvals_0.out_done() - time_cnt += 1 - - fiberwrite_X0_2.autosize() - fiberwrite_X1_1.autosize() - fiberwrite_Xvals_0.autosize() - - out_crds = [fiberwrite_X0_2.get_arr(), fiberwrite_X1_1.get_arr()] - out_segs = [fiberwrite_X0_2.get_seg_arr(), fiberwrite_X1_1.get_seg_arr()] - out_vals = fiberwrite_Xvals_0.get_arr() - - def bench(): - time.sleep(0.01) - - extra_info = dict() - extra_info["dataset"] = ssname - extra_info["cycles"] = time_cnt - extra_info["tensor_B_shape"] = B_shape - extra_info["tensor_C_shape"] = C_shape - extra_info["tensor_B/nnz"] = len(B_vals) - extra_info["tensor_C/nnz"] = len(C_vals) - - extra_info["result/vals_size"] = len(out_vals) - extra_info["result/nnz"] = len([x for x in out_vals if x != 0]) - - sample_dict = fiberlookup_Bk_17.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberlookup_Bk_17" + "/" + k] = sample_dict[k] - - sample_dict = fiberlookup_Ck_18.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberlookup_Ck_18" + "/" + k] = sample_dict[k] - - sample_dict = intersectk_16.return_statistics() - for k in sample_dict.keys(): - extra_info["intersectk_16" + "/" + k] = sample_dict[k] - - sample_dict = fiberlookup_Bi_15.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberlookup_Bi_15" + "/" + k] = sample_dict[k] - - sample_dict = repeat_Ci_12.return_statistics() - for k in sample_dict.keys(): - extra_info["repeat_Ci_12" + "/" + k] = sample_dict[k] - - sample_dict = fiberlookup_Cj_11.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberlookup_Cj_11" + "/" + k] = sample_dict[k] - - sample_dict = arrayvals_C_7.return_statistics() - for k in sample_dict.keys(): - extra_info["arrayvals_C_7" + "/" + k] = sample_dict[k] - - sample_dict = repeat_Bj_8.return_statistics() - for k in sample_dict.keys(): - extra_info["repeat_Bj_8" + "/" + k] = sample_dict[k] - - sample_dict = arrayvals_B_6.return_statistics() - for k in sample_dict.keys(): - extra_info["arrayvals_B_6" + "/" + k] = sample_dict[k] - - sample_dict = mul_5.return_statistics() - for k in sample_dict.keys(): - extra_info["mul_5" + "/" + k] = sample_dict[k] - - sample_dict = spaccumulator2_3.return_statistics() - for k in sample_dict.keys(): - extra_info["spaccumulator2_3" + "/" + k] = sample_dict[k] - - sample_dict = fiberwrite_Xvals_0.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberwrite_Xvals_0" + "/" + k] = sample_dict[k] - - sample_dict = fiberwrite_X1_1.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberwrite_X1_1" + "/" + k] = sample_dict[k] - - sample_dict = fiberwrite_X0_2.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberwrite_X0_2" + "/" + k] = sample_dict[k] - - gen_gantt(extra_info, "matmul_kij") - - if check_gold: - print("Checking gold...") - check_gold_matmul(ssname, debug_sim, cast, out_crds, out_segs, out_vals, "ss01") - samBench(bench, extra_info) diff --git a/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py b/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py deleted file mode 100644 index 26d36101..00000000 --- a/sam/sim/test/reorder-study-gina/test_reorder_matmul_ijk_GINA.py +++ /dev/null @@ -1,262 +0,0 @@ -import pytest -import time -import scipy.sparse -from sam.sim.src.rd_scanner import UncompressCrdRdScan, CompressedCrdRdScan -from sam.sim.src.wr_scanner import ValsWrScan -from sam.sim.src.joiner import Intersect2, Union2 -from sam.sim.src.compute import Multiply2, Add2 -from sam.sim.src.crd_manager import CrdDrop, CrdHold -from sam.sim.src.repeater import Repeat, RepeatSigGen -from sam.sim.src.accumulator import Reduce -from sam.sim.src.accumulator import SparseAccumulator1, SparseAccumulator2 -from sam.sim.src.token import * -from sam.sim.test.test import * -from sam.sim.test.gold import * -import os -import csv -from sam.sim.test.gen_gantt import gen_gantt - -cwd = os.getcwd() -formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) - - -@pytest.mark.suitesparse -def test_matmul_ijk_FINAL(samBench, ssname, check_gold, report_stats, debug_sim, cast, backpressure, depth, fill=0): - B_dirname = os.path.join(formatted_dir, ssname, "matmul_ijk") - B_shape_filename = os.path.join(B_dirname, "tensor_B_mode_shape") - B_shape = read_inputs(B_shape_filename) - - B0_seg_filename = os.path.join(B_dirname, "tensor_B_mode_0_seg") - B_seg0 = read_inputs(B0_seg_filename) - B0_crd_filename = os.path.join(B_dirname, "tensor_B_mode_0_crd") - B_crd0 = read_inputs(B0_crd_filename) - - B1_seg_filename = os.path.join(B_dirname, "tensor_B_mode_1_seg") - B_seg1 = read_inputs(B1_seg_filename) - B1_crd_filename = os.path.join(B_dirname, "tensor_B_mode_1_crd") - B_crd1 = read_inputs(B1_crd_filename) - - B_vals_filename = os.path.join(B_dirname, "tensor_B_mode_vals") - B_vals = read_inputs(B_vals_filename, float) - - C_dirname = B_dirname - C_shape_filename = os.path.join(C_dirname, "tensor_C_mode_shape") - C_shape = read_inputs(C_shape_filename) - - C0_seg_filename = os.path.join(C_dirname, "tensor_C_mode_0_seg") - C_seg0 = read_inputs(C0_seg_filename) - C0_crd_filename = os.path.join(C_dirname, "tensor_C_mode_0_crd") - C_crd0 = read_inputs(C0_crd_filename) - - C1_seg_filename = os.path.join(C_dirname, "tensor_C_mode_1_seg") - C_seg1 = read_inputs(C1_seg_filename) - C1_crd_filename = os.path.join(C_dirname, "tensor_C_mode_1_crd") - C_crd1 = read_inputs(C1_crd_filename) - - C_vals_filename = os.path.join(C_dirname, "tensor_C_mode_vals") - C_vals = read_inputs(C_vals_filename, float) - - # THIS IS FOR SIZE INFO - # Bs_dirname = B_dirname - # Bs_seg = read_inputs(os.path.join(Bs_dirname, "tensor_B_mode_0_seg")) - - fiberlookup_Bi_17 = CompressedCrdRdScan(crd_arr=B_crd0, seg_arr=B_seg0, debug=debug_sim, - back_en=backpressure, depth=int(depth), statistics=report_stats) - fiberwrite_X0_2 = CompressWrScan(seg_size=2, size=B_shape[0], fill=fill, debug=debug_sim, - back_en=backpressure, depth=int(depth), statistics=report_stats) - repsiggen_i_15 = RepeatSigGen(debug=debug_sim, back_en=backpressure, depth=int(depth)) - repeat_Ci_14 = Repeat(debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) - fiberlookup_Cj_13 = CompressedCrdRdScan(crd_arr=C_crd1, seg_arr=C_seg1, debug=debug_sim, - back_en=backpressure, depth=int(depth), statistics=report_stats) - fiberlookup_Ck_9 = CompressedCrdRdScan(crd_arr=C_crd0, seg_arr=C_seg0, debug=debug_sim, - back_en=backpressure, depth=int(depth), statistics=report_stats) - fiberwrite_X1_1 = CompressWrScan(seg_size=B_shape[0] + 1, size=B_shape[0] * C_shape[1], fill=fill, - debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) - repsiggen_j_11 = RepeatSigGen(debug=debug_sim, back_en=backpressure, depth=int(depth)) - repeat_Bj_10 = Repeat(debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) - fiberlookup_Bk_8 = CompressedCrdRdScan(crd_arr=B_crd1, seg_arr=B_seg1, debug=debug_sim, - back_en=backpressure, depth=int(depth), statistics=report_stats) - intersectk_7 = Intersect2(debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) - arrayvals_B_5 = Array(init_arr=B_vals, debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) - arrayvals_C_6 = Array(init_arr=C_vals, debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) - mul_4 = Multiply2(debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) - reduce_3 = Reduce(debug=debug_sim, back_en=backpressure, depth=int(depth), statistics=report_stats) - fiberwrite_Xvals_0 = ValsWrScan(size=1 * B_shape[0] * C_shape[1], fill=fill, debug=debug_sim, - back_en=backpressure, depth=int(depth), statistics=report_stats) - in_ref_B = [0, 'D'] - in_ref_C = [0, 'D'] - done = False - time_cnt = 0 - - while not done and time_cnt < TIMEOUT: - if len(in_ref_B) > 0: - fiberlookup_Bi_17.set_in_ref(in_ref_B.pop(0), "") - - fiberwrite_X0_2.set_input(fiberlookup_Bi_17.out_crd(), fiberlookup_Bi_17) - - repsiggen_i_15.set_istream(fiberlookup_Bi_17.out_crd(), fiberlookup_Bi_17) - - if len(in_ref_C) > 0: - repeat_Ci_14.set_in_ref(in_ref_C.pop(0), "") - repeat_Ci_14.set_in_repsig(repsiggen_i_15.out_repsig(), repsiggen_i_15) - - fiberlookup_Cj_13.set_in_ref(repeat_Ci_14.out_ref(), repeat_Ci_14) - - fiberlookup_Ck_9.set_in_ref(fiberlookup_Cj_13.out_ref(), fiberlookup_Cj_13) - - fiberwrite_X1_1.set_input(fiberlookup_Cj_13.out_crd(), fiberlookup_Cj_13) - - repsiggen_j_11.set_istream(fiberlookup_Cj_13.out_crd(), fiberlookup_Cj_13) - - repeat_Bj_10.set_in_ref(fiberlookup_Bi_17.out_ref(), fiberlookup_Bi_17) - repeat_Bj_10.set_in_repsig(repsiggen_j_11.out_repsig(), repsiggen_j_11) - - fiberlookup_Bk_8.set_in_ref(repeat_Bj_10.out_ref(), repeat_Bj_10) - - intersectk_7.set_in1(fiberlookup_Bk_8.out_ref(), fiberlookup_Bk_8.out_crd(), fiberlookup_Bk_8) - intersectk_7.set_in2(fiberlookup_Ck_9.out_ref(), fiberlookup_Ck_9.out_crd(), fiberlookup_Ck_9) - - arrayvals_B_5.set_load(intersectk_7.out_ref1(), intersectk_7) - - arrayvals_C_6.set_load(intersectk_7.out_ref2(), intersectk_7) - - mul_4.set_in1(arrayvals_B_5.out_val(), arrayvals_B_5) - mul_4.set_in2(arrayvals_C_6.out_val(), arrayvals_C_6) - - reduce_3.set_in_val(mul_4.out_val(), mul_4) - - fiberwrite_Xvals_0.set_input(reduce_3.out_val(), reduce_3) - - fiberlookup_Bi_17.update() - fiberwrite_X0_2.update() - repsiggen_i_15.update() - repeat_Ci_14.update() - fiberlookup_Cj_13.update() - fiberlookup_Ck_9.update() - fiberwrite_X1_1.update() - repsiggen_j_11.update() - repeat_Bj_10.update() - fiberlookup_Bk_8.update() - intersectk_7.update() - arrayvals_B_5.update() - arrayvals_C_6.update() - mul_4.update() - reduce_3.update() - fiberwrite_Xvals_0.update() - - done = fiberwrite_X0_2.out_done() and fiberwrite_X1_1.out_done() and fiberwrite_Xvals_0.out_done() - time_cnt += 1 - - fiberwrite_X0_2.autosize() - fiberwrite_X1_1.autosize() - fiberwrite_Xvals_0.autosize() - - out_crds = [fiberwrite_X0_2.get_arr(), fiberwrite_X1_1.get_arr()] - out_segs = [fiberwrite_X0_2.get_seg_arr(), fiberwrite_X1_1.get_seg_arr()] - out_vals = fiberwrite_Xvals_0.get_arr() - - def bench(): - time.sleep(0.01) - - extra_info = dict() - extra_info["dataset"] = ssname - extra_info["cycles"] = time_cnt - extra_info["tensor_B_shape"] = B_shape - extra_info["tensor_C_shape"] = C_shape - extra_info["tensor_B/nnz"] = len(B_vals) - extra_info["tensor_C/nnz"] = len(C_vals) - - extra_info["result/vals_size"] = len(out_vals) - extra_info["result/nnz"] = len([x for x in out_vals if x != 0]) - - sample_dict = fiberlookup_Bi_17.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberlookup_Bi_17" + "/" + k] = sample_dict[k] - - sample_dict = fiberwrite_X0_2.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberwrite_X0_2" + "/" + k] = sample_dict[k] - - sample_dict = repeat_Ci_14.return_statistics() - for k in sample_dict.keys(): - extra_info["repeat_Ci_14" + "/" + k] = sample_dict[k] - - sample_dict = fiberlookup_Cj_13.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberlookup_Cj_13" + "/" + k] = sample_dict[k] - - sample_dict = fiberwrite_X1_1.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberwrite_X1_1" + "/" + k] = sample_dict[k] - - sample_dict = repeat_Bj_10.return_statistics() - for k in sample_dict.keys(): - extra_info["repeat_Bj_10" + "/" + k] = sample_dict[k] - - sample_dict = fiberlookup_Bk_8.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberlookup_Bk_8" + "/" + k] = sample_dict[k] - - sample_dict = fiberlookup_Ck_9.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberlookup_Ck_9" + "/" + k] = sample_dict[k] - - sample_dict = intersectk_7.return_statistics() - for k in sample_dict.keys(): - extra_info["intersectk_7" + "/" + k] = sample_dict[k] - - sample_dict = arrayvals_B_5.return_statistics() - for k in sample_dict.keys(): - extra_info["arrayvals_B_5" + "/" + k] = sample_dict[k] - - sample_dict = arrayvals_C_6.return_statistics() - for k in sample_dict.keys(): - extra_info["arrayvals_C_6" + "/" + k] = sample_dict[k] - - sample_dict = mul_4.return_statistics() - for k in sample_dict.keys(): - extra_info["mul_4" + "/" + k] = sample_dict[k] - - sample_dict = reduce_3.return_statistics() - for k in sample_dict.keys(): - extra_info["reduce_3" + "/" + k] = sample_dict[k] - - sample_dict = fiberwrite_Xvals_0.return_statistics() - for k in sample_dict.keys(): - extra_info["fiberwrite_Xvals_0" + "/" + k] = sample_dict[k] - - # write total cycles to csv file - # with open('small_50_matmul_ijk.csv', 'a', newline='') as file: - # writer = csv.writer(file) - # writer.writerow([ssname, time_cnt]) - - # code for generating csv, gantt chart, txt file - extra_info["backpressure"]=backpressure - extra_info["depth"]=depth - gen_gantt(extra_info, "matmul_ijk") - - if check_gold: - print("Checking gold...") - sim_pt_list = get_point_list(out_crds, out_segs, val_arr=out_vals) - sim_mg = create_matrix_from_point_list(name="X", pt_list=sim_pt_list, shape=[B_shape[0], C_shape[0]]) - x_mat_sim = sim_mg.get_matrix() - - # GET NUMPY REPS OF INPUT MATS - b_mg = get_tensor_from_files(name="B", files_dir=B_dirname, shape=B_shape) - b_mat = b_mg.get_matrix() - # print(b_mat) - # C is stored in DCSC - need to transpose upon reading. - c_mg = get_tensor_from_files(name="C", files_dir=C_dirname, shape=C_shape) - c_mat = c_mg.get_matrix() - c_mat_transpose = numpy.transpose(c_mat) - # print(c_mat_transpose) - # c_mat_transpose = c_mat - - x_mat_gold = numpy.matmul(b_mat, c_mat_transpose) - print(x_mat_gold) - print(x_mat_sim) - - assert numpy.array_equal(x_mat_gold, x_mat_sim) - - # check_gold_matmul(ssname, debug_sim, out_crds, out_segs, out_vals, "ss01") - samBench(bench, extra_info) \ No newline at end of file From cd75b3e84d921338cd35c14e0c8af0b6131c77e7 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Thu, 5 Oct 2023 11:15:10 -0700 Subject: [PATCH 66/76] Add in fix to gen_gantt.py script to not fail matmul_kij --- sam/sim/test/gen_gantt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sam/sim/test/gen_gantt.py b/sam/sim/test/gen_gantt.py index 8f15587c..df124ecf 100644 --- a/sam/sim/test/gen_gantt.py +++ b/sam/sim/test/gen_gantt.py @@ -39,7 +39,7 @@ def gen_gantt(extra_info, testname): back_depth = 'N' # assume there is no back pressure for default - if extra_info["backpressure"]: + if "backpressure" in extra_info.keys() and extra_info["backpressure"]: back_depth = extra_info["depth"] # Writing cycle info to csv file From a98714951853802127545f49cb92e648089c7e2e Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Thu, 5 Oct 2023 14:10:38 -0700 Subject: [PATCH 67/76] Fix pycodestyle for gantt branch --- .../test/final-apps/test_mat_elemadd_FINAL.py | 18 ++++++++++-------- sam/sim/test/gen_gantt.py | 19 +++++++++---------- .../reorder-study/test_reorder_matmul_ikj.py | 5 ++--- .../reorder-study/test_reorder_matmul_jik.py | 2 +- .../reorder-study/test_reorder_matmul_kji.py | 4 +--- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/sam/sim/test/final-apps/test_mat_elemadd_FINAL.py b/sam/sim/test/final-apps/test_mat_elemadd_FINAL.py index 5648a816..c286a41d 100644 --- a/sam/sim/test/final-apps/test_mat_elemadd_FINAL.py +++ b/sam/sim/test/final-apps/test_mat_elemadd_FINAL.py @@ -16,10 +16,10 @@ import csv from sam.sim.test.gen_gantt import gen_gantt - cwd = os.getcwd() formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) + # csv file path @pytest.mark.suitesparse @@ -63,7 +63,8 @@ def test_mat_elemadd_FINAL(samBench, ssname, cast, check_gold, report_stats, bac fiberlookup_Ci_11 = CompressedCrdRdScan(crd_arr=C_crd0, seg_arr=C_seg0, debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) unioni_9 = Union2(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - fiberwrite_X0_2 = CompressWrScan(seg_size=2, size=2 * len(B_crd0), fill=fill, debug=debug_sim, statistics=report_stats, + fiberwrite_X0_2 = CompressWrScan(seg_size=2, size=2 * len(B_crd0), fill=fill, debug=debug_sim, + statistics=report_stats, back_en=backpressure, depth=int(depth)) fiberlookup_Bj_7 = CompressedCrdRdScan(crd_arr=B_crd1, seg_arr=B_seg1, debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) @@ -72,8 +73,10 @@ def test_mat_elemadd_FINAL(samBench, ssname, cast, check_gold, report_stats, bac unionj_6 = Union2(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) fiberwrite_X1_1 = CompressWrScan(seg_size=2 * len(B_crd0) + 1, size=2 * len(B_vals), fill=fill, debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - arrayvals_B_4 = Array(init_arr=B_vals, debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) - arrayvals_C_5 = Array(init_arr=C_vals, debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) + arrayvals_B_4 = Array(init_arr=B_vals, debug=debug_sim, statistics=report_stats, back_en=backpressure, + depth=int(depth)) + arrayvals_C_5 = Array(init_arr=C_vals, debug=debug_sim, statistics=report_stats, back_en=backpressure, + depth=int(depth)) add_3 = Add2(debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) fiberwrite_Xvals_0 = ValsWrScan(size=2 * len(B_vals), fill=fill, debug=debug_sim, statistics=report_stats, back_en=backpressure, depth=int(depth)) @@ -197,13 +200,12 @@ def bench(): sample_dict = fiberwrite_Xvals_0.return_statistics() for k in sample_dict.keys(): extra_info["fiberwrite_Xvals_0" + "/" + k] = sample_dict[k] - + # code for generating csv, gantt chart, txt file - extra_info["backpressure"]=backpressure - extra_info["depth"]=depth + extra_info["backpressure"] = backpressure + extra_info["depth"] = depth gen_gantt(extra_info, "mat_elemadd") - if check_gold: print("Checking gold...") check_gold_mat_elemadd(ssname, debug_sim, cast, out_crds, out_segs, out_vals, "ss01") diff --git a/sam/sim/test/gen_gantt.py b/sam/sim/test/gen_gantt.py index df124ecf..453a0553 100644 --- a/sam/sim/test/gen_gantt.py +++ b/sam/sim/test/gen_gantt.py @@ -37,26 +37,25 @@ def gen_gantt(extra_info, testname): start_list.insert(0, start_c) duration_list.insert(0, finish_c - start_c) - - back_depth = 'N' # assume there is no back pressure for default + back_depth = 'N' # assume there is no back pressure for default if "backpressure" in extra_info.keys() and extra_info["backpressure"]: back_depth = extra_info["depth"] - + # Writing cycle info to csv file - with open(testname + '_' + extra_info["dataset"] + '_back_'+back_depth+'.csv', 'w', newline='') as file: + with open(testname + '_' + extra_info["dataset"] + '_back_' + back_depth + '.csv', 'w', newline='') as file: writer = csv.writer(file) - writer.writerow(["block","start","finish","duration","valid_ops"]) + writer.writerow(["block", "start", "finish", "duration", "valid_ops"]) for idx, block in reversed(list(enumerate(block_list))): - writer.writerow([block, start_list[idx], finish_list[idx], duration_list[idx],'-']) - + writer.writerow([block, start_list[idx], finish_list[idx], duration_list[idx], '-']) + # Print all the statistics to a text file - text_file = open(testname + '_' + extra_info["dataset"] + '_back_'+back_depth+".txt","w") + text_file = open(testname + '_' + extra_info["dataset"] + '_back_' + back_depth + ".txt", "w") for k in extra_info.keys(): if "/" in k: - text_file.write(k+": "+str(extra_info[k])+"\n") + text_file.write(k + ": " + str(extra_info[k]) + "\n") text_file.close() # Creating gantt chart plt.barh(y=block_list, width=duration_list, left=start_list) - file_name = testname + '_' + extra_info["dataset"] + "_back_"+back_depth+".png" + file_name = testname + '_' + extra_info["dataset"] + "_back_" + back_depth + ".png" plt.savefig(file_name, bbox_inches="tight") diff --git a/sam/sim/test/reorder-study/test_reorder_matmul_ikj.py b/sam/sim/test/reorder-study/test_reorder_matmul_ikj.py index 0350a3ae..80347a06 100644 --- a/sam/sim/test/reorder-study/test_reorder_matmul_ikj.py +++ b/sam/sim/test/reorder-study/test_reorder_matmul_ikj.py @@ -20,7 +20,7 @@ cwd = os.getcwd() formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) -#formatted_dir = os.getenv('FROSTT_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) +# formatted_dir = os.getenv('FROSTT_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats')) synthetic_dir = os.getenv('SYNTHETIC_PATH', default=os.path.join(cwd, 'synthetic')) @@ -33,7 +33,6 @@ @pytest.mark.synth # @pytest.mark.parametrize("sparsity", [0.95]) def test_reorder_matmul_ikj(samBench, ssname, check_gold, report_stats, debug_sim, cast, backpressure, depth, fill=0): - B_dirname = os.path.join(formatted_dir, ssname, "matmul_kij") B_shape_filename = os.path.join(B_dirname, "tensor_B_mode_shape") B_shape = read_inputs(B_shape_filename) @@ -267,7 +266,7 @@ def bench(): sample_dict = arrayvals_C_8.return_statistics() for k in sample_dict.keys(): extra_info["arrayvals_C_8" + "_" + k] = sample_dict[k] - + gen_gantt(extra_info, "matmul_ikj") if check_gold: diff --git a/sam/sim/test/reorder-study/test_reorder_matmul_jik.py b/sam/sim/test/reorder-study/test_reorder_matmul_jik.py index c80a322f..6afbe6df 100644 --- a/sam/sim/test/reorder-study/test_reorder_matmul_jik.py +++ b/sam/sim/test/reorder-study/test_reorder_matmul_jik.py @@ -249,7 +249,7 @@ def bench(): sample_dict = arrayvals_C_6.return_statistics() for k in sample_dict.keys(): extra_info["arrayvals_C_6" + "_" + k] = sample_dict[k] - + gen_gantt(extra_info, "matmul_jik") if check_gold: diff --git a/sam/sim/test/reorder-study/test_reorder_matmul_kji.py b/sam/sim/test/reorder-study/test_reorder_matmul_kji.py index 2dce7d6e..60284171 100644 --- a/sam/sim/test/reorder-study/test_reorder_matmul_kji.py +++ b/sam/sim/test/reorder-study/test_reorder_matmul_kji.py @@ -33,7 +33,6 @@ @pytest.mark.synth @pytest.mark.parametrize("sparsity", [0.95]) def test_reorder_matmul_kji(samBench, sparsity, check_gold, debug_sim, backpressure, depth, fill=0): - # DCSC B_dirname = os.path.join(synthetic_dir, f"matrix/DCSC/B_random_sp_{sparsity}/") B_shape_filename = os.path.join(B_dirname, "tensor_B_mode_shape") @@ -233,7 +232,6 @@ def bench(): extra_info["tensor_B_shape"] = B_shape extra_info["tensor_C_shape"] = C_shape - sample_dict = intersectk_16.return_statistics() for k in sample_dict.keys(): extra_info["intersectk_16" + "_" + k] = sample_dict[k] @@ -269,7 +267,7 @@ def bench(): sample_dict = arrayvals_B_6.return_statistics() for k in sample_dict.keys(): extra_info["arrayvals_B_6" + "_" + k] = sample_dict[k] - + gen_gantt(extra_info, "matmul_kji") if check_gold: From 3fa90e0f0176e2f1d9220719d9ce1fb65a754f4b Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Thu, 5 Oct 2023 14:32:49 -0700 Subject: [PATCH 68/76] Add in fixes for PR --- .gitignore | 8 - datastructure_suitesparse.py | 281 ------------------ environment.yml | 4 +- .../download_suitesparse_stream_overhead.sh | 75 ----- .../download_unpack_format_suitesparse.sh | 18 +- 5 files changed, 11 insertions(+), 375 deletions(-) delete mode 100644 datastructure_suitesparse.py delete mode 100755 scripts/download_suitesparse_stream_overhead.sh diff --git a/.gitignore b/.gitignore index fac309be..0df30951 100644 --- a/.gitignore +++ b/.gitignore @@ -60,13 +60,5 @@ synthetic/ # Temporary scripts download_suitesparse_partial.sh -# Other files from gen_gantt_master (FIXME (owhsu): check this) -setenv.sh -parse_nnz.py -scripts/small50_script.sh -scripts/gen_cycle_csv.py -scripts/data_gen_suitesparse_g.sh -sam/sim/test/reorder-study-gina/* - # Network Filesystem .nfs* diff --git a/datastructure_suitesparse.py b/datastructure_suitesparse.py deleted file mode 100644 index 5b36b313..00000000 --- a/datastructure_suitesparse.py +++ /dev/null @@ -1,281 +0,0 @@ -import argparse -import os -import shutil -import scipy.sparse -import numpy as np - -from pathlib import Path - -from scripts.util import FormatWriter, SuiteSparseTensor, InputCacheSuiteSparse -from sam.util import SUITESPARSE_FORMATTED_PATH, ScipyTensorShifter - -all_formats = ["coo", "cooT", "csr", "dcsr", "dcsc", "csc", "dense", "denseT"] -formats = ["coo", "cooT", "csr", "dcsr", "dcsc", "csc", "dense"] -scipy_formats = ["coo", "csr", "csc"] - - -def write_datastructure_tiles(args, tensor, out_path, tile_name): - print("Writing " + args.name + " for test " + args.benchname + "...") - - dirname = args.output_dir_path if args.output_dir_path is not None else os.path.join(out_path, args.name, args.benchname) - dirname = os.path.join(dirname, tile_name) - dirpath = Path(dirname) - if os.path.exists(dirpath): - shutil.rmtree(dirpath) - dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) - - print(tile_name) - tensorname = tile_name.split("_")[1] - - coo = inputCache.load(tensor, False) - formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss01", hw=False) - - -def write_datastructure_bench(args, tensor, out_path, tiles=None): - shifter = ScipyTensorShifter() - - print("Writing " + args.name + " for test " + args.benchname + "...") - - dirname = args.output_dir_path if args.output_dir_path is not None else os.path.join(out_path, args.name, args.benchname) - if tiles is not None: - dirname = os.path.join(dirname, tiles) - dirpath = Path(dirname) - if os.path.exists(dirpath): - shutil.rmtree(dirpath) - dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) - - if "mat_mattransmul" in args.benchname or "mat_residual" in args.benchname: - tensorname = "C" - else: - tensorname = "B" - - coo = inputCache.load(tensor, False) - shape = coo.shape - - # These benchmarks need format_str == "ss10" - if args.benchname not in ["matmul_kij", "matmul_kji", "matmul_jki", "mat_vecmul", "mat_vecmul_ji", "mat_mattransmul"]: - formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss01") - - if "matmul_ijk" in args.benchname: - shifted = shifter.shiftLastMode(coo) - - print("Writing " + args.name + " shifted and transposed...") - tensorname = "C" - trans_shifted = shifted.transpose() - formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss10") - - elif "matmul_jik" in args.benchname: - shifted = shifter.shiftLastMode(coo) - - print("Writing " + args.name + " shifted and transposed...") - tensorname = "C" - trans_shifted = shifted.transpose() - formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss10") - elif "matmul_ikj" in args.benchname: - shifted = shifter.shiftLastMode(coo) - - print("Writing " + args.name + " shifted and transposed...") - tensorname = "C" - trans_shifted = shifted.transpose() - formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss01") - - elif "matmul_jki" in args.benchname: - formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") - - shifted = shifter.shiftLastMode(coo) - - print("Writing " + args.name + " shifted and transposed...") - tensorname = "C" - trans_shifted = shifted.transpose() - formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss10") - - elif "matmul_kij" in args.benchname: - formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") - - shifted = shifter.shiftLastMode(coo) - - print("Writing " + args.name + " shifted and transposed...") - tensorname = "C" - trans_shifted = shifted.transpose() - formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss01") - - elif "matmul_kji" in args.benchname: - formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") - - shifted = shifter.shiftLastMode(coo) - - print("Writing " + args.name + " shifted and transposed...") - tensorname = "C" - trans_shifted = shifted.transpose() - formatWriter.writeout_separate_sparse_only(trans_shifted, dirname, tensorname, format_str="ss01") - - elif "mat_elemadd3" in args.benchname: - print("Writing " + args.name + " shifted...") - tensorname = "C" - shifted = shifter.shiftLastMode(coo) - formatWriter.writeout_separate_sparse_only(shifted, dirname, tensorname, format_str="ss01") - - print("Writing " + args.name + " shifted2...") - tensorname = "D" - shifted2 = shifter.shiftLastMode(shifted) - formatWriter.writeout_separate_sparse_only(shifted2, dirname, tensorname, format_str="ss01") - - elif "mat_elemadd" in args.benchname or "mat_elemmul" in args.benchname: - print("Writing " + args.name + " shifted...") - tensorname = "C" - shifted = shifter.shiftLastMode(coo) - formatWriter.writeout_separate_sparse_only(shifted, dirname, tensorname, format_str="ss01") - - elif "mat_mattransmul" in args.benchname: - formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") - if not args.no_gen_other: - tensorname = 'd' - vec = scipy.sparse.random(shape[0], 1, density=args.density, data_rvs=np.ones) - vec = vec.toarray().flatten() - formatWriter.writeout_separate_vec(vec, dirname, tensorname) - - tensorname = 'f' - vec = scipy.sparse.random(shape[1], 1, density=args.density, data_rvs=np.ones) - vec = vec.toarray().flatten() - formatWriter.writeout_separate_vec(vec, dirname, tensorname) - elif "mat_vecmul" == args.benchname or "mat_vecmul_ji" in args.benchname: - formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") - if not args.no_gen_other: - tensorname = 'c' - vec = scipy.sparse.random(shape[1], 1, density=args.density, data_rvs=np.ones) - vec = vec.toarray().flatten() - formatWriter.writeout_separate_vec(vec, dirname, tensorname) - elif "mat_vecmul_ij" in args.benchname: - pass - elif "mat_sddmm" in args.benchname: - pass - elif "mat_residual" in args.benchname: - if not args.no_gen_other: - tensorname = 'b' - vec = scipy.sparse.random(shape[0], 1, density=args.density, data_rvs=np.ones) - vec = vec.toarray().flatten() - formatWriter.writeout_separate_vec(vec, dirname, tensorname) - - tensorname = 'd' - vec = scipy.sparse.random(shape[1], 1, density=args.density, data_rvs=np.ones) - vec = vec.toarray().flatten() - formatWriter.writeout_separate_vec(vec, dirname, tensorname) - elif "mat_identity" in args.benchname: - pass - else: - raise NotImplementedError - - -parser = argparse.ArgumentParser(description="Process some suitesparse matrices into per-level datastructures") -parser.add_argument('-n', '--name', metavar='ssname', type=str, action='store', help='tensor name to run format ' - 'conversion on one SS tensor') -parser.add_argument('-f', '--format', metavar='ssformat', type=str, action='store', help='The format that the tensor ' - 'should be converted to') -parser.add_argument('-comb', '--combined', action='store_true', default=False, help='Whether the formatted datastructures ' - 'should be in separate files') -parser.add_argument('-o', '--omit-dense', action='store_true', default=False, help='Do not create fully dense format') -parser.add_argument('-cast', '--cast', action='store_true', default=False, help='Safe sparsity cast to int for values') -parser.add_argument('-hw', '--hw', action='store_true', default=False, - help='Only generate formats used for hardware testing (all sparse' - 'levels, concordant)') -parser.add_argument('-b', '--benchname', type=str, default=None, help='test name to run format ' - 'conversion on') -parser.add_argument('--input_path', type=str, default=None) -parser.add_argument('--output_dir_path', type=str, default=None) -parser.add_argument('--tiles', action='store_true') -parser.add_argument('--no_gen_other', action='store_true', help="Whether this" - "script should generate the randmo 'other' tensors") -parser.add_argument('--seed', type=int, default=0, help='Random seed needed for gen_other') -parser.add_argument('--density', type=int, default=0.25, help='If gen_other, used for density of "other" tensor') -args = parser.parse_args() - -np.random.seed(args.seed) - -inputCache = InputCacheSuiteSparse() -formatWriter = FormatWriter(args.cast) - -cwd = os.getcwd() -if args.output_dir_path is None: - out_dirname = SUITESPARSE_FORMATTED_PATH -else: - out_dirname = args.output_dir_path - -out_path = Path(out_dirname) -out_path.mkdir(parents=True, exist_ok=True, mode=0o777) - -if args.name is None: - print("Please enter a matrix name") - exit() - -if args.input_path is None: - SS_PATH = os.getenv('SUITESPARSE_TENSOR_PATH', default=os.path.join(cwd, 'suitesparse')) - -else: - SS_PATH = args.input_path - -tensor = None -mtx_files = None -if args.tiles: - # get all mtx tile files from args.input_path - mtx_files = [os.path.join(args.input_path, fname) for fname in os.listdir(args.input_path) if fname.endswith(".mtx")] - - tensor = [SuiteSparseTensor(mtx_file) for mtx_file in mtx_files] -elif args.input_path is not None: - tensor = SuiteSparseTensor(args.input_path) -else: - print(SS_PATH) - tensor = SuiteSparseTensor(SS_PATH) - -if args.format is not None: - assert args.format in formats - filename = os.path.join(out_path, args.name + "_" + args.format + ".txt") - - coo = inputCache.load(tensor, False) - formatWriter.writeout(coo, args.format, filename) -elif args.combined: - for format_str in formats: - filename = os.path.join(out_path, args.name + "_" + format_str + ".txt") - print("Writing " + args.name + " " + format_str + "...") - - coo = inputCache.load(tensor, False) - formatWriter.writeout(coo, format_str, filename) - - shifted_filename = os.path.join(out_path, args.name + "_shifted_" + format_str + ".txt") - shifted = ScipyTensorShifter().shiftLastMode(coo) - formatWriter.writeout(shifted, format_str, shifted_filename) - - trans_filename = os.path.join(out_path, args.name + "_trans_shifted_" + format_str + ".txt") - trans_shifted = shifted.transpose() - formatWriter.writeout(trans_shifted, format_str, trans_filename) -elif args.hw: - if args.tiles and tensor is not None: - for i, ten in enumerate(tensor): - tile_name = os.path.split(mtx_files[i])[1].split(".")[0] - write_datastructure_tiles(args, ten, out_path, tile_name) - else: - write_datastructure_bench(args, tensor, out_path) - -else: - print("Writing " + args.name + " original...") - dirname = os.path.join(out_path, args.name, "orig") - dirpath = Path(dirname) - dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) - tensorname = "B" - coo = inputCache.load(tensor, False) - formatWriter.writeout_separate(coo, dirname, tensorname, omit_dense=args.omit_dense) - - print("Writing " + args.name + " shifted...") - dirname = os.path.join(out_path, args.name, "shift") - dirpath = Path(dirname) - dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) - tensorname = "C" - shifted = ScipyTensorShifter().shiftLastMode(coo) - formatWriter.writeout_separate(shifted, dirname, tensorname, omit_dense=args.omit_dense) - - print("Writing " + args.name + " shifted and transposed...") - dirname = os.path.join(out_path, args.name, "shift-trans") - dirpath = Path(dirname) - dirpath.mkdir(parents=True, exist_ok=True, mode=0o777) - tensorname = "C" - trans_shifted = shifted.transpose() - formatWriter.writeout_separate(trans_shifted, dirname, tensorname, omit_dense=args.omit_dense) diff --git a/environment.yml b/environment.yml index da05b414..9b648d7c 100644 --- a/environment.yml +++ b/environment.yml @@ -1,4 +1,4 @@ -name: py39 +name: sam channels: - pytorch - anaconda @@ -201,4 +201,4 @@ dependencies: - statsmodels==0.13.2 - threadpoolctl==3.1.0 - traitlets==5.3.0 -prefix: /home/ginasohn/Anaconda3/envs/py39 +prefix: ~/Anaconda3/envs/sam diff --git a/scripts/download_suitesparse_stream_overhead.sh b/scripts/download_suitesparse_stream_overhead.sh deleted file mode 100755 index 2765ca67..00000000 --- a/scripts/download_suitesparse_stream_overhead.sh +++ /dev/null @@ -1,75 +0,0 @@ -mkdir -p /home/ginasohn/sam-fixed/sam-fixed/data/suitesparse -pushd . -cd /home/ginasohn/sam-fixed/sam-fixed/data/suitesparse -wget https://sparse.tamu.edu/MM/HB/pores_1.tar.gz -wget https://sparse.tamu.edu/MM/FIDAP/ex5.tar.gz -wget https://sparse.tamu.edu/MM/Grund/b1_ss.tar.gz -wget https://sparse.tamu.edu/MM/LPnetlib/lpi_bgprtr.tar.gz -wget https://sparse.tamu.edu/MM/LPnetlib/lpi_itest2.tar.gz -wget https://sparse.tamu.edu/MM/LPnetlib/lpi_itest6.tar.gz -wget https://sparse.tamu.edu/MM/vanHeukelum/cage3.tar.gz -wget https://sparse.tamu.edu/MM/vanHeukelum/cage4.tar.gz -wget https://sparse.tamu.edu/MM/vanHeukelum/cage5.tar.gz -wget https://sparse.tamu.edu/MM/Hamrle/Hamrle1.tar.gz -wget https://sparse.tamu.edu/MM/Oberwolfach/LF10000.tar.gz -wget https://sparse.tamu.edu/MM/Oberwolfach/LF10.tar.gz -wget https://sparse.tamu.edu/MM/Oberwolfach/LFAT5000.tar.gz -wget https://sparse.tamu.edu/MM/Oberwolfach/LFAT5.tar.gz -wget https://sparse.tamu.edu/MM/Pajek/football.tar.gz -wget https://sparse.tamu.edu/MM/Pajek/GD01_c.tar.gz -wget https://sparse.tamu.edu/MM/Pajek/Ragusa16.tar.gz -wget https://sparse.tamu.edu/MM/Pajek/Ragusa18.tar.gz -wget https://sparse.tamu.edu/MM/Meszaros/farm.tar.gz -wget https://sparse.tamu.edu/MM/Meszaros/kleemin.tar.gz -wget https://sparse.tamu.edu/MM/NYPA/Maragal_1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_G5/IG5-6.tar.gz -wget https://sparse.tamu.edu/MM/JGD_GL7d/GL7d10.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/ch3-3-b1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/ch3-3-b2.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/ch4-4-b1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/ch5-5-b1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/ch7-6-b1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/cis-n4c6-b1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/cis-n4c6-b13.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/cis-n4c6-b14.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/cis-n4c6-b15.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/klein-b1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/klein-b2.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/mk9-b1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n2c6-b10.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n2c6-b1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n3c4-b1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n3c4-b2.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n3c4-b3.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n3c4-b4.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n3c5-b1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n3c6-b10.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n3c6-b1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n3c6-b11.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n4c5-b10.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n4c5-b1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n4c5-b11.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b10.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b11.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b1.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b12.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b13.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b14.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Homology/n4c6-b15.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Kocay/Trec5.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Kocay/Trec6.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Kocay/Trec7.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Relat/rel4.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Relat/rel5.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Relat/relat3.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Relat/relat4.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Relat/relat5.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_20b.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_20.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_200b.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_200.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_2000.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_20000b.tar.gz -wget https://sparse.tamu.edu/MM/JGD_Trefethen/Trefethen_20000.tar.gz -wget https://sparse.tamu.edu/MM/Newman/football.tar.gz -popd diff --git a/scripts/formatting/download_unpack_format_suitesparse.sh b/scripts/formatting/download_unpack_format_suitesparse.sh index c02f077c..5dc4b09c 100755 --- a/scripts/formatting/download_unpack_format_suitesparse.sh +++ b/scripts/formatting/download_unpack_format_suitesparse.sh @@ -16,15 +16,15 @@ BENCHMARKS=( matmul_ijk matmul_jik mat_elemadd - # mat_elemmul - # mat_identity - # mat_elemadd3 - # mat_mattransmul - # mat_residual - # mat_vecmul_ij - # mat_vecmul_ji - # mat_vecmul - # mat_sddmm + mat_elemmul + mat_identity + mat_elemadd3 + mat_mattransmul + mat_residual + mat_vecmul_ij + mat_vecmul_ji + mat_vecmul + mat_sddmm ) # Create download_script that downloads ONLY the suitesparse matrices listed in the text file that is passed in as the first argument of this script From a1440cd5d78d0f6be8962ac2b4b19b65208d823f Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Mon, 9 Oct 2023 11:41:39 -0700 Subject: [PATCH 69/76] syn mat --- maximum_tiling.py | 26 ++++++++-------- sam/sim/src/tiling/tile.py | 17 ++++++----- .../formatting/datastructure_suitesparse.py | 6 +++- .../generate_suitesparse_formats.sh | 14 ++++----- scripts/tiling/tile_ext.sh | 4 +-- setup_tiling_mat.py | 30 ++++++++++++------- 6 files changed, 55 insertions(+), 42 deletions(-) diff --git a/maximum_tiling.py b/maximum_tiling.py index e9a41415..2390ed21 100644 --- a/maximum_tiling.py +++ b/maximum_tiling.py @@ -249,22 +249,22 @@ def find_optimal_tilesize(app_name, datum, initial=30, step_size=10): if __name__ == "__main__": max_list = {} # for i in range(1, 11): - app_name = "mat_vecmul_iter" - datum = "qiulp" + app_name = "matmul_ijk" + datum = "N_biocarta" - tile_pairing = pair_tiles(app_name) - compute_outputs(tile_pairing, app_name) + # tile_pairing = pair_tiles(app_name) + # compute_outputs(tile_pairing, app_name) - # max_tile_size, tile_pairing = find_optimal_tilesize(app_name, datum, initial=20, step_size=10) - # print("-"*20) - # print(f"MAX TILESIZE for {app_name}, {datum}: {max_tile_size}") - # print(f"NUMBER OF TILES: {len(tile_pairing.keys())}") - # print("-"*20) + max_tile_size, tile_pairing = find_optimal_tilesize(app_name, datum, initial=40, step_size=10) + print("-"*20) + print(f"MAX TILESIZE for {app_name}, {datum}: {max_tile_size}") + print(f"NUMBER OF TILES: {len(tile_pairing.keys())}") + print("-"*20) - # # max_list[datum] = [max_tile_size, len(tile_pairing.keys())] + max_list[datum] = [max_tile_size, len(tile_pairing.keys())] - # call_tiling = f"python3 setup_tiling_mat.py {app_name} {datum} {max_tile_size} > temp.txt" - # os.system(call_tiling) - # print(call_tiling) + call_tiling = f"python3 setup_tiling_mat.py {app_name} {datum} {max_tile_size} > temp.txt" + os.system(call_tiling) + print(call_tiling) # print(max_list) \ No newline at end of file diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index c6ef86b7..47cf15a0 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -362,16 +362,17 @@ def get_other_tensors(app_str, tensor, other_nonempty=True): print("Writing other tensors...") tensorName = args.input_tensor # c(j) use mode1 - variant = "mode1" - path = constructOtherVecKey(tensorName,variant) - tensor_c_from_path = FrosttTensor(path) - tensor_c = tensor_c_from_path.load().todense() + + # variant = "mode1" + # path = constructOtherVecKey(tensorName,variant) + # tensor_c_from_path = FrosttTensor(path) + # tensor_c = tensor_c_from_path.load().todense() - print("TENSOR SHAPE: ", tensor.shape) - print("TENSOR_C SHAPE: ", tensor_c.shape) + # print("TENSOR SHAPE: ", tensor.shape) + # print("TENSOR_C SHAPE: ", tensor_c.shape) - # rows, cols = tensor.shape - # tensor_c = scipy.sparse.random(cols, 1, data_rvs=np.ones).toarray().flatten() + rows, cols = tensor.shape + tensor_c = scipy.sparse.random(cols, 1, data_rvs=np.ones).toarray().flatten() if other_nonempty: tensor_c[0] = 1 diff --git a/scripts/formatting/datastructure_suitesparse.py b/scripts/formatting/datastructure_suitesparse.py index 373bf81e..e2d9e496 100644 --- a/scripts/formatting/datastructure_suitesparse.py +++ b/scripts/formatting/datastructure_suitesparse.py @@ -6,7 +6,11 @@ from pathlib import Path -from scripts.util.util import FormatWriter, SuiteSparseTensor, InputCacheSuiteSparse +import sys +# the mock-0.3.1 dir contains testcase.py, testutils.py & mock.py +sys.path.append('/home/avb03/sam/scripts') + +from util.util import FormatWriter, SuiteSparseTensor, InputCacheSuiteSparse from sam.util import SUITESPARSE_FORMATTED_PATH, ScipyTensorShifter all_formats = ["coo", "cooT", "csr", "dcsr", "dcsc", "csc", "dense", "denseT"] diff --git a/scripts/formatting/generate_suitesparse_formats.sh b/scripts/formatting/generate_suitesparse_formats.sh index dd9822c3..6763f12b 100755 --- a/scripts/formatting/generate_suitesparse_formats.sh +++ b/scripts/formatting/generate_suitesparse_formats.sh @@ -6,16 +6,16 @@ BENCHMARKS=( # matmul_ikj -# matmul_ijk + matmul_ijk # matmul_kij -# mat_elemmul -# mat_elemadd -# mat_elemadd3 + mat_elemmul + mat_elemadd + mat_elemadd3 mat_residual mat_mattransmul mat_vecmul # mat_identity -# mat_sddmm + mat_sddmm ) # This is a list of benchmarks that have "other" tensors that are generated @@ -36,10 +36,10 @@ for b in ${!BENCHMARKS[@]}; do sspath=${SUITESPARSE_PATH}/$name echo "Generating input format files for $name..." - SUITESPARSE_TENSOR_PATH=$sspath python $basedir/scripts/formatting/datastructure_suitesparse.py -n $name -hw -b $bench + SUITESPARSE_TENSOR_PATH=$sspath python3 $basedir/scripts/formatting/datastructure_suitesparse.py -n $name -hw -b $bench if [[ $OTHERBENCHES =~ "$bench" ]]; then echo "Generating format of 'other' tensor" - python $basedir/scripts/formatting/datastructure_tns.py -n $line -f ss01 --other -ss -b $bench -hw + python3 $basedir/scripts/formatting/datastructure_tns.py -n $line -f ss01 --other -ss -b $bench -hw fi done <$textfile diff --git a/scripts/tiling/tile_ext.sh b/scripts/tiling/tile_ext.sh index 7fc23251..082c1c38 100755 --- a/scripts/tiling/tile_ext.sh +++ b/scripts/tiling/tile_ext.sh @@ -13,8 +13,8 @@ BENCHMARKS=( # mat_elemadd3 # matmul_ijk # mat_mask_tri - mat_vecmul_iter - # mat_elemmul + # mat_vecmul_iter + mat_elemadd ) appname=$3 diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py index 1202ac81..b153eec0 100644 --- a/setup_tiling_mat.py +++ b/setup_tiling_mat.py @@ -11,8 +11,8 @@ # data = ['rajat12'] -# data = [sys.argv[2]] -# tilesizes = [int(sys.argv[3])] +data = [sys.argv[2]] +tilesizes = [int(sys.argv[3])] # app_name = "mat_elemadd" # app_name = "mat_elemmul" # app_name = "mat_sddmm" @@ -21,16 +21,23 @@ # app_name = "mat_elemmul" # app_name = "mat_residual" -data = [] -data_file = open("onyx_final_eval_mid50_tensor_names.txt") -data_file_lines = data_file.readlines() -for line in data_file_lines: - data.append(line[:-1]) +# data = [] +# tilesizes = [] +# sparsities = [60, 80, 90, 95, 98] +# for sparsity in sparsities: +# for i in range(5): +# data.append(f"matrix_sp{str(sparsity)}_sm_{i+1}") +# tilesizes.append(30) -with open('matmul_tilesize_list.txt', 'r') as file: - lines = file.readlines() +# data_file = open("onyx_final_eval_mid50_tensor_names.txt") +# data_file_lines = data_file.readlines() +# for line in data_file_lines: +# data.append(line[:-1]) -tilesizes = [int(line.strip()) for line in lines] +# with open('matmul_tilesize_list.txt', 'r') as file: +# lines = file.readlines() + +# tilesizes = [int(line.strip()) for line in lines] print("TILESIZES: ", tilesizes) print("DATA: ", data) @@ -83,7 +90,8 @@ def replace_ones_with_zeros(mtx_file): rmdir = f"rm -rf tiles/{app_name}" os.system(rmdir) - + + print(f"{SUITESPARSE_PATH}/{datum}.mtx") mtx_file = glob.glob(f"{SUITESPARSE_PATH}/{datum}.mtx")[0] os.makedirs("extensor_mtx", exist_ok=True) shutil.copy(mtx_file,f"extensor_mtx/{datum}.mtx") From 809c467d450c07bbe928797f1cba72ebe6b3dd03 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Tue, 10 Oct 2023 14:23:26 -0700 Subject: [PATCH 70/76] Add in fixes to remove hard-coded paths --- scripts/formatting/generate_frostt_formats.sh | 6 ------ scripts/run_cpu/frostt_runner.sh | 4 +--- scripts/run_onyx/sam_hw_suitesparse_runner.sh | 19 +++++++------------ scripts/run_sam_sim/pytest_frostt.sh | 5 +---- .../pytest_frostt_with_benchmarks.sh | 6 +----- scripts/run_sam_sim/run_suitesparse.sh | 4 +--- scripts/run_sam_sim/run_suitesparse_final.sh | 2 +- scripts/run_sam_sim/sam_suitesparse_runner.sh | 10 +++++----- 8 files changed, 17 insertions(+), 39 deletions(-) diff --git a/scripts/formatting/generate_frostt_formats.sh b/scripts/formatting/generate_frostt_formats.sh index a83e76c7..26310bf8 100755 --- a/scripts/formatting/generate_frostt_formats.sh +++ b/scripts/formatting/generate_frostt_formats.sh @@ -22,12 +22,6 @@ FORMATS=( sss012 ) -#export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse/ -#export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt/ -#export SUITESPARSE_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/suitesparse-formatted -#export FROSTT_FORMATTED_TACO_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted/taco-tensor -#export FROSTT_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted - basedir=$(pwd) for i in ${!FORMATS[@]}; do diff --git a/scripts/run_cpu/frostt_runner.sh b/scripts/run_cpu/frostt_runner.sh index e8d6dfac..dbc53445 100755 --- a/scripts/run_cpu/frostt_runner.sh +++ b/scripts/run_cpu/frostt_runner.sh @@ -15,18 +15,16 @@ DATASET_NAMES=( nell-1 ) +sspath=$SUITESPARSE_PATH cwd=$(pwd) # LANKA if [ $1 -eq 1 ]; then - sspath=/data/scratch/changwan/florida_all/. lanka=ON neva=OFF elif [ $1 -eq 2 ]; then - sspath=/nobackup/owhsu/sparse-datasets/suitesparse lanka=OFF neva=ON else - sspath=cwd/. lanka=OFF neva=OFF fi diff --git a/scripts/run_onyx/sam_hw_suitesparse_runner.sh b/scripts/run_onyx/sam_hw_suitesparse_runner.sh index e9748bf1..adf680e3 100755 --- a/scripts/run_onyx/sam_hw_suitesparse_runner.sh +++ b/scripts/run_onyx/sam_hw_suitesparse_runner.sh @@ -29,25 +29,20 @@ errors=() RED='\033[0;31m' NC='\033[0m' # No Color +mkdir -p $TACO_TENSOR_PATH +mkdir -p $SUITESPARSE_FORMATTED_PATH +mkdir -p $FROSTT_FORMATTED_TACO_PATH +mkdir -p $FROSTT_FORMATTED_PATH + # LANKA if [ $2 -eq 1 ]; then - export SUITESPARSE_PATH=/data/scratch/changwan/florida_all - export FROSTT_PATH=/data/scratch/owhsu/datasets/frostt - export TACO_TENSOR_PATH=/data/scratch/owhsu/datasets - export SUITESPARSE_FORMATTED_PATH=/data/scratch/owhsu/datasets/suitesparse-formatted - export FROSTT_FORMATTED_TACO_PATH=/data/scratch/owhsu/datasets/frostt-formatted/taco-tensor - export FROSTT_FORMATTED_PATH=/data/scratch/owhsu/datasets/frostt-formatted - - mkdir -p $TACO_TENSOR_PATH - mkdir -p $SUITESPARSE_FORMATTED_PATH - mkdir -p $FROSTT_FORMATTED_TACO_PATH - mkdir -p $FROSTT_FORMATTED_PATH - lanka=ON neva=OFF +# KIWI/NEVA elif [ $2 -eq 2 ]; then lanka=OFF neva=ON +# Local Machine else lanka=OFF neva=OFF diff --git a/scripts/run_sam_sim/pytest_frostt.sh b/scripts/run_sam_sim/pytest_frostt.sh index ffc770a1..ba78463f 100755 --- a/scripts/run_sam_sim/pytest_frostt.sh +++ b/scripts/run_sam_sim/pytest_frostt.sh @@ -7,15 +7,12 @@ # Script that runs ALL test_tensor* pytest tests under sam/sim/test -outdir=/nobackup/owhsu/sparse-datasets/frostt-formatted +outdir=$FROSTT_FORMATTED_PATH errors=() RED='\033[0;31m' NC='\033[0m' # No Color -export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt -export FROSTT_FORMATTED_PATH=$outdir - mkdir -p $outdir cd ./sam/sim diff --git a/scripts/run_sam_sim/pytest_frostt_with_benchmarks.sh b/scripts/run_sam_sim/pytest_frostt_with_benchmarks.sh index da73cbb8..8056c3eb 100755 --- a/scripts/run_sam_sim/pytest_frostt_with_benchmarks.sh +++ b/scripts/run_sam_sim/pytest_frostt_with_benchmarks.sh @@ -14,11 +14,7 @@ BENCHMARKS=( tensor_mttkrp ) -outdir=/nobackup/owhsu/sparse-datasets/frostt-formatted - -export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt -export FROSTT_FORMATTED_PATH=$outdir - +outdir=$FROSTT_FORMATTED_PATH errors=() RED='\033[0;31m' diff --git a/scripts/run_sam_sim/run_suitesparse.sh b/scripts/run_sam_sim/run_suitesparse.sh index 2b3da4ce..a6b26601 100755 --- a/scripts/run_sam_sim/run_suitesparse.sh +++ b/scripts/run_sam_sim/run_suitesparse.sh @@ -8,15 +8,13 @@ # ./scripts/run_sam_sim/run_suitesparse.sh # THIS FILE MUST BE RUN FROM sam/ location -outdir=/nobackup/owhsu/sparse-datasets/suitesparse-formatted +outdir=$SUITESPARSE_FORMATTED_PATH basedir=$(pwd) errors=() RED='\033[0;31m' NC='\033[0m' # No Color -export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse -export SUITESPARSE_FORMATTED_PATH=$outdir mkdir -p $outdir diff --git a/scripts/run_sam_sim/run_suitesparse_final.sh b/scripts/run_sam_sim/run_suitesparse_final.sh index d2480f74..eac4e371 100755 --- a/scripts/run_sam_sim/run_suitesparse_final.sh +++ b/scripts/run_sam_sim/run_suitesparse_final.sh @@ -4,7 +4,7 @@ #SBATCH -p lanka-v3 #SBATCH --exclusive -# ./scripts/run_sam_sim/run +# ./scripts/run_sam_sim/run_suitesparse_final.sh pushd . cd sam/sim diff --git a/scripts/run_sam_sim/sam_suitesparse_runner.sh b/scripts/run_sam_sim/sam_suitesparse_runner.sh index 5604f524..ff78826f 100755 --- a/scripts/run_sam_sim/sam_suitesparse_runner.sh +++ b/scripts/run_sam_sim/sam_suitesparse_runner.sh @@ -9,12 +9,12 @@ set -u BENCHMARKS=( -# mat_vecmul_FINAL + mat_vecmul_FINAL matmul_FINAL -# mat_elemadd_FINAL -# mat_elemadd3_FINAL -# mat_residual_FINAL -# mat_mattransmul_FINAL + mat_elemadd_FINAL + mat_elemadd3_FINAL + mat_residual_FINAL + mat_mattransmul_FINAL ) errors=() From fe3ad32b70f3798d858b52c68e6776115864313f Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Tue, 10 Oct 2023 14:24:31 -0700 Subject: [PATCH 71/76] Continue fixes --- scripts/tiling/generate_gold_matmul_tiled.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/tiling/generate_gold_matmul_tiled.py b/scripts/tiling/generate_gold_matmul_tiled.py index 2adc9611..4fa3bfe3 100644 --- a/scripts/tiling/generate_gold_matmul_tiled.py +++ b/scripts/tiling/generate_gold_matmul_tiled.py @@ -73,11 +73,6 @@ def generate_gold_matmul_tiled(tile_crd_b, tile_crd_c, dirname, out_format="ss01 outpath = Path(outdir) outpath.mkdir(parents=True, exist_ok=True) - # generate_gold_matmul_tiled([0, 1, 2, 9], [1, 0, 9, 0], outdir) - - # generate_gold_matmul_tiled([0, 1, 0, 7], [1, 0, 7, 0], outdir) - # quit() with open("/nobackup/rsharma3/Sparsity/simulator/old_sam/sam/tiles/matmul_ikj/tensor_sizes", "rb") as ff: - with open("./tiles/matmul_ikj/tensor_sizes", "rb") as ff: sizes_dict_level_full = pickle.load(ff) From b5d954790b739de8872db2df69df5d205b470287 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Wed, 11 Oct 2023 10:06:02 -0700 Subject: [PATCH 72/76] Add in fixes for gen_gantt script --- sam/sim/test/gen_gantt.py | 3 +++ scripts/gen_sam_apps/test_generating_code.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/sam/sim/test/gen_gantt.py b/sam/sim/test/gen_gantt.py index 453a0553..b421a49b 100644 --- a/sam/sim/test/gen_gantt.py +++ b/sam/sim/test/gen_gantt.py @@ -13,6 +13,7 @@ def gen_gantt(extra_info, testname): sam_name = '' for k in extra_info.keys(): + print(k, sam_name) if "done_cycles" in k: sam_name = k.split('/')[0] finish_c = extra_info[k] @@ -41,6 +42,8 @@ def gen_gantt(extra_info, testname): if "backpressure" in extra_info.keys() and extra_info["backpressure"]: back_depth = extra_info["depth"] + print(finish_list, block_list, start_list, duration_list) + # Writing cycle info to csv file with open(testname + '_' + extra_info["dataset"] + '_back_' + back_depth + '.csv', 'w', newline='') as file: writer = csv.writer(file) diff --git a/scripts/gen_sam_apps/test_generating_code.py b/scripts/gen_sam_apps/test_generating_code.py index d92b39b9..5aaef13e 100755 --- a/scripts/gen_sam_apps/test_generating_code.py +++ b/scripts/gen_sam_apps/test_generating_code.py @@ -151,8 +151,11 @@ def generate_header(f, out_name): f.write("from sam.sim.src.token import *\n") f.write("from sam.sim.test.test import *\n") f.write("from sam.sim.test.gold import *\n") + f.write("from sam.sim.test.gen_gantt import gen_gantt\n") + f.write("\n") f.write("import os\n") f.write("import csv\n") + f.write("\n") f.write("cwd = os.getcwd()\n") if out_name in suitesparse_list: f.write("formatted_dir = os.getenv('SUITESPARSE_FORMATTED_PATH', default=os.path.join(cwd, 'mode-formats'))\n") @@ -402,8 +405,12 @@ def finish_outputs(f, elements, nodes_completed): def generate_benchmarking_code(f, tensor_format_parse, test_name): - f.write("\n" + tab(1) + "def bench():\n") + f.write("\n") + f.write(tab(1) + "# Print out cycle count for pytest output\n") + f.write(tab(1) + "print(time_cnt)\n") + f.write(tab(1) + "def bench():\n") f.write(tab(2) + "time.sleep(0.01)\n\n") + f.write("\n") f.write(tab(1) + "extra_info = dict()\n") f.write(tab(1) + "extra_info[\"dataset\"] = " + get_dataset_name(test_name) + "\n") f.write(tab(1) + "extra_info[\"cycles\"] = time_cnt\n") @@ -422,7 +429,10 @@ def generate_benchmarking_code(f, tensor_format_parse, test_name): if d[u]["type"] in statistic_available: f.write(tab(1) + "sample_dict = " + d[u]["object"] + ".return_statistics()\n") f.write(tab(1) + "for k in sample_dict.keys():\n") - f.write(tab(2) + "extra_info[\"" + d[u]["object"] + "\" + \"_\" + k] = sample_dict[k]\n\n") + f.write(tab(2) + "extra_info[\"" + d[u]["object"] + "\" + \"/\" + k] = sample_dict[k]\n\n") + + f.write(tab(1) + "gen_gantt(extra_info, \"" + test_name + "\")\n") + f.write("\n") def generate_check_against_gold_code(f, tensor_format_parse, test_name): From 15833acaaa4be657f7cac858f88893c3fd75c714 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Wed, 11 Oct 2023 10:32:00 -0700 Subject: [PATCH 73/76] Get matmul_ijk working --- scripts/gen_sam_apps/test_generating_code.py | 24 ++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/scripts/gen_sam_apps/test_generating_code.py b/scripts/gen_sam_apps/test_generating_code.py index 5aaef13e..17bfa91b 100755 --- a/scripts/gen_sam_apps/test_generating_code.py +++ b/scripts/gen_sam_apps/test_generating_code.py @@ -198,6 +198,19 @@ def get_common_test_name(test_name): return test_name +def get_out_crd_str(d, u_, index_value): + # By default, the input primitive connected to a crddrop will be a level scanner + out_crd_str = "out_crd" + # However, if the input primitive is another crddrop, we need to make sure it's reading from + # the correct input crddrop output. + if d[u_]["type"] == "crddrop": + if index_value == d[u_]["inner"]: + out_crd_str += "_inner" + elif index_value == d[u_]["outer"]: + out_crd_str += "_outer" + return out_crd_str + + def generate_datasets_code(f, tensor_formats, scope_lvl, tensor_info, tensor_format_parse, test_name): # Assuming the format is csr and csc: for ten in tensor_format_parse.return_all_tensors(): @@ -539,7 +552,7 @@ def get_all_files(directory_path): continue out_name.append(filename[0:-3]) # checking if it is a file - print(out_name[-1]) + print("Test Name:", out_name[-1]) if os.path.isfile(f): file_paths.append(f) return file_paths, out_name @@ -810,9 +823,13 @@ def get_all_files(directory_path): for u_ in data.get_parents()[v]: index_value = data.get_edge_data()[v][data.get_parents()[v].index(u_)][-1] if index_value == d[v]["inner"]: - f.write(tab(2) + d[v]["object"] + ".set_inner_crd" + "(" + d[u_]["object"] + ".out_crd())\n") + out_crd_str = get_out_crd_str(d, u_, index_value) + f.write(tab(2) + d[v]["object"] + ".set_inner_crd" + "(" + d[u_]["object"] + "." + + out_crd_str + "())\n") if index_value == d[v]["outer"]: - f.write(tab(2) + d[v]["object"] + ".set_outer_crd" + "(" + d[u_]["object"] + ".out_crd())\n") + out_crd_str = get_out_crd_str(d, u_, index_value) + f.write(tab(2) + d[v]["object"] + ".set_outer_crd" + "(" + d[u_]["object"] + "." + + out_crd_str + "())\n") nodes_updating_list.append(tab(2) + d[v]["object"] + ".update()\n") # f.write(tab(2) + d[v]["object"] + ".update()\n\n") data.add_done(v) @@ -933,7 +950,6 @@ def get_all_files(directory_path): if "val" not in data.get_edge_data()[v][i] and "spaccumulator" \ in d[u_]["object"]: local_index = data.get_edge_data()[v][i][-1] - print(d[u_], " ", local_index, " ", apath) if d[u_]["in0"] == local_index: local_cord = "_inner" else: From eaf33a6b43df6d2dc3121b20e10bdaf6c5287684 Mon Sep 17 00:00:00 2001 From: Olivia Hsu Date: Wed, 11 Oct 2023 11:16:46 -0700 Subject: [PATCH 74/76] Oops remove print statements --- sam/sim/test/gen_gantt.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/sam/sim/test/gen_gantt.py b/sam/sim/test/gen_gantt.py index b421a49b..453a0553 100644 --- a/sam/sim/test/gen_gantt.py +++ b/sam/sim/test/gen_gantt.py @@ -13,7 +13,6 @@ def gen_gantt(extra_info, testname): sam_name = '' for k in extra_info.keys(): - print(k, sam_name) if "done_cycles" in k: sam_name = k.split('/')[0] finish_c = extra_info[k] @@ -42,8 +41,6 @@ def gen_gantt(extra_info, testname): if "backpressure" in extra_info.keys() and extra_info["backpressure"]: back_depth = extra_info["depth"] - print(finish_list, block_list, start_list, duration_list) - # Writing cycle info to csv file with open(testname + '_' + extra_info["dataset"] + '_back_' + back_depth + '.csv', 'w', newline='') as file: writer = csv.writer(file) From 2c699f9fc43291e984892f932f61ffbfde854f25 Mon Sep 17 00:00:00 2001 From: Kalhan Koul Date: Thu, 14 Dec 2023 12:53:00 -0800 Subject: [PATCH 75/76] fixes for suitesparse apps --- scripts/formatting/datastructure_suitesparse.py | 2 +- scripts/util/util.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/formatting/datastructure_suitesparse.py b/scripts/formatting/datastructure_suitesparse.py index 502a8822..6e89d628 100644 --- a/scripts/formatting/datastructure_suitesparse.py +++ b/scripts/formatting/datastructure_suitesparse.py @@ -139,7 +139,7 @@ def write_datastructure_bench(args, tensor, out_path, tiles=None): vec = vec.toarray().flatten() formatWriter.writeout_separate_vec(vec, dirname, tensorname) elif "mat_vecmul" == args.benchname or "mat_vecmul_ji" in args.benchname: - formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss10") + formatWriter.writeout_separate_sparse_only(coo, dirname, tensorname, format_str="ss01") if not args.no_gen_other: tensorname = 'c' vec = scipy.sparse.random(shape[1], 1, density=args.density, data_rvs=np.ones) diff --git a/scripts/util/util.py b/scripts/util/util.py index 44d7323c..8332ba1b 100644 --- a/scripts/util/util.py +++ b/scripts/util/util.py @@ -496,7 +496,7 @@ def writeout_separate_vec(self, vec, dir_path, tensorname, format_str="s0", hw=T else: filename = os.path.join(vec_dir, "tensor_" + tensorname + "_mode_0_seg") with open(filename, "w") as ofile: - ofile.write(array_newline_str([0, len(vec_sp) + 1])) + ofile.write(array_newline_str([0, len(vec_sp)])) if not hw: filename = os.path.join(vec_dir, tensorname + "0_crd.txt") @@ -535,7 +535,7 @@ def writeout_separate_vec(self, vec, dir_path, tensorname, format_str="s0", hw=T ofile.write(array_newline_str(vec_shape)) def writeout_separate_sparse_only(self, coo, dir_path, tensorname, format_str="ss01", hw=True): - + if format_str == "ss01": dcsr_dir = Path(dir_path) dcsr_dir.mkdir(parents=True, exist_ok=True, mode=0o777) From c2a4d73decf32860a7a01c68eb02869b205f0167 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Mon, 18 Dec 2023 16:16:07 -0800 Subject: [PATCH 76/76] tiling script cleanup --- scripts/suitesparse_memory_model_runner.sh | 2 +- scripts/tiling/prepare_files.sh | 3 +- scripts/tiling/tile_ext.sh | 7 +- setup_tiling_mat.py | 103 +-------------------- 4 files changed, 12 insertions(+), 103 deletions(-) diff --git a/scripts/suitesparse_memory_model_runner.sh b/scripts/suitesparse_memory_model_runner.sh index e715a508..c79e5a81 100755 --- a/scripts/suitesparse_memory_model_runner.sh +++ b/scripts/suitesparse_memory_model_runner.sh @@ -31,7 +31,7 @@ mkdir -p $path mkdir -p $basedir/tiles/ rm -rf $basedir/tiles/* -./scripts/tiling/prepare_files.sh $fname.mtx $yaml_fname $fname +./scripts/tiling/prepare_files.sh $fname.mtx $yaml_fname $fname $appname cd $basedir/sam/sim # python3 -m pytest test/advanced-simulator/test_$bench.py --ssname $fname -s --check-gold --skip-empty --nbuffer --yaml_name=$yaml_fname --benchmark-json=$path/mem_model_$fname.json diff --git a/scripts/tiling/prepare_files.sh b/scripts/tiling/prepare_files.sh index d255f317..cab4ec41 100755 --- a/scripts/tiling/prepare_files.sh +++ b/scripts/tiling/prepare_files.sh @@ -7,11 +7,12 @@ # ./scripts/tiling/prepare_files.sh extensor__.mtx appname=$3 +testname=$4 basedir=$(pwd) rm -rf $basedir/tiles/* -./scripts/tiling/tile_ext.sh $1 memory_config_extensor_17M_llb.yaml $appname +./scripts/tiling/tile_ext.sh $1 memory_config_extensor_17M_llb.yaml $appname $testname # python3 scripts/tiling/generate_gold_matmul_tiled.py --yaml_name memory_config_extensor_17M_llb.yaml diff --git a/scripts/tiling/tile_ext.sh b/scripts/tiling/tile_ext.sh index 082c1c38..9c727db8 100755 --- a/scripts/tiling/tile_ext.sh +++ b/scripts/tiling/tile_ext.sh @@ -11,14 +11,17 @@ BENCHMARKS=( # mat_vecmul_ij # mat_residual # mat_elemadd3 - # matmul_ijk + $4 # mat_mask_tri # mat_vecmul_iter - mat_elemadd + # mat_elemadd ) appname=$3 +echo "APP NAME IS : $4" +# exit 0 + sspath=$SUITESPARSE_PATH basedir=$(pwd) diff --git a/setup_tiling_mat.py b/setup_tiling_mat.py index b153eec0..da8b082f 100644 --- a/setup_tiling_mat.py +++ b/setup_tiling_mat.py @@ -7,48 +7,17 @@ from sam.util import SUITESPARSE_PATH -## PARAMS ###################################################################### +#Usage: python3 setup_tiling_mat.py -# data = ['rajat12'] +## PARAMS ###################################################################### data = [sys.argv[2]] tilesizes = [int(sys.argv[3])] -# app_name = "mat_elemadd" -# app_name = "mat_elemmul" -# app_name = "mat_sddmm" -# app_name = "matmul_ijk" app_name = sys.argv[1] -# app_name = "mat_elemmul" -# app_name = "mat_residual" - -# data = [] -# tilesizes = [] -# sparsities = [60, 80, 90, 95, 98] -# for sparsity in sparsities: -# for i in range(5): -# data.append(f"matrix_sp{str(sparsity)}_sm_{i+1}") -# tilesizes.append(30) - -# data_file = open("onyx_final_eval_mid50_tensor_names.txt") -# data_file_lines = data_file.readlines() -# for line in data_file_lines: -# data.append(line[:-1]) - -# with open('matmul_tilesize_list.txt', 'r') as file: -# lines = file.readlines() - -# tilesizes = [int(line.strip()) for line in lines] +docker_path = sys.argv[4] + print("TILESIZES: ", tilesizes) print("DATA: ", data) - -mode_to_exclude = 0 -addition_vector_name = "d" #mattransmul (d) and residual (b) only - -other_tensors = ["c"] -samples_directory = f"samples/{app_name}" -docker_path = f"avb03-sparse-tiling" -use_dataset_files = False - ############################################################################### def write_to_line(file_path, line_number, new_content): @@ -98,71 +67,7 @@ def replace_ones_with_zeros(mtx_file): command = f"./scripts/suitesparse_memory_model_runner.sh {datum} {app_name}" os.system(command) - - directories = glob.glob(f'tiles/{app_name}/formatted/tensor_[a-z]*') - - #for vectors, do cleanup - for directory in directories: - print(directory) - match = re.search(r'tensor_([a-z])', directory) - if match: - lowercase_letter = match.group(1) - crd_file = os.path.join(directory, f"{lowercase_letter}{mode_to_exclude}_crd.txt") - seg_file = os.path.join(directory, f"{lowercase_letter}{mode_to_exclude}_seg.txt") - - # if os.path.exists(crd_file): - # os.remove(crd_file) - - # if os.path.exists(seg_file): - # os.remove(seg_file) - - samples_with_addition_vector = None - - # dense tile replacement for addition - if app_name == "mat_mattransmul" or app_name == "mat_residual": - # samples_with_addition_vector = glob.glob(f"{samples_directory}/*[{addition_vector_name}]*") - # samples_with_addition_vector = glob.glob(f"{samples_directory}/mtm_w_0_1/tensor_d_tile_0_0") - samples_with_addition_vector = glob.glob(f"{samples_directory}/mtm_w_0_1_BAK") - - - print(samples_with_addition_vector) - #fill in missing tiles with blanks - for sample in samples_with_addition_vector: - file_path = os.path.join(sample, f"{addition_vector_name}_vals.txt") - - with open(file_path, "r") as file: - file_contents = file.read() - - file_contents = file_contents.replace("1", "0") - - with open(file_path, "w") as file: - file.write(file_contents) - - tile_range = [(0,i) for i in range(8)] + [(1,i) for i in range(4)] - - for i,j in tile_range: - tile_dir = f"tiles/{app_name}/formatted/tensor_{addition_vector_name}_tile_{i}_{j}" - - if not os.path.exists(tile_dir): - # replace_ones_with_zeros("samples/mat_mattransmul/tensor_d_dense_mtx.mtx") - - # copy_over_to_mtx_dir = f"cp samples/mat_mattransmul/tensor_d_dense_gold_stash.mtx tiles/{app_name}/mtx/tensor_{addition_vector_name}_tile_{i}_{j}.mtx" - # os.system(copy_over_to_mtx_dir) - - sample_tile_dir = samples_with_addition_vector[0] - - if os.path.exists(sample_tile_dir): - shutil.copytree(sample_tile_dir, tile_dir) - - dump_gold_tiles = f"python3 scripts/tiling/generate_gold_mattransmul.py --yaml_name memory_config_extensor_17M_llb.yaml" - os.system(dump_gold_tiles) - - # os.makedirs("tiles_compiled", exist_ok=True) - # copy_rename = f"cp -r tiles/{app_name} tiles_compiled/{app_name}_{datum}" - # print(copy_rename) - # os.system(copy_rename) - docker_clean = f"docker exec {docker_path} rm -r /aha/garnet/tiles_{app_name}_{datum}" print(docker_clean) os.system(docker_clean)