Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_ITRANSFORMWEIGHTS_H |
| 25 | #define ARM_COMPUTE_ITRANSFORMWEIGHTS_H |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 26 | |
| 27 | #include <atomic> |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | // Forward declarations |
| 32 | class ITensor; |
| 33 | |
| 34 | /** Weights tensor transform interface |
| 35 | * In order to identify the different reshape functions, each reshape function has |
| 36 | * to generate a unique id. We use the following conversion using an unsigned 32bit value: |
| 37 | * |
| 38 | * Lower two bits store the target: |
| 39 | * 00 -> NEON |
| 40 | * 01 -> CL |
| 41 | * 10 -> GLES |
| 42 | * 11 -> Unused |
| 43 | * |
| 44 | * Five bits store the id of the reshape function: |
| 45 | * 00000 -> FullyConnectedLayerReshapeWeights |
| 46 | * 00001 -> ConvertFullyConnectedWeights |
| 47 | * 00010 -> ConvolutionLayerReshapeWeights |
| 48 | * 00011 -> DepthwiseConvolutionLayerReshapeWeights |
| 49 | * 00100 -> GEMMReshapeLHSMatrixKernel |
| 50 | * 00101 -> GEMMReshapeRHSMatrixKernel |
| 51 | * |
| 52 | * Rest of the bits are used for identifying special cases such as assembly functions and extra |
| 53 | * arguments in the reshape kernels. |
| 54 | * |
| 55 | * */ |
| 56 | class ITransformWeights |
| 57 | { |
| 58 | public: |
| 59 | /** Default Constructor */ |
| 60 | ITransformWeights() = default; |
| 61 | /** Default Destructor */ |
| 62 | virtual ~ITransformWeights() = default; |
| 63 | /** Prevent instances of this class to be copy constructed */ |
| 64 | ITransformWeights(const ITransformWeights &) = delete; |
| 65 | /** Prevent instances of this class to be copied */ |
| 66 | ITransformWeights &operator=(const ITransformWeights &) = delete; |
| 67 | /** Allow instances of this class to be move constructed */ |
Georgios Pinitas | 879d131 | 2019-09-30 13:25:53 +0100 | [diff] [blame] | 68 | ITransformWeights(ITransformWeights &&other) |
| 69 | { |
| 70 | *this = std::move(other); |
| 71 | } |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 72 | /** Allow instances of this class to be moved */ |
Georgios Pinitas | 879d131 | 2019-09-30 13:25:53 +0100 | [diff] [blame] | 73 | ITransformWeights &operator=(ITransformWeights &&other) |
| 74 | { |
| 75 | if(this != &other) |
| 76 | { |
| 77 | _num_refcount = other._num_refcount.load(); |
| 78 | _reshape_run = other._reshape_run; |
| 79 | } |
| 80 | return *this; |
| 81 | } |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 82 | |
| 83 | /** Get a pointer to the transformed weights |
| 84 | * |
| 85 | * @return The pointer to the transformed ITensor weights |
| 86 | */ |
| 87 | virtual ITensor *get_weights() = 0; |
| 88 | /** Function that returns a unique id of the reshape function |
| 89 | * |
| 90 | * @return The computed unique id |
| 91 | */ |
| 92 | virtual uint32_t uid() = 0; |
| 93 | /** Run the transformation function */ |
| 94 | virtual void run() = 0; |
| 95 | /** Release transformed weights memory */ |
| 96 | virtual void release() = 0; |
| 97 | /** Increase the object's refcount */ |
| 98 | void increase_refcount() |
| 99 | { |
| 100 | ++_num_refcount; |
| 101 | } |
| 102 | |
| 103 | /** Decrease the object's refcount and return the updated value |
| 104 | * |
| 105 | * @return The updated refcount |
| 106 | * */ |
| 107 | int32_t decrease_refcount() |
| 108 | { |
| 109 | return --_num_refcount; |
| 110 | } |
| 111 | |
| 112 | /** Function that returns a flag on whether the weights are reshaped or not |
| 113 | * |
| 114 | * @return True if the function is reshaped |
| 115 | */ |
| 116 | bool is_reshape_run() |
| 117 | { |
| 118 | return _reshape_run; |
| 119 | } |
| 120 | |
| 121 | protected: |
| 122 | std::atomic<int32_t> _num_refcount{ 0 }; |
| 123 | bool _reshape_run{ false }; |
| 124 | }; |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 125 | } // arm_compute |
| 126 | |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 127 | #endif /*ARM_COMPUTE_ITRANSFORMWEIGHTS_H */ |