8 #include "MomentumLCALayer.hpp" 13 #include "../cudakernels/CudaUpdateStateFunctions.hpp" 17 void MomentumLCALayer_update_state(
27 const int numChannels,
33 const bool selfInteract,
36 const float LCAMomentumRate,
43 MomentumLCALayer::MomentumLCALayer() { initialize_base(); }
45 MomentumLCALayer::MomentumLCALayer(
const char *name, HyPerCol *hc) {
50 MomentumLCALayer::~MomentumLCALayer() {}
52 int MomentumLCALayer::initialize_base() {
55 timeConstantTau = 1.0;
62 int MomentumLCALayer::initialize(
const char *name, HyPerCol *hc) {
63 HyPerLCALayer::initialize(name, hc);
68 Response::Status MomentumLCALayer::allocateDataStructures() {
69 auto status = HyPerLCALayer::allocateDataStructures();
73 for (
int i = 0; i < getNumNeuronsAllBatches(); i++) {
79 d_prevDrive->copyToDevice(prevDrive);
88 ioParam_LCAMomentumRate(ioFlag);
93 void MomentumLCALayer::ioParam_LCAMomentumRate(
enum ParamsIOFlag ioFlag) {
94 parent->parameters()->ioParamValue(
95 ioFlag, name,
"LCAMomentumRate", &LCAMomentumRate, LCAMomentumRate,
true );
99 int MomentumLCALayer::allocateUpdateKernel() {
100 PVCuda::CudaDevice *device = parent->getDevice();
101 d_prevDrive = device->createBuffer(getNumNeuronsAllBatches() *
sizeof(
float), &description);
107 const int nx = loc->nx;
108 const int ny = loc->ny;
109 const int nf = loc->nf;
110 const int num_neurons = nx * ny * nf;
111 const int nbatch = loc->nbatch;
112 const int lt = loc->halo.lt;
113 const int rt = loc->halo.rt;
114 const int dn = loc->halo.dn;
115 const int up = loc->halo.up;
116 const int numChannels = this->numChannels;
117 PVCuda::CudaBuffer *d_V = getDeviceV();
120 const float Vth = this->VThresh;
121 const float AMax = this->AMax;
122 const float AMin = this->AMin;
123 const float AShift = this->AShift;
124 const float VWidth = this->VWidth;
125 const bool selfInteract = this->selfInteract;
126 const float tau = timeConstantTau
127 / (float)parent->getDeltaTime();
128 PVCuda::CudaBuffer *d_GSyn = getDeviceGSyn();
129 PVCuda::CudaBuffer *d_activity = getDeviceActivity();
131 size_t size = parent->getNBatch() *
sizeof(double);
132 d_dtAdapt = device->createBuffer(size, &description);
134 size = (size_t)numVertices *
sizeof(*verticesV);
135 d_verticesV = device->createBuffer(size, &description);
136 d_verticesA = device->createBuffer(size, &description);
137 d_slopes = device->createBuffer(size +
sizeof(*slopes), &description);
139 d_verticesV->copyToDevice(verticesV);
140 d_verticesA->copyToDevice(verticesA);
141 d_slopes->copyToDevice(slopes);
144 updateKernel->setArgs(
171 krUpdate = updateKernel;
175 Response::Status MomentumLCALayer::updateStateGpu(
double time,
double dt) {
176 if (triggerLayer != NULL) {
177 Fatal().printf(
"HyPerLayer::Trigger reset of V does not work on GPUs\n");
180 d_dtAdapt->copyToDevice(deltaTimes());
185 assert(updateKernel);
188 return Response::SUCCESS;
192 Response::Status MomentumLCALayer::updateState(
double time,
double dt) {
194 float *A = clayer->activity->data;
196 int num_channels = getNumChannels();
197 float *gSynHead = GSyn == NULL ? NULL : GSyn[0];
201 int num_neurons = nx * ny * nf;
202 int nbatch = loc->nbatch;
205 MomentumLCALayer_update_state(
223 timeConstantTau / (
float)dt,
228 return Response::SUCCESS;
231 Response::Status MomentumLCALayer::registerData(
Checkpointer *checkpointer) {
232 auto status = HyPerLCALayer::registerData(checkpointer);
236 checkpointPvpActivityFloat(checkpointer,
"prevDrive", prevDrive,
false );
237 return Response::SUCCESS;
240 Response::Status MomentumLCALayer::processCheckpointRead() {
241 auto status = HyPerLCALayer::processCheckpointRead();
248 d_prevDrive->copyToDevice(prevDrive);
249 parent->getDevice()->syncDevice();
250 return Response::SUCCESS;
253 return Response::NO_ACTION;
256 return Response::NO_ACTION;
260 Response::Status MomentumLCALayer::prepareCheckpointWrite() {
264 d_prevDrive->copyFromDevice(prevDrive);
265 parent->getDevice()->syncDevice();
266 return Response::SUCCESS;
269 return Response::NO_ACTION;
272 return Response::NO_ACTION;
278 void MomentumLCALayer_update_state(
280 const int numNeurons,
288 const int numChannels,
295 const bool selfInteract,
298 const float LCAMomentumRate,
302 updateV_MomentumLCALayer(
void allocateRestrictedBuffer(float **buf, const char *bufname)
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
static bool completed(Status &a)
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override