diff --git a/libeasea/CCuda.cpp b/libeasea/CCuda.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4b806dcec4c8029e2834366edf6dbc27bd7ef6d9 --- /dev/null +++ b/libeasea/CCuda.cpp @@ -0,0 +1,46 @@ +#include +#include +#include "include/CCuda.h" +#include + + +CCuda::CCuda(unsigned parentSize, unsigned offSize, unsigned individualImplSize){ + this->sizeOfIndividualImpl = individualImplSize; + this->cudaBuffer = (void*)malloc(this->sizeOfIndividualImpl*( (parentSize>offSize) ? parentSize : offSize)); +} + +CCuda::~CCuda(){ +} + +/*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; + } + } + + + //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)) + return true; + else + return false; +} + + + +*/ diff --git a/libeasea/include/CCuda.h b/libeasea/include/CCuda.h new file mode 100755 index 0000000000000000000000000000000000000000..08d123842baa0d7592fe448449065a1be5b6908c --- /dev/null +++ b/libeasea/include/CCuda.h @@ -0,0 +1,69 @@ +/* + * CCuda.h + * + * Created on: 23 juin 2009 + * Author: maitre + */ + +#ifndef CCUDA_H_ +#define CCUDA_H_ + +#include +#include +#include +#include +//#include + + + +#define CUDA_SAFE_CALL(f) \ + { \ + cudaError_t err; \ + err = f; \ + if( err != cudaSuccess ){ \ + printf("Error : %s\n",cudaGetErrorString(err)); \ + exit(-1); \ + } \ + } + + +struct gpuOptions{}; + +struct my_struct_gpu{ + int indiv_start; + int sh_pop_size; + + int num_MP; + int num_thread_max; + int num_Warp; + + int dimGrid; + int dimBlock; + + cudaDeviceProp gpuProp; +}; + +struct gpuArg{ + int gpuId; + int threadId; + sem_t sem_in; + sem_t sem_out; + + void* d_population; + float* d_fitness; + +}; + +class CCuda { +public: + void* cudaBuffer; + unsigned sizeOfIndividualImpl; + struct gpuOptions initOpts; +public: + CCuda(unsigned parentSize, unsigned offSize, unsigned individualImplSize); + ~CCuda(); +}; + +bool repartition(struct my_struct_gpu* gpu_infos); + +#endif /* CCUDA_H_ */