Skip to content

Commit d4f77e5

Browse files
metascroyfacebook-github-bot
authored andcommitted
Re land asset management (#14768)
Summary: This re-lands #13560 To see changes from first attempt, see 16ff41b...428c1c4 Several notable changes: 1. In the original PR, we removed a backup path where if the transaction to store the compiled asset fails, the prediction could still succeed (https://github.com/pytorch/executorch/pull/13560/files#r2289523798). This is restored here: 16ff41b...428c1c4#diff-ce24872f2e45ee7bf53f50b319b8f77f2f340b01b0889748deaaa754084d4fefR495-R509 2. We add new logic to re-create the asset directory if needed inside _storeAssetAtURL: 16ff41b...428c1c4#diff-4178f5b6716f52c9cb12ee99be51a9d69d3ed0e4609e9afb0429571cf9cf84a3R468 3. We add new logic to re-create the trash directory if needed inside moveItemAtURLToTrash (16ff41b...428c1c4#diff-4178f5b6716f52c9cb12ee99be51a9d69d3ed0e4609e9afb0429571cf9cf84a3R432). Previously this function was called move_to_directory. 4. The previous code had a nested transaction inside _storeAssetAtURL (because _removeAssetAtURL also starts a transaction). We remove the nested transaction by passing in alreadyInsideTransaction to _removeAssetAtURL). 5. We add new NSFileProtectionCompleteUntilFirstUserAuthentication to our directories and database files. In addition to the above changes, we cleaned up some code: 1. The function create_directory_if_needed is removed from backend_delegate.mm: 16ff41b...428c1c4#diff-89543b8e2fe49bec8243d18801819bc2594e86d60af8823c03ac2c3e6fc7607dL48. An equivalent function exists in the asset manager. 2. Introduced loadModelWithCompiledAsset and use it rather than using loadModelWithContentsOfURL (16ff41b...428c1c4#diff-ce24872f2e45ee7bf53f50b319b8f77f2f340b01b0889748deaaa754084d4fefL585) Reviewed By: mergennachin Differential Revision: D83893376 Pulled By: metascroy
1 parent 06ea3d6 commit d4f77e5

File tree

6 files changed

+372
-189
lines changed

6 files changed

+372
-189
lines changed

backends/apple/coreml/runtime/delegate/ETCoreMLAssetManager.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ NS_ASSUME_NONNULL_BEGIN
9999
- (NSUInteger)compact:(NSUInteger)sizeInBytes error:(NSError* __autoreleasing*)error;
100100

101101

102+
/// Executes a block with a unique temporary directory.
103+
///
104+
/// A new temporary subdirectory URL is created inside the receiver’s designated
105+
/// base directory. The directory is passed to the block, which can use it to
106+
/// perform temporary file operations. After the block finishes executing,
107+
/// the directory and its contents are removed.
108+
///
109+
/// @param block A block to execute. The block receives a unique URL.
110+
- (void)withTemporaryDirectory:(void (^)(NSURL* directoryURL))block;
111+
112+
102113
/// Purges the assets storage. The assets are moved to the trash directory and are asynchronously
103114
/// deleted.
104115
///
@@ -117,6 +128,12 @@ NS_ASSUME_NONNULL_BEGIN
117128
/// contents are deleted asynchronously.
118129
@property (copy, readonly, nonatomic) NSURL* trashDirectoryURL;
119130

131+
132+
/// The staging directory URL, used to hold assets that are being prepared or processed
133+
/// before they are moved into their final location. The contents of this directory
134+
/// are temporary and may be cleared when no longer needed.
135+
@property (copy, readonly, nonatomic) NSURL* stagingDirectoryURL;
136+
120137
/// The file manager.
121138
@property (strong, readonly, nonatomic) NSFileManager* fileManager;
122139

0 commit comments

Comments
 (0)