Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions extension/apple/ExecuTorch/Exported/ExecuTorchModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ __attribute__((deprecated("This API is experimental.")))
*/
- (BOOL)isMethodLoaded:(NSString *)methodName NS_SWIFT_NAME(isLoaded(_:));

/**
* Retrieves the set of method names available in the loaded program.
*
* The method names are returned as an unordered set of strings. The program and methods
* are loaded as needed.
*
* @param error A pointer to an NSError pointer that is set if an error occurs.
* @return An unordered set of method names, or nil in case of an error.
*/
- (nullable NSSet<NSString *> *)methodNames:(NSError **)error;

+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

Expand Down
17 changes: 17 additions & 0 deletions extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,21 @@ - (BOOL)isMethodLoaded:(NSString *)methodName {
return _module->is_method_loaded(methodName.UTF8String);
}

- (nullable NSSet<NSString *> *)methodNames:(NSError **)error {
const auto result = _module->method_names();
if (!result.ok()) {
if (error) {
*error = [NSError errorWithDomain:ExecuTorchErrorDomain
code:(NSInteger)result.error()
userInfo:nil];
}
return nil;
}
NSMutableSet<NSString *> *methods = [NSMutableSet setWithCapacity:result->size()];
for (const auto &name : *result) {
[methods addObject:(NSString *)@(name.c_str())];
}
return methods;
}

@end
12 changes: 12 additions & 0 deletions extension/apple/ExecuTorch/__tests__/ModuleTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,16 @@ class ModuleTest: XCTestCase {
XCTAssertNoThrow(try module.load("forward"))
XCTAssertTrue(module.isLoaded("forward"))
}

func testMethodNames() {
let bundle = Bundle(for: type(of: self))
guard let modelPath = bundle.path(forResource: "add", ofType: "pte") else {
XCTFail("Couldn't find the model file")
return
}
let module = Module(filePath: modelPath)
var methodNames: Set<String>?
XCTAssertNoThrow(methodNames = try module.methodNames())
XCTAssertEqual(methodNames, Set(["forward"]))
}
}
Loading