Skip to content

Commit

Permalink
Merge pull request #107 from weiya711/mapping_to_cgra_suitesparse_fixes
Browse files Browse the repository at this point in the history
Mapping to cgra suitesparse fixes
  • Loading branch information
kalhankoul96 authored Jan 9, 2024
2 parents 9fc0993 + 4d03070 commit 0b78457
Show file tree
Hide file tree
Showing 120 changed files with 3,739 additions and 1,501 deletions.
33 changes: 24 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ __pycache__/
# Temporary output files
*.swp
*.swo
*.swn
*.txt
*.out
*.log

# Generated Python Package files
*.egg-info/

# Files for MacOS and IDEs
.DS_store
Expand All @@ -17,6 +22,8 @@ cmake-build-*/
# Generated SAM Graphs
*.gv

venv/

# Generated images
*.svg
*.png
Expand All @@ -26,6 +33,13 @@ cmake-build-*/
*.csv
*.json

# Tensor files
*.mtx
*.tns

# Generated formatted tensor files
tensor_*_mode_*

# Generated folders
build/
logs/
Expand All @@ -38,19 +52,20 @@ compiler/benchmark/
# Generated SAM simulator tests
*/sim/test/apps/test_*.py

*.gv

# Tensor files
*.mtx
*.tns

# Temporary matrices
# Temporary or generated tensor directories
tmp_mat*/
tiles/
synthetic/

# Jupyter notebook checkpoints
.ipynb_checkpoints/
# Generated SAM simulator tests
*/sim/test/apps/test_*.py

# Generated formatted tensor files
tensor_*_mode_*
# Temporary scripts
download_suitesparse_partial.sh

# Tensor files
tiles/
# Network Filesystem
.nfs*
44 changes: 18 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ endif

ifeq ("$(NEVA)","ON")
CMD := OMP_PROC_BIND=true LD_LIBRARY_PATH=compiler/build/lib/:$(LD_LIBRARY_PATH) numactl -C 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 -m 0 compiler/build/taco-bench $(BENCHFLAGS)
export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse/
export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt/
export SUITESPARSE_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/suitesparse-formatted
export FROSTT_FORMATTED_TACO_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted/taco-tensor
export FROSTT_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted
export TACO_TENSOR_PATH=/nobackup/owhsu/sparse-datasets
# export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse/
# export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt/
# export SUITESPARSE_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/suitesparse-formatted
# export FROSTT_FORMATTED_TACO_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted/taco-tensor
# export FROSTT_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted
# export TACO_TENSOR_PATH=/nobackup/owhsu/sparse-datasets
else ifeq ("$(LANKA)", "ON")
CMD := OMP_PROC_BIND=true LD_LIBRARY_PATH=compiler/build/lib/:$(LD_LIBRARY_PATH) numactl -C 0,2,4,6,8,10,24,26,28,30,32,34 -m 0 compiler/build/taco-bench $(BENCHFLAGS)
export SUITESPARSE_PATH=/data/scratch/changwan/florida_all
export FROSTT_PATH=/data/scratch/owhsu/datasets/frostt
export TACO_TENSOR_PATH=/data/scratch/owhsu/datasets
export SUITESPARSE_FORMATTED_PATH=/data/scratch/owhsu/datasets/suitesparse-formatted
export FROSTT_FORMATTED_TACO_PATH=/data/scratch/owhsu/datasets/frostt-formatted/taco-tensor
export FROSTT_FORMATTED_PATH=/data/scratch/owhsu/datasets/frostt-formatted
# export SUITESPARSE_PATH=/data/scratch/changwan/florida_all
# export FROSTT_PATH=/data/scratch/owhsu/datasets/frostt
# export TACO_TENSOR_PATH=/data/scratch/owhsu/datasets
# export SUITESPARSE_FORMATTED_PATH=/data/scratch/owhsu/datasets/suitesparse-formatted
# export FROSTT_FORMATTED_TACO_PATH=/data/scratch/owhsu/datasets/frostt-formatted/taco-tensor
# export FROSTT_FORMATTED_PATH=/data/scratch/owhsu/datasets/frostt-formatted
else
CMD := LD_LIBRARY_PATH=compiler/build/lib/:$(LD_LIBRARY_PATH) compiler/build/taco-bench $(BENCHFLAGS)
endif
Expand All @@ -57,16 +57,16 @@ guard-%:

# ---- Run SAM python simulator stuff ----
csv:
scripts/pytest_suitesparse_with_benchmarks.sh
scripts/run_sam_sim/pytest_suitesparse_with_benchmarks.sh
run-final: submodules
./scripts/run_suitesparse_final.sh $(realpath ./scripts/tensor_names/$(TENSOR_TXT))
./scripts/run_sam_sim/run_suitesparse_final.sh $(realpath ./scripts/tensor_names/$(TENSOR_TXT))

run-gen: submodules
./scripts/run_suitesparse_generated.sh $(realpath ./scripts/tensor_names/$(TENSOR_TXT))
./scripts/run_sam_sim/run_suitesparse_generated.sh $(realpath ./scripts/tensor_names/$(TENSOR_TXT))

tests: sam
mkdir -p sam/sim/test/apps
python scripts/test_generating_code.py
python scripts/gen_sam_apps/test_generating_code.py

# ---- Build taco and make sam graphs ----
.PHONY: sam
Expand Down Expand Up @@ -109,18 +109,10 @@ endif
# ---- Setup proper environment stuff ----
suitesparse-formats: guard-SUITESPARSE_FORMATTED_PATH guard-SUITESPARSE_PATH
rm -rf ${SUITESPARSE_FORMATTED_PATH}/*
set -e && ./scripts/generate_suitesparse_formats.sh
set -e && ./scripts/formatting/generate_suitesparse_formats.sh

frostt-formats: taco/build guard-FROSTT_FORMATTED_PATH guard-FROSTT_PATH
./scripts/generate_frostt_formats.sh

.PHONY: env
env:
export SUITESPARSE_PATH=/nobackup/owhsu/sparse-datasets/suitesparse/
export FROSTT_PATH=/nobackup/owhsu/sparse-datasets/frostt/
export SUITESPARSE_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/suitesparse-formatted
export FROSTT_FORMATTED_TACO_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted/taco-tensor
export FROSTT_FORMATTED_PATH=/nobackup/owhsu/sparse-datasets/frostt-formatted
./scripts/formatting/generate_frostt_formats.sh

.PHONY: pydepends
pydepends:
Expand Down
14 changes: 13 additions & 1 deletion compiler/baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ enum SuiteSparseOp {
SDDMM = 4,
MATTRANSMUL = 5,
RESIDUAL = 6,
MMADD = 7
MMADD = 7,
MMMUL = 8
};

std::string opName(SuiteSparseOp op) {
Expand All @@ -341,6 +342,9 @@ std::string opName(SuiteSparseOp op) {
case MMADD: {
return "mmadd";
}
case MMMUL: {
return "mmmul"
}
default:
return "";
}
Expand Down Expand Up @@ -467,6 +471,13 @@ static void bench_suitesparse(benchmark::State &state, SuiteSparseOp op, int fil
result(i, j) = ssTensor(i, j) + otherShifted(i, j);
break;
}
case MMMUL: {
result = Tensor<int64_t>("result", ssTensor.getDimensions(), ssTensor.getFormat(), fill_value);

IndexVar i, j, k;
result(i, j) = ssTensor(i, j) * otherShifted(i, j);
break;
}
case MATTRANSMUL: {
result = Tensor<int64_t>("result", {DIM1}, Format(Sparse), fill_value);

Expand Down Expand Up @@ -516,4 +527,5 @@ static void bench_suitesparse(benchmark::State &state, SuiteSparseOp op, int fil
// TODO: need to fix for DCSC for this
TACO_BENCH_ARGS(bench_suitesparse, mat_mattransmul, MATTRANSMUL);
TACO_BENCH_ARGS(bench_suitesparse, matmul_spmm, SPMM);
TACO_BENCH_ARGS(bench_suitesparse, mat_elemmul, MMMUL);

7 changes: 6 additions & 1 deletion compiler/sam-outputs/onyx-dot/mat_vecmul_ij.gv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ digraph SAM {
14 [comment="type=fiberlookup,index=i,tensor=B,mode=0,format=compressed,src=true,root=true" label="FiberLookup i: B0\ncompressed" color=green4 shape=box style=filled type="fiberlookup" index="i" tensor="B" mode="0" format="compressed" src="true" root="true"]
13 [comment="type=broadcast" shape=point style=invis type="broadcast"]
7 [comment="type=crddrop,outer=i,inner=j" label="CrdDrop i,j" color=orange shape=box style=filled type="crddrop" outer="i" inner="j"]
15 [comment="type=crddrop,outer=i,inner=j" label="CrdDrop i,j" color=orange shape=box style=filled type="crddrop" outer="i" inner="j"]
1 [comment="type=fiberwrite,index=i,tensor=x,mode=0,format=compressed,segsize=2,crdsize=B0_dim,sink=true" label="FiberWrite i: x0\ncompressed" color=green3 shape=box style=filled type="fiberwrite" index="i" tensor="x" mode="0" format="compressed" segsize="2" crdsize="B0_dim" sink="true"]
12 [comment="type=repsiggen,index=i" label="RepeatSignalGenerator i" color=cyan3 shape=box style=filled type="repsiggen" index="i"]
11 [comment="type=repeat,index=i,tensor=c,root=true" label="Repeat i: c" color=cyan2 shape=box style=filled type="repeat" index="i" tensor="c" root="true"]
Expand All @@ -24,12 +25,16 @@ digraph SAM {
8 -> 7 [label="crd_in-j" style=dashed type="crd" comment="in-j"]
8 -> 5 [label="ref_out-B" style=bold type="ref" comment="out-B"]
5 -> 4 [label="val" type="val"]
4 -> 3 [label="val" type="val"]
# 4 -> 3 [label="val" type="val"]
3 -> 0 [label="val" type="val"]
8 -> 6 [label="ref_out-c" style=bold type="ref" comment="out-c"]
6 -> 4 [label="val" type="val"]
10 -> 8 [label="ref_in-c" style=bold type="ref" comment="in-c"]
14 -> 9 [label="ref" style=bold type="ref" comment=""]
9 -> 8 [label="crd_in-B" style=dashed type="crd" comment="in-B"]
9 -> 8 [label="ref_in-B" style=bold type="ref" comment="in-B"]

4 -> 15 [label="val_inner-j" type="val" comment="inner-j"]
15 -> 3 [label="val_inner-j" type="val" comment="inner-j"]
13 -> 15 [label="crd_i" style=dashed type="crd" comment="i"]
}
52 changes: 52 additions & 0 deletions count_nnz_tiling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import glob


def count_nonzeros(matrix_values_file):
with open(matrix_values_file, 'r') as values_file:
matrix_values = [float(val) for val in values_file.readlines()]

nonzeros = sum(1 for val in matrix_values if val != 0)

return nonzeros


tile_dirs = glob.glob("SPARSE_TESTS/MAT_TMP_DIR/tile*")
num_tiles = len(tile_dirs)
limit = 900
print("there are ", num_tiles, "tiles")

sparsity_B = 0
sparsity_C = 0
# tilesize=int(sys.argv[1])**2
tot_num_nonzeros = 0
for tile_num in range(0, num_tiles):
tot_num_nonzeros = 0

tensor_C_values_file = f'SPARSE_TESTS/MAT_TMP_DIR/tile{tile_num}/tensor_C_mode_vals'

num_nonzeros = count_nonzeros(tensor_C_values_file)
tot_num_nonzeros += num_nonzeros
if num_nonzeros >= limit:
print("num_nonzeros: ", num_nonzeros)
print("error! too many nonzeros in INPUT matrices")
raise Exception

tensor_C_values_file = f'SPARSE_TESTS/MAT_TMP_DIR/tile{tile_num}/tensor_B_mode_vals'

num_nonzeros = count_nonzeros(tensor_C_values_file)
tot_num_nonzeros += num_nonzeros
if num_nonzeros >= limit:
print("num_nonzeros: ", num_nonzeros)
print("error! too many nonzeros in INPUT matrices")
raise Exception

if tot_num_nonzeros >= limit:
print("tot_num_nonzeros: ", tot_num_nonzeros)
print("error! too many nonzeros in matrices")
raise Exception

sparsity_B /= num_tiles
sparsity_C /= num_tiles

print("sparsity_B: ", sparsity_B)
print("sparsity_C: ", sparsity_C)
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: aha
name: sam
channels:
- pytorch
- anaconda
Expand Down Expand Up @@ -201,4 +201,4 @@ dependencies:
- statsmodels==0.13.2
- threadpoolctl==3.1.0
- traitlets==5.3.0
prefix: /home/oliviahsu/miniconda3/envs/aha
prefix: ~/Anaconda3/envs/sam
78 changes: 78 additions & 0 deletions find_max_tilesize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import os


def write_to_line(file_path, line_number, new_content):
with open(file_path, "r") as file:
lines = file.readlines()

if line_number > len(lines) or line_number < 1:
# Line number is out of range
return

lines[line_number - 1] = new_content + "\n"

with open(file_path, "w") as file:
file.writelines(lines)


def check_keyword_in_output(command, keyword):
# Run the command and redirect the output to a file
os.system(f"{command} > output.txt")

# Read the contents of the file
with open("output.txt", "r") as file:
output = file.read()

# Check if the keyword is present in the output
if keyword in output:
# Optionally, you can delete the output file
os.remove("output.txt")
return True
else:
# Optionally, you can delete the output file
os.remove("output.txt")
return False


tile_size = 300
step = 10

for _ in range(20):
print("********************")
print("tile size: ", tile_size)
print("step: ", step)

yaml_file = "sam/sim/src/tiling/memory_config_onyx.yaml"
mem_tile_line = f"Mem_tile_size: {tile_size}"
print(mem_tile_line)
write_to_line(yaml_file, 19, mem_tile_line)

run_setup_script = "python3 setup_tiling_mat.py > temp.txt"
os.system(run_setup_script)
print(run_setup_script)

run_tile_pairing = "python3 tile_pairing.py > temp.txt"
os.system(run_tile_pairing)
print(run_tile_pairing)

run_count = "python3 count_nnz_tiling.py"
print(run_count)

if (check_keyword_in_output(run_count, "error")) is False:
tile_size += step
step *= 2
else:
print("****************Tile broken!")
tile_size -= step
step //= 2

if tile_size == 450:
break

if step == 0:
if _ >= 15:
step = 10
else:
break

print("max tile size: ", tile_size)
Loading

0 comments on commit 0b78457

Please sign in to comment.