Skip to content

Commit 11c7dd6

Browse files
YUNQIUGUOrachguoedgchen1
authored
Update to 1.18.0 resources (#17)
* update to 1.18.0 resources * Update Package.swift Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com> * update --------- Co-authored-by: rachguo <rachguo@rachguos-Mini.attlocal.net> Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
1 parent ce64739 commit 11c7dd6

File tree

9 files changed

+53
-14
lines changed

9 files changed

+53
-14
lines changed

Package.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@ if let pod_archive_path = ProcessInfo.processInfo.environment["ORT_IOS_POD_LOCAL
9696
package.targets.append(Target.binaryTarget(name: "onnxruntime", path: pod_archive_path))
9797

9898
} else {
99-
// ORT 1.17.0 release
99+
// ORT 1.18.0 release
100100
package.targets.append(
101101
Target.binaryTarget(name: "onnxruntime",
102-
url: "https://onnxruntimepackages.z14.web.core.windows.net/pod-archive-onnxruntime-c-1.17.0.zip",
103-
checksum: "1623e1150507d9e50554e3d3e5cf9abf75e1bfd8324b74a602acfe45343db871")
102+
url: "https://download.onnxruntime.ai/pod-archive-onnxruntime-c-1.18.0.zip",
103+
checksum: "9f196b7d09129177f529be63a91e18731ab1ccc830828e29edcbe95bd652fa5c")
104104
)
105105
}
106106

107107
if let ext_pod_archive_path = ProcessInfo.processInfo.environment["ORT_EXTENSIONS_IOS_POD_LOCAL_PATH"] {
108108
package.targets.append(Target.binaryTarget(name: "onnxruntime_extensions", path: ext_pod_archive_path))
109109
} else {
110-
// ORT Extensions 0.10.0 release
110+
// ORT Extensions 0.11.0 release
111111
package.targets.append(
112112
Target.binaryTarget(name: "onnxruntime_extensions",
113-
url: "https://onnxruntimepackages.z14.web.core.windows.net/pod-archive-onnxruntime-extensions-c-0.10.0.zip",
114-
checksum: "c0fbe30bcf898b0f7428e913918803372ba986ed9c662c1b8300ceaff3f442e0")
113+
url: "https://download.onnxruntime.ai/pod-archive-onnxruntime-extensions-c-0.11.0.zip",
114+
checksum: "289e8b7847116744946003ed21e1ac9ee4897c3aca48e261238e329634c27c0a")
115115
)
116116
}

objectivec/include/ort_coreml_execution_provider.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ NS_ASSUME_NONNULL_BEGIN
4141
*/
4242
@property BOOL onlyEnableForDevicesWithANE;
4343

44+
/**
45+
* Only allow CoreML EP to take nodes with inputs with static shapes. By default it will also allow inputs with
46+
* dynamic shapes. However, the performance may be negatively impacted if inputs have dynamic shapes.
47+
*/
48+
@property BOOL onlyAllowStaticInputShapes;
49+
50+
/**
51+
* Create an MLProgram. By default it will create a NeuralNetwork model. Requires Core ML 5 or later.
52+
*/
53+
@property BOOL createMLProgram;
54+
4455
@end
4556

4657
@interface ORTSessionOptions (ORTSessionOptionsCoreMLEP)

objectivec/include/ort_env.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ NSString* _Nullable ORTVersion(void);
2424

2525
/**
2626
* The ORT environment.
27+
* It maintains shared state including the default logger.
28+
*
29+
* @note One ORTEnv should be created before and destroyed after other ORT API usage.
2730
*/
2831
@interface ORTEnv : NSObject
2932

objectivec/include/ort_training_session.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
3939
* session which will be moved to the device specified in the session option if needed.
4040
*
4141
* @param env The `ORTEnv` instance to use for the training session.
42-
* @param sessionOptions The `ORTSessionOptions` to use for the training session.
42+
* @param sessionOptions The optional `ORTSessionOptions` to use for the training session.
4343
* @param checkpoint Training states that are used as a starting point for training.
4444
* @param trainModelPath The path to the training onnx model.
4545
* @param evalModelPath The path to the evaluation onnx model.
@@ -52,7 +52,7 @@ NS_ASSUME_NONNULL_BEGIN
5252
* keeps a strong (owning) pointer to the checkpoint state.
5353
*/
5454
- (nullable instancetype)initWithEnv:(ORTEnv*)env
55-
sessionOptions:(ORTSessionOptions*)sessionOptions
55+
sessionOptions:(nullable ORTSessionOptions*)sessionOptions
5656
checkpoint:(ORTCheckpoint*)checkpoint
5757
trainModelPath:(NSString*)trainModelPath
5858
evalModelPath:(nullable NSString*)evalModelPath

objectivec/ort_checkpoint.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <variant>
99
#import "cxx_api.h"
1010

11+
#import "cxx_utils.h"
1112
#import "error_utils.h"
1213

1314
NS_ASSUME_NONNULL_BEGIN
@@ -73,7 +74,7 @@ - (nullable NSString*)getStringPropertyWithName:(NSString*)name error:(NSError**
7374
try {
7475
Ort::Property value = [self CXXAPIOrtCheckpoint].GetProperty(name.UTF8String);
7576
if (std::string* str = std::get_if<std::string>(&value)) {
76-
return [NSString stringWithUTF8String:str->c_str()];
77+
return utils::toNSString(str->c_str());
7778
}
7879
ORT_CXX_API_THROW("Property is not a string.", ORT_INVALID_ARGUMENT);
7980
}

objectivec/ort_coreml_execution_provider.mm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ - (BOOL)appendCoreMLExecutionProviderWithOptions:(ORTCoreMLExecutionProviderOpti
2626
const uint32_t flags =
2727
(options.useCPUOnly ? COREML_FLAG_USE_CPU_ONLY : 0) |
2828
(options.enableOnSubgraphs ? COREML_FLAG_ENABLE_ON_SUBGRAPH : 0) |
29-
(options.onlyEnableForDevicesWithANE ? COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE : 0);
29+
(options.onlyEnableForDevicesWithANE ? COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE : 0) |
30+
(options.onlyAllowStaticInputShapes ? COREML_FLAG_ONLY_ALLOW_STATIC_INPUT_SHAPES : 0) |
31+
(options.createMLProgram ? COREML_FLAG_CREATE_MLPROGRAM : 0);
32+
3033
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CoreML(
3134
[self CXXAPIOrtSessionOptions], flags));
3235
return YES;

objectivec/ort_session.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <vector>
88

99
#import "cxx_api.h"
10+
#import "cxx_utils.h"
1011
#import "error_utils.h"
1112
#import "ort_enums_internal.h"
1213
#import "ort_env_internal.h"
@@ -23,6 +24,7 @@
2324
NS_ASSUME_NONNULL_BEGIN
2425

2526
@implementation ORTSession {
27+
ORTEnv* _env; // keep a strong reference so the ORTEnv doesn't get destroyed before this does
2628
std::optional<Ort::Session> _session;
2729
}
2830

@@ -44,6 +46,7 @@ - (nullable instancetype)initWithEnv:(ORTEnv*)env
4446
}
4547
}
4648

49+
_env = env;
4750
_session = Ort::Session{[env CXXAPIOrtEnv],
4851
path.UTF8String,
4952
[sessionOptions CXXAPIOrtSessionOptions]};
@@ -196,8 +199,7 @@ - (BOOL)runWithInputs:(NSDictionary<NSString*, ORTValue*>*)inputs
196199

197200
for (size_t i = 0; i < nameCount; ++i) {
198201
auto name = getName(i, allocator);
199-
NSString* nameNsstr = [NSString stringWithUTF8String:name.get()];
200-
NSAssert(nameNsstr != nil, @"nameNsstr must not be nil");
202+
NSString* nameNsstr = utils::toNSString(name.get());
201203
[result addObject:nameNsstr];
202204
}
203205

objectivec/ort_training_session.mm

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919
NS_ASSUME_NONNULL_BEGIN
2020

2121
@implementation ORTTrainingSession {
22-
std::optional<Ort::TrainingSession> _session;
22+
ORTEnv* _env; // keep a strong reference so the ORTEnv doesn't get destroyed before this does
2323
ORTCheckpoint* _checkpoint;
24+
std::optional<Ort::TrainingSession> _session;
2425
}
2526

2627
- (Ort::TrainingSession&)CXXAPIOrtTrainingSession {
2728
return *_session;
2829
}
2930

3031
- (nullable instancetype)initWithEnv:(ORTEnv*)env
31-
sessionOptions:(ORTSessionOptions*)sessionOptions
32+
sessionOptions:(nullable ORTSessionOptions*)sessionOptions
3233
checkpoint:(ORTCheckpoint*)checkpoint
3334
trainModelPath:(NSString*)trainModelPath
3435
evalModelPath:(nullable NSString*)evalModelPath
@@ -39,9 +40,17 @@ - (nullable instancetype)initWithEnv:(ORTEnv*)env
3940
}
4041

4142
try {
43+
if (!sessionOptions) {
44+
sessionOptions = [[ORTSessionOptions alloc] initWithError:error];
45+
if (!sessionOptions) {
46+
return nil;
47+
}
48+
}
49+
4250
std::optional<std::string> evalPath = utils::toStdOptionalString(evalModelPath);
4351
std::optional<std::string> optimizerPath = utils::toStdOptionalString(optimizerModelPath);
4452

53+
_env = env;
4554
_checkpoint = checkpoint;
4655
_session = Ort::TrainingSession{
4756
[env CXXAPIOrtEnv],
@@ -50,6 +59,7 @@ - (nullable instancetype)initWithEnv:(ORTEnv*)env
5059
trainModelPath.UTF8String,
5160
evalPath,
5261
optimizerPath};
62+
5363
return self;
5464
}
5565
ORT_OBJC_API_IMPL_CATCH_RETURNING_NULLABLE(error)

objectivec/ort_value.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ - (nullable ORTValueTypeInfo*)typeInfoWithError:(NSError**)error {
148148
- (nullable ORTTensorTypeAndShapeInfo*)tensorTypeAndShapeInfoWithError:(NSError**)error {
149149
try {
150150
const auto tensorTypeAndShapeInfo = _typeInfo->GetTensorTypeAndShapeInfo();
151+
if (!tensorTypeAndShapeInfo) {
152+
ORT_CXX_API_THROW("ORTValue is not a tensor.", ORT_RUNTIME_EXCEPTION);
153+
}
151154
return CXXAPIToPublicTensorTypeAndShapeInfo(tensorTypeAndShapeInfo);
152155
}
153156
ORT_OBJC_API_IMPL_CATCH_RETURNING_NULLABLE(error)
@@ -156,6 +159,9 @@ - (nullable ORTTensorTypeAndShapeInfo*)tensorTypeAndShapeInfoWithError:(NSError*
156159
- (nullable NSMutableData*)tensorDataWithError:(NSError**)error {
157160
try {
158161
const auto tensorTypeAndShapeInfo = _typeInfo->GetTensorTypeAndShapeInfo();
162+
if (!tensorTypeAndShapeInfo) {
163+
ORT_CXX_API_THROW("ORTValue is not a tensor.", ORT_RUNTIME_EXCEPTION);
164+
}
159165
if (tensorTypeAndShapeInfo.GetElementType() == ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING) {
160166
ORT_CXX_API_THROW(
161167
"This ORTValue holds string data. Please call tensorStringDataWithError: "
@@ -182,6 +188,9 @@ - (nullable NSMutableData*)tensorDataWithError:(NSError**)error {
182188
- (nullable NSArray<NSString*>*)tensorStringDataWithError:(NSError**)error {
183189
try {
184190
const auto tensorTypeAndShapeInfo = _typeInfo->GetTensorTypeAndShapeInfo();
191+
if (!tensorTypeAndShapeInfo) {
192+
ORT_CXX_API_THROW("ORTValue is not a tensor.", ORT_RUNTIME_EXCEPTION);
193+
}
185194
const size_t elementCount = tensorTypeAndShapeInfo.GetElementCount();
186195
const size_t tensorStringDataLength = _value->GetStringTensorDataLength();
187196
std::vector<char> tensorStringData(tensorStringDataLength, '\0');

0 commit comments

Comments
 (0)