Commit bef9aa94 authored by Ogier Maitre's avatar Ogier Maitre

1.09rc3 + gp cpu

parent d21fd5e8
......@@ -27,7 +27,7 @@ Centre de Math
#define STD_FLAVOR_MO 1
#define CUDA_FLAVOR_SO 0
#define CUDA_FLAVOR_MO 1
#define CUDA_FLAVOR_GP 2
#define FLAVOR_GP 2
#define UNIX 1
......
This diff is collapsed.
......@@ -315,7 +315,7 @@ exponent ([Ee][+-]?[0-9]+)
fprintf(fpOutputFile,"#define MAX_PROGS_SIZE %d\n",iPRG_BUF_SIZE);
fprintf(fpOutputFile,"#define NB_GPU %d\n",iNB_GPU);
fprintf(fpOutputFile,"#define NO_FITNESS_CASES %d\n",iNO_FITNESS_CASES);
//fprintf(fpOutputFile,"#define NO_FITNESS_CASES %d\n",iNO_FITNESS_CASES);
}
/*
......@@ -345,14 +345,14 @@ exponent ([Ee][+-]?[0-9]+)
}
fprintf(fpOutputFile,"};\n");
/*
// count the number of variable (arity zero and non-erc operator)
unsigned var_len = 0;
for( unsigned i=0 ; i<iNoOp ; i++ ){
if( opDesc[i]->arity==0 && !opDesc[i]->isERC ) var_len++;
}
if( bVERBOSE ) printf("var length is %d\n",var_len);
fprintf(fpOutputFile,"#define VAR_LEN %d\n",var_len);
fprintf(fpOutputFile,"#define VAR_LEN %d\n",var_len); */
}
<TEMPLATE_ANALYSIS>"\\INSERT_GP_GPU_SWITCH" {
......@@ -389,7 +389,6 @@ exponent ([Ee][+-]?[0-9]+)
}
<GP_RULE_ANALYSIS>"\\end" {
if (bVERBOSE) printf ("found end section\n");
if( bGPOPCODE_ANALYSIS ){
rewind(fpGenomeFile);
yyin = fpTemplateFile;
......@@ -468,7 +467,6 @@ exponent ([Ee][+-]?[0-9]+)
fprintf(stderr,"Error, code must be given at the forth place\n");
exit(-1);
}
if( bVERBOSE ) printf("begining of the code part\n");
accolade_counter=1;
// printf("arity : %d\n",opDesc[iNoOp]->arity);
......@@ -1109,7 +1107,8 @@ exponent ([Ee][+-]?[0-9]+)
lineCounter=1;
BEGIN COPY_MUTATOR;
}
<TEMPLATE_ANALYSIS>"\\INSERT_EVALUATOR" {
<TEMPLATE_ANALYSIS>"\\INSERT_EVALUATOR" {
printf("evaluator insert\n");
yyreset();
yyin = fpGenomeFile; // switch to .ez file and analyser
lineCounter=1;
......@@ -1967,6 +1966,7 @@ if(OPERATING_SYSTEM=WINDOWS)
<COPY_EVALUATOR>. {}
<COPY_EVALUATOR>\n {lineCounter++;}
<COPY_OPTIMISER>"\\GenomeClass::optimiser"[ \t\n]*":" {
BEGIN COPY_USER_FUNCTION;
bWithinOptimiser=1;
......@@ -2478,7 +2478,7 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable)
strcat(sTemp,"CUDA.tpl");
else if(TARGET_FLAVOR == CMAES )
strcat(sTemp,"CMAES_CUDA.tpl");
else if( TARGET_FLAVOR == CUDA_FLAVOR_GP )
else if( TARGET_FLAVOR == FLAVOR_GP )
strcat(sTemp,"CUDA_GP.tpl");
else if(TARGET_FLAVOR == MEMETIC )
strcat(sTemp,"CUDA_MEM.tpl");
......@@ -2496,6 +2496,8 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable)
strcat(sTemp,"STD.tpl");
else if (TARGET_FLAVOR == CMAES)
strcat(sTemp,"CMAES.tpl");
else if (TARGET_FLAVOR == FLAVOR_GP)
strcat(sTemp,"GP.tpl");
else if (TARGET_FLAVOR == MEMETIC )
strcat(sTemp,"STD_MEM.tpl");
//else if (TARGET_FLAVOR == STD_FLAVOR_GP )
......@@ -2509,7 +2511,6 @@ int CEASEALexer::create(CEASEAParser* pParser, CSymbolTable* pSymTable)
}
}
if ((sRAW_PROJECT_NAME[0]=='"')&&(OPERATING_SYSTEM!=WINDOWS)){
strcpy(sRAW_PROJECT_NAME,&(sRAW_PROJECT_NAME[1]));
sRAW_PROJECT_NAME[strlen(sRAW_PROJECT_NAME)-1]=0;
......
......@@ -1644,9 +1644,14 @@ int main(int argc, char *argv[]){
TARGET_FLAVOR = CUDA_FLAVOR_MO;
}
else if( !mystricmp(sTemp,"cuda_gp") ){
printf("tpl argu : is gp\n");
printf("tpl is cuda gp\n");
TARGET=CUDA;
TARGET_FLAVOR = CUDA_FLAVOR_GP;
TARGET_FLAVOR = FLAVOR_GP;
}
else if( !mystricmp(sTemp,"gp") ){
printf("tpl is gp\n");
TARGET=STD;
TARGET_FLAVOR = FLAVOR_GP;
}
else if (!mystricmp(sTemp,"std")) {
TARGET=STD;
......@@ -1742,11 +1747,12 @@ double CEASEAParser::divide(double a, double b)
void CEASEAParser::yysyntaxerror(){
printf("Syntax Error at line : %d\nFor more details during the EASEA compiling, use the \"-v\" option\n",EASEALexer.yylineno);
printf("Syntax Error at line : %d (on text : %s)\nFor more details during the EASEA compiling, use the \"-v\" option\n",
EASEALexer.yylineno,EASEALexer.yytext);
}
#line 1750 "EaseaParse.cpp"
#line 1756 "EaseaParse.cpp"
void YYPARSENAME::yytables()
{
yyattribute_size = sizeof(YYSTYPE);
......
......@@ -752,9 +752,14 @@ int main(int argc, char *argv[]){
TARGET_FLAVOR = CUDA_FLAVOR_MO;
}
else if( !mystricmp(sTemp,"cuda_gp") ){
printf("tpl argu : is gp\n");
printf("tpl is cuda gp\n");
TARGET=CUDA;
TARGET_FLAVOR = CUDA_FLAVOR_GP;
TARGET_FLAVOR = FLAVOR_GP;
}
else if( !mystricmp(sTemp,"gp") ){
printf("tpl is gp\n");
TARGET=STD;
TARGET_FLAVOR = FLAVOR_GP;
}
else if (!mystricmp(sTemp,"std")) {
TARGET=STD;
......@@ -850,6 +855,7 @@ double CEASEAParser::divide(double a, double b)
void CEASEAParser::yysyntaxerror(){
printf("Syntax Error at line : %d\nFor more details during the EASEA compiling, use the \"-v\" option\n",EASEALexer.yylineno);
printf("Syntax Error at line : %d (on text : %s)\nFor more details during the EASEA compiling, use the \"-v\" option\n",
EASEALexer.yylineno,EASEALexer.yytext);
}
......@@ -160,9 +160,9 @@ endif
# rm -f EaseaParse.cpp EaseaParse.h EaseaLex.cpp EaseaLex.h
#EaseaParse.cpp: EaseaParse.y
# wine ~/.wine/drive_c/Program\ Files/Parser\ Generator/BIN/ayacc.exe $< -Tcpp -d
EaseaParse.cpp: EaseaParse.y
wine ~/.wine/drive_c/Program\ Files/Parser\ Generator/BIN/ayacc.exe $< -Tcpp -d
#EaseaLex.cpp: EaseaLex.l
# wine ~/.wine/drive_c/Program\ Files/Parser\ Generator/BIN/ALex.exe $< -Tcpp -i
EaseaLex.cpp: EaseaLex.l
wine ~/.wine/drive_c/Program\ Files/Parser\ Generator/BIN/ALex.exe $< -Tcpp -i
#endif
/*_________________________________________________________
This is a standard GP implementation on EASEA,
......@@ -12,6 +10,13 @@
__________________________________________________________*/
\User declarations :
// these 3 defines are mandatory here. Adjust as you like.
#define NO_FITNESS_CASES 1024
#define VAR_LEN 1
#define GROW_FULL_RATIO 0.5
#define PI (3.141592653589793)
\end
......@@ -44,7 +49,7 @@ int generateData(float*** inputs, float** outputs){
void free_data(){
for( int i=0 ; i<fitnessCasesSetLength ;i++ )
for( int i=0 ; i<NO_FITNESS_CASES ;i++ )
delete[] inputs[i] ;
delete[] outputs;
delete[] inputs;
......@@ -61,7 +66,9 @@ void free_data(){
\After everything else function:
{
toDotFile( ((IndividualImpl*)EA->population->Best)->root, "best", 0);
//toDotFile( ((IndividualImpl*)EA->population->Best)->root, "best", 0);
std::cout << toString(((IndividualImpl*)EA->population->Best)->root) << std::endl;
free_data();
}
\end
......@@ -91,11 +98,12 @@ GenomeClass {
\end
\GenomeClass::display:
\end
\GenomeClass::initialiser :
{
Genome.root = RAMPED_H_H(INIT_TREE_DEPTH_MIN,INIT_TREE_DEPTH_MAX,EA->population->actualParentPopulationSize,EA->population->parentPopulationSize,GROW_FULL_RATIO, VAR_LEN, OPCODE_SIZE,opArity, OP_ERC);
Genome.root = ramped_hh();
}
\end
......@@ -115,8 +123,10 @@ GenomeClass {
}
\end
\begin operator description :
OP_X, "x", 0, {RESULT=INPUT[0];};
OP_ERC, "ERC", 0, {RESULT=ERC;};
OP_ADD, "+", 2, {RESULT=OP1+OP2;};
OP_SUB, "-", 2, {RESULT=OP1-OP2;};
OP_MUL, "*", 2, {RESULT=OP1*OP2;};
......@@ -124,21 +134,23 @@ OP_DIV, "/", 2, {
if( !OP2 ) RESULT = 1;
else RESULT = OP1/OP2;
};
OP_ERC, "ERC", 0, {RESULT=ERC;};
\end
\GenomeClass::evaluator header:
\end
\GenomeClass::evaluator for each fc :
float expected_value = OUTPUT;
ERROR = powf(expected_value-EVOLVED_VALUE,2);
ERROR = (expected_value-EVOLVED_VALUE)*(expected_value-EVOLVED_VALUE);
\end
\GenomeClass::evaluator accumulator :
return sqrtf(ERROR/NO_FITNESS_CASES);
return sqrtf(ERROR);
\end
\User Makefile options:
CXXFLAGS+=-I/usr/local/cuda/common/inc/ -I/usr/local/cuda/include/
......@@ -146,36 +158,40 @@ LDFLAGS+=
\end
\Default run parameters : // Please let the parameters appear in this order
Number of generations : 100 // NB_GEN
Time limit: 0 // In seconds, 0 to deactivate
Population size : 4096 //POP_SIZE
Offspring size : 4096 // 40%
Mutation probability : 0.2 // MUT_PROB
Crossover probability : 0.9 // XOVER_PROB
Evaluator goal : minimise // Maximise
Selection operator: Tournament 2
Number of generations : 50 // NB_GEN
Time limit: 0 // In seconds, 0 to deactivate
Population size : 5000 //POP_SIZE
Offspring size : 5000 // 40%
Mutation probability : 0.1 // MUT_PROB
Crossover probability : 0.9 // XOVER_PROB
Evaluator goal : minimise // Maximise
Selection operator: Tournament 7
Surviving parents: 100%//percentage or absolute
Surviving offspring: 100%
Reduce parents operator: Tournament 2
Reduce offspring operator: Tournament 2
Final reduce operator: Tournament 2
Final reduce operator: Tournament 7
Elitism: Strong //Weak or Strong
Elite: 1
Print stats: true //Default: 1
Generate csv stats file:false
Generate gnuplot script:false
Generate R script:false
Plot stats:true //Default: 0
// Print stats:1 //Default: 1
// Generate csv stats file:0
// Generate gnuplot script:0
// Generate R script:0
// Plot stats:0 //Default: 0
// Remote island model: true
//IP file: ip.txt //File containing all the remote island's IP
//Server port : 2929
//Migration probability: 0.33
max init tree depth : 9
min init tree depth : 4
Save population: false
Start from file:false
max tree depth : 12
max init tree depth : 4
min init tree depth : 2
nb of GPUs : 1
size of prog buffer : 20000000
max tree depth : 8
nb of fitness cases : 128
size of prog buffer : 20000000
\end
#include <math.h>
#include <stdlib.h>
#include "include/CCuda.h"
#include <stdio.h>
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;
}
*/
......@@ -3,6 +3,9 @@
#include <stdlib.h>
#include <string.h>
#include<iostream>
#include<sstream>
extern CRandomGenerator* globalRandomGenerator;
extern unsigned opArity[];
......@@ -187,7 +190,8 @@ GPNode* construction_method( const int constLen, const int totalLen , const int
}
GPNode* RAMPED_H_H(unsigned INIT_TREE_DEPTH_MIN, unsigned INIT_TREE_DEPTH_MAX, unsigned actualParentPopulationSize, unsigned parentPopulationSize, float GROW_FULL_RATIO, unsigned VAR_LEN, unsigned OPCODE_SIZE, const unsigned* opArity, const int OP_ERC){
GPNode* RAMPED_H_H(unsigned INIT_TREE_DEPTH_MIN, unsigned INIT_TREE_DEPTH_MAX, unsigned actualParentPopulationSize, unsigned parentPopulationSize,
float GROW_FULL_RATIO, unsigned VAR_LEN, unsigned OPCODE_SIZE, const unsigned* opArity, const int OP_ERC){
/**
This is the standard ramped half-and-half method
for creation of trees.
......@@ -208,3 +212,94 @@ GPNode* RAMPED_H_H(unsigned INIT_TREE_DEPTH_MIN, unsigned INIT_TREE_DEPTH_MAX, u
void toString_r(std::ostringstream* oss, GPNode* root, const unsigned* opArity , const char** opCodeName, int OP_ERC) {
(*oss) << '(';
if (opArity[(int)root->opCode] == 2) {
toString_r(oss,root->children[0],opArity,opCodeName,OP_ERC);
(*oss) << ' ';
(*oss) << opCodeName[(int)root->opCode];
(*oss) << ' ';
toString_r(oss,root->children[1],opArity,opCodeName,OP_ERC);
} else {
if (root->opCode == OP_ERC) {
(*oss) << root->erc_value;
} else {
(*oss) << opCodeName[(int)root->opCode];
}
for (unsigned i = 0; i < opArity[(int)root->opCode]; ++i) {
if (root->children[i]) {
toString_r(oss,root->children[i],opArity,opCodeName,OP_ERC);
if (i < opArity[(int)root->opCode] - 1) {
(*oss) << ' ';
}
}
}
}
(*oss) << ')';
return;
}
std::string toString(GPNode* root, const unsigned* opArity , const char** opCodeName, int OP_ERC) {
std::ostringstream oss;
toString_r(&oss,root,opArity,opCodeName,OP_ERC);
return oss.str();
}
/**
This function handles printing of tree.
Every node is identify by its address, in memory,
and labeled by the actual opCode.
On our architecture (64bits, ubuntu 8.04 and gcc-4.3.2)
the long int variable is sufficient to store the address
without any warning.
*/
void toDotFile_r(GPNode* root, FILE* outputFile, const unsigned* opArity , const char** opCodeName, int OP_ERC){
if( root->opCode==OP_ERC )
fprintf(outputFile," %ld [label=\"%s : %f\"];\n", (long int)root, opCodeName[(int)root->opCode],
root->erc_value);
else
fprintf(outputFile," %ld [label=\"%s\"];\n", (long int)root, opCodeName[(int)root->opCode]);
for( unsigned i=0 ; i<opArity[(int)root->opCode] ; i++ ){
if( root->children[i] ){
fprintf(outputFile,"%ld -> %ld;\n", (long int)root, (long int)root->children[i]);
toDotFile_r( root->children[i] , outputFile,opArity,opCodeName,OP_ERC);
}
}
}
/**
This function prints a tree in dot (graphviz format).
This is the entry point for the print operation. (see toDotFile_r,
for the actual function)
@arg root : set of trees, same type than in a individual.
@arg baseFileName : base of filename for the output file.
@arg treeId : the id of the tree to print, in the given set.
*/
void toDotFile(GPNode* root, const char* baseFileName, int treeId, const unsigned* opArity , const char** opCodeName, int OP_ERC){
std::ostringstream oss;
oss << baseFileName << "-" << treeId << ".gv";
FILE* outputFile = fopen(oss.str().c_str(),"w");
if( !outputFile ){
perror("Opening file for outputing dot representation ");
printf("%s\n",oss.str().c_str());
exit(-1);
}
fprintf(outputFile,"digraph trees {\n");
if(root)
toDotFile_r( root, outputFile,opArity,opCodeName,OP_ERC);
fprintf(outputFile,"}\n");
fclose(outputFile);
}
......@@ -8,15 +8,15 @@ CXXFLAGS = -g -Wall -fmessage-length=0 -I/usr/local/cuda/include #-I../boost/
OBJS = CRandomGenerator.o CSelectionOperator.o CEvolutionaryAlgorithm.o\
CStoppingCriterion.o COptionParser.o CPopulation.o CIndividual.o\
CGrapher.o CCmaes.o CCmaesCuda.o Parameters.o CGPNode.o\
CComUDPLayer.o CStats.o CCuda.o
CComUDPLayer.o CStats.o CGPNode.o
ifneq ("$(OS)","")
OBJS += inet_pton.o
endif
ifeq ($(EZ_CUDA),1)
OBJS += CCuda.o
endif
#ifeq ($(EZ_CUDA),1)
#OBJS += CCuda.o
#endif
ifneq ("$(OS)","")
LIBS = -L"C:\MinGW\lib" -lws2_32 -lwinmm
......@@ -38,7 +38,7 @@ $(TARGET): $(OBJS)
all: $(TARGET)
clean:
ifneq ("$(OS)","")
-del $(OBJS) $(TARGET) CCuda.o
-del $(OBJS) $(TARGET)
else
rm -f $(OBJS) $(TARGET) CCuda.o
rm -f $(OBJS) $(TARGET)
endif
......@@ -27,9 +27,7 @@
}
struct gpuOptions{};
struct my_struct_gpu{
struct gpuEvaluationData{
int indiv_start;
int sh_pop_size;
......@@ -41,9 +39,7 @@ struct my_struct_gpu{
int dimBlock;
cudaDeviceProp gpuProp;
};
struct gpuArg{
int gpuId;
int threadId;
sem_t sem_in;
......@@ -54,16 +50,4 @@ struct gpuArg{
};
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_ */
......@@ -83,4 +83,8 @@ void flattenDatas2D( float** inputs, int length, int width, float** flat_inputs)
GPNode* construction_method( const int constLen, const int totalLen , const int currentDepth, const int maxDepth, const bool full, const unsigned* opArity, const int OP_ERC);
// display methods
void toDotFile(GPNode* root, const char* baseFileName, int treeId, const unsigned* opArity , const char** opCodeName, int OP_ERC);
std::string toString(GPNode* root, const unsigned* opArity , const char** opCodeName, int OP_ERC);
#endif // __C_GPNODE__
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment