You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/10/23 21:03:32 UTC

[GitHub] [incubator-mxnet] Zha0q1 commented on pull request #19419: [wip] CPU reduce kernel optimization

Zha0q1 commented on pull request #19419:
URL: https://github.com/apache/incubator-mxnet/pull/19419#issuecomment-715588614


   ```c++
   template<typename Reducer, int ndim, typename AType, typename DType, typename OType, typename OP,
            typename IndexOP = mxnet::op::mshadow_op::set_index_no_op<AType, index_t>>
   MSHADOW_XINLINE AType seq_reduce_assign_block(size_t start, size_t len,
                                                 size_t j,
                                                 const DType* __restrict big,
                                                 const Shape<ndim>& rshape,
                                                 const Shape<ndim>& rstride) {
     Shape<ndim> coord;
     AType val, residual;
     Reducer::SetInitValue(val, residual);
     for (size_t k = start; k < start + len; ++k) {
       coord = mxnet_op::unravel(k, rshape);
       AType temp = OP::Map(big[j + mxnet_op::dot(coord, rstride)]);
       if (IndexOP::do_op)
         IndexOP::Op(&temp, k);
       Reducer::Reduce(val, temp, residual);
     }
     Reducer::Finalize(val, residual);
     return val;
   }
   ```
   
   So here I can also get rid of `Reducer::Finallize` and return both `val` and 'residual' and use `Reducer::Merge` rather than `Reducer::Reduce` in `seq_reduce_assign`. This is more rigorous but is also more expensive (~5%). However the accuracy does not seem to differ by much so I use the current solution. My initial commit has the `Reducer::Merge` implementation for reference.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org