- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
I'd like to optimize the execution speed of my code using small matrices (3x3) and I tried to use IPP functions but the result seems to be slower than the original code. My program is running on Ubuntu 32-but using a VM (VirtualBox) that can only handle 1 processor on this computer. Here is the function I've tried to optimize :
[cpp]/* Compute an updated rotation matrix given the initial rotation______________________________________________________
* and the correction (w) */
void rot_update(double *R, double *w, double *Rnew)
{
double theta, sinth, costh, n[3];
double nx[9], nxsq[9], Rnew2[9];
double term2[9], term3[9];
double tmp[9], dR[9];
double ident[9] =
{ 1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0 };
theta = sqrt(w[0] * w[0] + w[1] * w[1] + w[2] * w[2]);
if (theta == 0.0) {
memcpy(Rnew, R, sizeof(double) * 9);
return;
}
n[0] = w[0] / theta;
n[1] = w[1] / theta;
n[2] = w[2] / theta;
nx[0] = 0.0; nx[1] = -n[2]; nx[2] = n[1];
nx[3] = n[2]; nx[4] = 0.0; nx[5] = -n[0];
nx[6] = -n[1]; nx[7] = n[0]; nx[8] = 0.0;
matrix_product33(nx, nx, nxsq);
sinth = sin(theta);
costh = cos(theta);
matrix_scale(3, 3, nx, sinth, term2);
matrix_scale(3, 3, nxsq, 1.0 - costh, term3);
matrix_sum(3, 3, 3, 3, ident, term2, tmp);
matrix_sum(3, 3, 3, 3, tmp, term3, dR);
matrix_product33(dR, R, Rnew2);
}
[/cpp]
[cpp]/* Compute an updated rotation matrix given the initial rotation * and the correction (w) */ void rot_update(double *R, double *w, double *Rnew) { int i, stride0, stride1; Ipp32f mtheta, msinth, mcosth, mn[3]; Ipp32f mat[9], matsq[9], matterm2[9], matterm3[9], mattmp[9], matdR[9], matR[9], matRNew[9]; Ipp32f matident[9] = { 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 }; mtheta = sqrt(w[0] * w[0] + w[1] * w[1] + w[2] * w[2]); if (mtheta == 0.0) { memcpy(Rnew, R, sizeof(double) * 9); return; } mn[0] = w[0] / mtheta; mn[1] = w[1] / mtheta; mn[2] = w[2] / mtheta; mat[0] = 0.0; mat[1] = -mn[2]; mat[2] = mn[1]; mat[3] = mn[2]; mat[4] = 0.0; mat[5] = -mn[0]; mat[6] = -mn[1]; mat[7] = mn[0]; mat[8] = 0.0; stride0 = 3*sizeof(Ipp32f); stride1 = sizeof(Ipp32f); ippmMul_mm_32f(mat, stride0, stride1, 3, 3, mat, stride0, stride1, 3, 3, matsq, stride0, stride1); msinth = sin(mtheta); mcosth = cos(mtheta); ippmMul_mc_32f(mat, stride0, stride1,msinth, matterm2, stride0, stride1, 3, 3); ippmMul_mc_32f(matsq, stride0, stride1, 1.0-mcosth, matterm3, stride0, stride1, 3, 3); ippmAdd_mm_32f(matident, stride0, stride1, matterm2, stride0, stride1, mattmp, stride0, stride1, 3, 3); ippmAdd_mm_32f(mattmp, stride0, stride1, matterm3, stride0, stride1, matdR, stride0, stride1, 3, 3); for(i=0; i<9; ++i) matR = R; ippmMul_mm_32f(matdR, stride0, stride1, 3, 3, matR, stride0, stride1, 3, 3, matRNew, stride0, stride1); for(i=0; i<9; ++i){ Rnew = matRNew; } }
[/cpp]
I didn't test it yet on other computers/systems with more processors/cores but I wanted to know if I was misusing the library or if something else in my code was wrong or could be enhanced.
Link copiado
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Regards
Viktor
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Here are the call graphs below, the first one without and the second one with IPP as you can guess :

- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Hello,
I think Viktor want to check if all CPU features are enabled in the Virtual Box, it needs make sure the optimized CPU code were actually used. You can check with ippsGetLibVersion() function, please see "Example 3-1 Using the Function ippsGetLibVersion" in the ippsman.pdf manual on this fucntions. If it used some PX code, actually the code did not use optimized function.
3x3 matrix computation is very fast operation, compared with the function call overhead. If possibly, you can combine the matrix multiplication into one function call with "matrix array operation".
Thanks,
Chao
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Here is the output of the printf showed in the 3-1 example :
libippsv8.so.6.1 6.1 build 137.36 6.1.137.827
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
I didn't manage to solve the problem yet, does anyone has an idea?
Allan
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Allan,
do you have your code implementation? We can have a benchmark here to check the performance (please reply with private message if you do not publish the code).
when looking at the code, in order to call the function, it adds some additional computation on data type conversion, it convert the data to single float first, then converting it back.
...
for(i=0; i<9; ++i)
matR = R;
...
for(i=0; i<9; ++i){
Rnew = matRNew;
}
If the matrix is small (fast in function call), such overheard may overcome the benefit of calling IPP functions.
Thanks,
Chao

- Subscrever fonte RSS
- Marcar tópico como novo
- Marcar tópico como lido
- Flutuar este Tópico para o utilizador atual
- Marcador
- Subscrever
- Página amigável para impressora