Skip to content

Commit 311c6cb

Browse files
authored
Create Module with a filepath and load mode.
Differential Revision: D71915597 Pull Request resolved: #9683
1 parent e02c136 commit 311c6cb

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

extension/apple/ExecuTorch/Exported/ExecuTorchModule.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,33 @@ typedef NS_ENUM(NSInteger, ExecuTorchModuleLoadMode) {
2222
ExecuTorchModuleLoadModeMmapUseMlockIgnoreErrors,
2323
} NS_SWIFT_NAME(ModuleLoadMode);
2424

25+
/**
26+
* Represents a module that encapsulates an ExecuTorch program.
27+
* This class is a facade for loading programs and executing methods within them.
28+
*/
2529
NS_SWIFT_NAME(Module)
2630
__attribute__((deprecated("This API is experimental.")))
2731
@interface ExecuTorchModule : NSObject
2832

33+
/**
34+
* Initializes a module with a file path and a specified load mode.
35+
*
36+
* @param filePath A string representing the path to the ExecuTorch program file.
37+
* @param loadMode A value from ExecuTorchModuleLoadMode that determines the file loading behavior.
38+
* @return An initialized ExecuTorchModule instance.
39+
*/
40+
- (instancetype)initWithFilePath:(NSString *)filePath
41+
loadMode:(ExecuTorchModuleLoadMode)loadMode
42+
NS_DESIGNATED_INITIALIZER;
43+
44+
/**
45+
* Initializes a module with a file path using the default load mode (File mode).
46+
*
47+
* @param filePath A string representing the path to the ExecuTorch program file.
48+
* @return An initialized ExecuTorchModule instance.
49+
*/
50+
- (instancetype)initWithFilePath:(NSString *)filePath;
51+
2952
+ (instancetype)new NS_UNAVAILABLE;
3053
- (instancetype)init NS_UNAVAILABLE;
3154

extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,26 @@
1313
#import <executorch/extension/module/module.h>
1414
#import <executorch/extension/tensor/tensor.h>
1515

16+
using namespace executorch::extension;
17+
1618
@implementation ExecuTorchModule {
17-
std::unique_ptr<executorch::extension::Module> _module;
19+
std::unique_ptr<Module> _module;
20+
}
21+
22+
- (instancetype)initWithFilePath:(NSString *)filePath
23+
loadMode:(ExecuTorchModuleLoadMode)loadMode {
24+
self = [super init];
25+
if (self) {
26+
_module = std::make_unique<Module>(
27+
filePath.UTF8String,
28+
static_cast<Module::LoadMode>(loadMode)
29+
);
30+
}
31+
return self;
32+
}
33+
34+
- (instancetype)initWithFilePath:(NSString *)filePath {
35+
return [self initWithFilePath:filePath loadMode:ExecuTorchModuleLoadModeFile];
1836
}
1937

2038
@end

0 commit comments

Comments
 (0)