summaryrefslogtreecommitdiff
path: root/runtimes/neurun/src/exec/Source.h
diff options
context:
space:
mode:
Diffstat (limited to 'runtimes/neurun/src/exec/Source.h')
-rw-r--r--runtimes/neurun/src/exec/Source.h139
1 files changed, 0 insertions, 139 deletions
diff --git a/runtimes/neurun/src/exec/Source.h b/runtimes/neurun/src/exec/Source.h
deleted file mode 100644
index 169f8b386..000000000
--- a/runtimes/neurun/src/exec/Source.h
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) 2018 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.
- */
-
-#ifndef __NEURUN_EXEC_SOURCE_H__
-#define __NEURUN_EXEC_SOURCE_H__
-
-#include <cassert>
-
-#include "cpp14/memory.h"
-#include "util/feature/nchw/View.h"
-#include "util/feature/nhwc/Reader.h"
-#include "util/feature/Coordinate4D.h"
-#include <misc/feature/IndexIterator.h>
-
-namespace neurun
-{
-namespace exec
-{
-
-struct ISource
-{
- virtual ~ISource() = default;
-
- virtual void push(::neurun::backend::operand::ITensor &tensor) const = 0;
-};
-
-template <typename T> class Source final : public ISource
-{
-public:
- Source(const T *base, const size_t size) : _base{base}, _size{size} {}
-
-public:
- void push(::neurun::backend::operand::ITensor &tensor) const override
- {
- memcpy(tensor.buffer(), _base, _size);
- }
-
-private:
- const T *const _base;
- const size_t _size;
-};
-
-class PermutateSource final : public ISource
-{
-public:
- PermutateSource(const void *input_buffer, const size_t &input_size,
- const model::operand::Shape &shape)
- : _input_buffer{(uint8_t *)input_buffer}, _input_size{input_size}, _shape{shape}
- {
- }
-
-public:
- void push(neurun::backend::operand::ITensor &tensor) const override
- {
- // do NHWC_TO_NCHW permutation
- auto output_buffer = tensor.buffer();
- auto rank = _shape.rank();
-
- switch (rank)
- {
- case 0:
- case 1:
- {
- memcpy(output_buffer, _input_buffer, _input_size);
- break;
- }
- case 2:
- {
- auto matrix_shape = _shape.asMatrix();
-
- for (auto h = 0; h < matrix_shape.H; ++h)
- {
- neurun::util::feature::Coordinate4D coord{0, h, 0, 0};
- memcpy(output_buffer + tensor.calcOffset(coord), _input_buffer + h * matrix_shape.W,
- matrix_shape.W * sizeof(float));
- }
- break;
- }
- case 3:
- {
- const int32_t depth = _shape.dim(0);
- const int32_t height = _shape.dim(1);
- const int32_t width = _shape.dim(2);
-
- for (auto c = 0; c < depth; ++c)
- {
- for (auto h = 0; h < height; ++h)
- {
- neurun::util::feature::Coordinate4D coord{0, h, 0, c};
- memcpy(output_buffer + tensor.calcOffset(coord),
- _input_buffer + c * height * width + h * width, width * sizeof(float));
- }
- }
- break;
- }
- case 4:
- {
- auto feature = _shape.asFeature();
-
- const util::feature::nhwc::Reader<float> from{
- feature, reinterpret_cast<const float *>(_input_buffer), _input_size};
- util::feature::nchw::View<float> into{&tensor};
-
- ::nnfw::misc::feature::iterate(feature)
- << [&](uint32_t batch, uint32_t ch, uint32_t row, uint32_t col) {
- const auto value = from.at(batch, ch, row, col);
- into.at(batch, ch, row, col) = value;
- };
- break;
- }
- default:
- throw "NYI";
- break;
- }
- }
-
-private:
- const uint8_t *_input_buffer;
- const size_t _input_size;
- const model::operand::Shape _shape;
-};
-
-} // namespace exec
-} // namespace neurun
-
-#endif // __NEURUN_EXEC_SOURCE_H__