xref: /aosp_15_r20/external/executorch/backends/apple/coreml/runtime/delegate/ETCoreMLAsset.h (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 //
2 // ETCoreMLAsset.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 <Foundation/Foundation.h>
9 
10 #import <asset.h>
11 
12 NS_ASSUME_NONNULL_BEGIN
13 
14 /// Represents an asset on the filesystem.
15 @interface ETCoreMLAsset : NSObject
16 
17 - (instancetype)init NS_UNAVAILABLE;
18 
19 + (instancetype)new NS_UNAVAILABLE;
20 
21 /// Constructs an `ETCoreMLAsset` instance from `ModelAsset`
22 ///
23 /// @param backingAsset The cpp asset.
24 - (instancetype)initWithBackingAsset:(executorchcoreml::Asset)backingAsset NS_DESIGNATED_INITIALIZER;
25 
26 /// The unique identifier.
27 @property (copy, readonly, nonatomic) NSString* identifier;
28 
29 /// The absolute URL of the asset.
30 @property (copy, readonly, nonatomic) NSURL* contentURL;
31 
32 /// The total size of the directory in bytes.
33 @property (assign, readonly, nonatomic) NSUInteger totalSizeInBytes;
34 
35 /// Returns `YES` is the asset is valid otherwise `NO`.
36 @property (assign, readonly, nonatomic) BOOL isValid;
37 
38 /// Returns `YES` is the asset is alive otherwise `NO`.
39 @property (assign, readonly, nonatomic) BOOL isAlive;
40 
41 /// Keeps the asset alive by opening and hanging on to the file handles in the asset.
42 /// The file handles are closed when `close` is called or at the time of deallocation.
43 ///
44 /// @param error   On failure, error is filled with the failure information.
45 /// @retval `YES` is the file handles could be opened otherwise `NO`.
46 - (BOOL)keepAliveAndReturnError:(NSError* __autoreleasing*)error;
47 
48 /// Pre-warms the asset by doing an advisory async read to all the content files.
49 ///
50 /// @param error   On failure, error is filled with the failure information.
51 /// @retval `YES` is the advisory read to all the files succeeded otherwise`NO`.
52 - (BOOL)prewarmAndReturnError:(NSError* __autoreleasing*)error;
53 
54 /// Closes all the file handles opened by the `keepAliveAndReturnError` call.
55 - (void)close;
56 
57 @end
58 
59 NS_ASSUME_NONNULL_END
60