Part Number: J784S4XEVM
I am testing a code's execution time with TI C 7000. The part of the code that I am benchmarking is MATLAB generated. What I observed is that given everything else is the same changing:
--opt_level from off to 4 : did not accelerate the code execution
--opt_for_speed from 0 to 4: did not accelerate the code execution
--fp_mode from strict to relaxed: did not accelerate the code execution
after seeing this indifference in execution times I replaced the code block with a testing function given below:
#define MATRIX_SIZE 1024
// Declare an external function to "consume" the matrix
// Prevents the compiler from optimizing everything away
#ifdef __cplusplus
extern "C" {
#endif
void useMatrix(float mat[MATRIX_SIZE][MATRIX_SIZE])
{
volatile float sink = mat[0][0];
(void)sink;
}
#ifdef __cplusplus
}
#endif
static float matrix[MATRIX_SIZE][MATRIX_SIZE];
int32_t TestClass::Init()
{
for (int i = 0; i < MATRIX_SIZE; i++) {
for (int j = 0; j < MATRIX_SIZE; j++) {
matrix[i][j] = (float)(i + j);
}
}
InitFlag = true;
}
void TestClass::TestOptimization()
{
// i increasing, j decreasing (as requested)
for (int i = MATRIX_SIZE - 1; i >= 0; i--) {
for (int j = MATRIX_SIZE - 1; j >= 0; j--) {
float val = matrix[i][j];
// Some arithmetic to encourage optimization (FMA, pipelining, etc.)
val = val * 1.2345f + 0.9876f;
val = val * val - 0.4321f;
matrix[i][j] = val;
}
}
// Pass to external function so compiler can't eliminate it
useMatrix(matrix);
}
and I measure the execution time of TestOptimization function. For compiler options, changing the --opt_level from off to 2 or 4 does not accelerate execution time.
Why might this be? Could you provide some direction to which we can turn the optimization on and observe and acceleration in code execution?