From d539da24979106b9ee6fa3dda30e70a5ffd5ee8f Mon Sep 17 00:00:00 2001 From: wejoncy Date: Tue, 10 Dec 2024 20:25:48 +0800 Subject: [PATCH] t --- .../core/providers/coreml/model/model.mm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/onnxruntime/core/providers/coreml/model/model.mm b/onnxruntime/core/providers/coreml/model/model.mm index 9c1343e4cd36c..45c94f07cd49c 100644 --- a/onnxruntime/core/providers/coreml/model/model.mm +++ b/onnxruntime/core/providers/coreml/model/model.mm @@ -303,7 +303,6 @@ Status GetMLMultiArrayCopyInfo(const MLMultiArray* _Nonnull array, // since macos(14.4), ios(17.4), MLComputePlan is introduced in // Otherwise, the compiler will complain `MLComputePlan` is not defined. -// we define __clang_analyzer__ here is for bypass static analysis #if __has_include() #define HAS_COREMLPLAN 1 #else @@ -331,7 +330,6 @@ void ProfileBlock(MLComputePlan* _Nullable computePlan, MLModelStructureProgramB // since macos(14.4), ios(17.4), MLComputePlan is introduced in // Otherwise, the compiler will complain `MLComputePlan` is not defined. -// we define __clang_analyzer__ here is for bypass static analysis API_AVAILABLE(macos(14.4), ios(17.4), tvos(17.4), watchos(10.4)) void ProfileComputePlan(NSURL* compileUrl, MLModelConfiguration* config) { #if HAS_COREMLPLAN @@ -365,9 +363,15 @@ void ProfileComputePlan(NSURL* compileUrl, MLModelConfiguration* config) { #endif } +#if __has_include() +#define HAS_COREMLOPTIMIZATIONHINT 1 +#else +#define HAS_COREMLOPTIMIZATIONHINT 0 +#endif + API_AVAILABLE_COREML8 void ConfigureOptimizationHints(MLModelConfiguration* config, const CoreMLOptions& coreml_options) { -#if !defined(__clang_analyzer__) +#if HAS_COREMLOPTIMIZATIONHINT MLOptimizationHints* optimizationHints = [[MLOptimizationHints alloc] init]; if (coreml_options.UseStrategy("FastPrediction")) { optimizationHints.specializationStrategy = MLSpecializationStrategyFastPrediction; @@ -388,7 +392,7 @@ Status CompileOrReadCachedModel(NSURL* modelUrl, const CoreMLOptions& coreml_opt cached_model_base_url = [cached_model_base_url URLByDeletingLastPathComponent]; } - if ([cached_model_base_url path] == nil) { + if (cached_model_base_url == nil) { return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Error creating cached model URL"); } @@ -397,12 +401,12 @@ Status CompileOrReadCachedModel(NSURL* modelUrl, const CoreMLOptions& coreml_opt // if cached_model_url is existed, just return NSError* error = nil; NSString* cached_model_path = [cached_model_url path]; - NS_ASSUME_NONNULL_BEGIN + if ([[NSFileManager defaultManager] fileExistsAtPath:cached_model_path]) { [compiled_model_path appendString:cached_model_path]; return Status::OK(); } - NS_ASSUME_NONNULL_END + // TODO: Update this to version with callback handler as the API used here is deprecated. // https://developer.apple.com/documentation/coreml/mlmodel/3929553-compilemodelaturl // As we call loadModel during EP Compile there shouldn't be an issue letting the actual compile run in the @@ -535,11 +539,8 @@ Status Predict(const std::unordered_map& inputs, } // Set the specialization strategy to FastPrediction for macOS 10.15+ - // we define __clang_analyzer__ here is for bypass static analysis if (HAS_COREML8_OR_LATER) { -#if !defined(__clang_analyzer__) ConfigureOptimizationHints(config, coreml_options_); -#endif } else { LOGS(logger_, WARNING) << "iOS 17.4+/macOS 14.4+ or later is required to ConfigureOptimizationHints"; }