Skip to content

Commit

Permalink
replace FusedNegateMultiplyAdd with FusedMultiplyAdd when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbkoch committed Oct 18, 2024
1 parent dbadbaa commit 333f8de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions shared/libebm/compute/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static INLINE_ALWAYS TFloat Exp32(const TFloat val) {
rounded = Round(val * TFloat{1.44269504088896340736f});
x = FusedMultiplyAdd(rounded, TFloat{-0.693359375f}, val);
}
x = FusedNegateMultiplyAdd(rounded, TFloat{-2.12194440e-4f}, x);
x = FusedMultiplyAdd(rounded, TFloat{2.12194440e-4f}, x);

const TFloat x2 = x * x;
TFloat ret = Polynomial32(x,
Expand Down Expand Up @@ -233,7 +233,7 @@ static INLINE_ALWAYS TFloat Log32(const TFloat& val) noexcept {
ret *= x2 * x;

ret = FusedMultiplyAdd(exponentFloat, TFloat{-2.12194440E-4f}, ret);
ret += FusedNegateMultiplyAdd(x2, TFloat{0.5f}, x);
ret += FusedMultiplyAdd(x2, TFloat{-0.5f}, x);

// exponentFloat must be a finite number, so use ret if we want an inf or NaN ret value
if(bNaNPossible) {
Expand Down Expand Up @@ -298,7 +298,7 @@ static INLINE_ALWAYS TFloat Exp64(const TFloat val) {
rounded = Round(val * TFloat{1.44269504088896340736});
x = FusedMultiplyAdd(rounded, TFloat{-0.693145751953125}, val);
}
x = FusedNegateMultiplyAdd(rounded, TFloat{1.42860682030941723212E-6}, x);
x = FusedMultiplyAdd(rounded, TFloat{-1.42860682030941723212E-6}, x);

TFloat ret = Polynomial64(x,
TFloat{1} / TFloat{2},
Expand Down Expand Up @@ -389,7 +389,7 @@ static INLINE_ALWAYS TFloat Log64(const TFloat& val) noexcept {
TFloat ret = poly1 / poly2;

ret = FusedMultiplyAdd(exponent, TFloat{-2.121944400546905827679E-4}, ret);
ret += FusedNegateMultiplyAdd(x2, TFloat{0.5}, x);
ret += FusedMultiplyAdd(x2, TFloat{-0.5}, x);

// exponent must be a finite number, so use ret if we want an inf or NaN ret value
if(bNaNPossible) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ template<typename TFloat> struct TweedieDevianceRegressionObjective : Regression

TFloat m_variancePowerParamSub1;
TFloat m_variancePowerParamSub2;
TFloat m_inverseVariancePowerParamSub1;
TFloat m_negInverseVariancePowerParamSub1;
TFloat m_inverseVariancePowerParamSub2;

// The constructor parameters following config must match the RegisterObjective parameters in
Expand Down Expand Up @@ -40,7 +40,7 @@ template<typename TFloat> struct TweedieDevianceRegressionObjective : Regression

m_variancePowerParamSub1 = variancePowerParamSub1;
m_variancePowerParamSub2 = variancePowerParamSub2;
m_inverseVariancePowerParamSub1 = 1.0 / variancePowerParamSub1;
m_negInverseVariancePowerParamSub1 = (-1.0) / variancePowerParamSub1;
m_inverseVariancePowerParamSub2 = 1.0 / variancePowerParamSub2;
}

Expand Down Expand Up @@ -79,8 +79,8 @@ template<typename TFloat> struct TweedieDevianceRegressionObjective : Regression
GPU_DEVICE inline TFloat CalcMetric(const TFloat& score, const TFloat& target) const noexcept {
const TFloat exp1Score = Exp(m_variancePowerParamSub1 * score);
const TFloat exp2Score = Exp(m_variancePowerParamSub2 * score);
const TFloat metric = FusedNegateMultiplyAdd(
target * m_inverseVariancePowerParamSub1, exp1Score, exp2Score * m_inverseVariancePowerParamSub2);
const TFloat metric = FusedMultiplyAdd(
target * m_negInverseVariancePowerParamSub1, exp1Score, exp2Score * m_inverseVariancePowerParamSub2);
return metric;
}

Expand Down

0 comments on commit 333f8de

Please sign in to comment.