未验证 提交 ec2ffb68 编写于 作者: N niuliling123 提交者: GitHub

make high precision for avg_pool and adaptive_avg_pool when data_type is float16 (#31887)

* make high precision for avg_pool
上级 ccf5709d
......@@ -18,6 +18,7 @@ limitations under the License. */
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/operators/amp/fp16_type_traits.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/hostdevice.h"
#include "paddle/fluid/platform/macros.h"
......@@ -46,10 +47,22 @@ class MaxPool {
template <class T>
class AvgPool {
using MT = typename details::MPTypeTrait<T>::Type;
MT intermediate_res;
public:
DEVICE inline T initial() { return static_cast<T>(0); }
DEVICE inline void compute(const T& x, T* y) { *y += x; }
DEVICE inline void finalize(const T& pool_field, T* y) { *y /= pool_field; }
DEVICE inline T initial() {
intermediate_res = static_cast<MT>(0.0f);
return static_cast<T>(0);
}
DEVICE inline void compute(const T& x, T* y) {
intermediate_res += static_cast<MT>(x);
}
DEVICE inline void finalize(const T& pool_field, T* y) {
*y = static_cast<T>(intermediate_res / (static_cast<MT>(pool_field)));
}
};
template <class T>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册