3.3.3.2 : Sans les transfert de données
Développons le fichier main_kernel.cpp :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
#include <iostream> #include "timer.h" #include "asterics_cuda.h" #include "hadamard_product_cuda.h" ///Get the number of cycles per elements of the Hadamard product /** @param nbElement : number of elements of the tables * @param nbRepetition : number of repetition to evaluate the function hadamard_product * @param maxNbThreadPerBlockX : maximum number of thread per block on X * @param maxNbBlockX : maximum number of block in the grid on X * @param warpSize : number of thread per warp */ void evaluateHadamardProduct(long unsigned int nbElement, long unsigned int nbRepetition, int maxNbThreadPerBlockX, int maxNbBlockX, int warpSize){ //Allocation of the tables float * tabResult = new float[nbElement]; float * tabX = new float[nbElement]; float * tabY = new float[nbElement]; //Initialisation of the tables for(long unsigned int i(0lu); i < nbElement; ++i){ tabX[i] = (float)(i*32lu%17lu); tabY[i] = (float)(i*57lu%31lu); } hadamard_product_cuda_clock(tabResult, tabX, tabY, nbElement, nbRepetition, maxNbThreadPerBlockX, maxNbBlockX, warpSize); //Deallocate the tables delete[] tabResult; delete[] tabX; delete[] tabY; } int main(int argc, char** argv){ std::cout << "Hadamard product Kernel" << std::endl; #ifdef SELECTED_GPU if(!asterics_setDevice(SELECTED_GPU)){std::cerr << "Device '" SELECTED_GPU "' not found" << std::endl;return -1;} #else int deviceCount(asterics_getNbCudaDevice()); int maxNbThreadPerBlockX(0), maxNbBlockX(0), warpSize(0); asterics_getGpuInfo(maxNbThreadPerBlockX, maxNbBlockX, warpSize, 0); #endif evaluateHadamardProduct(1000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(2000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(3000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(5000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(10000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(20000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(50000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(100000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(500000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(1000000lu, 10000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(10000000lu, 10000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(100000000lu, 1000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(500000000lu, 100lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); return 0; } |
Le fichier main_kernel.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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
/*************************************** Auteur : Pierre Aubert Mail : pierre.aubert@lapp.in2p3.fr Licence : CeCILL-C ****************************************/ #include <iostream> #include "timer.h" #include "asterics_cuda.h" #include "hadamard_product_cuda.h" ///Get the number of cycles per elements of the Hadamard product /** @param nbElement : number of elements of the tables * @param nbRepetition : number of repetition to evaluate the function hadamard_product * @param maxNbThreadPerBlockX : maximum number of thread per block on X * @param maxNbBlockX : maximum number of block in the grid on X * @param warpSize : number of thread per warp */ void evaluateHadamardProduct(long unsigned int nbElement, long unsigned int nbRepetition, int maxNbThreadPerBlockX, int maxNbBlockX, int warpSize){ //Allocation of the tables float * tabResult = new float[nbElement]; float * tabX = new float[nbElement]; float * tabY = new float[nbElement]; //Initialisation of the tables for(long unsigned int i(0lu); i < nbElement; ++i){ tabX[i] = (float)(i*32lu%17lu); tabY[i] = (float)(i*57lu%31lu); } hadamard_product_cuda_clock(tabResult, tabX, tabY, nbElement, nbRepetition, maxNbThreadPerBlockX, maxNbBlockX, warpSize); //Deallocate the tables delete[] tabResult; delete[] tabX; delete[] tabY; } int main(int argc, char** argv){ std::cout << "Hadamard product Kernel" << std::endl; #ifdef SELECTED_GPU if(!asterics_setDevice(SELECTED_GPU)){std::cerr << "Device '" SELECTED_GPU "' not found" << std::endl;return -1;} #else int deviceCount(asterics_getNbCudaDevice()); int maxNbThreadPerBlockX(0), maxNbBlockX(0), warpSize(0); asterics_getGpuInfo(maxNbThreadPerBlockX, maxNbBlockX, warpSize, 0); #endif evaluateHadamardProduct(1000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(2000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(3000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(5000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(10000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(20000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(50000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(100000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(500000lu, 100000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(1000000lu, 10000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(10000000lu, 10000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(100000000lu, 1000lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); evaluateHadamardProduct(500000000lu, 100lu, maxNbThreadPerBlockX, maxNbBlockX, warpSize); return 0; } |
Vous pouvez télécharger le fichier ici.