VCELPF3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!*****************************************************************************
33  * @file VCELPF3.h
34  * @brief <b>PRELIMINARY</b> VCE driver interface
35  *
36  * <b>WARNING</b> These APIs are <b>PRELIMINARY</b>, and subject to
37  * change in the next few months.
38  *
39  * @anchor ti_drivers_VCE_Overview
40  * # Overview
41  * The VCE driver allows you to interact with the Vector Compute Engine
42  * (VCE), a linear algebra accellerator peripheral using 64-bit complex numbers.
43  * Complex numbers are represented by the _float complex_ type from _complex.h_,
44  * where each number is made up of two 32-bit floats. The VCE works with
45  * complex numbers in either Cartesian or Polar formats. In the Cartesian
46  * representation, the lower 32 bits are the real part and the upper 32 bits
47  * are the imaginary part. In Polar format, the lower 32 bits are the absolute
48  * part and the upper 32 bits are the angle, represented as pi radians.
49  * As long as arguments to the VCE
50  * functions use the same format, the result will also be in that format.
51  * Mixing formats produces wrong results. The driver provides basic data types
52  * for vectors and matrices constructed from _float complex_, as well as many
53  * common linear algebra operations on these data types.
54  *
55  * @anchor ti_drivers_VCE_DataManagement
56  * ## Data management
57  * All the vector/matrix operations can accept input and output pointers that
58  * are inside or outside VCE RAM. If all pointers provided to an operation are
59  * inside VCE RAM, the VCE will operate in <b> scratchpad mode </b>.
60  * This means the driver will assume that, given the current pointers,
61  * the input is already in VCE memory and that input and result will not
62  * overlap eachother. Therefore, no data will be copied, and the function
63  * output will be placed inside VCE memory. This is the most efficient way to
64  * utilize the VCE and is ideal for algorithms with multiple operations that
65  * feed into each other, such as
66  * MUSIC (https://en.wikipedia.org/wiki/MUSIC_(algorithm)). When chaining
67  * together operations, make sure as many as possible use vectors and matrices
68  * that are already in VCE memory, to prevent unnecessary copying and overhead.
69  *
70  * If any of the pointers are outside VCE memory, the driver will copy input
71  * data to the start of its memory, place the result immediately following,
72  * and then copy the output back to the provided pointer. This may overwrite
73  * data that was already in this location.
74  *
75  *
76  * The primary purpose of this driver is executing the MUSIC algorithm for
77  * distance estimation in Bluetooth Channel Sounding. An implementation of
78  * MUSIC using the VCE can be found in the vce_music example.
79  *
80  * @anchor ti_drivers_VCE_Usage
81  * # Usage
82  * This section will cover driver usage.
83  *
84  * @anchor ti_drivers_VCE_Synopsis
85  * ## Synopsis
86  * @anchor ti_drivers_VCE_Synopsis_Code
87  * @code
88  *
89  * VCELPF3_init();
90  *
91  * float complex *vceMem = (float complex *)VCELPF3_MEM_BASE;
92  * float complex argA[10];
93  * float complex argB[10];
94  *
95  * VCELPF3_ComplexVector vecA = {.data = bufA, .size = 10};
96  * VCELPF3_ComplexVector vecB = {.data = bufB, .size = 10};
97  * VCELPF3_ComplexVector resultVec = {.data = vceMem, .size = 10};
98  *
99  * // Get control of VCE
100  * VCELPF3_startOperationSequence();
101  *
102  * // Perform element-wise product, placing the result in resultVec,
103  * // which is inside VCE memory
104  * VCELPF3_elemProduct(&argA, &argB, resultVec);
105  *
106  * // Perform non-conjugated dot product inside of VCE memory, which
107  * // reduces overhead.
108  * VCELPF3_dotProduct(&resultVec, &resultVec, false, vceMem)
109  *
110  * // Give up control of VCE
111  * VCELPF3_finishOperationSequence();
112  *
113  * @endcode
114  ***************************************************************************
115  */
116 #ifndef ti_drivers_VCELPF3__include
117 #define ti_drivers_VCELPF3__include
118 
119 #include <stddef.h>
120 #include <stdint.h>
121 #include <stdbool.h>
122 #include <complex.h>
123 
124 #include <ti/drivers/dpl/HwiP.h>
126 
127 #include <ti/devices/DeviceFamily.h>
128 #include DeviceFamily_constructPath(inc/hw_memmap.h)
129 
130 #ifdef __cplusplus
131 extern "C" {
132 #endif
133 
134 /*
135  * ========= VCE datatype structs =========
136  * These structs define the core data types used by VCE functions,
137  * which are vectors, full matrices and upper tiangle matrices of
138  * complex numbers. Matrices are column-major.
139  */
140 
154 typedef struct
155 {
157  complex float *data;
159  uint16_t size;
161 
173 typedef struct
174 {
176  complex float *data;
178  uint16_t rows;
180  uint16_t cols;
182 
197 typedef struct
198 {
200  complex float *data;
202  uint16_t size;
203 
205 
213 typedef enum
214 {
218 
224 typedef enum
225 {
230 
232 
236 typedef struct
237 {
239  void *object;
241  void const *hwAttrs;
243 
247 typedef struct
248 {
249  unsigned int intPriority;
250 
251  VCELPF3_OperationMode operationMode;
252 
253  VCELPF3_SchedulingMode schedulingMode;
255 
263 #define VCELPF3_STATUS_SUCCESS 0
264 
268 #define VCELPF3_STATUS_ERROR 1
269 
274 #define VCELPF3_STATUS_RESOURCE_UNAVAILABLE 2
275 
280 #define VCELPF3_RESULT_INPLACE 0
281 
285 #define VCELPF3_MEM_BASE VCERAM_DATA0_BASE
286 
290 #define VCELPF3_MEM_SIZE_MIRRORED VCERAM_DATA0_SIZE
291 
300 void VCELPF3_init(void);
301 
315 
329 
330 /* Vector functions */
363 int_fast16_t VCELPF3_dotProduct(VCELPF3_ComplexVector *vecA,
364  VCELPF3_ComplexVector *vecB,
365  bool conjugate,
366  float complex *result);
367 
403 int_fast16_t VCELPF3_vectorMult(VCELPF3_ComplexVector *vecA,
404  VCELPF3_ComplexVector *vecB,
405  bool conjugate,
406  VCELPF3_ComplexVector *result);
407 
456 
479  float complex *temp,
480  VCELPF3_ComplexVector *result);
481 
501 
532  uint16_t covMatrixSize,
533  bool fbAveraging,
535 
555 int_fast16_t VCELPF3_computeFFT(VCELPF3_ComplexVector *vec, bool inverse, VCELPF3_ComplexVector *result);
558 /* Matrix functions */
589 int_fast16_t VCELPF3_matrixMult(VCELPF3_ComplexMatrix *matA,
590  VCELPF3_ComplexMatrix *matB,
591  VCELPF3_ComplexMatrix *result);
592 
619 
643 int_fast16_t VCELPF3_matrixScalarSum(VCELPF3_ComplexMatrix *mat, float complex *scalar, VCELPF3_ComplexMatrix *result);
644 
668 int_fast16_t VCELPF3_matrixScalarMult(VCELPF3_ComplexMatrix *mat, float complex *scalar, VCELPF3_ComplexMatrix *result);
669 
689 int_fast16_t VCELPF3_matrixNorm(VCELPF3_ComplexMatrix *mat, float complex *result);
692 /* Matrix algorithms */
740  uint16_t maxIter,
741  float stopThreshold,
742  VCELPF3_ComplexVector *result);
743 
766 int_fast16_t VCELPF3_gaussJordanElim(VCELPF3_ComplexMatrix *mat, float zeroThreshold, VCELPF3_ComplexMatrix *result);
767 
770 /* Utility functions */
771 
800 int_fast16_t VCELPF3_unitCircle(uint16_t numPoints,
801  uint16_t constant,
802  uint16_t phase,
803  bool conjugate,
804  VCELPF3_ComplexVector *result);
805 
825 void VCELPF3_prepareResult(uint16_t resultSize, uint16_t inputSize, complex float *resultBuffer);
826 
839 
852 
862 void *VCELPF3_loadTriangular(VCELPF3_ComplexMatrix *mat, uint16_t offset);
863 
877 void *VCELPF3_loadArgMirrored(uint16_t argSize, uint16_t offset, float complex *src);
878 
879 #ifdef __cplusplus
880 }
881 #endif
882 
883 #endif /* ti_drivers_VCE__include */
Definition: VCELPF3.h:229
VCELPF3_SchedulingMode schedulingMode
Definition: VCELPF3.h:253
VCELPF3_OperationMode operationMode
Definition: VCELPF3.h:251
uint16_t size
Definition: VCELPF3.h:159
int_fast16_t VCELPF3_covMatrixSpatialSmoothing(VCELPF3_ComplexVector *vec, uint16_t covMatrixSize, bool fbAveraging, VCELPF3_ComplexTriangleMatrix *result)
VCE function for covariance matrix computation using spatial smoothing and optionally forward-backwar...
void * VCELPF3_loadArgMirrored(uint16_t argSize, uint16_t offset, float complex *src)
Load operation arguments into VCE memory, assuming the VCE is in mirrored mode. This means memory is ...
int_fast16_t VCELPF3_cartesianToPolarVector(VCELPF3_ComplexVector *vec, VCELPF3_ComplexVector *result)
VCE function for converting a complex vector in cartesian format to polar format. ...
VCELPF3 Matrix Struct.
Definition: VCELPF3.h:173
uint16_t rows
Definition: VCELPF3.h:178
uint16_t size
Definition: VCELPF3.h:202
uint16_t VCELPF3_prepareVectors(VCELPF3_ComplexVector *vecA, VCELPF3_ComplexVector *vecB)
Configure the VCE for vector operation inputs. If not in scratchpad mode, the vectors are loaded one ...
VCELPF3_OperationMode
Define the VCE memory operation modes, which are the ways the VCE expects data to be stored in its me...
Definition: VCELPF3.h:213
complex float * data
Definition: VCELPF3.h:200
uint16_t VCELPF3_prepareMatrices(VCELPF3_ComplexMatrix *matA, VCELPF3_ComplexMatrix *matB)
Configure the VCE for matrix operation inputs. If not in scratchpad mode, the matrices are loaded one...
void VCELPF3_startOperationSequence()
VCE function to prepare the start of an operation chain.
VCELPF3 Vector Struct.
Definition: VCELPF3.h:154
int_fast16_t VCELPF3_unitCircle(uint16_t numPoints, uint16_t constant, uint16_t phase, bool conjugate, VCELPF3_ComplexVector *result)
Generate points evenly distributed on a unit circle VCE generates a unit circle as follow: exp(-j*2*p...
int_fast16_t VCELPF3_polarToCartesianVector(VCELPF3_ComplexVector *vec, float complex *temp, VCELPF3_ComplexVector *result)
VCE function for converting a complex vector in polar format to cartesian format. ...
Semaphore module for the RTOS Porting Interface.
int_fast16_t VCELPF3_sortVector(VCELPF3_ComplexVector *vec, VCELPF3_ComplexVector *result)
VCE function for sorting the real parts of a complex vector in descending order. This function ignore...
uint16_t cols
Definition: VCELPF3.h:180
VCELPF3 Hardware attributes.
Definition: VCELPF3.h:247
int_fast16_t VCELPF3_vectorMult(VCELPF3_ComplexVector *vecA, VCELPF3_ComplexVector *vecB, bool conjugate, VCELPF3_ComplexVector *result)
VCE function for calculating the element-wise product of two vectors, with the option to perform the ...
complex float * data
Definition: VCELPF3.h:157
int_fast16_t VCELPF3_vectorSum(VCELPF3_ComplexVector *vecA, VCELPF3_ComplexVector *vecB, VCELPF3_ComplexVector *result)
VCE function for calculating the element-wise sum of two vectors.
int_fast16_t VCELPF3_matrixMult(VCELPF3_ComplexMatrix *matA, VCELPF3_ComplexMatrix *matB, VCELPF3_ComplexMatrix *result)
VCE function for multiplying two matrices. The number of rows in the first matrix must be equal to th...
int_fast16_t VCELPF3_matrixScalarMult(VCELPF3_ComplexMatrix *mat, float complex *scalar, VCELPF3_ComplexMatrix *result)
VCE function for multiplying each of a matrix&#39; elements by a scalar.
void VCELPF3_stopOperationSequence()
VCE function to finish an operation chain.
int_fast16_t VCELPF3_dotProduct(VCELPF3_ComplexVector *vecA, VCELPF3_ComplexVector *vecB, bool conjugate, float complex *result)
VCE function for calculating the dot product of two vectors, with the option to perform the complex c...
int_fast16_t VCELPF3_computeFFT(VCELPF3_ComplexVector *vec, bool inverse, VCELPF3_ComplexVector *result)
VCE function for computing the Discrete Fourier transform (DFT) of a complex vector using the Fast Fo...
VCELPF3 Upper Triangle Matrix Struct.
Definition: VCELPF3.h:197
unsigned int intPriority
Definition: VCELPF3.h:249
void VCELPF3_prepareResult(uint16_t resultSize, uint16_t inputSize, complex float *resultBuffer)
Configure the VCE pointers for temporary (in VCE memory) and final results for a VCE operation...
Definition: VCELPF3.h:216
int_fast16_t VCELPF3_matrixScalarSum(VCELPF3_ComplexMatrix *mat, float complex *scalar, VCELPF3_ComplexMatrix *result)
VCE function for adding a scalar to a each of a matrix&#39; elements.
void * object
Definition: VCELPF3.h:239
void * VCELPF3_loadTriangular(VCELPF3_ComplexMatrix *mat, uint16_t offset)
Loads the upper triangular part of a full matrix into VCE memory.
complex float * data
Definition: VCELPF3.h:176
int_fast16_t VCELPF3_gaussJordanElim(VCELPF3_ComplexMatrix *mat, float zeroThreshold, VCELPF3_ComplexMatrix *result)
Reduce the input matrix A[MxN] to reduced echelon form using Gauss-Jordan Elimination.
void const * hwAttrs
Definition: VCELPF3.h:241
int_fast16_t VCELPF3_matrixNorm(VCELPF3_ComplexMatrix *mat, float complex *result)
Compute the Frobenius norm of a matrix.
int_fast16_t VCELPF3_matrixSum(VCELPF3_ComplexMatrix *matA, VCELPF3_ComplexMatrix *matB, VCELPF3_ComplexMatrix *result)
VCE function for adding two matrices. The matrices must be of exact same sizes.
Hardware Interrupt module for the RTOS Porting Interface.
void VCELPF3_init(void)
VCE init function.
int_fast16_t VCELPF3_jacobiEVD(VCELPF3_ComplexTriangleMatrix *mat, uint16_t maxIter, float stopThreshold, VCELPF3_ComplexVector *result)
VCE function to compute the Jacobi Eigen-Decomposition (EVD) of a triangular Hermitian Matrix...
VCELPF3_SchedulingMode
Define the VCE memory scheduling modes, which are the ways VCE memory operations are scheduled and pi...
Definition: VCELPF3.h:224
VCELPF3 Global configuration.
Definition: VCELPF3.h:236
© Copyright 1995-2024, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale