Skip to content

Commit

Permalink
Pickup some more linux build changes
Browse files Browse the repository at this point in the history
  • Loading branch information
skottmckay committed Jan 26, 2024
1 parent 3eb3e99 commit 5268ee5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -54,7 +54,7 @@ Status BaseOpBuilder::AddToModelBuilder(ModelBuilder& model_builder, const Node&
return status;
}

// #endif
#endif

// Operator support related

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions onnxruntime/core/providers/coreml/builders/impl/builder_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,24 @@ void CopyDataToTensorValue(MILSpec::TensorValue& tensor_value, const gsl::span<c
static_assert(false_for_T<T1> && false_for_T<T2>, "Unsupported data type"); // add specializations below as needed
}

template <>
void CopyDataToTensorValue<float>(MILSpec::TensorValue& tensor_value, const gsl::span<const float>& data) {
tensor_value.mutable_floats()->mutable_values()->Add(data.begin(), data.end());
};
// template <>
// void CopyDataToTensorValue<float>(MILSpec::TensorValue& tensor_value, const gsl::span<const float> data) {
// tensor_value.mutable_floats()->mutable_values()->Add(data.begin(), data.end());
// };

template <>
void CopyDataToTensorValue<int32_t>(MILSpec::TensorValue& tensor_value, const gsl::span<const int32_t>& data) {
void CopyDataToTensorValue<int32_t>(MILSpec::TensorValue& tensor_value, const gsl::span<const int32_t> data) {
tensor_value.mutable_ints()->mutable_values()->Add(data.begin(), data.end());
};

template <>
void CopyDataToTensorValue<std::string>(MILSpec::TensorValue& tensor_value, const gsl::span<const std::string>& data) {
void CopyDataToTensorValue<std::string>(MILSpec::TensorValue& tensor_value, const gsl::span<const std::string> 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<int64_t, int32_t>(MILSpec::TensorValue& tensor_value, const gsl::span<const int64_t>& data) {
void CopyDataToTensorValue<int64_t, int32_t>(MILSpec::TensorValue& tensor_value, const gsl::span<const int64_t> data) {
auto& int32_out = *tensor_value.mutable_ints()->mutable_values();
int32_out.Reserve(narrow<int32_t>(data.size()));
for (const int64_t v : data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ std::vector<int32_t> GetCoreMLShape(const gsl::span<const int64_t> dims);
/// <returns>New TensorValue</returns>
template <typename T1, typename T2 = T1>
COREML_SPEC::MILSpec::Value CreateTensorValue(const gsl::span<const T1> data,
std::optional<const gsl::span<const int32_t>> shape = nullopt);
std::optional<const gsl::span<const int32_t>> shape = std::nullopt);

template <typename T>
COREML_SPEC::MILSpec::Value CreateScalarTensorValue(const T& data);
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/providers/coreml/builders/op_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5268ee5

Please sign in to comment.