xref: /aosp_15_r20/external/executorch/backends/apple/coreml/runtime/sdk/model_event_logger_impl.h (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 //
2 // model_event_logger_impl.h
3 //
4 // Copyright © 2024 Apple Inc. All rights reserved.
5 //
6 // Please refer to the license found in the LICENSE file in the root directory of the source tree.
7 
8 #pragma once
9 
10 #import "model_event_logger.h"
11 #import <CoreML/CoreML.h>
12 
13 namespace executorch::runtime {
14 class EventTracer;
15 }
16 
17 namespace executorchcoreml {
18 /// A class implementing the `ModelEventLogger` protocol.
19 ///
20 /// It doesn't own the tracer object, the object must not be used if the tracer is gone.
21 class ModelEventLoggerImpl final : public ModelEventLogger {
22 public:
23     /// Construct a `ModelEventLoggerImpl` from the `EventTracer`.
ModelEventLoggerImpl(::executorch::runtime::EventTracer * tracer)24     explicit ModelEventLoggerImpl(::executorch::runtime::EventTracer* tracer) : tracer_(tracer) { }
25 
26     /// Logs profiling infos.
27     ///
28     /// @param op_path_to_profiling_info_map A dictionary with the operation path as the key and operation's profiling
29     /// info as the value.
30     /// @param op_path_to_debug_symbol_name_map A dictionary with the operation path as the key and the debug symbol
31     /// name as the value.
32     void log_profiling_infos(
33         NSDictionary<ETCoreMLModelStructurePath*, ETCoreMLOperationProfilingInfo*>* op_path_to_profiling_info_map,
34         NSDictionary<ETCoreMLModelStructurePath*, NSString*>* op_path_to_debug_symbol_name_map) const noexcept override;
35 
36     /// Logs intermediate tensor values.
37     ///
38     /// @param op_path_to_value_map A dictionary with the operation path as the key and the operation's value as the
39     /// value.
40     /// @param op_path_to_debug_symbol_name_map A dictionary with the operation path as the key and the debug symbol
41     /// name as the value.
42     void log_intermediate_tensors(
43         NSDictionary<ETCoreMLModelStructurePath*, MLMultiArray*>* op_path_to_value_map,
44         NSDictionary<ETCoreMLModelStructurePath*, NSString*>* op_path_to_debug_symbol_map) const noexcept override;
45 
46 private:
47     ::executorch::runtime::EventTracer* tracer_;
48 };
49 } // namespace executorchcoreml
50