@@ -233,6 +233,55 @@ void ConvolutionLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
233233 weight_mutable += slice;
234234 }
235235 }
236+
237+ if (this ->submanifold_sparse_ )
238+ {
239+ if (bottom[0 ]->num_axes ()==4 )
240+ {
241+ CHECK_EQ (bottom[0 ]->height (), top[0 ]->height ())<<
242+ " Input and output blob height not equal! Submanifold sparse computation is invalid!" ;
243+ CHECK_EQ (bottom[0 ]->width (), top[0 ]->width ())<<
244+ " Input and output blob width not equal! Submanifold sparse computation is invalid!" ;
245+ }
246+ else if (bottom[0 ]->num_axes ()==5 )
247+ {
248+ CHECK_EQ (bottom[0 ]->shape (2 ), top[0 ]->shape (2 ))<<
249+ " Input and output blob depth not equal! Submanifold sparse computation is invalid!" ;
250+ CHECK_EQ (bottom[0 ]->shape (3 ), top[0 ]->shape (3 ))<<
251+ " Input and output blob height not equal! Submanifold sparse computation is invalid!" ;
252+ CHECK_EQ (bottom[0 ]->shape (4 ), top[0 ]->shape (4 ))<<
253+ " Input and output blob width not equal! Submanifold sparse computation is invalid!" ;
254+ }
255+ else
256+ {
257+ CHECK_EQ (bottom[0 ]->num_axes (), 3 )<<" Not support Submanifold sparse computation for such blob dimension yet!" ;
258+ CHECK_EQ (bottom[0 ]->shape (2 ), top[0 ]->shape (2 ))<<
259+ " Input and output blob length not equal! Submanifold sparse computation is invalid!" ;
260+ }
261+ LOG (INFO)<<" Starts submanifold sparse computation." ;
262+
263+ for (int index=0 ; index<bottom[0 ]->count (2 ); index++)
264+ {
265+ bool active=false ;
266+ // TODO: add handling for pre-quantized model with non 0 zero-points
267+ for (int in_c=0 ; in_c<bottom[0 ]->shape (1 ); in_c++)
268+ {
269+ Dtype data=bottom[0 ]->cpu_data ()[in_c*bottom[0 ]->count (2 )+index];
270+ if (data!=Dtype (0 ))
271+ {
272+ active = true ;
273+ break ;
274+ }
275+ }
276+ if (!active)
277+ {
278+ for (int out_c=0 ; out_c<top[0 ]->shape (1 ); out_c++)
279+ {
280+ top[0 ]->mutable_cpu_data ()[out_c*bottom[0 ]->count (2 )+index]=0 ;
281+ }
282+ }
283+ }
284+ }
236285}
237286
238287template <typename Dtype>
0 commit comments