Skip to content

Commit

Permalink
syn mat
Browse files Browse the repository at this point in the history
  • Loading branch information
Akhilesh Varadan Balasingam committed Oct 9, 2023
1 parent 6c9dbd7 commit a1440cd
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 42 deletions.
26 changes: 13 additions & 13 deletions maximum_tiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 9 additions & 8 deletions sam/sim/src/tiling/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion scripts/formatting/datastructure_suitesparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
14 changes: 7 additions & 7 deletions scripts/formatting/generate_suitesparse_formats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/tiling/tile_ext.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ BENCHMARKS=(
# mat_elemadd3
# matmul_ijk
# mat_mask_tri
mat_vecmul_iter
# mat_elemmul
# mat_vecmul_iter
mat_elemadd
)

appname=$3
Expand Down
30 changes: 19 additions & 11 deletions setup_tiling_mat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit a1440cd

Please sign in to comment.