1313import functools
1414from pathlib import Path
1515from triton .backends .tsingmicro import txda_tools
16+ from triton .backends .tsingmicro .logger_config import setup_logger
17+
18+ logger = setup_logger ("tsingmicro_launch" )
1619
1720ir_index = - 1
1821
@@ -80,21 +83,20 @@ def compile_accelerator(src, metadata, o_path):
8083 dst_path
8184 ]
8285
83- if txda_tools .is_use_profile ():
84- gcc_args .append ("-lprofiler_riscv" )
86+ # if txda_tools.is_use_profile():
87+ # gcc_args.append("-lprofiler_riscv")
8588
8689 txda_tools .runLoweringCmd (dst_path , gcc_args )
8790
8891 with open (dst_path , 'rb' ) as f :
8992 cache_path = cache .put (f .read (), f"{ name } .so" , binary = True )
9093 txda_tools .dump_file_if_needed (cache_path , f"kernel_{ ir_index } .so" )
91- else :
92- print ("cache_path: " , cache_path , flush = True )
9394
9495 with open (cache_path , 'rb' ) as fd_out :
9596 so = fd_out .read ()
9697 metadata ["kernel_path" ] = cache_path
97- txda_tools .record_key_v (last_ir , cache_path )
98+ metadata ["so_key" ] = os .path .basename (os .path .dirname (cache_path ))
99+ logger .debug (f"{ last_ir } :{ cache_path } " )
98100 return so
99101
100102
@@ -103,7 +105,7 @@ def _ttir_to_coreir(mod):
103105 ir_index = ir_index + 1
104106 # Get Triton-MLIR as string
105107 ttir_code = str (mod )
106- txda_tools . record_log (f"get ttir:{ txda_tools .calculate_str_md5 (ttir_code .encode ())} \n " )
108+ logger . debug (f"get ttir:{ txda_tools .calculate_str_md5 (ttir_code .encode ())} " )
107109 with tempfile .TemporaryDirectory () as tmpdir :
108110 src_path = os .path .join (tmpdir , f"tt_{ ir_index } .mlir" )
109111 dst_path = os .path .join (tmpdir , f"core_{ ir_index } .mlir" )
@@ -247,19 +249,19 @@ def _txir_to_llir(mod, metadata):
247249 dest_name = ir_file
248250 break
249251 else :
250- print (f"error name { ir_file } : use customized ir like this : test_0.mlir, test_1.mlir" )
252+ logger . error (f"error name { ir_file } : use customized ir like this : test_0.mlir, test_1.mlir" )
251253 if dest_name :
252- print (f"get CUSTOMIZED_IR path:{ dest_name } " )
254+ logger . info (f"get CUSTOMIZED_IR path:{ dest_name } " )
253255 dump_path = os .getenv ("TRITON_DUMP_PATH" , "" )
254256
255257 if not dump_path :
256- print ("TRITON_DUMP_PATH not find!" )
258+ logger . error ("TRITON_DUMP_PATH not find!" )
257259 return
258260
259261 cust_ir = os .path .join (dump_path , dest_name )
260262 if os .path .exists (cust_ir ):
261263 llvmir_path = cust_ir
262- print (f"!!!!!!!!!!!!!!!!!!using customized ir:{ llvmir_path } " )
264+ logger . info (f"!!!!!!!!!!!!!!!!!!using customized ir:{ llvmir_path } " )
263265
264266 # Get spm memory use metadata
265267 from mlir .ir import Context , Module
@@ -276,22 +278,24 @@ def _txir_to_llir(mod, metadata):
276278 txda_tools .dump_ir_if_needed ([llir_path ])
277279 dest_ir = llir_path
278280
279- if txda_tools .is_use_profile ():
280- profile_ir_path = os .path .join (tmpdir , f"profile_ll_{ ir_index } .ir" )
281- trace_points = os .getenv ("TRACE_POINTS" , "" )
282- profiler_path = txda_tools .get_tx8_profiler_path ()
283- compile_args = [
284- profiler_path , llir_path , f"--trace-points={ trace_points } " , "-index" , f"{ ir_index } " , "-o" ,
285- profile_ir_path
286- ]
287- txda_tools .dump_cmd_if_needed (compile_args , "trace-points" )
288- txda_tools .runLoweringCmd (profile_ir_path , compile_args )
289- txda_tools .dump_ir_if_needed ([profile_ir_path ])
290- dest_ir = profile_ir_path
281+ # if txda_tools.is_use_profile():
282+ # profile_ir_path = os.path.join(tmpdir, f"profile_ll_{ir_index}.ir")
283+ # trace_points = os.getenv("TRACE_POINTS", "")
284+ # profiler_path = txda_tools.get_tx8_profiler_path()
285+ # compile_args = [
286+ # profiler_path, llir_path,
287+ # f"--trace-points={trace_points}",
288+ # "-index", f"{ir_index}",
289+ # "-o", profile_ir_path
290+ # ]
291+ # txda_tools.dump_cmd_if_needed(compile_args, "trace-points")
292+ # txda_tools.runLoweringCmd(profile_ir_path, compile_args)
293+ # txda_tools.dump_ir_if_needed([profile_ir_path])
294+ # dest_ir = profile_ir_path
291295
292296 global last_ir
293297 last_ir = os .path .basename (dest_ir )
294- txda_tools . record_log (f"last ir:{ dest_ir } , { txda_tools .calculate_file_md5 (dest_ir )} \n " )
298+ logger . debug (f"last ir:{ dest_ir } , { txda_tools .calculate_file_md5 (dest_ir )} " )
295299 return Path (dest_ir ).read_text ()
296300
297301
@@ -365,8 +369,8 @@ def _llir_to_bin(llir: str, metadata):
365369 if not sim_mode :
366370 compile_args .extend (["--target=riscv64-unknown-elf" , "-march=rv64imfdc" ])
367371
368- if txda_tools .is_use_profile ():
369- compile_args .append ("-DUSE_PROFILE " )
372+ # if txda_tools.is_use_profile():
373+ # compile_args.append("-DENABLE_PROFILING ")
370374
371375 txda_tools .runLoweringCmd (dst_path , compile_args )
372376
0 commit comments