59 Impl(
int nNeur,
bool onGPU): nNeur_(nNeur), onGPU_(onGPU) {
68 CUDA_CHECK_ERRORS(cudaMalloc((
void**)&d_rates_,
sizeof(
float)*nNeur));
69 CUDA_CHECK_ERRORS(cudaMemset(d_rates_, 0,
sizeof(
float)*nNeur));
71 printf(
"Cannot use onGPU when compiled without CUDA library.\n");
76 h_rates_ =
new float[nNeur];
77 memset(h_rates_, 0,
sizeof(
float)*nNeur);
86 CUDA_CHECK_ERRORS(cudaFree(d_rates_));
109 float h_d_rate = 0.0f;
113 CUDA_CHECK_ERRORS( cudaMemcpy(&h_d_rate, &(d_rates_[neurId]),
sizeof(
float), cudaMemcpyDeviceToHost) );
118 return h_rates_[neurId];
129 float *h_d_rates = (
float*)malloc(
sizeof(
float)*
getNumNeurons());
130 CUDA_CHECK_ERRORS( cudaMemcpy(h_d_rates, d_rates_,
sizeof(
float)*
getNumNeurons(), cudaMemcpyDeviceToHost) );
133 std::vector<float> rates(h_d_rates, h_d_rates +
getNumNeurons());
138 return std::vector<float>();
142 std::vector<float> rates(h_rates_, h_rates_ +
getNumNeurons());
172 CUDA_CHECK_ERRORS( cudaMemcpy(&(d_rates_[neurId]), &rate,
sizeof(
float), cudaMemcpyHostToDevice) );
176 h_rates_[neurId] = rate;
197 std::copy(rate.begin(), rate.end(), h_rates_arr);
198 CUDA_CHECK_ERRORS( cudaMemcpy(d_rates_, h_rates_arr,
sizeof(
float)*
getNumNeurons(), cudaMemcpyHostToDevice) );
199 delete[] h_rates_arr;
203 std::copy(rate.begin(), rate.end(), h_rates_);
void setRates(float rate)
std::vector< float > getRates()
void setRates(float rate)
Assigns the same mean firing rate to all neurons.
#define ALL
CARLsim common definitions.
float * getRatePtrCPU()
Returns pointer to CPU-allocated firing rate array (deprecated)
Impl(int nNeur, bool onGPU)
float getRate(int neurId)
Returns the mean firing rate of a specific neuron ID.
~PoissonRate()
PoissonRate destructor.
int getNumNeurons()
Returns the number of neurons for which to generate Poisson spike trains.
void setRate(int neurId, float rate)
std::vector< float > getRates()
Returns a vector of firing rates, one element per neuron.
void setRates(const std::vector< float > &rate)
void setRate(int neurId, float rate)
Sets the mean firing rate of a particular neuron ID.
PoissonRate(int nNeur, bool onGPU=false)
PoissonRate constructor.
float getRate(int neurId)
float * getRatePtrGPU()
Returns pointer to GPU-allocated firing rate array (deprecated)
bool isOnGPU()
Checks whether the firing rates are allocated on CPU or GPU.