CCuda.cpp 1.67 KB
Newer Older
kruger's avatar
kruger committed
1
#include <math.h>
maitre's avatar
maitre committed
2
#include <stdlib.h>
kruger's avatar
kruger committed
3
#include "include/CCuda.h"
4
#include <stdio.h>
5
 
kruger's avatar
kruger committed
6

Ogier Maitre's avatar
Ogier Maitre committed
7
CCuda::CCuda(unsigned parentSize, unsigned offSize, unsigned individualImplSize){
kruger's avatar
kruger committed
8
	this->sizeOfIndividualImpl = individualImplSize;
9
	this->cudaBuffer = (void*)malloc(this->sizeOfIndividualImpl*( (parentSize>offSize) ? parentSize : offSize));
kruger's avatar
kruger committed
10 11 12 13 14
}

CCuda::~CCuda(){
}

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
bool repartition(struct my_struct_gpu* gpu_infos){
	
	//There is an implied minimum number of threads for each block
        if(gpu_infos->num_Warp > gpu_infos->num_thread_max){
            printf("You need to authorized at least %d threads on each block!\n",gpu_infos->num_Warp);
            exit(1);
        }

        gpu_infos->dimGrid = gpu_infos->num_MP;
        gpu_infos->dimBlock = gpu_infos->num_Warp;;
  	
        //While each element of the population can't be placed on the card
        while(gpu_infos->dimBlock * gpu_infos->dimGrid < gpu_infos->sh_pop_size) {
             //Every time we add the number of Warp to the value of dimBlock
             if( (gpu_infos->dimBlock += gpu_infos->num_Warp) > gpu_infos->num_thread_max ) {
                  //If the number of dimBlock exceeds the number of threads max, we add the number of MP to the value of dimGrid and we reset the value of dimBlock with the number of Warp
                  gpu_infos->dimGrid += gpu_infos->num_MP;
                  gpu_infos->dimBlock = gpu_infos->num_Warp;
             }
        }
kruger's avatar
kruger committed
35 36


37 38
	//Verification that we have enough place for all the population and that every constraints are respected
	if( (gpu_infos->dimBlock*gpu_infos->dimGrid >= gpu_infos->sh_pop_size) && (gpu_infos->dimBlock <= gpu_infos->num_thread_max))
kruger's avatar
kruger committed
39 40 41 42 43
		return true;
	else 
		return false;
}

44 45