Skip to content

Commit 38760e5

Browse files
tsingmicro-public-e王宗祥
andauthored
[BACKEND] Update tsingmicro code to 3.3.x (#361)
Co-authored-by: 王宗祥 <[email protected]>
1 parent e4eb677 commit 38760e5

111 files changed

Lines changed: 3988 additions & 828 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

third_party/tsingmicro/CMakeLists.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ if(NOT DEFINED TX8_DEPS_ROOT)
55
message(FATAL_ERROR "TX8_DEPS_ROOT environment variable is not defined")
66
endif()
77
endif()
8+
89
# Enable ccache if available
910
find_program(CCACHE_PROGRAM ccache)
1011
if(CCACHE_PROGRAM)
@@ -18,9 +19,9 @@ if(NOT DEFINED USE_HOST_PROFILE)
1819
endif()
1920
endif()
2021

21-
if(NOT DEFINED USE_PROFILE)
22-
if(DEFINED ENV{USE_PROFILE})
23-
set(USE_PROFILE $ENV{USE_PROFILE})
22+
if(NOT DEFINED ENABLE_PROFILING)
23+
if(DEFINED ENV{ENABLE_PROFILING})
24+
set(ENABLE_PROFILING $ENV{ENABLE_PROFILING})
2425
endif()
2526
endif()
2627

@@ -30,10 +31,13 @@ if(NOT DEFINED NO_INTRNISIC_RUN)
3031
endif()
3132
endif()
3233

34+
if(NOT DEFINED ENABLE_SYNCHRONOUS_INTRINSIC)
35+
if(DEFINED ENV{ENABLE_SYNCHRONOUS_INTRINSIC})
36+
set(ENABLE_SYNCHRONOUS_INTRINSIC $ENV{ENABLE_SYNCHRONOUS_INTRINSIC})
37+
endif()
38+
endif()
39+
3340
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
34-
execute_process(COMMAND llvm-config --libs OUTPUT_VARIABLE LIBS)
35-
execute_process(COMMAND llvm-config --system-libs OUTPUT_VARIABLE SYS_LIBS)
36-
execute_process(COMMAND llvm-config --ldflags OUTPUT_VARIABLE LDF)
3741

3842
set(XUANTIE_NAME Xuantie-900-gcc-elf-newlib-x86_64-V2.10.2)
3943
set(INSTALL_TSINGMICRO_DIR ${CMAKE_INSTALL_PREFIX}/triton/backends/tsingmicro/)

third_party/tsingmicro/backend/compiler.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import functools
1414
from pathlib import Path
1515
from triton.backends.tsingmicro import txda_tools
16+
from triton.backends.tsingmicro.logger_config import setup_logger
17+
18+
logger = setup_logger("tsingmicro_launch")
1619

1720
ir_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

Comments
 (0)