2222)
2323from triton .backends .qcom_hexagon_backend .hexagon_profiler import HexagonProfiler
2424
25+
26+ def _sdk_tool_version (q6_version : str ) -> str :
27+ """Return the SDK prebuilt tool version for the given Hexagon arch version.
28+
29+ v79+ devices require toolv88; older devices use toolv87.
30+ """
31+ return "v88" if int (q6_version .lstrip ("v" )) >= 79 else "v87"
32+
33+
34+ def _qhmath_sdk_path (q6_version : str ) -> tuple :
35+ """Tool/arch version for qhmath_hvx prebuilt libs.
36+
37+ v79 qhmath_hvx in SDK <= 6.4.0.0 is missing fp16 _ahf symbols;
38+ fall back to v75 toolv87 libs until HSDK 6.6.0.
39+ """
40+ if int (q6_version .lstrip ("v" )) >= 79 :
41+ return ("v87" , "75" )
42+ return (_sdk_tool_version (q6_version ), q6_version )
43+
44+
2545# This file is part of a small subset of python files that uses some type-annotations
2646# and it passes type-verification with mypy (a type checker).
2747# To typecheck this set of files, do:
3151class HexagonExecutor :
3252 def __init__ (
3353 self ,
34- kernel_run_id ,
54+ kernel_run_id : str ,
3555 enable_lwp = False ,
3656 enable_etm = False ,
3757 compile_only = False ,
@@ -50,6 +70,11 @@ def __init__(
5070 environment variables, tools paths, and Q6 version, set by
5171 calling the `get_config` method.
5272 """
73+ if not compile_only :
74+ if (not isinstance (kernel_run_id , str )) or (len (kernel_run_id ) == 0 ):
75+ raise ValueError (
76+ "kernel_run_id must be well-formed, non-empty string for execution via standalone launcher"
77+ )
5378 self .exec_mode = get_exec_mode () if not compile_only else "compile_only"
5479 self .device_path = f"/data/local/tmp/{ kernel_run_id } "
5580 self .lib_path = f"{ self .device_path } /lib"
@@ -229,9 +254,11 @@ def generate_shared_object(
229254 HEXAGON_SDK_ROOT = self .config .env_vars ["HEXAGON_SDK_ROOT" ],
230255 Q6_VERSION = self .config .Q6_VERSION ,
231256 )
232- QHL_LINK_DIR = """{HEXAGON_SDK_ROOT}/libs/qhl_hvx/prebuilt/hexagon_toolv87_v{Q6_VERSION}""" .format (
257+ qhmath_tool_ver , qhmath_arch_ver = _qhmath_sdk_path (self .config .Q6_VERSION )
258+ QHL_LINK_DIR = "{HEXAGON_SDK_ROOT}/libs/qhl_hvx/prebuilt/hexagon_tool{TOOL_VERSION}_v{Q6_VERSION}" .format (
233259 HEXAGON_SDK_ROOT = self .config .env_vars ["HEXAGON_SDK_ROOT" ],
234- Q6_VERSION = self .config .Q6_VERSION ,
260+ TOOL_VERSION = qhmath_tool_ver ,
261+ Q6_VERSION = qhmath_arch_ver ,
235262 )
236263
237264 if not (
@@ -248,9 +275,10 @@ def generate_shared_object(
248275 QHL_LINK_DIR ,
249276 )
250277
251- QHMATH_DIR = """ {HEXAGON_SDK_ROOT}/libs/qhl/prebuilt/hexagon_toolv87_v{ Q6_VERSION}"" " .format (
278+ QHMATH_DIR = "{HEXAGON_SDK_ROOT}/libs/qhl/prebuilt/hexagon_tool{TOOL_VERSION}_v{ Q6_VERSION}" .format (
252279 HEXAGON_SDK_ROOT = self .config .env_vars ["HEXAGON_SDK_ROOT" ],
253- Q6_VERSION = self .config .Q6_VERSION ,
280+ TOOL_VERSION = qhmath_tool_ver ,
281+ Q6_VERSION = qhmath_arch_ver ,
254282 )
255283 if os .path .exists (QHMATH_DIR ) and os .path .exists (
256284 os .path .join (QHMATH_DIR , "libqhmath.a" )
@@ -366,11 +394,10 @@ def run_kernel_on_device(
366394 )
367395 librun_main_on_hexagon_skel_path = os .path .join (
368396 self .config .env_vars ["HEXAGON_SDK_ROOT" ],
369- "libs/run_main_on_hexagon/ship/hexagon_toolv87_v {}/librun_main_on_hexagon_skel.so" .format (
370- self .config .Q6_VERSION
397+ "libs/run_main_on_hexagon/ship/hexagon_tool{}_v {}/librun_main_on_hexagon_skel.so" .format (
398+ _sdk_tool_version ( self . config . Q6_VERSION ), self .config .Q6_VERSION
371399 ),
372400 )
373-
374401 libcpp_path = os .path .join (
375402 self .config .env_vars ["HEXAGON_TOOLS" ],
376403 "target/hexagon/lib/v{}/G0/pic/libc++.so.1" .format (self .config .Q6_VERSION ),
@@ -602,13 +629,11 @@ def run_kernel_on_device(
602629
603630 try :
604631 if self .enable_etm :
605- if "mlir_ciface" in principal_lib_without_ext :
606- kernel_name = "" # torch-mlir flow -> not just one kernel
607- else :
608- kernel_name = principal_lib_without_ext [3 :] # remove lib prefix
609-
610632 hex_prof = HexagonProfiler (
611- etm_local_dir , profiling_mode = "etm" , kernel_name = kernel_name
633+ etm_local_dir ,
634+ profiling_mode = "etm" ,
635+ device_lib_path = path_to_principal_lib_on_device ,
636+ local_lib_filename = f"{ principal_lib_without_ext } .so" ,
612637 )
613638 for command , should_run in commands :
614639 if not should_run :
@@ -724,16 +749,18 @@ def run_kernel_on_simulator(self, paths_to_shared_libs_local: list[str]):
724749 self .config .env_vars ["HEXAGON_TOOLS" ], SIM_Q6SS_PATH
725750 )
726751 ),
727- ("{} -mv{} \
752+ (
753+ "{} -mv{} \
728754 --usefs={}/../Tools/target/hexagon/lib/v{}/G0/pic \
729755 --simulated_returnval \
730756 --cosim_file {} \
731757 --l2tcm_base 0xd800 \
732758 --rtos {} \
733759 {}/rtos/qurt/computev{}/sdksim_bin/runelf.pbn -- \
734- {}/libs/run_main_on_hexagon/ship/hexagon_toolv87_v {}/run_main_on_hexagon_sim \
760+ {}/libs/run_main_on_hexagon/ship/hexagon_tool{}_v {}/run_main_on_hexagon_sim \
735761 stack_size=0x400000 -- \
736- {}" ).format (
762+ {}"
763+ ).format (
737764 self .config .HEX_TOOLS ["hexagon-sim" ],
738765 self .config .Q6_VERSION ,
739766 self .config .env_vars ["HEXAGON_TOOLS" ],
@@ -743,6 +770,7 @@ def run_kernel_on_simulator(self, paths_to_shared_libs_local: list[str]):
743770 self .config .env_vars ["HEXAGON_SDK_ROOT" ],
744771 self .config .Q6_VERSION ,
745772 self .config .env_vars ["HEXAGON_SDK_ROOT" ],
773+ _sdk_tool_version (self .config .Q6_VERSION ),
746774 self .config .Q6_VERSION ,
747775 path_to_principal_lib_local ,
748776 ),
0 commit comments