Skip to content
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

Compile nbody test from LFortran #89

Merged
merged 11 commits into from
Feb 9, 2024
Merged

Conversation

czgdp1807
Copy link
Collaborator

@czgdp1807 czgdp1807 commented Feb 8, 2024

num = 1000000

Compiler Time (s) Relative
lc 1.22 1.0
clang++ -O3 -std=c++20 3.03 2.48
clang++ -std=c++20 >= 44.94 >= 36.84

DEV: Added support for sqrt intrinsic

DEV: Compile time evaluation of BinOp node for Real and Integer

DEV: Added support for StructTypeConstructor

DEV: Added support for initialisation of const variables
@czgdp1807
Copy link
Collaborator Author

Not ready for review yet.

@czgdp1807 czgdp1807 marked this pull request as ready for review February 9, 2024 20:10
@czgdp1807 czgdp1807 merged commit 79d859c into lcompilers:main Feb 9, 2024
2 checks passed
@czgdp1807 czgdp1807 deleted the nbody branch February 9, 2024 20:24
@certik
Copy link
Contributor

certik commented Feb 9, 2024

If you compile using:

$ clang++ -O3 -march=native -ffast-math nbody.cpp

Then I get 2.827s on Apple M1 Max and Clang 16.0.6.

I get the following timings without optimization:

$ lc nbody.cpp
$ time ./nbody.out
...
./nbody.out  1.30s user 0.00s system 99% cpu 1.305 total

And with optimizations:

$ CPATH=$CONDA_PREFIX/include lc --show-llvm integration_tests/nbody.cpp > x.ll
$ clang++ -O3 -march=native -ffast-math x.ll src/runtime/liblc_runtime_static.a
$ time ./a.out
[...]
./a.out  0.17s user 0.00s system 98% cpu 0.170 total

As far as compilation speed goes, I get 1.019s for LC and 1.428s for Clang++, in the default (no compiler options) mode.

@certik
Copy link
Contributor

certik commented Feb 9, 2024

I also tried the fastest C++ version from here: https://gist.github.com/certik/c7803fe6cbf4f8a5ec3070dd699ecad3

And I get

$ clang++ -O3 -march=native -ffast-math a.cpp
$ time ./a.out 1000000                       
-0.169075164
-0.169086185
./a.out 1000000  0.04s user 0.00s system 92% cpu 0.046 total

So 3.6x faster than our LC version. Overall not bad I think as a start. We'll optimize things more in the future.

This version https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-gpp-3.html runs at 0.073s, so only 2.3x faster.

@czgdp1807
Copy link
Collaborator Author

Sure. I will work on these two examples next. There are excellent features which will be added through these two examples.

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.

2 participants