mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-14 20:48:00 +00:00
### Description <!-- Describe your changes. --> Adds infrastructure to create an ML Package containing the Model using ML Program. Updated coremltools files to v7.1 to bring in new protobuf definitions along with the tools to write the weight.bin file and create an ML Package correctly. Enables building a CoreML Model on all platforms which means all the operator builder code can be debugged anywhere. Execution of the generated CoreML model is obviously limited to Apple platforms. The Conv operator builder has been updated to be able to generate an ML Program Operation. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> NeuralNetwork is no longer being developed and ML Program is the replacement going forward.
47 lines
1.5 KiB
Text
47 lines
1.5 KiB
Text
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#import "ort_coreml_execution_provider.h"
|
|
|
|
#import "cxx_api.h"
|
|
#import "error_utils.h"
|
|
#import "ort_session_internal.h"
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
BOOL ORTIsCoreMLExecutionProviderAvailable() {
|
|
return ORT_OBJC_API_COREML_EP_AVAILABLE ? YES : NO;
|
|
}
|
|
|
|
@implementation ORTCoreMLExecutionProviderOptions
|
|
|
|
@end
|
|
|
|
@implementation ORTSessionOptions (ORTSessionOptionsCoreMLEP)
|
|
|
|
- (BOOL)appendCoreMLExecutionProviderWithOptions:(ORTCoreMLExecutionProviderOptions*)options
|
|
error:(NSError**)error {
|
|
#if ORT_OBJC_API_COREML_EP_AVAILABLE
|
|
try {
|
|
const uint32_t flags =
|
|
(options.useCPUOnly ? COREML_FLAG_USE_CPU_ONLY : 0) |
|
|
(options.enableOnSubgraphs ? COREML_FLAG_ENABLE_ON_SUBGRAPH : 0) |
|
|
(options.onlyEnableForDevicesWithANE ? COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE : 0) |
|
|
(options.onlyAllowStaticInputShapes ? COREML_FLAG_ONLY_ALLOW_STATIC_INPUT_SHAPES : 0) |
|
|
(options.createMLProgram ? COREML_FLAG_CREATE_MLPROGRAM : 0);
|
|
|
|
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CoreML(
|
|
[self CXXAPIOrtSessionOptions], flags));
|
|
return YES;
|
|
}
|
|
ORT_OBJC_API_IMPL_CATCH_RETURNING_BOOL(error);
|
|
#else // !ORT_OBJC_API_COREML_EP_AVAILABLE
|
|
static_cast<void>(options);
|
|
ORTSaveCodeAndDescriptionToError(ORT_FAIL, "CoreML execution provider is not enabled.", error);
|
|
return NO;
|
|
#endif
|
|
}
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|