Skip to content

Commit

Permalink
Fix -cuda_gp (#39)
Browse files Browse the repository at this point in the history
* Fixed -cuda_gp

* Fixed Boost to 1.79.0 on Windows.
  • Loading branch information
zeFresk authored Aug 24, 2022
1 parent 7dc4930 commit 9fae6c6
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,12 @@ jobs:
- uses: actions/checkout@v3

- name: Installing dependencies
run: choco install winflexbison3 boost-msvc-14.3 sed
run: choco install winflexbison3 sed
shell: bash

- name: Installing Boost 1.79
run: choco install boost-msvc-14.3 --version 1.79.0

- name: CMake configure
id: cmake-configure
run: cmake -B ./build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ The other dependencies can be installed using chocolatey by opening a Powershell
choco install winflexbison3 boost-msvc-14.3 cmake
```

Some users have reported issues with the latest version of Boost. This software is guaranteed to run on Boost 1.79.0.
To install this version specifically it is recommended to uninstall the latest version and reinstall Boost 1.79.0 :

```bash
choco uninstall boost-msvc-14.3
choco install boost-msvc-14.3 --version 1.79.0
```

### Building and installing EASEA with CMake

1. Once all dependencies are installed open either a bash shell on Linux/MacOS or a [MSBuild shell](https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170) on Windows
Expand Down
3 changes: 2 additions & 1 deletion examples/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ for edir in $all_examples; do

# Convert args if CUDA not available
if [[ "$2" == "--no-cuda" ]]; then
EASEA_ARGS=$(echo $EASEA_ARGS | $SED 's/\(cuda_\|-cuda\|_cuda\)//')
EASEA_ARGS=$(echo $EASEA_ARGS | $SED 's/\(cuda_\|_cuda\)//')
EASEA_ARGS=$(echo $EASEA_ARGS | $SED 's/\(-cuda\)//')
fi

# build
Expand Down
9 changes: 9 additions & 0 deletions examples/regression_cuda/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
To Compile this example:
$ easea -cuda_gp regression.ez
$ cmake . && cmake --build . --config Release

To test it:
$ ./regression

To clean easea related file:
$ make easeaclean
180 changes: 180 additions & 0 deletions examples/regression_cuda/regression.ez
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*_________________________________________________________

This is a standard GP implementation on EASEA,
aimed for regression.

use : easena -gp regression.ez
make

OR (if you'd like to exploit a CUDA-compatible graphic card)

easena -cuda_gp regression.ez
make

in order to generate and compile this code.
You can use C++ colour formatting for enhanced reading
__________________________________________________________*/

\User declarations :
// these 3 defines are mandatory here. Adjust as you like.
#define NO_FITNESS_CASES 1024
// VAR_LEN defines the number of dimensions of the problem
#define VAR_LEN 1
#define GROW_FULL_RATIO 0.5

// this is the number of learning cases computed in parallel.
// note that on 1024 is the maximum size on fermi architectures 512 on older cards.
#define NUMTHREAD 1024
#define MAX_STACK 15

#define PI (3.141592653589793)
\end

\User functions:
#define FUNC(x) 4*sin(3*x)+x*x/10
//#define FUNC(x) x*x*x-3*x*x+x
/**
This function generates data NO_FITNESS_CASES fitness cases,
from function FUNC(X) with X randomly picked between (-1,1)

@inputs address of the inputs array. (array will be allocated here)
@outputs adddress of the outputs array. (array will be allocated here)

@ret number of loaded fitness cases (should be equal to NO_FITNESS_CASES).
*/
int generateData(float*** inputs, float** outputs){
int i=0;

(*inputs) = new float*[NO_FITNESS_CASES];
(*outputs) = new float[NO_FITNESS_CASES];

for( i=0 ; i<NO_FITNESS_CASES ; i++ ){
(*inputs)[i]=new float[VAR_LEN];
float x = random(-10.,+10.);
(*inputs)[i][0] = x;
(*outputs)[i] = FUNC(x);
}
return NO_FITNESS_CASES;
}

void free_data(){
for( int i=0 ; i<NO_FITNESS_CASES ;i++ ) delete[] inputs[i] ;
delete[] outputs;
delete[] inputs;
}
\end

\Before everything else function:
generateData(&inputs,&outputs);
\end

\After everything else function:
std::cout << "----------\n";
std::cout << "y="<<toString(((IndividualImpl*)EA->population->Best)->root) << std::endl;
std::cout << "----------\n";
free_data();
\end

\At the beginning of each generation function:
//cout << "At the beginning of each generation function called" << endl;
\end

\At the end of each generation function:
//cout << "At the end of each generation function called" << endl;
\end

\At each generation before reduce function:
//cout << "At each generation before replacement function called" << endl;
\end

\User classes :
GenomeClass { // GPNode is a reserved name that must be used to create a GP tree
GPNode* root;
}
\end

\GenomeClass::display:
\end

\GenomeClass::initialiser :
Genome.root = ramped_hh(); // ramped-hh() is a reserved name
\end

\GenomeClass::crossover :
simpleCrossOver(parent1,parent2,child); // simpleCrossOver is reserved
child.valid = false; // child is reserved
\end

\GenomeClass::mutator :
simple_mutator(&Genome); // simple_mutator does a Koza mutation
\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;};
//OP_wEXP, "exp", 1, {RESULT=exp(OP1);};
OP_SIN, "sin", 1, {RESULT=sin(OP1);};
OP_DIV, "/", 2, {
if( !OP2 ) RESULT = 1;
else RESULT = OP1/OP2;
};
\end

\GenomeClass::evaluator header:
\end

\GenomeClass::evaluator for each fc :
//error = pow((OUTPUT-EVOLVED_VALUE),2); // not good for noisy real-world data
error = fabs(OUTPUT-EVOLVED_VALUE);
\end

\GenomeClass::evaluator accumulator :
//return sqrtf(error);
return error;
\end

\User Makefile options:
CXXFLAGS+=-I/usr/local/cuda/common/inc/ -I/usr/local/cuda/include/
LDFLAGS+=
\end

\Default run parameters : // Please let the parameters appear in this order
Number of generations : 65 // NB_GEN
Time limit: 60 // In seconds, 0 to deactivate
Population size : 50000 //POP_SIZE
Offspring size : 50000 // 40%
Mutation probability : 0.3 // MUT_PROB
Crossover probability : 1 // XOVER_PROB
Evaluator goal : minimise // Maximise
Selection operator: Tournament 30
Surviving parents: 100%//percentage or absolute
Surviving offspring: 100%
Reduce parents operator: Tournament 2
Reduce offspring operator: Tournament 2
Final reduce operator: Tournament 5

Elitism: Weak //Weak or Strong
Elite: 1
Print stats: true
Generate csv stats file:false
Generate gnuplot script:false
Generate R script:false
Plot stats:true

Remote island model: false
IP file: ip.txt //File containing all the remote island's IP
Server port : 2929
Migration probability: 0.33

Save population: false
Start from file:false

max init tree depth : 3 // must be strictly greater than min init tree depth
min init tree depth : 2
max tree depth : 5

size of prog buffer : 200000000
\end
16 changes: 8 additions & 8 deletions tpl/CUDA_GP.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ EvaluatePostFixIndividuals( const float * k_progs, const int maxprogssize, cons
for( int index = bid; index<popsize ; index+=gridDim.x ){
// int index; // index of the prog processed by the block
float sum = 0.0;
float ERROR;
float error;
// index = bid; // one program per block => block ID = program number
Expand Down Expand Up @@ -321,11 +321,11 @@ EvaluatePostFixIndividuals( const float * k_progs, const int maxprogssize, cons
\INSERT_GENOME_EVAL_BDY_GPU;
if (!(ERROR < BIG_NUMBER)) ERROR = BIG_NUMBER;
else if (ERROR < PROBABLY_ZERO) ERROR = 0.0;
if (!(error < BIG_NUMBER)) error = BIG_NUMBER;
else if (error < PROBABLY_ZERO) error = 0.0;
sum += ERROR; // sum raw error on all training cases
sum += error; // sum raw error on all training cases
} // LOOP ON TRAINING CASES

Expand All @@ -338,7 +338,7 @@ EvaluatePostFixIndividuals( const float * k_progs, const int maxprogssize, cons
for (int i = 1; i < NUMTHREAD; i++) {
tmpresult[0] += tmpresult[i];
}
ERROR = tmpresult[0];
error = tmpresult[0];
\INSERT_GENOME_EVAL_FTR_GPU;
}
// here results and hits have been stored in their respective array: we can leave
Expand Down Expand Up @@ -706,17 +706,17 @@ IndividualImpl::~IndividualImpl(){
float IndividualImpl::evaluate(){
float ERROR;
float error;
float sum = 0;
\INSERT_GENOME_EVAL_HDR
for( int i=0 ; i<NO_FITNESS_CASES ; i++ ){
float EVOLVED_VALUE = recEval(this->root,inputs[i]);
\INSERT_GENOME_EVAL_BDY
sum += ERROR;
sum += error;
}
this->valid = true;
ERROR = sum;
error = sum;
\INSERT_GENOME_EVAL_FTR
}
Expand Down

0 comments on commit 9fae6c6

Please sign in to comment.