2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "StridedSliceLayer.h"
19 #include "OperationUtils.h"
21 #include <cker/operation/StridedSlice.h>
32 StridedSliceLayer::StridedSliceLayer()
33 : _input(nullptr), _begin(nullptr), _end(nullptr), _strides(nullptr), _output(nullptr),
34 _begin_mask(0), _ellipsis_mask(0), _end_mask(0), _new_axis_mask(0), _shrink_axis_mask(0)
38 template <typename T> void StridedSliceLayer::stridedSliceImpl()
40 auto op_params = nnfw::cker::buildStridedSliceParams(
41 reinterpret_cast<uint32_t *>(_begin->buffer()), reinterpret_cast<uint32_t *>(_end->buffer()),
42 reinterpret_cast<uint32_t *>(_strides->buffer()), _begin_mask, _end_mask, _shrink_axis_mask,
43 getTensorShape(_input).DimensionsCount());
45 nnfw::cker::checkOutputSize(op_params, getTensorShape(_input), getTensorShape(_output),
46 getTensorShape(_input).DimensionsCount());
48 nnfw::cker::StridedSlice(op_params, getTensorShape(_input),
49 reinterpret_cast<const T *>(_input->buffer()), getTensorShape(_output),
50 reinterpret_cast<T *>(_output->buffer()));
53 void StridedSliceLayer::configure(const IPortableTensor *input, const IPortableTensor *begin,
54 const IPortableTensor *end, const IPortableTensor *strides,
55 IPortableTensor *output, const int32_t begin_mask,
56 const int32_t end_mask, const int32_t shrink_axis_mask)
64 _begin_mask = begin_mask;
68 _shrink_axis_mask = shrink_axis_mask;
71 void StridedSliceLayer::run()
73 if (_input->data_type() == OperandType::FLOAT32)
75 stridedSliceImpl<float>();
77 else if (_input->data_type() == OperandType::INT32)
79 stridedSliceImpl<int32_t>();
81 else if (_input->data_type() == OperandType::INT64)
83 stridedSliceImpl<int64_t>();
87 throw std::runtime_error{"StridedSlice: unsupported data type"};
93 } // namespace backend