@@ -48,7 +48,7 @@ static int opt_arch = 0; // autodetect
4848static int opt_etm = 0 ;
4949static int opt_verbose = 0 ;
5050static int opt_profile = 0 ;
51- static int opt_trace = 1 ;
51+ static int opt_trace = 0 ;
5252static itrace_logger_handle_t g_itrace_logger_handle = NULL ;
5353static itrace_profiler_handle_t g_itrace_cpu_profiler_handle = NULL ;
5454static int opt_hostbuf = 1 ;
@@ -2901,6 +2901,13 @@ static const char * ggml_backend_hexagon_name(ggml_backend_t backend) {
29012901}
29022902
29032903static void ggml_backend_hexagon_free (ggml_backend_t backend) {
2904+ // Flush and close itrace logger if profiling was enabled
2905+ if (opt_trace) {
2906+ itrace_flush_logs (g_itrace_logger_handle);
2907+ itrace_close_logger (g_itrace_logger_handle);
2908+ HEX_VERBOSE (" ggml-hex: close itrace\n " );
2909+ }
2910+
29042911 // we just need to delete the backend here
29052912 // the sessions are allocated & freed as part of the registry
29062913 delete backend;
@@ -3448,12 +3455,6 @@ ggml_hexagon_registry::~ggml_hexagon_registry() {
34483455 auto sess = static_cast <ggml_hexagon_session *>(devices[i].context );
34493456 delete sess;
34503457 }
3451-
3452- // Flush and close itrace logger if profiling was enabled
3453- if (opt_trace) {
3454- itrace_flush_logs (g_itrace_logger_handle);
3455- itrace_close_logger (g_itrace_logger_handle);
3456- }
34573458}
34583459
34593460static const char * ggml_backend_hexagon_reg_get_name (ggml_backend_reg_t reg) {
@@ -3501,11 +3502,16 @@ static void ggml_hexagon_init(ggml_backend_reg * reg) {
35013502 opt_profile = getenv (" GGML_HEXAGON_PROFILE" ) != nullptr ;
35023503 opt_etm = getenv (" GGML_HEXAGON_ETM" ) != nullptr ;
35033504 opt_experimental = getenv (" GGML_HEXAGON_EXPERIMENTAL" ) != nullptr ;
3505+ opt_trace = getenv (" GGML_HEXAGON_TRACE" ) != nullptr ;
35043506
35053507 // Initialize itrace if profiling is enabled
35063508 if (opt_trace) {
3509+ HEX_VERBOSE (" ggml-hex: open itrace\n " );
35073510 itrace_open_logger (CPU_DOMAIN_ID, &g_itrace_logger_handle);
35083511 itrace_open_profiler (g_itrace_logger_handle, CPU_DOMAIN_ID, 0 , &g_itrace_cpu_profiler_handle);
3512+
3513+ itrace_start_section (g_itrace_cpu_profiler_handle, " open-itrace" , NULL );
3514+ itrace_end_section (g_itrace_cpu_profiler_handle, NULL );
35093515 }
35103516
35113517 const char * str_opmask = getenv (" GGML_HEXAGON_OPMASK" );
0 commit comments