57 Impl(
int nNeur,
bool onGPU): nNeur_(nNeur), onGPU_(onGPU) {
66 CUDA_CHECK_ERRORS(cudaMalloc((
void**)&d_rates_,
sizeof(
float)*nNeur));
67 CUDA_CHECK_ERRORS(cudaMemset(d_rates_, 0,
sizeof(
float)*nNeur));
69 printf(
"Cannot use onGPU when compiled without CUDA library.\n");
74 h_rates_ =
new float[nNeur];
75 memset(h_rates_, 0,
sizeof(
float)*nNeur);
84 CUDA_CHECK_ERRORS(cudaFree(d_rates_));
108 float h_d_rate = 0.0f;
109 CUDA_CHECK_ERRORS( cudaMemcpy(&h_d_rate, &(d_rates_[neurId]),
sizeof(
float), cudaMemcpyDeviceToHost) );
114 return h_rates_[neurId];
123 float *h_d_rates = (
float*)malloc(
sizeof(
float)*
getNumNeurons());
124 CUDA_CHECK_ERRORS( cudaMemcpy(h_d_rates, d_rates_,
sizeof(
float)*
getNumNeurons(), cudaMemcpyDeviceToHost) );
127 std::vector<float> rates(h_d_rates, h_d_rates +
getNumNeurons());
134 std::vector<float> rates(h_rates_, h_rates_ +
getNumNeurons());
164 CUDA_CHECK_ERRORS( cudaMemcpy(&(d_rates_[neurId]), &rate,
sizeof(
float), cudaMemcpyHostToDevice) );
168 h_rates_[neurId] = rate;
189 std::copy(rate.begin(), rate.end(), h_rates_arr);
190 CUDA_CHECK_ERRORS( cudaMemcpy(d_rates_, h_rates_arr,
sizeof(
float)*
getNumNeurons(), cudaMemcpyHostToDevice) );
191 delete[] h_rates_arr;
195 std::copy(rate.begin(), rate.end(), h_rates_);