2 * Copyright (c) 2019 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.
18 * Copyright (c) 2019 ARM Limited.
20 * SPDX-License-Identifier: MIT
22 * Permission is hereby granted, free of charge, to any person obtaining a copy
23 * of this software and associated documentation files (the "Software"), to
24 * deal in the Software without restriction, including without limitation the
25 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
26 * sell copies of the Software, and to permit persons to whom the Software is
27 * furnished to do so, subject to the following conditions:
29 * The above copyright notice and this permission notice shall be included in all
30 * copies or substantial portions of the Software.
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41 #include "arm_compute/runtime/NEON/functions/NEInstanceNormalizationLayerEx.h"
43 #include "arm_compute/core/Helpers.h"
44 #include "arm_compute/runtime/NEON/NEScheduler.h"
48 NEInstanceNormalizationLayerEx::NEInstanceNormalizationLayerEx(
49 std::shared_ptr<IMemoryManager> memory_manager)
50 : _memory_group(std::move(memory_manager)), _normalization_kernel(), _is_nchw(false),
51 _permute_input(), _permute_output(), _permuted_input(), _permuted_output()
55 void NEInstanceNormalizationLayerEx::configure(ITensor *input, ITensor *output, ITensor *gamma,
56 ITensor *beta, float epsilon)
58 const DataLayout data_layout = input->info()->data_layout();
61 _is_nchw = data_layout == DataLayout::NCHW;
65 _memory_group.manage(&_permuted_input);
66 _memory_group.manage(&_permuted_output);
68 // Configure the function to transform the input tensor from NHWC -> NCHW
69 _permute_input.configure(input, &_permuted_input, PermutationVector(1U, 2U, 0U));
70 _permuted_input.info()->set_data_layout(DataLayout::NCHW);
72 _normalization_kernel.configure(&_permuted_input, &_permuted_output, gamma, beta, epsilon);
73 _permuted_output.info()->set_data_layout(DataLayout::NCHW);
75 _permute_output.configure(&_permuted_output, output != nullptr ? output : input,
76 PermutationVector(2U, 0U, 1U));
77 _permuted_input.allocator()->allocate();
78 _permuted_output.allocator()->allocate();
82 _normalization_kernel.configure(input, output, gamma, beta, epsilon);
86 Status NEInstanceNormalizationLayerEx::validate(const ITensorInfo *input, const ITensorInfo *output,
87 const ITensorInfo *gamma, const ITensorInfo *beta,
90 return NEInstanceNormalizationLayerKernelEx::validate(
91 &input->clone()->set_data_layout(DataLayout::NCHW),
92 &output->clone()->set_data_layout(DataLayout::NCHW), gamma, beta, epsilon);
95 void NEInstanceNormalizationLayerEx::run()
97 MemoryGroupResourceScope scope_mg(_memory_group);
102 _permute_input.run();
105 NEScheduler::get().schedule(&_normalization_kernel, Window::DimZ);
110 _permute_output.run();
113 } // namespace arm_compute