/*************************************************************************** * VectorNeuronState_GPU.cpp * * ------------------- * * copyright : (C) 2012 by Jesus Garrido and Francisco Naveros * * email : jgarrido@atc.ugr.es, fnaveros@atc.ugr.es * ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "../../include/neuron_model/VectorNeuronState_GPU.h" #include "../../include/cudaError.h" #include //Library for CUDA #include using namespace std; VectorNeuronState_GPU::VectorNeuronState_GPU(unsigned int NumVariables):VectorNeuronState(NumVariables, true, true){ }; VectorNeuronState_GPU::~VectorNeuronState_GPU(){ HANDLE_ERROR(cudaFree(VectorNeuronStates_GPU)); HANDLE_ERROR(cudaFree(LastUpdateGPU)); HANDLE_ERROR(cudaFree(LastSpikeTimeGPU)); HANDLE_ERROR(cudaFreeHost(AuxStateCPU)); HANDLE_ERROR(cudaFreeHost(InternalSpikeCPU)); //GPU can use MapHostMemory if(!prop.canMapHostMemory){ HANDLE_ERROR(cudaFree(AuxStateGPU)); HANDLE_ERROR(cudaFree(InternalSpikeGPU)); } } void VectorNeuronState_GPU::InitializeStatesGPU(int N_Neurons, float * initialization, int N_AuxNeuronStates, cudaDeviceProp NewProp){ prop=NewProp; //Initilize State in CPU SetSizeState(N_Neurons); VectorNeuronStates = new float[GetNumberOfVariables()*GetSizeState()](); LastUpdate=new double[GetSizeState()](); LastSpikeTime=new double[GetSizeState()](); if(!TimeDriven){ PredictedSpike=new double[GetSizeState()](); PredictionEnd=new double[GetSizeState()](); }else{ InternalSpike=new bool[GetSizeState()](); } //For the GPU, we store all the variables of the same type in adjacent memory positions //to perform coalescent access to data. for(int z=0; z