Support CoreML for macOS (#151)

This commit is contained in:
Fangjun Kuang
2023-05-12 15:57:44 +08:00
committed by GitHub
parent de1880948b
commit cea718e3d8
22 changed files with 216 additions and 87 deletions

View File

@@ -6,7 +6,6 @@
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <utility>
@@ -36,7 +35,7 @@ template <typename T /*=float*/>
Ort::Value Stack(OrtAllocator *allocator,
const std::vector<const Ort::Value *> &values, int32_t dim) {
std::vector<int64_t> v0_shape =
values[0]->GetTensorTypeAndShapeInfo().GetShape();
values[0]->GetTensorTypeAndShapeInfo().GetShape();
for (int32_t i = 1; i != static_cast<int32_t>(values.size()); ++i) {
auto s = values[i]->GetTensorTypeAndShapeInfo().GetShape();
@@ -58,21 +57,17 @@ Ort::Value Stack(OrtAllocator *allocator,
ans_shape.reserve(v0_shape.size() + 1);
ans_shape.insert(ans_shape.end(), v0_shape.data(), v0_shape.data() + dim);
ans_shape.push_back(values.size());
ans_shape.insert(
ans_shape.end(),
v0_shape.data() + dim,
v0_shape.data() + v0_shape.size());
ans_shape.insert(ans_shape.end(), v0_shape.data() + dim,
v0_shape.data() + v0_shape.size());
auto leading_size = static_cast<int32_t>(std::accumulate(
v0_shape.begin(), v0_shape.begin() + dim, 1, std::multiplies<int64_t>()));
v0_shape.begin(), v0_shape.begin() + dim, 1, std::multiplies<int64_t>()));
auto trailing_size = static_cast<int32_t>(
std::accumulate(v0_shape.begin() + dim,
v0_shape.end(), 1,
std::multiplies<int64_t>()));
auto trailing_size = static_cast<int32_t>(std::accumulate(
v0_shape.begin() + dim, v0_shape.end(), 1, std::multiplies<int64_t>()));
Ort::Value ans = Ort::Value::CreateTensor<T>(
allocator, ans_shape.data(), ans_shape.size());
Ort::Value ans = Ort::Value::CreateTensor<T>(allocator, ans_shape.data(),
ans_shape.size());
T *dst = ans.GetTensorMutableData<T>();
for (int32_t i = 0; i != leading_size; ++i) {
@@ -88,14 +83,12 @@ Ort::Value Stack(OrtAllocator *allocator,
return ans;
}
template Ort::Value Stack<float>(
OrtAllocator *allocator,
const std::vector<const Ort::Value *> &values,
int32_t dim);
template Ort::Value Stack<float>(OrtAllocator *allocator,
const std::vector<const Ort::Value *> &values,
int32_t dim);
template Ort::Value Stack<int64_t>(
OrtAllocator *allocator,
const std::vector<const Ort::Value *> &values,
int32_t dim);
OrtAllocator *allocator, const std::vector<const Ort::Value *> &values,
int32_t dim);
} // namespace sherpa_onnx