Skip to content

Commit

Permalink
merged tiling branch with mapping_to_cgra dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
kalhankoul96 committed Dec 19, 2023
2 parents b2d3c7d + c2a4d73 commit 768f5fa
Show file tree
Hide file tree
Showing 117 changed files with 3,690 additions and 1,498 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);

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
import sys
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
import sys
import glob

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")) == 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 768f5fa

Please sign in to comment.