+++ /dev/null
-/*
- * 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.
- */
-
-#include "PadLayer.h"
-#include <arm_compute/runtime/CL/CLScheduler.h>
-#include "internal/arm_compute.h"
-
-void PadLayer::configure(::arm_compute::ITensor *input, ::arm_compute::ITensor *output,
- unsigned int border_width)
-{
- _input = input;
- _output = output;
- _border_width = border_width;
- _output_height = _output->info()->dimension(0);
- _output_width = _output->info()->dimension(1);
-
- uint8_t constant_border_value = 0;
- ::arm_compute::PixelValue constant_pixel_value = ::arm_compute::PixelValue(constant_border_value);
-
- unsigned int padding_size = _border_width;
- input->info()->extend_padding(::arm_compute::PaddingSize{padding_size});
- if (::internal::arm_compute::isGpuMode())
- {
- _fillborderkernel.configure(CAST_CL(input), _border_width, ::arm_compute::BorderMode::CONSTANT,
- constant_pixel_value);
- }
- else
- {
- _nefillborderkernel.configure(input, _border_width, ::arm_compute::BorderMode::CONSTANT,
- constant_pixel_value);
- }
-}
-
-void PadLayer::run(void)
-{
- if (::internal::arm_compute::isGpuMode())
- {
- _fillborderkernel.run();
- }
- else
- {
- _nefillborderkernel.run();
- }
-
- ::arm_compute::Coordinates coordinates =
- ::arm_compute::Coordinates(-_border_width, -_border_width);
- ::arm_compute::TensorShape new_tensor_shape =
- ::arm_compute::TensorShape(_output_height, _output_width);
-
- /* NOTE: The cl kernel fills the data in the borders(not in the tensor).
- Once the tensor is received back at NNAPI, we are adjusting
- the valid region in such a way that the padding becomes part of the tensor itself
- and matches the size of output. */
- _input->info()->set_valid_region(::arm_compute::ValidRegion(coordinates, new_tensor_shape));
-
- /* NOTE: Since cl kernel does not have an argument for output tensor while NNAPI does.
- We need to map the input (tensor that is passed to the cl kernel) back to
- output. */
-
- // TODO: Write a modified CLCopy kernel to do this job.
- populateOutput();
-}
-
-void PadLayer::populateOutput()
-{
- auto &queue = ::arm_compute::CLScheduler::get().queue();
- if (::internal::arm_compute::isGpuMode())
- {
- CAST_CL(_input)->map(queue);
- CAST_CL(_output)->map(queue);
- }
-
- auto input_tensor = static_cast<::arm_compute::ITensor *>(_input);
- auto const source_data = input_tensor->buffer();
-
- auto output_tensor = static_cast<::arm_compute::ITensor *>(_output);
- auto dst_data = output_tensor->buffer();
-
- memmove(dst_data, source_data, _output_height * _output_width * 4);
-
- if (::internal::arm_compute::isGpuMode())
- {
- CAST_CL(_input)->unmap(queue);
- CAST_CL(_output)->unmap(queue);
- }
-}
+++ /dev/null
-/*
- * 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.
- */
-
-/**
- * @file PadLayer.h
- * @brief This file contains PadLayer class
- * @ingroup COM_AI_RUNTIME
- */
-
-#ifndef __PAD_LAYER_H__
-#define __PAD_LAYER_H__
-
-#include <arm_compute/runtime/Tensor.h>
-#include <arm_compute/runtime/CL/CLTensor.h>
-#include <arm_compute/runtime/CL/functions/CLFillBorder.h>
-#include <arm_compute/runtime/NEON/functions/NEFillBorder.h>
-
-class PadLayer : public ::arm_compute::IFunction
-{
-public:
- PadLayer(void)
- : _input(nullptr), _output(nullptr), _border_width(0), _output_height(0), _output_width(0),
- _fillborderkernel{}, _nefillborderkernel{}
- {
- // DO NOTHING
- }
-
- /**
- * @brief Configure the layer
- * @param[in] input The source tensor
- * @param[in] output The destination tensor
- * @param[in] border_width The padding size
- * @return N/A
- */
- void configure(::arm_compute::ITensor *input, ::arm_compute::ITensor *output,
- unsigned int border_width);
- /**
- * @brief Run the operation. Must be called after configure().
- * @return N/A
- */
- void run(void) override;
-
-private:
- ::arm_compute::ITensor *_input;
- ::arm_compute::ITensor *_output;
- int _border_width;
- int _output_height;
- int _output_width;
-
- ::arm_compute::CLFillBorder _fillborderkernel;
- ::arm_compute::NEFillBorder _nefillborderkernel;
- /**
- * @brief Copy the data to output
- * @return N/A
- */
- void populateOutput();
-};
-
-#endif // __PAD_LAYER_H__