Skip to content

Commit da45eea

Browse files
shoumikhinkirklandsign
authored andcommitted
Module API to execute with a single Tensor.
Differential Revision: D71955238 Pull Request resolved: #9706
1 parent 558022b commit da45eea

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

extension/apple/ExecuTorch/Exported/ExecuTorchModule.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ __attribute__((deprecated("This API is experimental.")))
173173
error:(NSError **)error
174174
NS_SWIFT_NAME(execute(_:_:));
175175

176+
/**
177+
* Executes a specific method with the provided single input tensor.
178+
*
179+
* The method is loaded on demand if not already loaded.
180+
*
181+
* @param methodName A string representing the method name.
182+
* @param tensor An ExecuTorchTensor object representing the input.
183+
* @param error A pointer to an NSError pointer that is set if an error occurs.
184+
* @return An NSArray of ExecuTorchValue objects representing the outputs, or nil in case of an error.
185+
*/
186+
- (nullable NSArray<ExecuTorchValue *> *)executeMethod:(NSString *)methodName
187+
withTensor:(ExecuTorchTensor *)tensor
188+
error:(NSError **)error
189+
NS_SWIFT_NAME(execute(_:_:));
190+
176191
/**
177192
* Executes the "forward" method with the provided input values.
178193
*
@@ -210,7 +225,7 @@ __attribute__((deprecated("This API is experimental.")))
210225
- (nullable NSArray<ExecuTorchValue *> *)forward:(NSError **)error;
211226

212227
/**
213-
* Executes the "forward" method with no inputs.
228+
* Executes the "forward" method with the provided input tensors.
214229
*
215230
* This is a convenience method that calls the executeMethod with "forward" as the method name.
216231
*
@@ -222,6 +237,19 @@ __attribute__((deprecated("This API is experimental.")))
222237
error:(NSError **)error
223238
NS_SWIFT_NAME(forward(_:));
224239

240+
/**
241+
* Executes the "forward" method with the provided single input tensor.
242+
*
243+
* This is a convenience method that calls the executeMethod with "forward" as the method name.
244+
*
245+
* @param tensor An ExecuTorchTensor object representing the input.
246+
* @param error A pointer to an NSError pointer that is set if an error occurs.
247+
* @return An NSArray of ExecuTorchValue objects representing the outputs, or nil in case of an error.
248+
*/
249+
- (nullable NSArray<ExecuTorchValue *> *)forwardWithTensor:(ExecuTorchTensor *)tensor
250+
error:(NSError **)error
251+
NS_SWIFT_NAME(forward(_:));
252+
225253
+ (instancetype)new NS_UNAVAILABLE;
226254
- (instancetype)init NS_UNAVAILABLE;
227255

extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ - (BOOL)isMethodLoaded:(NSString *)methodName {
191191
error:error];
192192
}
193193

194+
- (nullable NSArray<ExecuTorchValue *> *)executeMethod:(NSString *)methodName
195+
withTensor:(ExecuTorchTensor *)tensor
196+
error:(NSError **)error {
197+
return [self executeMethod:methodName
198+
withInputs:@[[ExecuTorchValue valueWithTensor:tensor]]
199+
error:error];
200+
}
201+
194202
- (nullable NSArray<ExecuTorchValue *> *)forwardWithInputs:(NSArray<ExecuTorchValue *> *)values
195203
error:(NSError **)error {
196204
return [self executeMethod:@"forward"
@@ -222,4 +230,11 @@ - (BOOL)isMethodLoaded:(NSString *)methodName {
222230
error:error];
223231
}
224232

233+
- (nullable NSArray<ExecuTorchValue *> *)forwardWithTensor:(ExecuTorchTensor *)tensor
234+
error:(NSError **)error {
235+
return [self executeMethod:@"forward"
236+
withInputs:@[[ExecuTorchValue valueWithTensor:tensor]]
237+
error:error];
238+
}
239+
225240
@end

0 commit comments

Comments
 (0)