From 016c0753751e5f5e70dc84685c22cc01d3983d20 Mon Sep 17 00:00:00 2001 From: Kalhan Koul Date: Wed, 17 Jan 2024 11:13:55 -0800 Subject: [PATCH 1/5] debug with akhilesh --- sam/sim/src/tiling/tile.py | 2 ++ .../formatting/generate_tensor_tile_formats_onyx.sh | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 59022253..5a8d5df4 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -529,6 +529,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi help="If this is enabled, the 'other' tensors will have at least one nonzero value") args = parser.parse_args() + print("Args:", args) random.seed(args.seed) np.random.seed(args.seed) @@ -557,6 +558,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi inputCache = inputCacheTensor tensor_path = os.path.join(FROSTT_PATH, args.input_tensor + ".tns") + print("tensor_path", tensor_path) # FIXME: This is broken frostt_tensor = FrosttTensor(tensor_path) diff --git a/scripts/formatting/generate_tensor_tile_formats_onyx.sh b/scripts/formatting/generate_tensor_tile_formats_onyx.sh index c5c51a6d..1c01ec0e 100755 --- a/scripts/formatting/generate_tensor_tile_formats_onyx.sh +++ b/scripts/formatting/generate_tensor_tile_formats_onyx.sh @@ -67,10 +67,20 @@ run_format(){ export FROSTT_TENSOR_PATH=$filename export FROSTT_FORMATTED_PATH=$bench_path/formatted/ export TENSOR_FORMAT=$tensor_format - echo "Tensor format: $TENSOR_FORMAT" + echo "FROSTT_FORMATTED_TACO_PATH: $FROSTT_FORMATTED_TACO_PATH" + echo "FROSTT_PATH: $FROSTT_PATH" + echo "FROSTT_TENSOR_PATH: $FROSTT_TENSOR_PATH" + echo "FROSTT_FORMATTED_PATH: $FROSTT_FORMATTED_PATH" + echo "TENSOR_FORMAT: $TENSOR_FORMAT" + echo "format: $format" $basedir/compiler/taco/build/bin/taco-test sam.pack_$format + echo "Name: $name" + echo "Format: $format" + echo "Bench: $bench" + echo "Bench path: $bench_path" + python3 $basedir/scripts/formatting/datastructure_tns.py -n $name -f $format --other -b $bench -hw --output_dir $bench_path/formatted/$name echo "Done processing $name" From 7f2ae26f7d5ed420df6af542ee92db80013559b6 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Sun, 21 Jan 2024 22:03:36 -0800 Subject: [PATCH 2/5] clean up tiling flow --- .../generate_tensor_tile_formats_onyx.sh | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/scripts/formatting/generate_tensor_tile_formats_onyx.sh b/scripts/formatting/generate_tensor_tile_formats_onyx.sh index 1c01ec0e..5cd8c1b4 100755 --- a/scripts/formatting/generate_tensor_tile_formats_onyx.sh +++ b/scripts/formatting/generate_tensor_tile_formats_onyx.sh @@ -2,7 +2,8 @@ #SBATCH -N 1 #SBATCH -t 360 -# ./scripts/generate_frostt_formats_onyx.sh +# edit tensor_name.txt with tensors to tile +# ./scripts/generate_frostt_formats_onyx.sh shopt -s extglob @@ -15,7 +16,8 @@ BENCHMARKS=( # tensor3_elemadd # tensor3_innerprod # tensor3_mttkrp - tensor3_ttm +# tensor3_ttm +$3 # tensor3_ttm # tensor3_mttkrp # tensor3_elemmul @@ -23,14 +25,8 @@ BENCHMARKS=( ) OTHER_FORMATS=( -# sss -# sss -# s - ss -# ss -# sss - # ss - ) + $4 +) OTHERBENCHES='["tensor3_ttv", "tensor3_ttm", "tensor3_mttkrp"]' @@ -55,6 +51,7 @@ run_format(){ bench_path=$4 tile_path=$5 tensor_format=$6 + other_form=$7 basedir=$(pwd) echo "Processing $f" @@ -74,12 +71,17 @@ run_format(){ echo "TENSOR_FORMAT: $TENSOR_FORMAT" echo "format: $format" + # if tensor_format == "ss": $basedir/compiler/taco/build/bin/taco-test sam.pack_$format - + # else: + # $basedir/compiler/taco/build/bin/taco-test sam.pack_ echo "Name: $name" echo "Format: $format" echo "Bench: $bench" echo "Bench path: $bench_path" + echo "tile_path: $tile_path" + echo "tensor_format: $tensor_format" + echo "other_form: $other_form" python3 $basedir/scripts/formatting/datastructure_tns.py -n $name -f $format --other -b $bench -hw --output_dir $bench_path/formatted/$name @@ -117,5 +119,8 @@ for i in ${!FORMATS[@]}; do set_temp_env $old_frostt_formatted_taco_path $old_frostt_path $old_frostt_tensor_path $old_frostt_formatted_path chmod -R 775 $FROSTT_FORMATTED_PATH + done -done \ No newline at end of file +done + +docker cp tiles $5:/aha/garnet/tiles_$3 From 3a8a485fbcd4731127c30d47f6a520210e5c4198 Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Sun, 21 Jan 2024 22:12:26 -0800 Subject: [PATCH 3/5] style cleanup --- sam/sim/src/tiling/tile.py | 19 +++++++++---------- sam/util.py | 8 +++++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/sam/sim/src/tiling/tile.py b/sam/sim/src/tiling/tile.py index 5a8d5df4..55615b15 100644 --- a/sam/sim/src/tiling/tile.py +++ b/sam/sim/src/tiling/tile.py @@ -273,7 +273,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) @@ -327,8 +326,8 @@ def get_other_tensors(app_str, tensor, other_nonempty=True): print("Writing other tensors...") tensorName = args.input_tensor - variant="mode2" # k dimension is mode 2 - path = constructOtherVecKey(tensorName,variant) + variant = "mode2" # k dimension is mode 2 + path = constructOtherVecKey(tensorName, variant) tensor_c_loader = FrosttTensor(path) tensor_c = tensor_c_loader.load().todense() print(tensor_c) @@ -346,7 +345,7 @@ def get_other_tensors(app_str, tensor, other_nonempty=True): print("Writing other tensors...") tensorName = args.input_tensor - variant="mode2_ttm" + variant = "mode2_ttm" path = constructOtherMatKey(tensorName, variant) matrix_c_loader = FrosttTensor(path) matrix_c = matrix_c_loader.load().todense() @@ -381,14 +380,14 @@ def get_other_tensors(app_str, tensor, other_nonempty=True): size_i, size_j, size_l = tensor.shape # i,j,k tensorName = args.input_tensor - variant="mode1_mttkrp" + variant = "mode1_mttkrp" path = constructOtherMatKey(tensorName, variant) matrix_c_loader = FrosttTensor(path) matrix_c = matrix_c_loader.load().todense() print(matrix_c) tensorName = args.input_tensor - variant="mode2_mttkrp" + variant = "mode2_mttkrp" path = constructOtherMatKey(tensorName, variant) matrix_d_loader = FrosttTensor(path) matrix_d = matrix_d_loader.load().todense() @@ -397,11 +396,11 @@ def get_other_tensors(app_str, tensor, other_nonempty=True): # # C & D are dense according to TACO documentation # matrix_c = scipy.sparse.random(size_j, size_k, density=1, data_rvs=np.ones).toarray() # matrix_d = scipy.sparse.random(size_j, size_l, density=1, data_rvs=np.ones).toarray() - + if other_nonempty: matrix_c[0] = 1 matrix_d[0] = 1 - + tensors.append(matrix_c) tensors.append(matrix_d) else: @@ -579,7 +578,7 @@ def cotile_multilevel_coo(app_str, hw_config_fname, tensors, output_dir_path, hi else: output_mtx_name = os.path.join(args.output_dir_path, "mtx") output_mtx_path = Path(output_mtx_name) - + output_mtx_path.mkdir(parents=True, exist_ok=True) print(os.path.exists(output_mtx_path)) @@ -623,4 +622,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 9ba1fea3..b6d88edb 100644 --- a/sam/util.py +++ b/sam/util.py @@ -64,10 +64,12 @@ def round_sparse(x): else: return math.ceil(x - 0.5) + 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') filename = f"{path}/{tensorName}-mat_{variant}*" @@ -75,6 +77,8 @@ def constructOtherMatKey(tensorName, variant, sparsity=0.001): return dirlist[0] # TnsFileLoader loads a tensor stored in .tns format. + + class TnsFileLoader: def __init__(self, cast_int=False): self.cast = cast_int @@ -198,6 +202,8 @@ def shiftLastMode(self, tensor): # ScipyTensorShifter shifts all elements in the last mode # of the input scipy/sparse tensor by one. + + class ScipyTensorShifter: def __init__(self): pass @@ -625,4 +631,4 @@ def safeCastPydataTensorToInts(tensor): # else: # data[i] = int(tensor.data[i]) data[i] = round_sparse(tensor.data[i]) - return sparse.COO(tensor.coords, data, tensor.shape) \ No newline at end of file + return sparse.COO(tensor.coords, data, tensor.shape) From c3f97059909ff3570d0e3093cbfd3a8c771f09ff Mon Sep 17 00:00:00 2001 From: Akhilesh Varadan Balasingam Date: Sun, 21 Jan 2024 22:59:06 -0800 Subject: [PATCH 4/5] pointing to right taco --- compiler/taco | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/taco b/compiler/taco index 78a3e9bb..e248cefc 160000 --- a/compiler/taco +++ b/compiler/taco @@ -1 +1 @@ -Subproject commit 78a3e9bb5258e6f20303efba457d8443cb211c7a +Subproject commit e248cefc991bfa114b96af4d806acd6ab15eb44c From 47ca51a53743dd129bf080b2e4ee24c24f5b7d74 Mon Sep 17 00:00:00 2001 From: Kalhan Koul Date: Mon, 22 Jan 2024 10:28:56 -0800 Subject: [PATCH 5/5] fixed matrix flow --- scripts/tiling/tile_ext.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tiling/tile_ext.sh b/scripts/tiling/tile_ext.sh index 9c727db8..131c701e 100755 --- a/scripts/tiling/tile_ext.sh +++ b/scripts/tiling/tile_ext.sh @@ -43,7 +43,7 @@ for b in ${!BENCHMARKS[@]}; do 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 + python3 $basedir/scripts/formatting/datastructure_suitesparse.py -n temp -hw -b $bench --input $basedir/tiles/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