MMALIB User Guide
MMALIB_CNN_fullyConnected_ixX_ixX_oxX.h
Go to the documentation of this file.
1 /*******************************************************************************
2  **+--------------------------------------------------------------------------+**
3  **| **** |**
4  **| **** |**
5  **| ******o*** |**
6  **| ********_///_**** |**
7  **| ***** /_//_/ **** |**
8  **| ** ** (__/ **** |**
9  **| ********* |**
10  **| **** |**
11  **| *** |**
12  **| |**
13  **| Copyright (c) 2016 Texas Instruments Incorporated |**
14  **| |**
15  **| All rights reserved not granted herein. |**
16  **| |**
17  **| Limited License. |**
18  **| |**
19  **| Texas Instruments Incorporated grants a world-wide, royalty-free, |**
20  **| non-exclusive license under copyrights and patents it now or |**
21  **| hereafter owns or controls to make, have made, use, import, offer to |**
22  **| sell and sell ("Utilize") this software subject to the terms herein. |**
23  **| With respect to the foregoing patent license, such license is granted |**
24  **| solely to the extent that any such patent is necessary to Utilize the |**
25  **| software alone. The patent license shall not apply to any |**
26  **| combinations which include this software, other than combinations |**
27  **| with devices manufactured by or for TI ("TI Devices"). No hardware |**
28  **| patent is licensed hereunder. |**
29  **| |**
30  **| Redistributions must preserve existing copyright notices and |**
31  **| reproduce this license (including the above copyright notice and the |**
32  **| disclaimer and (if applicable) source code license limitations below) |**
33  **| in the documentation and/or other materials provided with the |**
34  **| distribution |**
35  **| |**
36  **| Redistribution and use in binary form, without modification, are |**
37  **| permitted provided that the following conditions are met: |**
38  **| |**
39  **| * No reverse engineering, decompilation, or disassembly of this |**
40  **| software is permitted with respect to any software provided in binary |**
41  **| form. |**
42  **| |**
43  **| * any redistribution and use are licensed by TI for use only with |**
44  **| TI Devices. |**
45  **| |**
46  **| * Nothing shall obligate TI to provide you with source code for |**
47  **| the software licensed and provided to you in object code. |**
48  **| |**
49  **| If software source code is provided to you, modification and |**
50  **| redistribution of the source code are permitted provided that the |**
51  **| following conditions are met: |**
52  **| |**
53  **| * any redistribution and use of the source code, including any |**
54  **| resulting derivative works, are licensed by TI for use only with TI |**
55  **| Devices. |**
56  **| |**
57  **| * any redistribution and use of any object code compiled from the |**
58  **| source code and any resulting derivative works, are licensed by TI |**
59  **| for use only with TI Devices. |**
60  **| |**
61  **| Neither the name of Texas Instruments Incorporated nor the names of |**
62  **| its suppliers may be used to endorse or promote products derived from |**
63  **| this software without specific prior written permission. |**
64  **| |**
65  **| DISCLAIMER. |**
66  **| |**
67  **| THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY |**
68  **| EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |**
69  **| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |**
70  **| PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TI AND TI'S LICENSORS BE |**
71  **| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |**
72  **| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |**
73  **| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |**
74  **| BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |**
75  **| WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |**
76  **| OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |**
77  **| EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |**
78  **+--------------------------------------------------------------------------+**
79  *******************************************************************************/
80 
81 #ifndef MMALIB_CNN_FULLYCONNECTED_IXX_IXX_OXX_H_
82 #define MMALIB_CNN_FULLYCONNECTED_IXX_IXX_OXX_H_
83 
84 #include "../../common/MMALIB_types.h"
85 
86 #ifdef __cplusplus
87 extern "C" {
88 #endif
89 
180 /* @{ */
181 
189 typedef enum {
191  /*@todo Add more appropriate error codes */
194 
199 typedef struct {
201  int8_t funcStyle;
203  int8_t shift;
205  int32_t bias;
209  int32_t Ni;
211  int32_t kDimRows;
221 
226 typedef struct {
236  bool firstCall;
238  bool lastCall;
242  int32_t blockOffsetA;
244 
256 
278  MMALIB_kernelHandle handle,
279  const MMALIB_bufParams2D_t * src0_addr,
280  const MMALIB_bufParams2D_t * src1_addr,
281  const MMALIB_bufParams2D_t * dst_addr,
283 
304  MMALIB_kernelHandle handle,
305  const MMALIB_bufParams2D_t * src0_addr,
306  const MMALIB_bufParams2D_t * src1_addr,
307  const MMALIB_bufParams2D_t * dst_addr,
309 
343  MMALIB_kernelHandle handle,
344  const void * src0,
345  const void * src1,
346  void * dst,
348 
369  const void * src0,
370  const void * src1,
371  const void * dst);
372 
387  int32_t inputWidth,
388  int32_t processWidth,
389  uint32_t mmaWidth);
390 
414  int32_t NiBias,
415  int32_t No,
416  uint32_t strideOut,
417  const void *restrict pWeights,
418  void *restrict pReorderWeights);
419 
446  const MMALIB_bufParams2D_t *src0_addr,
447  const MMALIB_bufParams2D_t *src1_addr,
448  const MMALIB_bufParams2D_t *dst_addr,
449  uint64_t *archCycles,
450  uint64_t *estCycles,
451  int32_t * caseNumber);
452 
455 #ifdef __cplusplus
456 }
457 #endif
458 
459 #endif /* MMALIB_CNN_FULLYCONNECTED_IXX_IXX_OXX_H_ */
460 
461 /* ======================================================================== */
462 /* End of file: MMALIB_CNN_fullyConnected_ixX_ixX_oxX.h */
463 /* ======================================================================== */
MMALIB_STATUS MMALIB_CNN_fullyConnected_ixX_ixX_oxX_exec(MMALIB_kernelHandle handle, const void *src0, const void *src1, void *dst, const MMALIB_CNN_fullyConnected_ixX_ixX_oxX_ExecArgs *pKerExecArgs)
This function is the main compute function, and performs matrix-matrix multiplication.
MMALIB_STATUS MMALIB_CNN_fullyConnected_ixX_ixX_oxX_reorderWeights(int32_t mmaSize, int32_t NiBias, int32_t No, uint32_t strideOut, const void *restrict pWeights, void *restrict pReorderWeights)
This function re-orders the input weights (kernel matrix). Reordering of data is required to alleviat...
void MMALIB_CNN_fullyConnected_ixX_ixX_oxX_perfEst(MMALIB_kernelHandle handle, const MMALIB_bufParams2D_t *src0_addr, const MMALIB_bufParams2D_t *src1_addr, const MMALIB_bufParams2D_t *dst_addr, uint64_t *archCycles, uint64_t *estCycles, int32_t *caseNumber)
This function estimates the cycles consumed for the kernel execution.
MMALIB_CNN_FULLYCONNECTED_IXX_IXX_OXX_STATUS_NAME
Enumeration of different error codes for the MMALIB_CNN_FULLYCONNECTED kernel.
@ MMALIB_CNN_FULLYCONNECTED_IXX_IXX_OXX_ERR_MAX
@ MMALIB_CNN_FULLYCONNECTED_IXX_IXX_OXX_ERR_SMALL_K
int32_t MMALIB_CNN_fullyConnected_ixX_ixX_oxX_getHandleSize(MMALIB_CNN_fullyConnected_ixX_ixX_oxX_InitArgs *pKerInitArgs)
This is a query function to return the size of internal handle.
MMALIB_STATUS MMALIB_CNN_fullyConnected_ixX_ixX_oxX_init_checkParams(MMALIB_kernelHandle handle, const MMALIB_bufParams2D_t *src0_addr, const MMALIB_bufParams2D_t *src1_addr, const MMALIB_bufParams2D_t *dst_addr, const MMALIB_CNN_fullyConnected_ixX_ixX_oxX_InitArgs *pKerInitArgs)
This function checks the parameters and should be called before kernel execution. It can be called on...
MMALIB_STATUS MMALIB_CNN_fullyConnected_ixX_ixX_oxX_init(MMALIB_kernelHandle handle, const MMALIB_bufParams2D_t *src0_addr, const MMALIB_bufParams2D_t *src1_addr, const MMALIB_bufParams2D_t *dst_addr, const MMALIB_CNN_fullyConnected_ixX_ixX_oxX_InitArgs *pKerInitArgs)
This function call is required to initialize the handle. In this function most of the one time operat...
MMALIB_STATUS MMALIB_CNN_fullyConnected_ixX_ixX_oxX_exec_checkParams(MMALIB_kernelHandle handle, const void *src0, const void *src1, const void *dst)
This function checks the parameters and should be called before kernel executuon. It can be called on...
int32_t MMALIB_CNN_generateFillBiasPredicateRegisters(MMALIB_kernelHandle handle, int32_t inputWidth, int32_t processWidth, uint32_t mmaWidth)
This function generates the predicate buffer for feature matrix.
MMALIB_STATUS_NAME
The enumeration of all status codes.
Definition: MMALIB_types.h:176
@ MMALIB_ERROR_MAX
Definition: MMALIB_types.h:190
void * MMALIB_kernelHandle
Handle type for MMALIB operations.
Definition: MMALIB_types.h:279
bool lastCall
flag signifies last call to kernel when compute is broken down
bool multiPassH
flag signifies kernel matrix cannot be fit in memory; therefore, compute is broken down by processin...
int32_t blockOffsetA
Offset of A matrix when kernel matrix is broken down in multi-pass case to pick appropriate block of ...
bool firstCall
flag signifies first call to kernel when compute is broken down
bool multiPassX
flag signifies feature matrix cannot be fit in memory; therefore, compute is broken down by processi...
bool writeCBuffer
flag signifies when to write accumulated value out Cbuffer
int8_t funcStyle
Variant of the function refer to MMALIB_FUNCTION_STYLE
int8_t activationType
Output activation type: Saturation or ReLU
bool multiPassX
flag signifies feature matrix cannot be fit in memory; therefore, compute is broken down by processi...
bool multiPassH
flag signifies kernel matrix cannot be fit in memory; therefore, compute is broken down by processin...
void * bufCAccum_cn
Buffer pointer to hold partially accumulated values in multi-pass case.
A structure for a 2 dimensional buffer descriptor.