Skip to content

Commit

Permalink
Performance: Convert an FDIV to an FMUL in a hot loop
Browse files Browse the repository at this point in the history
  • Loading branch information
heshpdx committed Sep 17, 2024
1 parent a6ab8af commit 471fe24
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Convert an FDIV to an FMUL in a hot loop in CPU tensor operation.
- Fixed compilation with clang 16.0.6
- Added Threads::Threads to `EXT_LIBS`
- Updates to pymarian: building for multiple python versions; disabling tcmalloc; hosting gated COMETs on HuggingFace
Expand Down
4 changes: 2 additions & 2 deletions src/tensors/cpu/tensor_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,11 +1110,11 @@ void LayerNormalizationImpl(float* out,
sqSum += ex * ex;
}

float sigma = std::sqrt(sqSum / cols + eps);
float invSigma = 1.0/std::sqrt(sqSum / cols + eps);

#pragma omp simd
for(int i = 0; i < cols; ++i) {
float t = alpha[alphaStride * i] * ((sp[i] - mean) / sigma);
float t = alpha[alphaStride * i] * ((sp[i] - mean) * invSigma);
if(hasBeta)
t += beta[betaStride * i];

Expand Down

0 comments on commit 471fe24

Please sign in to comment.