23 #define MAX_GPU_DEVICES 4
24 #define MAX_SEQUENCES 100
28 #include <cuda_runtime.h>
34 class MTRNN :
public yarp::os::Thread
43 string trainingFileName;
44 string networkFileName;
55 float *previousDelta_h;
56 float *individualError_h;
58 float *previousDeltaWeight_h;
61 float *previousPotential_h;
97 int totalSequenceSteps;
102 int numControlNeurons;
103 int numLinguisticNeurons;
104 int numVisionNeurons;
105 int numActionNeurons;
109 int *sequenceOffsets;
134 float initWeightRange;
140 void allocateMemory();
141 void copyMemoryToDevice();
143 float scaleRange(
float in,
float oldMin,
float oldMax,
float newMin,
float newMax);
145 void forwardPass(
int step,
int sequenceOffset,
float *activity,
float *input,
float *weight,
float *previousPotential,
float *potential,
float *error,
int *deltaT,
int numNeurons,
int numIONeurons);
146 void backwardPass(
int step,
int sequenceOffset,
int numNeurons,
int numIONeurons,
float *input,
float *activity,
float *delta,
float *previousDelta,
float *error,
float *weight,
float *deltaWeight,
float *mse,
int *deltaT);
147 void updateWeights(
float learningRate,
float momentum,
float *weight,
float *deltaWeight,
float *previousDeltaWeight,
int numWeights);
148 void setInitStates(
float initState,
float *activity,
float *zeroActivity,
int numNeurons,
int numIONeurons,
int numFastNeurons);
149 void resetParameters(
int numNeurons,
int maxsequenceSteps,
float *delta,
float *previousDelta,
float *potential,
float *previousPotential,
float *error,
float *zeroNeuron,
float *zeroError);
150 void resetDeltaWeights(
int numWeights,
float *deltaWeight,
float *zeroWeight);
159 void randomiseWeights();
160 bool loadTrainingData();
161 vector<string> queryGPU();
163 void printGPUProperties(
int deviceID);
165 void printConfiguration();
166 void printKernelConfiguration();
167 void printNetworkConfiguration();
169 void setGPUMode(
bool gpuMode);
170 void setDebuggingLevel(
int level);
171 void setTrainingFile(
string fileName);
172 void setTrainingData(Bottle data);
173 void setNetworkFile(
string fileName);
174 void setShowProgress(
bool show);
175 void setMaxThreads(
int threads);
176 void setMaxIterations(
int iterations);
177 void setSeed(
int value);
178 void setIODeltaT(
int value);
179 void setFastDeltaT(
int value);
180 void setSlowDeltaT(
int value);
181 void setNumFastNeurons(
int fastNeurons);
182 void setNumSlowNeurons(
int slowNeurons);
183 void setInitWeightRange(
float value);
184 void setThreshold(
float value);
185 void setLearningRate(
float value);
186 void setMomentum(
float value);
187 void setDevice(
int deviceID);
191 void setFeedbackInterval(
int interval);
193 void getWeightsAsBottle(Bottle *bottle);
194 void getErrorsAsBottle(Bottle *bottle);
198 int getMaxIterations();
200 int getNumFastNeurons();
201 int getNumSlowNeurons();
205 int getDebuggingLevel();
206 int getFeedbackInterval();
207 float getLearningRate();
209 float getWeightRange();
210 float getThreshold();
211 string getNetworkFile();
212 string getTrainingFile();
216 void resetDeltaWeightsOnDevice(dim3 grid, dim3 block, cudaStream_t stream,
int numWeights,
int numIONeurons,
float *deltaWeight,
float *individualError);
217 void setInitStatesOnDevice(dim3 grid, dim3 block, cudaStream_t stream,
float initState,
float *activity,
int numNeurons,
int numIONeurons,
int numFastNeurons);
218 void resetParametersOnDevice(dim3 grid, dim3 block, cudaStream_t stream,
int numNeurons,
int maxSequenceSteps,
float *delta,
float *previousDelta,
float *potential,
float *previousPotential,
float *error);
219 void updateWeightsOnDevice(dim3 grid, dim3 block,
float learningRate,
float momentum,
float *weight,
float *deltaWeight,
float *previousDeltaWeight,
int numWeights);
220 void forwardPassV1onDevice(dim3 grid, dim3 block, cudaStream_t stream,
int step,
int sequenceOffset,
float *activity,
float *input,
float *weight,
float *previousPotential,
float *error,
float *potential,
int *deltaT,
int numNeurons,
int numIONeurons);
221 void forwardPassV2onDevice(dim3 grid, dim3 block, cudaStream_t stream,
int step,
int sequenceOffset,
float *activity,
float *input,
float *weight,
int numNeurons,
int numIONeurons,
float *buffer);
222 void forwardPassV21onDevice(dim3 grid, dim3 block,
int smemSize, cudaStream_t stream,
int step,
int sequenceOffset,
float *activity,
float *input,
float *buffer,
float *potential,
float *weight,
float *previousPotential,
float *error,
int *deltaT,
int numNeurons,
int numIONeurons);
223 void backwardPassV1onDevice(dim3 grid, dim3 block, cudaStream_t stream,
int step,
int sequenceOffset,
int numNeurons,
int numIONeurons,
float *input,
float *activity,
float *delta,
float *deltaWeight,
float *previousDelta,
float *error,
float *individualError,
int *deltaT,
float *weight);
224 void backwardPassV11onDevice(dim3 grid, dim3 block, cudaStream_t stream,
int step,
int numNeurons,
int numIONeurons,
float *activity,
float *delta,
float *previousDelta,
int *deltaT,
float *weight);
225 void backwardPassV2onDevice(dim3 grid, dim3 block, cudaStream_t stream,
int step,
int sequenceOffset,
int numNeurons,
int numIONeurons,
float *input,
float *activity,
float *delta,
float *deltaWeight,
float *previousDelta,
float *error,
float *individualError,
int *deltaT,
float *weight,
float *buffer);
226 void backwardPassV21onDevice(dim3 grid, dim3 block,
int smemSize, cudaStream_t stream,
float *input,
float *output,
int numNeurons,
int numIONeurons);
227 void backwardPassV3onDevice(dim3 grid, dim3 block, cudaStream_t stream,
int step,
int numNeurons,
int numIONeurons,
float *activity,
float *delta,
float *previousDelta,
float *deltaWeight,
int *deltaT,
float *weight);
229 void updateWeightsP2PonDevice(dim3 grid, dim3 block,
int numWeights,
float learningRate,
float momentum,
float *masterWeight,
float *peerWeight,
float *deltaWeight,
float *previousDeltaWeight);
231 void reduceOnDevice(
int size, dim3 grid, dim3 block,
int smemSize, cudaStream_t stream,
float *input,
float *output,
unsigned int n,
bool nIsPow2);