DSPLIB User Guide
DSPLIB_matMul_fixed.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * *
3  * module name :DSPLIB *
4  * *
5  * module descripton :Matrix Multiply Accelerator Library module for C7x+MMA *
6  * *
7  * Copyright (C) 2017-2018 Texas Instruments Incorporated - https://www.ti.com/ *
8  * ALL RIGHTS RESERVED *
9  * *
10  ******************************************************************************/
11 
23 #include "DSPLIB_bufParams.h"
25 
27 {
28  int32_t privBufSize = sizeof(DSPLIB_matMul_fixed_PrivArgs);
29  return privBufSize;
30 }
31 
34  const DSPLIB_bufParams2D_t *bufParamsIn0,
35  const DSPLIB_bufParams2D_t *bufParamsIn1,
36  const DSPLIB_bufParams2D_t *bufParamsOut,
37  const DSPLIB_matMul_fixed_InitArgs *pKerInitArgs)
38 {
40 
41 #if DSPLIB_DEBUGPRINT
42  printf("Enter DSPLIB_matMul_fixed_init_checkParams\n");
43 #endif
44  if (handle == NULL) {
45  status = DSPLIB_ERR_NULL_POINTER;
46  }
47 
48  if (status == DSPLIB_SUCCESS) {
49  if ((bufParamsIn0->data_type != DSPLIB_INT8) && (bufParamsIn0->data_type != DSPLIB_INT16)) {
50  status = DSPLIB_ERR_INVALID_TYPE;
51  }
52 
53  else if (bufParamsIn0->data_type != bufParamsOut->data_type ||
54  bufParamsIn1->data_type != bufParamsOut->data_type) {
55  status = DSPLIB_ERR_INVALID_TYPE;
56  }
57  else {
58  /* Nothing to do here */
59  }
60  }
61 
62  if (status == DSPLIB_SUCCESS) {
63 
64  if ((bufParamsIn0->dim_x != bufParamsIn1->dim_y) || // A is m x k, B is k x n, C is m x n
65  (bufParamsIn0->dim_y != bufParamsOut->dim_y) || (bufParamsIn1->dim_x != bufParamsOut->dim_x)) {
67  }
68  }
69 
70  return status;
71 }
72 
74  const void *restrict pIn0,
75  const void *restrict pIn1,
76  const void *restrict pOut)
77 {
78  DSPLIB_STATUS status;
79 
80 #if DSPLIB_DEBUGPRINT
81  printf("Enter DSPLIB_matMul_fixed_exec_checkParams\n");
82 #endif
83  if ((pIn0 == NULL) || (pIn1 == NULL) || (pOut == NULL)) {
84  status = DSPLIB_ERR_NULL_POINTER;
85  }
86  else {
87  status = DSPLIB_SUCCESS;
88  }
89 
90  return status;
91 }
92 
94  DSPLIB_bufParams2D_t *bufParamsIn0,
95  DSPLIB_bufParams2D_t *bufParamsIn1,
96  DSPLIB_bufParams2D_t *bufParamsOut,
97  const DSPLIB_matMul_fixed_InitArgs *pKerInitArgs)
98 {
101 
102  uint32_t M = bufParamsOut->dim_y;
103  uint32_t N = bufParamsOut->dim_x;
104  uint32_t K = bufParamsIn0->dim_x;
105 
106  pKerPrivArgs->M = M;
107  pKerPrivArgs->N = N;
108  pKerPrivArgs->K = K;
109  pKerPrivArgs->qs = pKerInitArgs->qs;
110 
111  uint32_t datatype = bufParamsIn0->data_type;
112  uint32_t strideIn0Elements = bufParamsIn0->stride_y / DSPLIB_sizeof(datatype);
113  uint32_t strideIn1Elements = bufParamsIn1->stride_y / DSPLIB_sizeof(datatype);
114  uint32_t strideOutElements = bufParamsOut->stride_y / DSPLIB_sizeof(datatype);
115 
116  pKerPrivArgs->strideIn0Elements = strideIn0Elements;
117  pKerPrivArgs->strideIn1Elements = strideIn1Elements;
118  pKerPrivArgs->strideOutElements = strideOutElements;
119 
120 #if DSPLIB_DEBUGPRINT
121  printf("DSPLIB_DEBUGPRINT Enter DSPLIB_matMul_fixed_init\n");
122 #endif
123 
124  if (pKerInitArgs->funcStyle == DSPLIB_FUNCTION_NATC) {
125  if (bufParamsIn0->data_type == DSPLIB_INT8) {
127  }
128  else if (bufParamsIn0->data_type == DSPLIB_INT16) {
130  }
131  else {
132  status = DSPLIB_ERR_INVALID_TYPE;
133 #if DSPLIB_DEBUGPRINT
134  printf("DSPLIB_DEBUGPRINT CP 2 status %d\n", status);
135 #endif
136  }
137  }
138  else {
139  if (bufParamsIn0->data_type == DSPLIB_INT8) {
140 #if DSPLIB_DEBUGPRINT
141  printf("DSPLIB_DEBUGPRINT bufParamsIn->data_type == DSPLIB_INT8_T\n");
142 #endif
144  status = DSPLIB_matMul_fixed_init_ci<DSPLIB_MATMAPY_FXD_I8S_O8S>(handle, bufParamsIn0, bufParamsIn1,
145  bufParamsOut, pKerInitArgs);
146  }
147  else if (bufParamsIn0->data_type == DSPLIB_INT16) {
148 #if DSPLIB_DEBUGPRINT
149  printf("DSPLIB_DEBUGPRINT bufParamsIn->data_type == DSPLIB_INT16_T\n");
150 #endif
152  status = DSPLIB_matMul_fixed_init_ci<DSPLIB_MATMAPY_FXD_I16S_O16S>(handle, bufParamsIn0, bufParamsIn1,
153  bufParamsOut, pKerInitArgs);
154  }
155  else {
156  status = DSPLIB_ERR_INVALID_TYPE;
157  }
158  }
159 #if DSPLIB_DEBUGPRINT
160  printf("DSPLIB_DEBUGPRINT CP 3 status %d\n", status);
161 #endif
162  return status;
163 }
164 
166 DSPLIB_matMul_fixed_exec(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
167 {
168  DSPLIB_STATUS status;
169 
170 #if DSPLIB_DEBUGPRINT
171  printf("DSPLIB_DEBUGPRINT Enter DSPLIB_matMul_fixed_exec\n");
172 #endif
173 
175 
176  status = pKerPrivArgs->execute(handle, pIn0, pIn1, pOut);
177 
178  return status;
179 }
template DSPLIB_STATUS DSPLIB_matMul_fixed_init_ci< DSPLIB_MATMAPY_FXD_I16S_O16S >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn0, const DSPLIB_bufParams2D_t *bufParamsIn1, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matMul_fixed_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_matMul_fixed_exec_ci< DSPLIB_MATMAPY_FXD_I16S_O16S >(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_matMul_fixed_exec_ci< DSPLIB_MATMAPY_FXD_I8S_O8S >(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_matMul_fixed_init_ci< DSPLIB_MATMAPY_FXD_I8S_O8S >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn0, const DSPLIB_bufParams2D_t *bufParamsIn1, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matMul_fixed_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_matMul_fixed_exec_cn< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_matMul_fixed_exec_cn< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_matMul_fixed.
static int32_t DSPLIB_sizeof(uint32_t type)
Inline function returns number of bytes per element given a type of DSPLIB_data_type_e.
DSPLIB_STATUS_NAME
The enumeration of all status codes.
Definition: DSPLIB_types.h:151
void * DSPLIB_kernelHandle
Handle type for DSPLIB operations.
Definition: DSPLIB_types.h:172
@ DSPLIB_FUNCTION_NATC
Definition: DSPLIB_types.h:176
@ DSPLIB_INT16
@ DSPLIB_INT8
@ DSPLIB_ERR_INVALID_DIMENSION
Definition: DSPLIB_types.h:156
@ DSPLIB_SUCCESS
Definition: DSPLIB_types.h:152
@ DSPLIB_ERR_NULL_POINTER
Definition: DSPLIB_types.h:157
@ DSPLIB_ERR_INVALID_TYPE
Definition: DSPLIB_types.h:155
int32_t DSPLIB_matMul_fixed_getHandleSize(DSPLIB_matMul_fixed_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
DSPLIB_STATUS DSPLIB_matMul_fixed_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn0, const void *restrict pIn1, const void *restrict pOut)
This function checks the validity of the parameters passed to DSPLIB_matMul_fixed_exec function....
DSPLIB_STATUS DSPLIB_matMul_fixed_init(DSPLIB_kernelHandle handle, DSPLIB_bufParams2D_t *bufParamsIn0, DSPLIB_bufParams2D_t *bufParamsIn1, DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matMul_fixed_InitArgs *pKerInitArgs)
This function should be called before the DSPLIB_matMul_fixed_exec function is called....
DSPLIB_STATUS DSPLIB_matMul_fixed_exec(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
This function is the main kernel compute function.
DSPLIB_STATUS DSPLIB_matMul_fixed_init_checkParams(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn0, const DSPLIB_bufParams2D_t *bufParamsIn1, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matMul_fixed_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to DSPLIB_matMul_fixed_init function....
A structure for a 2 dimensional buffer descriptor.
uint32_t data_type
Values are of type DSPLIB_data_type_e.
int32_t stride_y
Stride in Y dimension in bytes.
uint32_t dim_x
Width of buffer in X dimension in elements.
uint32_t dim_y
Height of buffer in Y dimension in elements.
Structure containing the parameters to initialize the kernel.
int8_t funcStyle
Variant of the function refer to DSPLIB_FUNCTION_STYLE
Structure that is reserved for internal use by the kernel.
pFxnDSPLIB_matMul_fixed_exec execute
Function pointer to point to the right execution variant between DSPLIB_matMul_fixed_exec_cn and DSPL...