MATLAB Answers

Coder not replacing CMSIS library

2 views (last 30 days)
Jose Cazarin
Jose Cazarin on 7 Feb 2020
Hello! Im trying to use Matlab coder to generate C code for an ARM M4 device
The problem is: coder is not replacing basic matrix operations with the optimized functions of the CMSIS library
I know the replacement is working because some square root operations were in fact being replaced.
I have an example code:
function C = my_matrix_multiply(A, B)%#codegen
C = A*B;
my_sqrt = sqrt(A);
end
The script that is calling this function is
A = [3 3 3;3 3 3;3 3 3];
B = A;
C = my_matrix_multiply(single(A), single(B));
And the generated code is:
void my_matrix_multiply(const float A[9], const float B[9], float C[9])
{
int k;
float f;
float f1;
float x[9];
int i;
float f2;
for (k = 0; k < 3; k++) {
f = A[k + 3];
f1 = A[k + 6];
for (i = 0; i < 3; i++) {
C[k + 3 * i] = (A[k] * B[3 * i] + f * B[3 * i + 1]) + f1 * B[3 * i + 2];
}
}
for (k = 0; k < 9; k++) {
x[k] = A[k];
}
for (k = 0; k < 9; k++) {
mw_arm_sqrt_f32(x[k], &f2);
x[k] = f2;
}
}
I would expect for the coder to replace the loop where it is making the multiplication by the function arm_mult_f32 (or the mw_arm_mult_f32 defined)
Is there anything I'm missing here?
I'm attaching the .prj file for the project

  0 Comments

Sign in to comment.

Answers (2)

Jose Cazarin
Jose Cazarin on 7 Feb 2020
Edited: Jose Cazarin on 7 Feb 2020
I just realized that the arm_mult_f32 is a function to multiply vectors not matrices, sorry for the confusion, I mean the function arm_mat_mult_f32.
But now I realized that this function is not in the header file mw_cmsis.h created by the coder. Looks like that whenever some piece of code is replaced by the call of a CMSIS library function this header is generated with all the supported functions from the CMSIS library, and there's no functions for matrix multiplication in this file. Does this mean that the Coder doesn't support replacing code for matrix multiplications?
Thanks!

  0 Comments

Sign in to comment.


Darshan Ramakant Bhat
Darshan Ramakant Bhat on 11 Feb 2020
According to this page, https://au.mathworks.com/help/supportpkg/armcortexm/ug/supported-cmsis-functions.html the matrix multiply is not supported. You can run below command to bring up replacement library and check the support
>>crviewer('ARM Cortex-M')

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!