ORTSessionOptions
Objective-C
@interface ORTSessionOptions : NSObject
Swift
class ORTSessionOptions : NSObject
Options for configuring a session.
-
Unavailable
Declaration
Objective-C
- (instancetype)init NS_UNAVAILABLE; -
Creates session configuration options.
Declaration
Objective-C
- (nullable instancetype)initWithError:(NSError *_Nullable *_Nullable)error;Swift
init() throwsParameters
errorOptional error information set if an error occurs.
Return Value
The instance, or nil if an error occurs.
-
Appends an execution provider to the session options to enable the execution provider to be used when running the model.
Available since 1.14.
The execution provider list is ordered by decreasing priority. i.e. the first provider registered has the highest priority.
Declaration
Objective-C
- (BOOL)appendExecutionProvider:(nonnull NSString *)providerName providerOptions:(nonnull NSDictionary<NSString *, NSString *> *) providerOptions error:(NSError *_Nullable *_Nullable)error;Swift
func appendExecutionProvider(_ providerName: String, providerOptions: [String : String] = [:]) throwsParameters
providerNameProvider name. For example, “xnnpack”.
providerOptionsProvider-specific options. For example, for provider “xnnpack”, {“intra_op_num_threads”: “2”}.
errorOptional error information set if an error occurs.
Return Value
Whether the execution provider was appended successfully
-
Sets the number of threads used to parallelize the execution within nodes. A value of 0 means ORT will pick a default value.
Declaration
Objective-C
- (BOOL)setIntraOpNumThreads:(int)intraOpNumThreads error:(NSError *_Nullable *_Nullable)error;Swift
func setIntraOpNumThreads(_ intraOpNumThreads: Int32) throwsParameters
intraOpNumThreadsThe number of threads.
errorOptional error information set if an error occurs.
Return Value
Whether the option was set successfully.
-
Sets the graph optimization level.
Declaration
Objective-C
- (BOOL)setGraphOptimizationLevel: (ORTGraphOptimizationLevel)graphOptimizationLevel error:(NSError *_Nullable *_Nullable)error;Swift
func setGraphOptimizationLevel(_ graphOptimizationLevel: ORTGraphOptimizationLevel) throwsParameters
graphOptimizationLevelThe graph optimization level.
errorOptional error information set if an error occurs.
Return Value
Whether the option was set successfully.
-
Sets the path to which the optimized model file will be saved.
Declaration
Objective-C
- (BOOL)setOptimizedModelFilePath:(nonnull NSString *)optimizedModelFilePath error:(NSError *_Nullable *_Nullable)error;Swift
func setOptimizedModelFilePath(_ optimizedModelFilePath: String) throwsParameters
optimizedModelFilePathThe optimized model file path.
errorOptional error information set if an error occurs.
Return Value
Whether the option was set successfully.
-
Sets the session log ID.
Declaration
Objective-C
- (BOOL)setLogID:(nonnull NSString *)logID error:(NSError *_Nullable *_Nullable)error;Swift
func setLogID(_ logID: String) throwsParameters
logIDThe log ID.
errorOptional error information set if an error occurs.
Return Value
Whether the option was set successfully.
-
Sets the session log severity level.
Declaration
Objective-C
- (BOOL)setLogSeverityLevel:(ORTLoggingLevel)loggingLevel error:(NSError *_Nullable *_Nullable)error;Swift
func setLogSeverityLevel(_ loggingLevel: ORTLoggingLevel) throwsParameters
loggingLevelThe log severity level.
errorOptional error information set if an error occurs.
Return Value
Whether the option was set successfully.
-
Sets a session configuration key-value pair. Any value for a previously set key will be overwritten. The session configuration keys and values are documented here: https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h
Declaration
Objective-C
- (BOOL)addConfigEntryWithKey:(nonnull NSString *)key value:(nonnull NSString *)value error:(NSError *_Nullable *_Nullable)error;Swift
func addConfigEntry(withKey key: String, value: String) throwsParameters
keyThe key.
valueThe value.
errorOptional error information set if an error occurs.
Return Value
Whether the option was set successfully.
-
Registers custom ops for use with
ORTSessions using this SessionOptions by calling the specified native function name. The custom ops library must either be linked against, or have previously been loaded by the user.Available since 1.14.
The registration function must have the signature:
OrtStatus* (*fn)(OrtSessionOptions* options, const OrtApiBase* api);The signature is defined in the ONNX Runtime C API: https://github.com/microsoft/onnxruntime/blob/67f4cd54fab321d83e4a75a40efeee95a6a17079/include/onnxruntime/core/session/onnxruntime_c_api.h#L697
See https://onnxruntime.ai/docs/reference/operators/add-custom-op.html for more information on custom ops. See https://github.com/microsoft/onnxruntime/blob/342a5bf2b756d1a1fc6fdc582cfeac15182632fe/onnxruntime/test/testdata/custom_op_library/custom_op_library.cc#L115 for an example of a custom op library registration function.
Note
The caller must ensure that
registrationFuncNamenames a valid function that is visible to the native ONNX Runtime code and has the correct signature. They must ensure that the function does what they expect it to do because this method will just call it.Declaration
Objective-C
- (BOOL)registerCustomOpsUsingFunction:(nonnull NSString *)registrationFuncName error:(NSError *_Nullable *_Nullable)error;Swift
func registerCustomOps(usingFunction registrationFuncName: String) throwsParameters
registrationFuncNameThe name of the registration function to call.
errorOptional error information set if an error occurs.
Return Value
Whether the registration function was successfully called.
-
Registers custom ops for use with
ORTSessions using this SessionOptions by calling the specified function pointed to byregisterCustomOpsFn.Available since 1.16.
The registration function must have the signature:
OrtStatus* (*fn)(OrtSessionOptions* options, const OrtApiBase* api);The signature is defined in the ONNX Runtime C API: https://github.com/microsoft/onnxruntime/blob/67f4cd54fab321d83e4a75a40efeee95a6a17079/include/onnxruntime/core/session/onnxruntime_c_api.h#L697
See https://onnxruntime.ai/docs/reference/operators/add-custom-op.html for more information on custom ops. See https://github.com/microsoft/onnxruntime/blob/342a5bf2b756d1a1fc6fdc582cfeac15182632fe/onnxruntime/test/testdata/custom_op_library/custom_op_library.cc#L115 for an example of a custom op library registration function.
Note
The caller must ensure that
registerCustomOpsFnis a valid function pointer and has the correct signature. They must ensure that the function does what they expect it to do because this method will just call it.Declaration
Objective-C
- (BOOL)registerCustomOpsUsingFunctionPointer: (nonnull ORTCAPIRegisterCustomOpsFnPtr)registerCustomOpsFn error:(NSError *_Nullable *_Nullable) error;Swift
func registerCustomOps(functionPointer registerCustomOpsFn: ORTCAPIRegisterCustomOpsFnPtr) throwsParameters
registerCustomOpsFnA pointer to the registration function to call.
errorOptional error information set if an error occurs.
Return Value
Whether the registration function was successfully called.
-
Registers ONNX Runtime Extensions custom ops that have been built in to ONNX Runtime.
Available since 1.16.
Note
ONNX Runtime must have been built with the
--use_extensionsflag for the ONNX Runtime Extensions custom ops to be able to be registered with this method. When using a separate ONNX Runtime Extensions library, useregisterCustomOpsUsingFunctionPointer:error:instead.Declaration
Objective-C
- (BOOL)enableOrtExtensionsCustomOpsWithError: (NSError *_Nullable *_Nullable)error;Swift
func enableOrtExtensionsCustomOps() throwsParameters
errorOptional error information set if an error occurs.
Return Value
Whether the ONNX Runtime Extensions custom ops were successfully registered.
-
Enables the CoreML execution provider in the session configuration options. It is appended to the execution provider list which is ordered by decreasing priority.
Declaration
Objective-C
- (BOOL)appendCoreMLExecutionProviderWithOptions: (nonnull ORTCoreMLExecutionProviderOptions *)options error:(NSError *_Nullable *_Nullable) error;Swift
func appendCoreMLExecutionProvider(with options: ORTCoreMLExecutionProviderOptions) throwsParameters
optionsThe CoreML execution provider configuration options.
errorOptional error information set if an error occurs.
Return Value
Whether the provider was enabled successfully.
-
Available since 1.14. Enables the Xnnpack execution provider in the session configuration options. It is appended to the execution provider list which is ordered by decreasing priority.
Declaration
Objective-C
- (BOOL)appendXnnpackExecutionProviderWithOptions: (nonnull ORTXnnpackExecutionProviderOptions *)options error: (NSError *_Nullable *_Nullable) error;Swift
func appendXnnpackExecutionProvider(with options: ORTXnnpackExecutionProviderOptions) throwsParameters
optionsThe Xnnpack execution provider configuration options.
errorOptional error information set if an error occurs.
Return Value
Whether the provider was enabled successfully.
View on GitHub
ORTSessionOptions Class Reference