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>
This commit is contained in:
Rachel Guo
2024-06-04 15:41:38 -07:00
committed by GitHub
parent ce64739c6d
commit 11c7dd6dd4
9 changed files with 53 additions and 14 deletions
@@ -41,6 +41,17 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property BOOL onlyEnableForDevicesWithANE;
/**
* Only allow CoreML EP to take nodes with inputs with static shapes. By default it will also allow inputs with
* dynamic shapes. However, the performance may be negatively impacted if inputs have dynamic shapes.
*/
@property BOOL onlyAllowStaticInputShapes;
/**
* Create an MLProgram. By default it will create a NeuralNetwork model. Requires Core ML 5 or later.
*/
@property BOOL createMLProgram;
@end
@interface ORTSessionOptions (ORTSessionOptionsCoreMLEP)
+3
View File
@@ -24,6 +24,9 @@ NSString* _Nullable ORTVersion(void);
/**
* The ORT environment.
* It maintains shared state including the default logger.
*
* @note One ORTEnv should be created before and destroyed after other ORT API usage.
*/
@interface ORTEnv : NSObject
+2 -2
View File
@@ -39,7 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
* session which will be moved to the device specified in the session option if needed.
*
* @param env The `ORTEnv` instance to use for the training session.
* @param sessionOptions The `ORTSessionOptions` to use for the training session.
* @param sessionOptions The optional `ORTSessionOptions` to use for the training session.
* @param checkpoint Training states that are used as a starting point for training.
* @param trainModelPath The path to the training onnx model.
* @param evalModelPath The path to the evaluation onnx model.
@@ -52,7 +52,7 @@ NS_ASSUME_NONNULL_BEGIN
* keeps a strong (owning) pointer to the checkpoint state.
*/
- (nullable instancetype)initWithEnv:(ORTEnv*)env
sessionOptions:(ORTSessionOptions*)sessionOptions
sessionOptions:(nullable ORTSessionOptions*)sessionOptions
checkpoint:(ORTCheckpoint*)checkpoint
trainModelPath:(NSString*)trainModelPath
evalModelPath:(nullable NSString*)evalModelPath
+2 -1
View File
@@ -8,6 +8,7 @@
#include <variant>
#import "cxx_api.h"
#import "cxx_utils.h"
#import "error_utils.h"
NS_ASSUME_NONNULL_BEGIN
@@ -73,7 +74,7 @@ NS_ASSUME_NONNULL_BEGIN
try {
Ort::Property value = [self CXXAPIOrtCheckpoint].GetProperty(name.UTF8String);
if (std::string* str = std::get_if<std::string>(&value)) {
return [NSString stringWithUTF8String:str->c_str()];
return utils::toNSString(str->c_str());
}
ORT_CXX_API_THROW("Property is not a string.", ORT_INVALID_ARGUMENT);
}
+4 -1
View File
@@ -26,7 +26,10 @@ BOOL ORTIsCoreMLExecutionProviderAvailable() {
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.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;
+4 -2
View File
@@ -7,6 +7,7 @@
#include <vector>
#import "cxx_api.h"
#import "cxx_utils.h"
#import "error_utils.h"
#import "ort_enums_internal.h"
#import "ort_env_internal.h"
@@ -23,6 +24,7 @@ enum class NamedValueType {
NS_ASSUME_NONNULL_BEGIN
@implementation ORTSession {
ORTEnv* _env; // keep a strong reference so the ORTEnv doesn't get destroyed before this does
std::optional<Ort::Session> _session;
}
@@ -44,6 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
}
}
_env = env;
_session = Ort::Session{[env CXXAPIOrtEnv],
path.UTF8String,
[sessionOptions CXXAPIOrtSessionOptions]};
@@ -196,8 +199,7 @@ NS_ASSUME_NONNULL_BEGIN
for (size_t i = 0; i < nameCount; ++i) {
auto name = getName(i, allocator);
NSString* nameNsstr = [NSString stringWithUTF8String:name.get()];
NSAssert(nameNsstr != nil, @"nameNsstr must not be nil");
NSString* nameNsstr = utils::toNSString(name.get());
[result addObject:nameNsstr];
}
+12 -2
View File
@@ -19,8 +19,9 @@
NS_ASSUME_NONNULL_BEGIN
@implementation ORTTrainingSession {
std::optional<Ort::TrainingSession> _session;
ORTEnv* _env; // keep a strong reference so the ORTEnv doesn't get destroyed before this does
ORTCheckpoint* _checkpoint;
std::optional<Ort::TrainingSession> _session;
}
- (Ort::TrainingSession&)CXXAPIOrtTrainingSession {
@@ -28,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
}
- (nullable instancetype)initWithEnv:(ORTEnv*)env
sessionOptions:(ORTSessionOptions*)sessionOptions
sessionOptions:(nullable ORTSessionOptions*)sessionOptions
checkpoint:(ORTCheckpoint*)checkpoint
trainModelPath:(NSString*)trainModelPath
evalModelPath:(nullable NSString*)evalModelPath
@@ -39,9 +40,17 @@ NS_ASSUME_NONNULL_BEGIN
}
try {
if (!sessionOptions) {
sessionOptions = [[ORTSessionOptions alloc] initWithError:error];
if (!sessionOptions) {
return nil;
}
}
std::optional<std::string> evalPath = utils::toStdOptionalString(evalModelPath);
std::optional<std::string> optimizerPath = utils::toStdOptionalString(optimizerModelPath);
_env = env;
_checkpoint = checkpoint;
_session = Ort::TrainingSession{
[env CXXAPIOrtEnv],
@@ -50,6 +59,7 @@ NS_ASSUME_NONNULL_BEGIN
trainModelPath.UTF8String,
evalPath,
optimizerPath};
return self;
}
ORT_OBJC_API_IMPL_CATCH_RETURNING_NULLABLE(error)
+9
View File
@@ -148,6 +148,9 @@ bool SafeMultiply(size_t a, size_t b, size_t& out) {
- (nullable ORTTensorTypeAndShapeInfo*)tensorTypeAndShapeInfoWithError:(NSError**)error {
try {
const auto tensorTypeAndShapeInfo = _typeInfo->GetTensorTypeAndShapeInfo();
if (!tensorTypeAndShapeInfo) {
ORT_CXX_API_THROW("ORTValue is not a tensor.", ORT_RUNTIME_EXCEPTION);
}
return CXXAPIToPublicTensorTypeAndShapeInfo(tensorTypeAndShapeInfo);
}
ORT_OBJC_API_IMPL_CATCH_RETURNING_NULLABLE(error)
@@ -156,6 +159,9 @@ bool SafeMultiply(size_t a, size_t b, size_t& out) {
- (nullable NSMutableData*)tensorDataWithError:(NSError**)error {
try {
const auto tensorTypeAndShapeInfo = _typeInfo->GetTensorTypeAndShapeInfo();
if (!tensorTypeAndShapeInfo) {
ORT_CXX_API_THROW("ORTValue is not a tensor.", ORT_RUNTIME_EXCEPTION);
}
if (tensorTypeAndShapeInfo.GetElementType() == ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING) {
ORT_CXX_API_THROW(
"This ORTValue holds string data. Please call tensorStringDataWithError: "
@@ -182,6 +188,9 @@ bool SafeMultiply(size_t a, size_t b, size_t& out) {
- (nullable NSArray<NSString*>*)tensorStringDataWithError:(NSError**)error {
try {
const auto tensorTypeAndShapeInfo = _typeInfo->GetTensorTypeAndShapeInfo();
if (!tensorTypeAndShapeInfo) {
ORT_CXX_API_THROW("ORTValue is not a tensor.", ORT_RUNTIME_EXCEPTION);
}
const size_t elementCount = tensorTypeAndShapeInfo.GetElementCount();
const size_t tensorStringDataLength = _value->GetStringTensorDataLength();
std::vector<char> tensorStringData(tensorStringDataLength, '\0');