aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/runtime/ITransformWeights.h
diff options
context:
space:
mode:
authorMichalis Spyrou <michalis.spyrou@arm.com>2019-09-10 17:20:34 +0100
committerMichalis Spyrou <michalis.spyrou@arm.com>2019-09-26 10:17:30 +0000
commit1a569a30a2f456ff1a3e0a665201e1c3ab92df80 (patch)
tree9d68934f461579edefbe65246f6ee435aaa18808 /arm_compute/runtime/ITransformWeights.h
parentf1cf394ae882e6e8fb2e0986f88d2548b82a85bb (diff)
downloadComputeLibrary-1a569a30a2f456ff1a3e0a665201e1c3ab92df80.tar.gz
COMPMID-2161 [NEON] Create IWeightManager class
Change-Id: I1a9a46da2f98e896b825099151b56d1d8271dd31 Signed-off-by: Michalis Spyrou <michalis.spyrou@arm.com> Reviewed-on: https://review.mlplatform.org/c/1915 Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'arm_compute/runtime/ITransformWeights.h')
-rw-r--r--arm_compute/runtime/ITransformWeights.h117
1 files changed, 117 insertions, 0 deletions
diff --git a/arm_compute/runtime/ITransformWeights.h b/arm_compute/runtime/ITransformWeights.h
new file mode 100644
index 0000000000..6376c30088
--- /dev/null
+++ b/arm_compute/runtime/ITransformWeights.h
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2019 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_ITRANSFORMWEIGHTS_H__
+#define __ARM_COMPUTE_ITRANSFORMWEIGHTS_H__
+
+#include <atomic>
+
+namespace arm_compute
+{
+// Forward declarations
+class ITensor;
+
+/** Weights tensor transform interface
+ * In order to identify the different reshape functions, each reshape function has
+ * to generate a unique id. We use the following conversion using an unsigned 32bit value:
+ *
+ * Lower two bits store the target:
+ * 00 -> NEON
+ * 01 -> CL
+ * 10 -> GLES
+ * 11 -> Unused
+ *
+ * Five bits store the id of the reshape function:
+ * 00000 -> FullyConnectedLayerReshapeWeights
+ * 00001 -> ConvertFullyConnectedWeights
+ * 00010 -> ConvolutionLayerReshapeWeights
+ * 00011 -> DepthwiseConvolutionLayerReshapeWeights
+ * 00100 -> GEMMReshapeLHSMatrixKernel
+ * 00101 -> GEMMReshapeRHSMatrixKernel
+ *
+ * Rest of the bits are used for identifying special cases such as assembly functions and extra
+ * arguments in the reshape kernels.
+ *
+ * */
+class ITransformWeights
+{
+public:
+ /** Default Constructor */
+ ITransformWeights() = default;
+ /** Default Destructor */
+ virtual ~ITransformWeights() = default;
+ /** Prevent instances of this class to be copy constructed */
+ ITransformWeights(const ITransformWeights &) = delete;
+ /** Prevent instances of this class to be copied */
+ ITransformWeights &operator=(const ITransformWeights &) = delete;
+ /** Allow instances of this class to be move constructed */
+ ITransformWeights(ITransformWeights &&) = default;
+ /** Allow instances of this class to be moved */
+ ITransformWeights &operator=(ITransformWeights &&) = default;
+
+ /** Get a pointer to the transformed weights
+ *
+ * @return The pointer to the transformed ITensor weights
+ */
+ virtual ITensor *get_weights() = 0;
+ /** Function that returns a unique id of the reshape function
+ *
+ * @return The computed unique id
+ */
+ virtual uint32_t uid() = 0;
+ /** Run the transformation function */
+ virtual void run() = 0;
+ /** Release transformed weights memory */
+ virtual void release() = 0;
+ /** Increase the object's refcount */
+ void increase_refcount()
+ {
+ ++_num_refcount;
+ }
+
+ /** Decrease the object's refcount and return the updated value
+ *
+ * @return The updated refcount
+ * */
+ int32_t decrease_refcount()
+ {
+ return --_num_refcount;
+ }
+
+ /** Function that returns a flag on whether the weights are reshaped or not
+ *
+ * @return True if the function is reshaped
+ */
+ bool is_reshape_run()
+ {
+ return _reshape_run;
+ }
+
+protected:
+ std::atomic<int32_t> _num_refcount{ 0 };
+ bool _reshape_run{ false };
+};
+
+} // arm_compute
+
+#endif /*__ARM_COMPUTE_ITRANSFORMWEIGHTS_H__ */ \ No newline at end of file