xref: /aosp_15_r20/external/executorch/backends/apple/coreml/runtime/sdk/ETCoreMLModelProfiler.h (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 //
2 // ETCoreMLModelProfiler.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 #import "ETCoreMLPair.h"
9 #import <CoreML/CoreML.h>
10 #import <TargetConditionals.h>
11 
12 @class ETCoreMLAsset;
13 @class ETCoreMLModel;
14 @class ETCoreMLModelStructurePath;
15 @class ETCoreMLOperationProfilingInfo;
16 
17 typedef NSDictionary<ETCoreMLModelStructurePath*, ETCoreMLOperationProfilingInfo*> ETCoreMLModelProfilingResult;
18 
19 #if !defined(MODEL_PROFILING_IS_AVAILABLE) && __has_include(<CoreML/MLComputePlan.h>)
20 #define MODEL_PROFILING_IS_AVAILABLE 1
21 #endif
22 
23 NS_ASSUME_NONNULL_BEGIN
24 /// A class responsible for profiling a model.
25 __attribute__((objc_subclassing_restricted))
26 @interface ETCoreMLModelProfiler : NSObject
27 
28 - (instancetype)init NS_UNAVAILABLE;
29 
30 + (instancetype)new NS_UNAVAILABLE;
31 
32 /// Constructs an `ETCoreMLModelProfiler` instance.
33 ///
34 /// @param model The model.
35 /// @param configuration The model configuration.
36 /// @param error   On failure, error is filled with the failure information.
37 - (nullable instancetype)initWithModel:(ETCoreMLModel*)model
38                          configuration:(MLModelConfiguration*)configuration
39                                  error:(NSError* __autoreleasing*)error NS_DESIGNATED_INITIALIZER;
40 
41 /// Returns profiling info of operations at the specified paths.
42 ///
43 /// @param paths The operation paths.
44 /// @param options The prediction options.
45 /// @param inputs The model inputs..
46 /// @param modelOutputs  On success, modelOutputs is filled with the model outputs.
47 /// @param error   On failure, error is filled with the failure information.
48 /// @retval A dictionary with the operation path as the key and the profiling info as the value.
49 - (nullable ETCoreMLModelProfilingResult*)
50     profilingInfoForOperationsAtPaths:(NSArray<ETCoreMLModelStructurePath*>*)paths
51                               options:(MLPredictionOptions*)options
52                                inputs:(id<MLFeatureProvider>)inputs
53                          modelOutputs:(NSArray<MLMultiArray*>* _Nullable __autoreleasing* _Nonnull)modelOutputs
54                                 error:(NSError* __autoreleasing*)error;
55 
56 /// The paths to all the operations for which we can get the profiling info.
57 @property (readonly, copy, nonatomic) NSArray<ETCoreMLModelStructurePath*>* operationPaths;
58 
59 @end
60 
61 NS_ASSUME_NONNULL_END
62