Skip to content

Commit

Permalink
workaround l2 norm produce -inf value with subnormals (#5272)
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui authored Jan 10, 2024
1 parent c222208 commit ba42369
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/layer/reduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,11 @@ struct post_process_sqrt
{
T operator()(const T& x) const
{
return static_cast<T>(sqrtf(x));
// math optimization will probably generate rsqrt
// that produce -inf on sse with subnormal input
// flush subnormal input to zero as a workaround
// TODO explicit use simd sqrt like unaryop --- nihui
return static_cast<T>(sqrtf(x < FLT_MIN ? 0.f : x));
}
};

Expand Down

0 comments on commit ba42369

Please sign in to comment.