From 5268ee5ffd175545c651d6e35209f077f817ee95 Mon Sep 17 00:00:00 2001 From: Scott McKay Date: Fri, 26 Jan 2024 15:42:24 +1000 Subject: [PATCH] Pickup some more linux build changes --- .../coreml/builders/impl/activation_op_builder.cc | 4 ++-- .../coreml/builders/impl/base_op_builder.cc | 4 ++-- .../coreml/builders/impl/base_op_builder.h | 11 ++++++----- .../coreml/builders/impl/builder_utils.cc | 14 +++++++------- .../providers/coreml/builders/impl/builder_utils.h | 2 +- .../core/providers/coreml/builders/op_builder.h | 2 +- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/onnxruntime/core/providers/coreml/builders/impl/activation_op_builder.cc b/onnxruntime/core/providers/coreml/builders/impl/activation_op_builder.cc index e85e67bab6b21..a6580c87eeb10 100644 --- a/onnxruntime/core/providers/coreml/builders/impl/activation_op_builder.cc +++ b/onnxruntime/core/providers/coreml/builders/impl/activation_op_builder.cc @@ -21,14 +21,14 @@ namespace coreml { class ActivationOpBuilder : public BaseOpBuilder { // Add operator related - // #ifdef __APPLE__OR__TEST__ +#ifdef __APPLE__OR__TEST__ public: void AddInitializersToSkip(ModelBuilder& model_builder, const Node& node) const override; private: Status AddToModelBuilderImpl(ModelBuilder& model_builder, const Node& node, const logging::Logger& logger) const override; - // #endif +#endif // Operator support related private: diff --git a/onnxruntime/core/providers/coreml/builders/impl/base_op_builder.cc b/onnxruntime/core/providers/coreml/builders/impl/base_op_builder.cc index 1f3f4c3901704..f950910ef7815 100644 --- a/onnxruntime/core/providers/coreml/builders/impl/base_op_builder.cc +++ b/onnxruntime/core/providers/coreml/builders/impl/base_op_builder.cc @@ -42,7 +42,7 @@ bool HasExternalInitializer(const InitializedTensorSet& initializers, const Node } // namespace // Add operator related -// #if defined(__APPLE__OR__TEST__) || defined(__linux__) +#if defined(__APPLE__OR__TEST__) Status BaseOpBuilder::AddToModelBuilder(ModelBuilder& model_builder, const Node& node, const logging::Logger& logger) const { Status status = AddToModelBuilderImpl(model_builder, node, logger); @@ -54,7 +54,7 @@ Status BaseOpBuilder::AddToModelBuilder(ModelBuilder& model_builder, const Node& return status; } -// #endif +#endif // Operator support related diff --git a/onnxruntime/core/providers/coreml/builders/impl/base_op_builder.h b/onnxruntime/core/providers/coreml/builders/impl/base_op_builder.h index 53709eebf8d7c..c9467ec1616c2 100644 --- a/onnxruntime/core/providers/coreml/builders/impl/base_op_builder.h +++ b/onnxruntime/core/providers/coreml/builders/impl/base_op_builder.h @@ -19,23 +19,22 @@ class BaseOpBuilder : public IOpBuilder { public: virtual ~BaseOpBuilder() = default; - // Add operator related + bool SupportsMLProgram() const override { return false; } -#if defined(__APPLE__OR__TEST__) + // Add operator related public: bool IsOpSupported(const Node& node, const OpBuilderInputParams& input_params, const logging::Logger& logger) const override final; +#if defined(__APPLE__OR__TEST__) Status AddToModelBuilder(ModelBuilder& model_builder, const Node& node, const logging::Logger& logger) const override final; void AddInitializersToSkip(ModelBuilder& /*model_builder*/, const Node& /*node*/) const override {} - bool SupportsMLProgram() const override { return false; } - - protected: #endif + protected: // check if the first input is supported. used for static bool IsInput0Supported(const Node& node, const OpBuilderInputParams& input_params, const logging::Logger& logger); @@ -57,8 +56,10 @@ class BaseOpBuilder : public IOpBuilder { bool HasSupportedInputs(const Node& node, const OpBuilderInputParams& input_params, const logging::Logger& logger) const; +#if defined(__APPLE__OR__TEST__) virtual Status AddToModelBuilderImpl(ModelBuilder& model_builder, const Node& node, const logging::Logger& logger) const = 0; +#endif }; } // namespace coreml diff --git a/onnxruntime/core/providers/coreml/builders/impl/builder_utils.cc b/onnxruntime/core/providers/coreml/builders/impl/builder_utils.cc index 9c03b29a7817b..77f4750dc240e 100644 --- a/onnxruntime/core/providers/coreml/builders/impl/builder_utils.cc +++ b/onnxruntime/core/providers/coreml/builders/impl/builder_utils.cc @@ -169,24 +169,24 @@ void CopyDataToTensorValue(MILSpec::TensorValue& tensor_value, const gsl::span && false_for_T, "Unsupported data type"); // add specializations below as needed } -template <> -void CopyDataToTensorValue(MILSpec::TensorValue& tensor_value, const gsl::span& data) { - tensor_value.mutable_floats()->mutable_values()->Add(data.begin(), data.end()); -}; +// template <> +// void CopyDataToTensorValue(MILSpec::TensorValue& tensor_value, const gsl::span data) { +// tensor_value.mutable_floats()->mutable_values()->Add(data.begin(), data.end()); +// }; template <> -void CopyDataToTensorValue(MILSpec::TensorValue& tensor_value, const gsl::span& data) { +void CopyDataToTensorValue(MILSpec::TensorValue& tensor_value, const gsl::span data) { tensor_value.mutable_ints()->mutable_values()->Add(data.begin(), data.end()); }; template <> -void CopyDataToTensorValue(MILSpec::TensorValue& tensor_value, const gsl::span& data) { +void CopyDataToTensorValue(MILSpec::TensorValue& tensor_value, const gsl::span data) { tensor_value.mutable_strings()->mutable_values()->Add(data.begin(), data.end()); }; // copy int64_t (used by ONNX for strides/indexes/etc.) to int32_t (used by CoreML) template <> -void CopyDataToTensorValue(MILSpec::TensorValue& tensor_value, const gsl::span& data) { +void CopyDataToTensorValue(MILSpec::TensorValue& tensor_value, const gsl::span data) { auto& int32_out = *tensor_value.mutable_ints()->mutable_values(); int32_out.Reserve(narrow(data.size())); for (const int64_t v : data) { diff --git a/onnxruntime/core/providers/coreml/builders/impl/builder_utils.h b/onnxruntime/core/providers/coreml/builders/impl/builder_utils.h index aae3cb8e50eeb..6d6eea0cda010 100644 --- a/onnxruntime/core/providers/coreml/builders/impl/builder_utils.h +++ b/onnxruntime/core/providers/coreml/builders/impl/builder_utils.h @@ -116,7 +116,7 @@ std::vector GetCoreMLShape(const gsl::span dims); /// New TensorValue template COREML_SPEC::MILSpec::Value CreateTensorValue(const gsl::span data, - std::optional> shape = nullopt); + std::optional> shape = std::nullopt); template COREML_SPEC::MILSpec::Value CreateScalarTensorValue(const T& data); diff --git a/onnxruntime/core/providers/coreml/builders/op_builder.h b/onnxruntime/core/providers/coreml/builders/op_builder.h index 6f8d357b8f0fb..3b0dbcebb8689 100644 --- a/onnxruntime/core/providers/coreml/builders/op_builder.h +++ b/onnxruntime/core/providers/coreml/builders/op_builder.h @@ -31,7 +31,7 @@ class IOpBuilder { virtual ~IOpBuilder() = default; // Add operator related -#if defined(__APPLE__OR__TEST__) || defined(__linux__) +#if defined(__APPLE__OR__TEST__) // Check if the initializers of this operator need preprocess // which will not be copied virtual void AddInitializersToSkip(ModelBuilder& model_builder, const Node& node) const = 0;