blob: af9ecee1574c09413a5d1e3d9438c1c7c02dbf97 [file] [log] [blame]
Michalis Spyrou27c9efb2017-10-09 15:46:30 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/graph/nodes/DequantizationLayer.h"
25
Michalis Spyroued194b12017-10-31 15:04:34 +000026#include "arm_compute/graph/Error.h"
Michalis Spyrou27c9efb2017-10-09 15:46:30 +010027#include "arm_compute/graph/NodeContext.h"
28#include "arm_compute/graph/OperationRegistry.h"
29
30using namespace arm_compute::graph;
31
32std::unique_ptr<arm_compute::IFunction> DequantizationLayer::instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output)
33{
Michalis Spyroued194b12017-10-31 15:04:34 +000034 ARM_COMPUTE_ERROR_ON_UNALLOCATED_TENSOR_OBJECT(input, output);
Michalis Spyrou27c9efb2017-10-09 15:46:30 +010035
36 _target_hint = ctx.hints().target_hint();
37 arm_compute::ITensor *in = input->tensor();
38 arm_compute::ITensor *out = output->tensor();
39
40 if(_min_max.tensor() == nullptr)
41 {
42 TensorShape shape = in->info()->tensor_shape();
43 shape.set(Window::DimX, 2);
44 shape.remove_dimension(1);
45 shape.remove_dimension(1);
46
47 _min_max.set_info(TensorInfo(shape, in->info()->num_channels(), DataType::F32));
48 _min_max.set_target(_target_hint);
49 }
50
51 bool minmax_is_loaded = _min_max.tensor() != nullptr;
52
53 // Create node context
54 NodeContext node_ctx(OperationType::DequantizationLayer);
55 node_ctx.set_target(_target_hint);
56 node_ctx.add_input(in);
57 node_ctx.add_output(_min_max.tensor());
58 node_ctx.add_output(out);
59
60 // Fill min max
61 if(!minmax_is_loaded)
62 {
63 _min_max.allocate_and_fill_if_needed();
64 }
65
66 // Get function
67 return OperationRegistry::get().find_operation(OperationType::DequantizationLayer, _target_hint)->configure(node_ctx);
68}