Skip to content

Commit 8711a9a

Browse files
committed
refine code
1 parent a0c1190 commit 8711a9a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

paddle/operators/elementwise_add_op.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace operators {
2121

2222
template <typename T>
2323
struct AddFunctor {
24-
HOSTDEVICE T operator()(T a, T b) const { return a + b; }
24+
inline HOSTDEVICE T operator()(T a, T b) const { return a + b; }
2525
};
2626

2727
template <typename Place, typename T>

paddle/operators/elementwise_op_function.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class RowwiseTransformIterator<T, platform::CPUPlace> {
7171

7272
RowwiseTransformIterator<T, platform::CPUPlace>& operator++() {
7373
++i_;
74-
i_ %= n_;
74+
if (UNLIKELY(i_ == n_)) {
75+
i_ = 0;
76+
}
7577
return *this;
7678
}
7779

@@ -100,7 +102,12 @@ class MidWiseTransformIterator<T, platform::CPUPlace> {
100102
: ptr_(ptr), i_(0), j_(0), n_(n), post_(post) {}
101103

102104
MidWiseTransformIterator<T, platform::CPUPlace>& operator++() {
103-
i_ = (++j_ / post_) % n_;
105+
++j_;
106+
i_ = j_ / post_;
107+
if (UNLIKELY(i_ == n_)) {
108+
j_ = 0;
109+
i_ = 0;
110+
}
104111
return *this;
105112
}
106113

0 commit comments

Comments
 (0)