@@ -16,6 +16,12 @@ void AdaDeltaSolver<Dtype>::AdaDeltaPreSolve() {
1616 }
1717}
1818
19+ #ifndef CPU_ONLY
20+ template <typename Dtype>
21+ void adadelta_update_gpu (int N, Dtype* g, Dtype* h, Dtype* h2, Dtype momentum,
22+ Dtype delta, Dtype local_rate);
23+ #endif
24+
1925template <typename Dtype>
2026void AdaDeltaSolver<Dtype>::ComputeUpdateValue(int param_id, Dtype rate) {
2127 const vector<Blob<Dtype>*>& net_params = this ->net_ ->learnable_params ();
@@ -85,61 +91,11 @@ void AdaDeltaSolver<Dtype>::ComputeUpdateValue(int param_id, Dtype rate) {
8591 }
8692 case Caffe::GPU : {
8793#ifndef CPU_ONLY
88- // compute square of gradient in update
89- caffe_gpu_powx (net_params[param_id]->count (),
90- net_params[param_id]->gpu_diff (), Dtype (2 ),
91- this ->update_ [param_id]->mutable_gpu_data ());
92-
93- // update history of gradients
94- caffe_gpu_axpby (net_params[param_id]->count (), Dtype (1 ) - momentum,
95- this ->update_ [param_id]->gpu_data (), momentum,
96- this ->history_ [param_id]->mutable_gpu_data ());
97-
98- // add delta to history to guard against dividing by zero later
99- caffe_gpu_set (net_params[param_id]->count (), delta,
100- this ->temp_ [param_id]->mutable_gpu_data ());
101-
102- caffe_gpu_add (net_params[param_id]->count (),
103- this ->temp_ [param_id]->gpu_data (),
104- this ->history_ [update_history_offset + param_id]->gpu_data (),
105- this ->update_ [param_id]->mutable_gpu_data ());
106-
107- caffe_gpu_add (net_params[param_id]->count (),
108- this ->temp_ [param_id]->gpu_data (),
109- this ->history_ [param_id]->gpu_data (),
110- this ->temp_ [param_id]->mutable_gpu_data ());
111-
112- // divide history of updates by history of gradients
113- caffe_gpu_div (net_params[param_id]->count (),
114- this ->update_ [param_id]->gpu_data (),
115- this ->temp_ [param_id]->gpu_data (),
116- this ->update_ [param_id]->mutable_gpu_data ());
117-
118- // jointly compute the RMS of both for update and gradient history
119- caffe_gpu_powx (net_params[param_id]->count (),
120- this ->update_ [param_id]->gpu_data (), Dtype (0.5 ),
121- this ->update_ [param_id]->mutable_gpu_data ());
122-
123- // compute the update and copy to net_diff
124- caffe_gpu_mul (net_params[param_id]->count (),
125- net_params[param_id]->gpu_diff (),
126- this ->update_ [param_id]->gpu_data (),
127- net_params[param_id]->mutable_gpu_diff ());
128-
129- // compute square of update
130- caffe_gpu_powx (net_params[param_id]->count (),
131- net_params[param_id]->gpu_diff (), Dtype (2 ),
132- this ->update_ [param_id]->mutable_gpu_data ());
133-
134- // update history of updates
135- caffe_gpu_axpby (net_params[param_id]->count (), Dtype (1 ) - momentum,
136- this ->update_ [param_id]->gpu_data (), momentum,
137- this ->history_ [update_history_offset + param_id]->mutable_gpu_data ());
138-
139- // apply learning rate
140- caffe_gpu_scale (net_params[param_id]->count (), local_rate,
141- net_params[param_id]->gpu_diff (),
142- net_params[param_id]->mutable_gpu_diff ());
94+ adadelta_update_gpu (net_params[param_id]->count (),
95+ net_params[param_id]->mutable_gpu_diff (),
96+ this ->history_ [param_id]->mutable_gpu_data (),
97+ this ->history_ [update_history_offset + param_id]->mutable_gpu_data (),
98+ momentum, delta, local_rate);
14399#else
144100 NO_GPU ;
145101#endif
0 commit comments