Skip to content

Commit eaf8e4e

Browse files
committed
[Refactor] Remove CONFIG_ prefix
1 parent 51d7028 commit eaf8e4e

21 files changed

Lines changed: 167 additions & 183 deletions

PyTorchSimFrontend/extension_codecache.py

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def hash_prefix(hash_value):
1515
return hash_value[1:12]
1616

1717
def get_write_path(src_code):
18-
return os.path.join(extension_config.CONFIG_TORCHSIM_DUMP_PATH, "tmp", hash_prefix(get_hash(src_code.strip())))
18+
return os.path.join(extension_config.TORCHSIM_DUMP_PATH, "tmp", hash_prefix(get_hash(src_code.strip())))
1919

2020
def dump_metadata(args, arg_attributes, path):
2121
meta_path = os.path.join(path, "meta.txt")
@@ -27,23 +27,10 @@ def dump_metadata(args, arg_attributes, path):
2727
file.write(f'{arg_name}=({arg_attribute[0]}, {arg.dtype}, {arg.shape})\n')
2828
return
2929

30-
def llvm_compile_command(input, output):
31-
opt_output = f"{input[:-3]}_opt.ll"
32-
return [re.sub(r"[ \n]+", " ",
33-
f"""
34-
{extension_config.CONFIG_TORCHSIM_LLVM_PATH}/opt --load-pass-plugin={extension_config.CONFIG_TORCHSIM_CUSTOM_PASS_PATH}/libLowerGemminiPass.so -S -march=riscv64 --passes=LowerGemminiPass {input} -o {opt_output}
35-
""",
36-
).strip(),
37-
re.sub(r"[ \n]+", " ",
38-
f"""
39-
{extension_config.CONFIG_TORCHSIM_LLVM_PATH}/llc -march=riscv64 -mattr=+m,+f,+d,+a,+c,+v -O2 {opt_output} -o {output}
40-
""",
41-
).strip()]
42-
4330
def mlir_compile_command(filename, vectorlane_size, vlen=256):
4431
return [re.sub(r"[ \n]+", " ",
4532
f"""
46-
{extension_config.CONFIG_TORCHSIM_LLVM_PATH}/mlir-opt \
33+
{extension_config.TORCHSIM_LLVM_PATH}/mlir-opt \
4734
-test-loop-padding \
4835
-dma-fine-grained='systolic-array-size={vectorlane_size}' \
4936
-global-idx='vlen={vlen}' \
@@ -62,34 +49,34 @@ def mlir_compile_command(filename, vectorlane_size, vlen=256):
6249
-convert-func-to-llvm \
6350
-convert-index-to-llvm \
6451
-reconcile-unrealized-casts \
65-
{'--mlir-print-ir-after-all' if extension_config.CONFIG_TORCHSIM_DUMP_MLIR_IR else ''} \
52+
{'--mlir-print-ir-after-all' if extension_config.TORCHSIM_DUMP_MLIR_IR else ''} \
6653
{filename}.mlir -o {filename}_llvm.mlir
6754
""",
6855
).strip(),
6956
re.sub(r"[ \n]+", " ",
7057
f"""
71-
{extension_config.CONFIG_TORCHSIM_LLVM_PATH}/mlir-translate -mlir-to-llvmir {filename}_llvm.mlir -o {filename}.ll
58+
{extension_config.TORCHSIM_LLVM_PATH}/mlir-translate -mlir-to-llvmir {filename}_llvm.mlir -o {filename}.ll
7259
""",
7360
).strip(),
7461
re.sub(r"[ \n]+", " ",
7562
f"""
76-
{extension_config.CONFIG_TORCHSIM_LLVM_PATH}/llc \
63+
{extension_config.TORCHSIM_LLVM_PATH}/llc \
7764
-relocation-model=pic -march=riscv64 -O3 --stack-size-section \
7865
-mattr=+m,+f,+d,+a,+c,+v,+xsfvcp,zvl{vlen}b \
79-
{'--print-after-all' if extension_config.CONFIG_TORCHSIM_DUMP_LLVM_IR else ''} \
66+
{'--print-after-all' if extension_config.TORCHSIM_DUMP_LLVM_IR else ''} \
8067
-O2 {filename}.ll -o {filename}.s
8168
""",
8269
).strip()]
8370

8471
def mlir_gem5_compile_command(filename, sample_filename, tog_file, vectorlane_size, vlen=256):
8572
return [re.sub(r"[ \n]+", " ",
8673
f"""
87-
{extension_config.CONFIG_TORCHSIM_LLVM_PATH}/mlir-opt \
74+
{extension_config.TORCHSIM_LLVM_PATH}/mlir-opt \
8875
-test-loop-padding='timing_mode=1' \
8976
-dma-fine-grained='systolic-array-size={vectorlane_size}' \
9077
-global-idx='vlen={vlen}' \
9178
-test-pytorchsim-to-vcix='systolic-array-size={vectorlane_size} vlen={vlen}' \
92-
-test-tile-operation-graph='vectorlane={vectorlane_size} tls_mode={extension_config.CONFIG_TLS_MODE}' \
79+
-test-tile-operation-graph='vectorlane={vectorlane_size} tls_mode={extension_config.TLS_MODE}' \
9380
-test-memref-to-gemmini="vectorlane={vectorlane_size} timing=1" \
9481
-convert-linalg-to-loops \
9582
-convert-vector-to-scf='full-unroll' \
@@ -104,21 +91,21 @@ def mlir_gem5_compile_command(filename, sample_filename, tog_file, vectorlane_si
10491
-convert-func-to-llvm \
10592
-convert-index-to-llvm \
10693
-reconcile-unrealized-casts \
107-
{'--mlir-print-ir-after-all' if extension_config.CONFIG_TORCHSIM_DUMP_MLIR_IR else ''} \
94+
{'--mlir-print-ir-after-all' if extension_config.TORCHSIM_DUMP_MLIR_IR else ''} \
10895
{filename}.mlir -o {sample_filename}_llvm.mlir
10996
""",
11097
).strip(),
11198
re.sub(r"[ \n]+", " ",
11299
f"""
113-
{extension_config.CONFIG_TORCHSIM_LLVM_PATH}/mlir-translate -mlir-to-llvmir {sample_filename}_llvm.mlir -o {sample_filename}.ll
100+
{extension_config.TORCHSIM_LLVM_PATH}/mlir-translate -mlir-to-llvmir {sample_filename}_llvm.mlir -o {sample_filename}.ll
114101
""",
115102
).strip(),
116103
re.sub(r"[ \n]+", " ",
117104
f"""
118-
{extension_config.CONFIG_TORCHSIM_LLVM_PATH}/llc \
105+
{extension_config.TORCHSIM_LLVM_PATH}/llc \
119106
-relocation-model=pic -march=riscv64 -O3 --stack-size-section \
120107
-mattr=+m,+f,+d,+a,+c,+v,+xsfvcp,zvl{vlen}b \
121-
{'--print-after-all' if extension_config.CONFIG_TORCHSIM_DUMP_LLVM_IR else ''} \
108+
{'--print-after-all' if extension_config.TORCHSIM_DUMP_LLVM_IR else ''} \
122109
-O2 {sample_filename}.ll -o {sample_filename}.s
123110
""",
124111
).strip()]
@@ -165,7 +152,7 @@ def load(cls, source_code,
165152
else:
166153
link_option = ""
167154
# Generate LLVM kernel calller and binary for validation
168-
if extension_config.CONFIG_TORCHSIM_FUNCTIONAL_MODE:
155+
if extension_config.TORCHSIM_FUNCTIONAL_MODE:
169156
# Use custom malloc to avoid size error
170157
new_link_option = link_option + " -Wl,--wrap=malloc -Wl,--wrap=free"
171158
cmds = mlir_compile_command(new_input_path, vectorlane_size, vlen=vlen)
@@ -182,17 +169,17 @@ def load(cls, source_code,
182169
print("Error output:", e.output)
183170
assert(0)
184171

185-
val_llvm_caller = MLIRKernelCallerCodeGen(extension_config.CONFIG_TORCHSIM_FUNCTIONAL_MODE, arg_attributes)
172+
val_llvm_caller = MLIRKernelCallerCodeGen(extension_config.TORCHSIM_FUNCTIONAL_MODE, arg_attributes)
186173
val_llvm_caller.generate_wrapper_file(write_path, validation_wrapper_name)
187174
val_llvm_caller.compile_wih_kernel(write_path, key, validation_wrapper_name,
188175
validation_binary_name, new_link_option)
189176
target = os.path.join(write_path, validation_binary_name)
190177
stack_size = val_llvm_caller.parse_stack_sizes(f"{write_path}/{key}.s", vlenb=vlenb)
191178
spad_size = val_llvm_caller.get_spad_size(target)
192179
spad_usage = stack_size + spad_size # Spad usage per lane
193-
if extension_config.CONFIG_SPAD_INFO["spad_size"] < spad_usage:
180+
if extension_config.SPAD_INFO["spad_size"] < spad_usage:
194181
print(f"[Warning] Scratchpad size exceeded: required {spad_usage} bytes, "
195-
f"but only {extension_config.CONFIG_SPAD_INFO['spad_size']} bytes available.")
182+
f"but only {extension_config.SPAD_INFO['spad_size']} bytes available.")
196183
raise SpadOverflowError()
197184

198185
# Launch tile graph generator
@@ -213,7 +200,7 @@ def load(cls, source_code,
213200
print("Error output:", e.output)
214201
assert(0)
215202

216-
if not extension_config.CONFIG_TORCHSIM_TIMING_MODE:
203+
if not extension_config.TORCHSIM_TIMING_MODE:
217204
return key
218205

219206
# Generate MLIR kernel calller and binary for cycle calculation
@@ -280,23 +267,23 @@ def dummy_simulator(*args, **kwargs):
280267
lock = FileLock(os.path.join(lock_dir, key + ".lock"), timeout=LOCK_TIMEOUT)
281268
with lock:
282269
# Run simulator pass
283-
result_path = os.path.join(extension_config.CONFIG_TORCHSIM_DUMP_PATH, "tmp", hash_prefix(key))
270+
result_path = os.path.join(extension_config.TORCHSIM_DUMP_PATH, "tmp", hash_prefix(key))
284271
# Dump arguments and meta data
285272
dump_metadata(args, arg_attributes, result_path)
286273
runtime_path = FunctionalSimulator.get_runtime_dump_path(result_path)
287-
if not autotune and (extension_config.CONFIG_TORCHSIM_FUNCTIONAL_MODE or validate):
274+
if not autotune and (extension_config.TORCHSIM_FUNCTIONAL_MODE or validate):
288275
funcsim = FunctionalSimulator(result_path, key)
289276
funcsim.run_spike(args, arg_attributes,
290277
runtime_path, self.validation_binary_name,
291278
vectorlane_size=vectorlane_size, spad_info=spad_info,
292-
cleanup=extension_config.CONFIG_CLEANUP_DUMP_ARGS, silent_mode=silent_mode)
293-
if not extension_config.CONFIG_TORCHSIM_TIMING_MODE:
279+
cleanup=extension_config.CLEANUP_DUMP_ARGS, silent_mode=silent_mode)
280+
if not extension_config.TORCHSIM_TIMING_MODE:
294281
return
295282

296283
onnx_path = os.path.join(result_path, "tile_graph.onnx")
297284
attribute_path = os.path.join(runtime_path, "attribute")
298-
togsim_path = os.path.join(extension_config.CONFIG_TORCHSIM_DIR, "TOGSim")
299-
TOGSim = TOGSimulator(togsim_path, extension_config.CONFIG_TOGSIM_CONFIG)
285+
togsim_path = os.path.join(extension_config.TORCHSIM_DIR, "TOGSim")
286+
TOGSim = TOGSimulator(togsim_path, extension_config.TOGSIM_CONFIG)
300287
TOGSim.vectorlane_size = vectorlane_size
301288
attribute_path = TOGSim.create_attribute_file(attribute_path, args, loop_size=loop_size)
302289
result_path = TOGSim.simulation(onnx_path, attribute_path, silent_mode=silent_mode)
@@ -310,20 +297,20 @@ def dryrun_simulator(*args, **kwargs):
310297
lock = FileLock(os.path.join(lock_dir, key + ".lock"), timeout=LOCK_TIMEOUT)
311298
with lock:
312299
# Run simulator pass
313-
result_path = os.path.join(extension_config.CONFIG_TORCHSIM_DUMP_PATH, "tmp", hash_prefix(key))
300+
result_path = os.path.join(extension_config.TORCHSIM_DUMP_PATH, "tmp", hash_prefix(key))
314301
# Dump arguments and meta data
315302
dump_metadata(args, arg_attributes, result_path)
316303
runtime_path = FunctionalSimulator.get_runtime_dump_path(result_path)
317-
if not extension_config.CONFIG_TORCHSIM_TIMING_MODE:
304+
if not extension_config.TORCHSIM_TIMING_MODE:
318305
return
319306

320307
# Todo. Support valude dependent mode for graph mode
321-
if False: # extension_config.CONFIG_TORCHSIM_FUNCTIONAL_MODE:
308+
if False: # extension_config.TORCHSIM_FUNCTIONAL_MODE:
322309
funcsim = FunctionalSimulator(result_path, key)
323310
funcsim.run_spike(args, arg_attributes,
324311
runtime_path, self.validation_binary_name,
325312
vectorlane_size=vectorlane_size, spad_info=spad_info,
326-
cleanup=extension_config.CONFIG_CLEANUP_DUMP_ARGS)
313+
cleanup=extension_config.CLEANUP_DUMP_ARGS)
327314
return result_path, runtime_path, None
328315

329316
is_dryrun = int(os.environ.get('TOGSIM_DRYRUN', default=False)) and not autotune

0 commit comments

Comments
 (0)