diff options
author | Chunseok Lee <chunseok.lee@samsung.com> | 2020-03-05 15:10:09 +0900 |
---|---|---|
committer | Chunseok Lee <chunseok.lee@samsung.com> | 2020-03-05 15:22:53 +0900 |
commit | d91a039e0eda6fd70dcd22672b8ce1817c1ca50e (patch) | |
tree | 62668ec548cf31fadbbf4e99522999ad13434a25 /runtimes/neurun/backend/srcn/kernel/OperationUtils.cc | |
parent | bd11b24234d7d43dfe05a81c520aa01ffad06e42 (diff) | |
download | nnfw-d91a039e0eda6fd70dcd22672b8ce1817c1ca50e.tar.gz nnfw-d91a039e0eda6fd70dcd22672b8ce1817c1ca50e.tar.bz2 nnfw-d91a039e0eda6fd70dcd22672b8ce1817c1ca50e.zip |
catch up to tizen_5.5 and remove unness dir
- update to tizen_5.5
- remove dirs
Diffstat (limited to 'runtimes/neurun/backend/srcn/kernel/OperationUtils.cc')
-rw-r--r-- | runtimes/neurun/backend/srcn/kernel/OperationUtils.cc | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/runtimes/neurun/backend/srcn/kernel/OperationUtils.cc b/runtimes/neurun/backend/srcn/kernel/OperationUtils.cc new file mode 100644 index 000000000..0df0f7b33 --- /dev/null +++ b/runtimes/neurun/backend/srcn/kernel/OperationUtils.cc @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "OperationUtils.h" + +#include <cmath> +#include <algorithm> +#include <cassert> + +#include "util/Utils.h" + +namespace neurun +{ +namespace backend +{ +namespace srcn +{ +namespace kernel +{ + +uint32_t MatchingDim(const Shape &shape1, int index1, const Shape &shape2, int index2) +{ + UNUSED_RELEASE(shape2); + UNUSED_RELEASE(index2); + assert(shape1.dimensions[index1] == shape2.dimensions[index2]); + return shape1.dimensions[index1]; +} + +Coordinates convertCoordinates(const Coordinates &from_coordinates, FilterLayout from_layout, + FilterLayout to_layout) +{ + assert(from_coordinates.size() == 4); + Coordinates to{from_coordinates}; + if (from_layout == FilterLayout::OHWI && to_layout == FilterLayout::HWOI) + { + to.set(0, from_coordinates[1]); + to.set(1, from_coordinates[2]); + to.set(2, from_coordinates[0]); + to.set(3, from_coordinates[3]); + } + else + { + throw std::runtime_error{"NYI"}; + } + + return to; +} + +Shape getShape(const ::neurun::model::Operand &o, ::neurun::model::Layout frontend_layout) +{ + Shape shape; + + auto dims = o.shape().dims(); + if (frontend_layout == ::neurun::model::Layout::NCHW && o.shape().rank() == 4) + { + // NCHW -> NHWC + uint32_t permutation[4] = {0, 2, 3, 1}; + for (int i = 0; i < o.shape().rank(); ++i) + { + dims.at(i) = o.shape().dim(permutation[i]); + } + } + shape.dimensions = std::vector<uint32_t>(dims.begin(), dims.end()); + shape.type = static_cast<OperandType>(static_cast<int32_t>(o.typeInfo().type())); + shape.scale = o.typeInfo().scale(); + shape.offset = o.typeInfo().offset(); + + // CPU backend assume that neurun internal shape's rank is always same or less than 4 + assert(shape.dimensions.size() <= 4); + + return shape; +} + +} // namespace kernel +} // namespace srcn +} // namespace backend +} // namespace neurun |