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

Add macro trixi_include_changeprecision to make a double precision elixir run with single precision #35

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

efaulhaber
Copy link
Member

@efaulhaber efaulhaber commented Dec 23, 2024

This is similar to how Base.include is defined:

include(mod::Module, _path::AbstractString) = _include(identity, mod, _path)
include(mapexpr::Function, mod::Module, _path::AbstractString) = _include(mapexpr, mod, _path)

@efaulhaber efaulhaber added the enhancement New feature or request label Dec 23, 2024
@efaulhaber efaulhaber requested a review from sloede December 23, 2024 19:02
@coveralls
Copy link

coveralls commented Dec 23, 2024

Pull Request Test Coverage Report for Build 12471675311

Details

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 95.122%

Totals Coverage Status
Change from base Build 12102967779: 0.1%
Covered Lines: 78
Relevant Lines: 82

💛 - Coveralls

Copy link

codecov bot commented Dec 23, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 12 lines in your changes missing coverage. Please review.

Project coverage is 82.97%. Comparing base (91eb18c) to head (f720829).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/trixi_include.jl 25.00% 12 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #35       +/-   ##
===========================================
- Coverage   95.00%   82.97%   -12.03%     
===========================================
  Files           5        5               
  Lines          80       94       +14     
===========================================
+ Hits           76       78        +2     
- Misses          4       16       +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@sloede sloede left a comment

Choose a reason for hiding this comment

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

Fine by me, though I do not really understand most of the changes 😅. Would be good if @ranocha could give the final green light :-)

Copy link
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

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

Thanks! Why do you need this functionality?

src/trixi_include.jl Show resolved Hide resolved
Comment on lines +48 to +49
Base.include(ex -> replace_assignments(insert_maxiters(mapexpr(ex)); kwargs...),
mod, elixir)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Base.include(ex -> replace_assignments(insert_maxiters(mapexpr(ex)); kwargs...),
mod, elixir)
Base.include(replace_assignments insert_maxiters mapexpr; kwargs...),
mod, elixir)

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, the Trixi style guide says:

Executable code should only use ASCII characters.

Copy link
Member

Choose a reason for hiding this comment

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

@sloede? Composing functions is only available using . From my point of view, makes it easier to read the code in this case.

src/trixi_include.jl Show resolved Hide resolved
@efaulhaber
Copy link
Member Author

Thanks! Why do you need this functionality?

I want to add a macro trixi_include_changeprecision to TrixiParticles that behaves like trixi_include, but uses ChangePrecision.jl to change the precision of an elixir to Float32 to run it on GPUs.

I could also add this macro to TrixiBase, but so far it will only be used by TrixiParticles.

https://github.com/trixi-framework/TrixiParticles.jl/blob/ef/more-gpu-support/src/util.jl#L138-L163

@efaulhaber efaulhaber requested a review from ranocha January 9, 2025 10:09
@ranocha
Copy link
Member

ranocha commented Jan 9, 2025

Thanks! Why do you need this functionality?

I want to add a macro trixi_include_changeprecision to TrixiParticles that behaves like trixi_include, but uses ChangePrecision.jl to change the precision of an elixir to Float32 to run it on GPUs.

I could also add this macro to TrixiBase, but so far it will only be used by TrixiParticles.

https://github.com/trixi-framework/TrixiParticles.jl/blob/ef/more-gpu-support/src/util.jl#L138-L163

This would be nice to have here

@efaulhaber efaulhaber changed the title Make trixi_include more flexible by allowing a mapping to be passed Add macro trixi_include_changeprecision to make a double precision elixir run with single precision Jan 14, 2025
@efaulhaber
Copy link
Member Author

I now moved the macro from TrixiParticles to this PR.

@efaulhaber efaulhaber requested a review from sloede January 14, 2025 13:17
The purpose of this function is to conveniently run a full simulation with `Float32`,
which is orders of magnitude faster on most GPUs than `Float64`, by just including
the elixir with `trixi_include_changeprecision(Float32, elixir)`.
Most code in the Trixi framework is written in a way that changing all floating-point
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Most code in the Trixi framework is written in a way that changing all floating-point
Most code in the Trixi.jl framework is written in a way that changing all floating-point

Comment on lines +81 to +82
Most code in the Trixi framework is written in a way that changing all floating-point
numbers in the elixir to `Float32` manually will run the full simulation with single precision.
Copy link
Member

Choose a reason for hiding this comment

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

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

Successfully merging this pull request may close these issues.

4 participants