Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping to cgra tensor debug #112

Merged
merged 5 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/taco
Submodule taco updated from 78a3e9 to e248ce
21 changes: 11 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 @@ -529,6 +528,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)
Expand Down Expand Up @@ -557,6 +557,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)
Expand All @@ -577,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 @@ -621,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)
41 changes: 28 additions & 13 deletions scripts/formatting/generate_tensor_tile_formats_onyx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#SBATCH -N 1
#SBATCH -t 360

# ./scripts/generate_frostt_formats_onyx.sh <tensor_name.txt>
# edit tensor_name.txt with tensors to tile
# ./scripts/generate_frostt_formats_onyx.sh <tensor_name.txt> <yaml_file> <benchmark> <other_format> <docker name>

shopt -s extglob

Expand All @@ -15,22 +16,17 @@ BENCHMARKS=(
# tensor3_elemadd
# tensor3_innerprod
# tensor3_mttkrp
tensor3_ttm
# tensor3_ttm
$3
# tensor3_ttm
# tensor3_mttkrp
# tensor3_elemmul
# tensor3_mttkrp
)

OTHER_FORMATS=(
# sss
# sss
# s
ss
# ss
# sss
# ss
)
$4
)

OTHERBENCHES='["tensor3_ttv", "tensor3_ttm", "tensor3_mttkrp"]'

Expand All @@ -55,6 +51,7 @@ run_format(){
bench_path=$4
tile_path=$5
tensor_format=$6
other_form=$7

basedir=$(pwd)
echo "Processing $f"
Expand All @@ -67,9 +64,24 @@ 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"

# 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

Expand Down Expand Up @@ -107,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
done

docker cp tiles $5:/aha/garnet/tiles_$3
2 changes: 1 addition & 1 deletion scripts/tiling/tile_ext.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down