use eval() to improve CPU performance (#25243)

fix_copy_if_different
Zhang Ting 5 years ago committed by GitHub
parent 88e05c4048
commit bc7610583b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -82,8 +82,13 @@ class ClipByNormKernel : public framework::OpKernel<T> {
auto scaling = temp + (static_cast<T>(1) - temp) * max_norm / x_norm;
Eigen::array<int, 1> one_dim{{1}};
Eigen::DSizes<int, 1> m_dsize(input->numel());
if (context.GetPlace() == platform::CPUPlace()) {
out.device(place) =
x * scaling.reshape(one_dim).eval().broadcast(m_dsize);
} else {
out.device(place) = x * scaling.reshape(one_dim).broadcast(m_dsize);
}
}
};
class ClipByNormOp : public framework::OperatorWithKernel {

Loading…
Cancel
Save