From a1440cd5d78d0f6be8962ac2b4b19b65208d823f Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Mon, 9 Oct 2023 11:41:39 -0700 Subject: [PATCH] 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")