6.1.1.1.2 : Le fichier source
Écrivons le fichier sgemm_base.cpp :
Nous incluons juste notre header :
1 |
#include "sgemm_base.h"
|
Et nous implémentons le produit de matrices :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
///Compute the Matrix-Matrix product of the x,y matrices /** @param[out] matOut : result * @param matX : left matrix * @param matY : right matrix * @param size : size of the square matrices */ void sgemm_base(float* matOut, const float * matX, const float* matY, long unsigned int size){ for(long unsigned int i(0lu); i < size; ++i){ for(long unsigned int j(0lu); j < size; ++j){ float res(0.0f); for(long unsigned int k(0lu); k < size; ++k){ res += matX[i*size + k]*matY[k*size + j]; } matOut[i*size + j] = res; } } } |
Le fichier sgemm_base.cpp complet :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
/*************************************** Auteur : Pierre Aubert Mail : pierre.aubert@lapp.in2p3.fr Licence : CeCILL-C ****************************************/ #include "sgemm_base.h" ///Compute the Matrix-Matrix product of the x,y matrices /** @param[out] matOut : result * @param matX : left matrix * @param matY : right matrix * @param size : size of the square matrices */ void sgemm_base(float* matOut, const float * matX, const float* matY, long unsigned int size){ for(long unsigned int i(0lu); i < size; ++i){ for(long unsigned int j(0lu); j < size; ++j){ float res(0.0f); for(long unsigned int k(0lu); k < size; ++k){ res += matX[i*size + k]*matY[k*size + j]; } matOut[i*size + j] = res; } } } |
Vous pouvez le télécharger ici.