Skip to content

Commit

Permalink
style cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Akhilesh Varadan Balasingam committed Jan 22, 2024
1 parent 7f2ae26 commit 3a8a485
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
19 changes: 9 additions & 10 deletions sam/sim/src/tiling/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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)
scipy.io.mmwrite(mtx_path_name, tile)
8 changes: 7 additions & 1 deletion sam/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,21 @@ 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}*"
dirlist = glob.glob(filename)
return dirlist[0]

# TnsFileLoader loads a tensor stored in .tns format.


class TnsFileLoader:
def __init__(self, cast_int=False):
self.cast = cast_int
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
return sparse.COO(tensor.coords, data, tensor.shape)

0 comments on commit 3a8a485

Please sign in to comment.