From 43e1f0614fc67bd759fba31a11968565d19a0c34 Mon Sep 17 00:00:00 2001 From: boufaras Date: Thu, 17 Mar 2011 13:46:57 +0000 Subject: [PATCH] git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2199 331e1502-861f-0410-8da2-ba01fb791d7f --- branches/ParadisEO-GPU/src/eval/moCudaEval.h | 139 ++++++++++--------- 1 file changed, 71 insertions(+), 68 deletions(-) diff --git a/branches/ParadisEO-GPU/src/eval/moCudaEval.h b/branches/ParadisEO-GPU/src/eval/moCudaEval.h index cc780a113..ed76cdce5 100644 --- a/branches/ParadisEO-GPU/src/eval/moCudaEval.h +++ b/branches/ParadisEO-GPU/src/eval/moCudaEval.h @@ -39,97 +39,100 @@ /** * Abstract class for evaluation on GPU */ + template class moCudaEval: public moEval { - public: +public: - /** - * Define type of a solution corresponding to Neighbor - */ - typedef typename Neighbor::EOT EOT; + /** + * Define type of a solution corresponding to Neighbor + */ + typedef typename Neighbor::EOT EOT; - typedef typename EOT::Fitness Fitness; + typedef typename EOT::Fitness Fitness; - /** - * Constructor - * @param _neighborhoodSize the size of the neighborhood - */ + /** + * Constructor + * @param _neighborhoodSize the size of the neighborhood + */ - moCudaEval(unsigned int _neighborhoodSize) { + moCudaEval(unsigned int _neighborhoodSize) { - neighborhoodSize = _neighborhoodSize; - host_FitnessArray = new Fitness[neighborhoodSize]; - cudaMalloc((void**) &device_FitnessArray, neighborhoodSize - * sizeof(Fitness)); - kernel_Dim = neighborhoodSize / BLOCK_SIZE + ((neighborhoodSize - % BLOCK_SIZE == 0) ? 0 : 1); - } + neighborhoodSize = _neighborhoodSize; + host_FitnessArray = new Fitness[neighborhoodSize]; + cudaMalloc((void**) &device_FitnessArray, neighborhoodSize + * sizeof(Fitness)); + kernel_Dim = neighborhoodSize / BLOCK_SIZE + ((neighborhoodSize + % BLOCK_SIZE == 0) ? 0 : 1); + } - /** - * Destructor - */ + /** + * Destructor + */ - ~moCudaEval() { + ~moCudaEval() { - delete[] host_FitnessArray; - cudaFree(device_FitnessArray); - cudaFree(&device_solution); - } + delete[] host_FitnessArray; + cudaFree(device_FitnessArray); + cudaFree(&device_solution); - /** - * Set fitness of a solution neighbors - *@param _sol the solution which generate the neighborhood - *@param _neighbor the current neighbor - */ + } - void operator()(EOT & _sol, Neighbor & _neighbor) { + /** + * Set fitness of a solution neighbors + *@param _sol the solution which generate the neighborhood + *@param _neighbor the current neighbor + */ - _neighbor.fitness(host_FitnessArray[_neighbor.index()]); + void operator()(EOT & _sol, Neighbor & _neighbor) { - } + _neighbor.fitness(host_FitnessArray[_neighbor.index()]); - /** - * Compute fitness for all Kswap solution neighbors in device - * @param _sol the solution which generate the neighborhood - * @param _mapping the neighborhood mapping - * @param _Kswap the number of swap - */ - virtual void neighborhoodKswapEval(EOT & _sol, unsigned * _mapping, - unsigned _Kswap) { + } - } + /** + * Compute fitness for all Kswap solution neighbors in device + * @param _sol the solution which generate the neighborhood + * @param _mapping the neighborhood mapping + * @param _Kswap the number of swap + */ - /** - * Compute fitness for all Kflip solution neighbors in device - * @param _sol the solution which generate the neighborhood - * @param _mapping the neighborhood mapping - * @param _Kflip the number of bit to flip - */ - virtual void neighborhoodKflipEval(EOT & _sol, unsigned * _mapping, - unsigned _Kflip) { + virtual void neighborhoodKswapEval(EOT & _sol, unsigned * _mapping, + unsigned _Kswap) { - } + } - /** - * Compute fitness for all solution neighbors in device - * @param _sol the solution which generate the neighborhood - */ + /** + * Compute fitness for all Kflip solution neighbors in device + * @param _sol the solution which generate the neighborhood + * @param _mapping the neighborhood mapping + * @param _Kflip the number of bit to flip + */ + virtual void neighborhoodKflipEval(EOT & _sol, unsigned * _mapping, + unsigned _Kflip) { - virtual void neighborhoodEval(EOT & _sol)=0; + } - protected: + /** + * Compute fitness for all solution neighbors in device + * @param _sol the solution which generate the neighborhood + */ - //the host array to save all neighbors fitness - Fitness * host_FitnessArray; - //the device array to save neighbors fitness computed in device - Fitness * device_FitnessArray; - //the device solution - EOT device_solution; - //the size of neighborhood - unsigned int neighborhoodSize; - //Cuda kernel dimension - int kernel_Dim; + virtual void neighborhoodEval(EOT & _sol)=0; + +protected: + + //the host array to save all neighbors fitness + Fitness * host_FitnessArray; + //the device array to save neighbors fitness computed in device + Fitness * device_FitnessArray; + //the device solution + EOT device_solution; + //the size of neighborhood + unsigned int neighborhoodSize; + //Cuda kernel dimension + int kernel_Dim; };