blob: f0359ecc759ce889861fb88516d8be52a115173d [file] [log] [blame]
Giorgio Arena657bdb32018-04-26 18:52:01 +01001/*
Michalis Spyrou1a569a32019-09-10 17:20:34 +01002 * Copyright (c) 2018-2019 ARM Limited.
Giorgio Arena657bdb32018-04-26 18:52:01 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CLCONVERTFULLYCONNECTEDWEIGHTS_H
25#define ARM_COMPUTE_CLCONVERTFULLYCONNECTEDWEIGHTS_H
Giorgio Arena657bdb32018-04-26 18:52:01 +010026
27#include "arm_compute/core/CL/kernels/CLConvertFullyConnectedWeightsKernel.h"
Michalis Spyroub27e13a2019-09-27 11:04:27 +010028#include "arm_compute/runtime/CL/CLTensor.h"
Giorgio Arena657bdb32018-04-26 18:52:01 +010029#include "arm_compute/runtime/CL/ICLSimpleFunction.h"
Michalis Spyroub27e13a2019-09-27 11:04:27 +010030#include "arm_compute/runtime/ITransformWeights.h"
Giorgio Arena657bdb32018-04-26 18:52:01 +010031
32namespace arm_compute
33{
34class ICLTensor;
35
36/** Basic function to run @ref CLConvertFullyConnectedWeightsKernel. */
37class CLConvertFullyConnectedWeights : public ICLSimpleFunction
38{
39public:
40 /** Initialize the function.
41 *
Vidhya Sudhan Loganathanf4cb81b2018-07-04 15:13:14 +010042 * @param[in] input Source weights tensor to convert. Must be 2 dimensional. Data types supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32.
Giorgio Arena657bdb32018-04-26 18:52:01 +010043 * @param[out] output The converted weights tensor. Shape and Data Type: Same as @p input.
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +010044 * @param[in] original_input_shape Shape of the original input tensor (the one entering fully connected layer).
Giorgio Arena657bdb32018-04-26 18:52:01 +010045 * @param[in] data_layout The data layout the weights have been trained in.
Michalis Spyrou1a569a32019-09-10 17:20:34 +010046 *
47 * @return A status
Giorgio Arena657bdb32018-04-26 18:52:01 +010048 */
49 void configure(const ICLTensor *input, ICLTensor *output, const TensorShape &original_input_shape, DataLayout data_layout);
50 /** Static function to check if given info will lead to a valid configuration of @ref CLConvertFullyConnectedWeights
51 *
Vidhya Sudhan Loganathanf4cb81b2018-07-04 15:13:14 +010052 * @param[in] input Source weights tensor info to convert. Must be 2 dimensional. Data types supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32.
Giorgio Arena657bdb32018-04-26 18:52:01 +010053 * @param[in] output The converted weights tensor info. Shape and Data Type: Same as @p input.
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +010054 * @param[in] original_input_shape Shape of the original input tensor (the one entering fully connected layer).
Giorgio Arena657bdb32018-04-26 18:52:01 +010055 * @param[in] data_layout The data layout the weights have been trained in.
56 */
57 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const TensorShape &original_input_shape, DataLayout data_layout);
58};
Michalis Spyroub27e13a2019-09-27 11:04:27 +010059
60namespace weights_transformations
61{
62/** Basic function to run @ref CLConvertFullyConnectedWeightsKernel. */
63class CLConvertFullyConnectedWeightsManaged : public ITransformWeights
64{
65public:
66 //Inherited method override
67 void run() override
68 {
69 _output.allocator()->allocate();
70 _func.run();
71 _reshape_run = true;
72 }
73
74 //Inherited method override
75 void release() override
76 {
77 _output.allocator()->free();
78 }
79
80 //Inherited method override
81 ICLTensor *get_weights() override
82 {
83 return &_output;
84 }
85
86 //Inherited method override
87 uint32_t uid() override
88 {
89 return _uid;
90 }
91 /** Configures the @ref CLConvertFullyConnectedWeights function
92 *
93 * @param[in] input Source weights tensor info to convert. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32.
94 * @param[in] original_input_shape Shape of the original input tensor (the one entering fully connected layer).
95 * @param[in] data_layout The data layout the weights have been trained in.
96 */
97 void configure(const ICLTensor *input, const TensorShape &original_input_shape, DataLayout data_layout)
98 {
99 _func.configure(input, &_output, original_input_shape, data_layout);
100 }
101
102private:
103 static constexpr uint32_t _uid = 0x5;
104 CLTensor _output{};
105 CLConvertFullyConnectedWeights _func{};
106};
107} // namespace weights_transformations
Giorgio Arena657bdb32018-04-26 18:52:01 +0100108} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000109#endif /* ARM_COMPUTE_CLCONVERTFULLYCONNECTEDWEIGHTS_H */