diff --git a/paddle/operators/elementwise_add_op.h b/paddle/operators/elementwise_add_op.h index 3a198c167e4cb0e9c106038bf2ac64ba7a680421..921dc5f6a69a01f40de66f77680803cadf7ef537 100644 --- a/paddle/operators/elementwise_add_op.h +++ b/paddle/operators/elementwise_add_op.h @@ -21,7 +21,7 @@ namespace operators { template struct AddFunctor { - HOSTDEVICE T operator()(T a, T b) const { return a + b; } + inline HOSTDEVICE T operator()(T a, T b) const { return a + b; } }; template diff --git a/paddle/operators/elementwise_op_function.h b/paddle/operators/elementwise_op_function.h index ec448a9e9564046aeda1e6d9c6609ac1ecc137cd..ca3542e7838219090d2b6634a043856daae83e9c 100644 --- a/paddle/operators/elementwise_op_function.h +++ b/paddle/operators/elementwise_op_function.h @@ -71,7 +71,9 @@ class RowwiseTransformIterator { RowwiseTransformIterator& operator++() { ++i_; - i_ %= n_; + if (UNLIKELY(i_ == n_)) { + i_ = 0; + } return *this; } @@ -100,7 +102,12 @@ class MidWiseTransformIterator { : ptr_(ptr), i_(0), j_(0), n_(n), post_(post) {} MidWiseTransformIterator& operator++() { - i_ = (++j_ / post_) % n_; + ++j_; + i_ = j_ / post_; + if (UNLIKELY(i_ == n_)) { + j_ = 0; + i_ = 0; + } return *this; }