Skip to content

Applying simd to AnnUpdateSgradient #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions nn.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,10 +737,23 @@ void AnnUpdateSgradient(struct Ann *net) {
for (j = 1; j < layers; j++) {
int units = UNITS(net, j);
int weights = units * UNITS(net,j-1);
/* In theory this is a good target for SSE "ADDPS" instructions,
* however modern compilers figure out this automatically. */
for (i = 0; i < weights; i++)
net->layer[j].sgradient[i] += net->layer[j].gradient[i];
float *sgradient = net->layer[j].sgradient;
float *gradient = net->layer[j].gradient;
i = 0;
#ifdef USING_SIMD
int psteps = weights/SIMDF_SIZE;
for (int x = 0; x < psteps; x++) {
simdf_t sg = simdf_loadu(sgradient);
simdf_t g = simdf_loadu(gradient);
simdf_storeu(sgradient, simdf_add( sg, g));
sg += SIMDF_SIZE;
g += SIMDF_SIZE;
}
i += SIMDF_SIZE*psteps;
#endif
/* Handle final piece shorter than SIMDF_SIZE . */
for (; i < weights; i++)
(*sgradient++) += (*gradient++);
}
}

Expand Down