8000 aarch64 performance fix: replace long double with double by heshpdx · Pull Request #790 · uber/h3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

aarch64 performance fix: replace long double with double #790

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

Merged
merged 5 commits into from
Oct 22, 2023
Merged

aarch64 performance fix: replace long double with double #790

merged 5 commits into from
Oct 22, 2023

Conversation

heshpdx
Copy link
Contributor
@heshpdx heshpdx commented Oct 20, 2023

On aarch64 systems, we are seeing a significant overhead in libgcc - __multf3.

26.28%  h3geo  libgcc_s.so.1      [.] __multf3

This overhead is due to the usage of lroundl in coordijk.c. To prevent this overhead, we are proposing to replace long double type with double type and use lround instead of lroundl. This should have no impact on other systems than aarch64. We have verified the behavior matches on some test cases. For coherency sake, we also changed long double constants to double type.

This was found by the SPEC CPU committee, where h3 is being considered as a candidate benchmark for SPEC CPU v8 and undergoing testing across a wide variety of systems and compilers.

Feel free to squash these commits.

Use lround instead of lroundl, for perf improvements on aarch64 machines.
Use lround instead of lroundl, for perf improvements on aarch64 machines.
Use lround instead of lroundl, for perf improvements on aarch64 machines.
Update copyright year.
@coveralls
Copy link

Coverage Status

coverage: 98.657%. remained the same when pulling ef0a87a on heshpdx:master into 017f810 on uber:master.

Copy link
Collaborator
@dfellis dfellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This might provide a small perf boost on other platforms since it looks like all uses of long double get casted back into regular double, and none of them look like the extra 16 bits should impact the intermediate values except maybe the branches in _hex2dToCoordIJK? (But the comparisons of long-double intermediate values look like they are always against regular doubles, so I presume they get casted during the comparison and the extra bits of precision are dropped.)

@grim7reaper
Copy link
Contributor

FWIW, h3o only uses double (since long double no longer exists in Rust), so it's likely possible to get rid of long double on every platform without impacting the correctness

@isaacbrodsky
Copy link
Collaborator

Thanks for the PR!

I remember removing some uses of long double before (I was checking if that was in the Git history and didn't see it, maybe it was before we open sourced the library?). I am pretty comfortable with removing remaining long double usage.

@sahrk
Copy link
Collaborator
sahrk commented Oct 21, 2023

Thanks for the PR!

I remember removing some uses of long double before (I was checking if that was in the Git history and didn't see it, maybe it was before we open sourced the library?). I am pretty comfortable with removing remaining long double usage.

Everything was long double when we started, until it became clear that was unnecessary. When we switched to double some of them must have been missed.

@isaacbrodsky isaacbrodsky merged commit 693d084 into uber:master Oct 22, 2023
@heshpdx
Copy link
Contributor Author
heshpdx commented Oct 23, 2023

I measured a 40% performance uplift on an Ampere Altra QS80-30 on the benchmark cmdline below. Building with gcc-12 -O3, runtime dropped from 481s to 340s.

./h3geo 110,10,25,82 vertex,is_valid_cell,grid_disk_cells,grid_path_cells

@@ -346,8 +346,8 @@ H3Error _upAp7Checked(CoordIJK *ijk) {
}

// TODO: Do the int math parts here in long double?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little late here, but it looks like there are some TODO comments that are now out of date

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0