-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from weiya711/mapping_to_cgra_suitesparse_fixes
Mapping to cgra suitesparse fixes
- Loading branch information
Showing
120 changed files
with
3,739 additions
and
1,501 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.