Skip to content

Commit

Permalink
remove comments, atoi to std::stoi
Browse files Browse the repository at this point in the history
  • Loading branch information
buensons committed Nov 16, 2020
1 parent 3da0f2c commit 7c8e8de
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
20 changes: 16 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@
#include "include/TimeSeriesPredictor.cuh"

auto readDataToMemory() -> std::vector<float>;
auto usage(char * arg) -> void;

int main(int argc, char ** argv) {
int nodes, populationSize, windowSize;

if(argc != 4) {
std::cerr << "Usage: " << argv[0] << " <num_of_nodes> <population_size> <window_size>" << std::endl;
usage(argv[0]);
return 1;
}

int nodes = atoi(argv[1]);
int populationSize = atoi(argv[2]);
int windowSize = atoi(argv[3]);
try {
nodes = std::stoi(argv[1]);
populationSize = std::stoi(argv[2]);
windowSize = std::stoi(argv[3]);
} catch(std::exception const & e) {
usage(argv[0]);
return 1;
}

auto timeSeries = readDataToMemory();

Expand All @@ -28,6 +36,10 @@ int main(int argc, char ** argv) {
return 0;
}

auto usage(char * arg) -> void {
std::cerr << "Usage: " << arg << " <num_of_nodes> <population_size> <window_size>" << std::endl;
}

auto readDataToMemory() -> std::vector<float> {
std::string dataFolder = "./data/";
std::vector<float> dataVector;
Expand Down
7 changes: 0 additions & 7 deletions src/FitnessFunctionKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ __global__ void calculate_fitness(
int i = 0;

while(i < data_size - window_size * node_number) {
// float * input_data = new float[window_size * node_number];
// memcpy(input_data, &data[i], window_size * node_number * sizeof(float));

for(int j = 0; j < window_size * node_number; ++j) {
// map_input[j % node_number] += data_weights[j] * input_data[j];
mapInput[j % node_number + index * node_number] += dataWeights[j + window_size * node_number * index] * data[i + j];
}

Expand All @@ -31,8 +28,6 @@ __global__ void calculate_fitness(
}

for(int j = 0; j < node_number; ++j) {
// float * current_weights = new float[node_number];
// memcpy(current_weights, &mapWeights[j * node_number], node_number * sizeof(float));

float x = 0.0f;
for(int k = 0; k < node_number; ++k) {
Expand All @@ -42,10 +37,8 @@ __global__ void calculate_fitness(
float y = 1.0 / (1.0 + expf(-5 * x));
float prediction_error = abs(y - data[j+i+1]);
cumulative_error += prediction_error;
// delete [] current_weights;
}
i += node_number;
// delete [] input_data;
}

float epsilon = cumulative_error / ((node_number * data_size) - (node_number * window_size));
Expand Down
4 changes: 2 additions & 2 deletions src/TimeSeriesPredictor.cu
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ auto TimeSeriesPredictor::train() -> std::vector<float> {
Chromosome bestCandidate = this->maxFitness(this->population);
if(generation == 500 || abs(1.0 - bestCandidate.fitness) < 1e-5) break;

std::cout << "-----GEN {generation}-------" << std::endl;
std::cout << "-----GEN " << generation << " -------" << std::endl;
std::cout << "Best fitness: " << bestCandidate.fitness << std::endl;

while(nextGen.size() < this->populationSize) {
Expand Down Expand Up @@ -156,7 +156,7 @@ auto TimeSeriesPredictor::launchCudaKernel() -> void {
gpuErrchk(cudaMemcpy(&this->mapWeightsGpu[i * n * n], &weights[w * n], n * n * sizeof(float), cudaMemcpyHostToDevice));
}

cudaMemset(this->mapInputGpu, 0, n * sizeof(float));
gpuErrchk(cudaMemset(this->mapInputGpu, 0, n * sizeof(float)));

calculate_fitness<<<4, 512>>>(this->dataWeightsGpu, this->mapWeightsGpu, this->dataGpu, this->fitnessGpu, this->mapInputGpu, w, n, this->populationSize, dataSize);
gpuErrchk(cudaPeekAtLastError());
Expand Down

0 comments on commit 7c8e8de

Please sign in to comment.