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 const auto input_shape = getShape(_input);
41 const auto output_shape = getShape(_output);
42 auto op_params = nnfw::cker::buildStridedSliceParams(
43 getBuffer<uint32_t>(_begin), getBuffer<uint32_t>(_end), getBuffer<uint32_t>(_strides),
44 _begin_mask, _end_mask, _shrink_axis_mask, input_shape.DimensionsCount());
46 nnfw::cker::checkOutputSize(op_params, input_shape, output_shape, input_shape.DimensionsCount());
48 nnfw::cker::StridedSlice(op_params, input_shape, getBuffer<T>(_input), output_shape,
49 getBuffer<T>(_output));
52 void StridedSliceLayer::configure(const IPortableTensor *input, const IPortableTensor *begin,
53 const IPortableTensor *end, const IPortableTensor *strides,
54 IPortableTensor *output, const int32_t begin_mask,
55 const int32_t end_mask, const int32_t shrink_axis_mask)
63 _begin_mask = begin_mask;
67 _shrink_axis_mask = shrink_axis_mask;
70 void StridedSliceLayer::run()
72 if (_input->data_type() == OperandType::FLOAT32)
74 stridedSliceImpl<float>();
76 else if (_input->data_type() == OperandType::INT32)
78 stridedSliceImpl<int32_t>();
80 else if (_input->data_type() == OperandType::INT64)
82 stridedSliceImpl<int64_t>();
86 throw std::runtime_error{"StridedSlice: unsupported data type"};
92 } // namespace backend