1616#include < executorch/runtime/core/evalue.h>
1717#include < executorch/runtime/executor/pte_data_map.h>
1818
19+ #include < cinttypes>
1920#include < memory>
2021#include < mutex>
2122
@@ -129,6 +130,17 @@ class XnnpackBackend final
129130 Error, " XNNCompiler::compileModel failed: 0x%x" , (unsigned int )err);
130131 return err;
131132 }
133+
134+ ET_LOG (
135+ Info,
136+ " XnnpackBackend::init delegate=%p workspace_id=%" PRIu64
137+ " workspace_ptr=%p program_id=0x%" PRIxPTR " weight_cache=%s" ,
138+ (void *)executor,
139+ workspace->id (),
140+ (void *)workspace_ptr,
141+ program_id,
142+ use_weight_cache ? " true" : " false" );
143+
132144 return executor;
133145 }
134146
@@ -138,13 +150,23 @@ class XnnpackBackend final
138150 Span<EValue*> args) const override {
139151 auto executor = static_cast <xnnpack::delegate::XNNExecutor*>(handle);
140152
153+ auto workspace = executor->get_workspace ();
154+ ET_LOG (
155+ Info,
156+ " XnnpackBackend::execute begin delegate=%p workspace_id=%" PRIu64
157+ " num_args=%zu weight_cache=%s" ,
158+ (void *)executor,
159+ workspace->id (),
160+ (size_t )args.size (),
161+ executor->uses_weight_cache () ? " true" : " false" );
162+
141163 std::unique_lock<std::mutex> lock_weights_cache (
142164 weights_cache_mutex_, std::defer_lock);
143165 if (executor->uses_weight_cache ()) {
144166 lock_weights_cache.lock ();
145167 }
146168
147- auto [raii_lock, _] = executor-> get_workspace () ->acquire ();
169+ auto [raii_lock, _] = workspace ->acquire ();
148170
149171 // Prepare Inputs/Outputs and Propagate Input Shapes
150172 Error err = executor->prepare_args (args);
@@ -161,20 +183,36 @@ class XnnpackBackend final
161183 // Convert output data types if necessary (e.g., int32 -> int64 for Long)
162184 err = executor->convert_outputs (args);
163185
186+ ET_LOG (
187+ Info,
188+ " XnnpackBackend::execute end delegate=%p workspace_id=%" PRIu64
189+ " err=0x%x" ,
190+ (void *)executor,
191+ workspace->id (),
192+ (unsigned int )err);
193+
164194 return err;
165195 }
166196
167197 void destroy (DelegateHandle* handle) const override {
168198 if (handle != nullptr ) {
169199 auto executor = static_cast <xnnpack::delegate::XNNExecutor*>(handle);
200+ auto workspace = executor->get_workspace ();
201+
202+ ET_LOG (
203+ Info,
204+ " XnnpackBackend::destroy delegate=%p workspace_id=%" PRIu64,
205+ (void *)executor,
206+ workspace->id ());
207+
208+ const std::lock_guard<std::mutex> lock_weights_cache (
209+ weights_cache_mutex_);
170210
171211#ifdef ENABLE_XNNPACK_PROFILING
172212 executor->print_avg_op_timings ();
173213#endif
174214
175215 if (executor->uses_weight_cache ()) {
176- const std::lock_guard<std::mutex> lock_weights_cache (
177- weights_cache_mutex_);
178216 weights_cache_->delete_packed_data (executor->get_packed_data_names ());
179217 }
180218
@@ -183,7 +221,6 @@ class XnnpackBackend final
183221 // the same backend instance. Make sure to hold onto the workspace
184222 // shared_ptr, as the pointer in the executor is freed, which includes
185223 // the mutex referenced by raii_lock.
186- auto workspace = executor->get_workspace ();
187224 auto [raii_lock, _] = workspace->acquire ();
188225
189226 // XNNExecutor is not trivially destructible. Since this was constructed
0 commit comments