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 suitesparse fixes #107

Merged
merged 96 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
b958b36
changes for FIXMEs and added a memory mdoel flag
Feb 2, 2023
505bc56
corrected block start for rd scan
Feb 3, 2023
d70968f
code style correction
Feb 3, 2023
44faefa
Add gantt chart generation code
gina7484 Feb 3, 2023
29112a0
Follow Flake8 formatting
gina7484 Feb 3, 2023
7daabe2
update gen_gantt for string cycle numbers
gina7484 Feb 6, 2023
155e62c
reorder-ijk
gina7484 Feb 8, 2023
06b9b0c
gantt chart bars in a consistent order
gina7484 Feb 10, 2023
f7036d7
Add in fixes for suitesparse_runner script
weiya711 Feb 10, 2023
d485cda
Fixes to suitesparse_runner
weiya711 Feb 10, 2023
f8b0fa5
Add in fix to bench_csv_aggregator
weiya711 Feb 10, 2023
704d00c
Add in info about scripts
weiya711 Feb 10, 2023
f6b558e
Fix a README mistake
weiya711 Feb 10, 2023
394581b
Get md table working
weiya711 Feb 10, 2023
afabcc4
Update README.md
weiya711 Feb 11, 2023
9c3109b
Add in scripts for onyx tiling
weiya711 Feb 17, 2023
5968062
Add in file, oops
weiya711 Feb 17, 2023
b66156e
code to generate cycle info csv file & stats txt file
gina7484 Feb 21, 2023
20d69ec
Add gant-chart generation for matmul
gina7484 Mar 7, 2023
0e2b789
fix error in ijk (loading problem)
gina7484 Mar 7, 2023
b90607e
comment out code to record total cycles
gina7484 Apr 6, 2023
b4bf167
Change the default case into no backpressure
gina7484 Apr 7, 2023
9bd41a0
change the name formatting for other files too
gina7484 Apr 7, 2023
b4dba5d
Add in fixes to tile script and add in a suitesparse runner
weiya711 Apr 7, 2023
cc9667f
Add in elemmul to cpu runs
weiya711 May 26, 2023
0af7d33
Add in all the files with the folders. WIP still need to clean up eac…
weiya711 Jun 29, 2023
8fb9066
Fix codestyle for script refactor
weiya711 Jun 29, 2023
d22c73f
Fix makefile with updated script locations
weiya711 Jun 29, 2023
6aa0122
Add in README for scripts/ dir
weiya711 Jun 29, 2023
6448e0a
Update READMe for run_cpu directory
weiya711 Jun 30, 2023
257a74a
Finish adding scripts/ hierarchy. Tried to add in all READMEs, commen…
weiya711 Jul 17, 2023
9dae114
Fix pycodestyle
weiya711 Jul 17, 2023
9556295
tiling for apps
Jul 19, 2023
3074ade
mat_mattransmul prob
Jul 19, 2023
5df6eac
setup script added
Jul 19, 2023
ceb4ff1
Add in tiling script to tile tensors for mattransmul. Frostt tensors …
weiya711 Jul 27, 2023
9e1b84d
Add pydata/sparse to requirements for CI
weiya711 Jul 27, 2023
7a06b1f
Update gitignore
weiya711 Jul 27, 2023
1678d58
Add in updated gitignore
weiya711 Jul 27, 2023
1b45a01
Fix pycodestyle for CI
weiya711 Jul 27, 2023
875569d
spmv sparsity sweep stuff
Jul 27, 2023
fc5f466
merge conflict
Jul 27, 2023
37ebc3e
Merge branch 'avb03-tiling' of https://github.com/weiya711/sam into a…
Jul 27, 2023
68f0567
pushing all fixed merge conflicts
Jul 27, 2023
09fb1b0
Add in fixes to tile.py that broke during merge
weiya711 Jul 27, 2023
479a566
formatting scripts mod
Jul 29, 2023
8846e91
mtx vs tns file for vector tiling
Jul 29, 2023
5a0998f
correct tile.py
Jul 29, 2023
91ad37f
orig tile files
Jul 31, 2023
3947620
Add in fixes to get tensor apps working
weiya711 Jul 31, 2023
588a1c0
Update pydata sparse import
weiya711 Aug 4, 2023
9c8431a
Merge branch 'master_refactor_scripts' of github.com:weiya711/sam int…
weiya711 Aug 4, 2023
6aa9f6f
Add in pydata/sparse and update gitignore
weiya711 Aug 8, 2023
11502cb
Update util.py to pass codestyle
weiya711 Aug 8, 2023
870205d
Change suitesparse file formatting
weiya711 Aug 9, 2023
c3eb538
current matrix tiling flow
Aug 19, 2023
9c64433
updated matrix tiling flow
Aug 20, 2023
5be8b8f
minor matrix tiling updates
Aug 20, 2023
887b0a5
all matrix apps tiling flow
Aug 22, 2023
0f0b87e
loading in same vectors as CPU
Aug 24, 2023
2232c26
max tilesize matmul
Aug 26, 2023
60f4ad7
input arg setup
Sep 2, 2023
19080a3
latest update tiling
Sep 2, 2023
a80b449
helper scripts (need cleanup)
Sep 2, 2023
9f73f16
square matrices for vecmul iter
Sep 3, 2023
a192512
moved to right place
Sep 3, 2023
6c9dbd7
changes for new complex apps
Sep 3, 2023
2b1d0bf
Merge pull request #92 from weiya711/master_refactor_scripts
weiya711 Sep 30, 2023
5dbbfdc
Merge branch 'master' of github.com:weiya711/sam into gen_gantt_merged
weiya711 Sep 30, 2023
46ce268
Add in fixes to scripts
weiya711 Sep 30, 2023
d19e7da
Remove gantt reorder study to get CI passing
weiya711 Sep 30, 2023
cd75b3e
Add in fix to gen_gantt.py script to not fail matmul_kij
weiya711 Oct 5, 2023
a987149
Fix pycodestyle for gantt branch
weiya711 Oct 5, 2023
3fa90e0
Add in fixes for PR
weiya711 Oct 5, 2023
a1440cd
syn mat
Oct 9, 2023
809c467
Add in fixes to remove hard-coded paths
weiya711 Oct 10, 2023
fe3ad32
Continue fixes
weiya711 Oct 10, 2023
b5d9547
Add in fixes for gen_gantt script
weiya711 Oct 11, 2023
15833ac
Get matmul_ijk working
weiya711 Oct 11, 2023
08c2205
Merge pull request #94 from weiya711/gen_gantt_merged
kalhankoul96 Oct 11, 2023
eaf33a6
Oops remove print statements
weiya711 Oct 11, 2023
a7f8938
Merge branch 'master' of github.com:weiya711/sam into gen_gantt_merged
weiya711 Oct 11, 2023
80dae0c
Merge pull request #95 from weiya711/gen_gantt_merged
kalhankoul96 Oct 11, 2023
2c699f9
fixes for suitesparse apps
Dec 14, 2023
b2d3c7d
add crddrops to mat_vecmul
kalhankoul96 Dec 14, 2023
f308aed
merge in tiling branch
kalhankoul96 Dec 18, 2023
c2a4d73
tiling script cleanup
Dec 19, 2023
768f5fa
merged tiling branch with mapping_to_cgra dev branch
kalhankoul96 Dec 19, 2023
50cd072
added support for multiple tiles
kalhankoul96 Jan 8, 2024
0dc4a47
Merge branch 'mapping_to_cgra' into mapping_to_cgra_suitesparse_fixes
kalhankoul96 Jan 9, 2024
1558668
style fixing
kalhankoul96 Jan 9, 2024
2c067d1
more style cleanup
kalhankoul96 Jan 9, 2024
1134683
more style fixes
kalhankoul96 Jan 9, 2024
cd2dda3
more style fixes
kalhankoul96 Jan 9, 2024
7af1acc
more style fixes
kalhankoul96 Jan 9, 2024
4d03070
more style fixes
kalhankoul96 Jan 9, 2024
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
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