Skip to content

Commit 2633a9d

Browse files
committed
data path support for ios
1 parent fe84495 commit 2633a9d

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

extension/apple/ExecuTorch/Exported/ExecuTorchModule.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ NS_SWIFT_NAME(Module)
123123
__attribute__((deprecated("This API is experimental.")))
124124
@interface ExecuTorchModule : NSObject
125125

126+
/**
127+
* Initializes a module with a file path, data path and a specified load mode.
128+
*
129+
* @param filePath A string representing the path to the ExecuTorch program file.
130+
* @param dataFilePath A string representing the path to a .ptd file with
131+
* external tensors and external data.
132+
* @param loadMode A value from ExecuTorchModuleLoadMode that determines the
133+
* file loading behavior.
134+
* @return An initialized ExecuTorchModule instance.
135+
*/
136+
- (instancetype)initWithFilePath:(NSString *)filePath
137+
dataFilePath:(NSString *)dataPath
138+
loadMode:(ExecuTorchModuleLoadMode)loadMode
139+
NS_DESIGNATED_INITIALIZER;
140+
126141
/**
127142
* Initializes a module with a file path and a specified load mode.
128143
*

extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,37 @@ @implementation ExecuTorchModule {
250250
}
251251

252252
- (instancetype)initWithFilePath:(NSString *)filePath
253+
dataFilePath:(NSString *)dataFilePath
253254
loadMode:(ExecuTorchModuleLoadMode)loadMode {
254255
self = [super init];
255256
if (self) {
256-
_module = std::make_unique<Module>(
257-
filePath.UTF8String,
258-
static_cast<Module::LoadMode>(loadMode)
259-
);
260-
_inputs = [NSMutableDictionary new];
261-
_outputs = [NSMutableDictionary new];
257+
if (dataFilePath) {
258+
_module = std::make_unique<Module>(
259+
filePath.UTF8String,
260+
dataFilePath.UTF8String,
261+
static_cast<Module::LoadMode>(loadMode)
262+
);
263+
_inputs = [NSMutableDictionary new];
264+
_outputs = [NSMutableDictionary new];
265+
} else {
266+
_module = std::make_unique<Module>(
267+
filePath.UTF8String,
268+
static_cast<Module::LoadMode>(loadMode)
269+
);
270+
_inputs = [NSMutableDictionary new];
271+
_outputs = [NSMutableDictionary new];
272+
}
262273
}
263274
return self;
264275
}
265276

277+
- (instancetype)initWithFilePath:(NSString *)filePath
278+
loadMode:(ExecuTorchModuleLoadMode)loadMode {
279+
return [self initWithFilePath:filePath
280+
dataFilePath:nil
281+
loadMode:loadMode];
282+
}
283+
266284
- (instancetype)initWithFilePath:(NSString *)filePath {
267285
return [self initWithFilePath:filePath loadMode:ExecuTorchModuleLoadModeFile];
268286
}

0 commit comments

Comments
 (0)