Skip to content

Conversation

@efaulhaber
Copy link
Member

@efaulhaber efaulhaber commented Nov 12, 2025

The rectangular tank example now runs on Apple GPUs (and should therefore also run on Nvidia and AMD):

julia> using TrixiParticles, Metal

julia> trixi_include_changeprecision(Float32, "examples/dem/rectangular_tank_2d.jl", sol=nothing);
[ Info: You just called `trixi_include`. Julia may now compile the code, please be patient.

julia> min_corner = minimum(tank.boundary.coordinates, dims=2)
2×1 Matrix{Float32}:
 -0.15
 -0.15

julia> max_corner = maximum(tank.boundary.coordinates, dims=2)
2×1 Matrix{Float32}:
 2.15
 4.15

julia> cell_list = FullGridCellList(; min_corner, max_corner);

julia> neighborhood_search = GridNeighborhoodSearch{2}(; cell_list, update_strategy=ParallelUpdate());

julia> trixi_include_changeprecision(Float32, "examples/dem/rectangular_tank_2d.jl", neighborhood_search=neighborhood_search, parallelization_backend=MetalBackend());

@efaulhaber
Copy link
Member Author

/run-gpu-tests

@efaulhaber
Copy link
Member Author

/run-gpu-tests

@efaulhaber efaulhaber self-assigned this Nov 17, 2025
@efaulhaber efaulhaber requested a review from Copilot November 17, 2025 14:44
@efaulhaber efaulhaber marked this pull request as ready for review November 17, 2025 14:44
@efaulhaber efaulhaber added the gpu label Nov 17, 2025
Copilot finished reviewing on behalf of efaulhaber November 17, 2025 14:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request enables the Discrete Element Method (DEM) to run on GPUs with Float32 precision support, primarily for Apple Metal GPUs but compatible with NVIDIA and AMD as well. The changes focus on making the code GPU-compatible through Adapt.jl integration and ensuring proper Float32 handling throughout the DEM implementation.

Key changes:

  • Refactored DEM and boundary system constructors to work with Adapt.jl for GPU compatibility
  • Replaced hardcoded floating-point literals with type-safe conversions to support Float32
  • Added GPU test coverage for the DEM rectangular tank example

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/examples/gpu.jl Added comprehensive GPU test for DEM rectangular tank example with Float32 precision
src/schemes/structure/discrete_element_method/system.jl Refactored constructor for Adapt.jl compatibility and fixed Float32 support in radius calculations
src/schemes/structure/discrete_element_method/rhs.jl Replaced hardcoded doubles with type-safe conversions and updated comments
src/schemes/structure/discrete_element_method/contact_models.jl Reordered arithmetic to avoid hardcoded division
src/schemes/boundary/dem_boundary/system.jl Refactored constructor for Adapt.jl compatibility with proper Float32 handling
src/general/gpu.jl Registered DEMSystem and BoundaryDEMSystem with Adapt.jl
examples/dem/rectangular_tank_2d.jl Updated perturbation logic and added default parallelization backend

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@efaulhaber
Copy link
Member Author

/run-gpu-tests

@efaulhaber efaulhaber requested review from LasNikas and svchb November 17, 2025 14:56
svchb
svchb previously approved these changes Nov 17, 2025
@LasNikas
Copy link
Collaborator

/run-gpu-tests

@LasNikas LasNikas enabled auto-merge (squash) November 18, 2025 08:49
@svchb
Copy link
Collaborator

svchb commented Nov 18, 2025

/run-gpu-tests

@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

❌ Patch coverage is 75.86207% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.63%. Comparing base (7f6ec8a) to head (583ee09).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...c/schemes/structure/discrete_element_method/rhs.jl 0.00% 6 Missing ⚠️
...chemes/structure/discrete_element_method/system.jl 92.85% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #979       +/-   ##
===========================================
+ Coverage   64.87%   89.63%   +24.76%     
===========================================
  Files         120      120               
  Lines        8560     8587       +27     
===========================================
+ Hits         5553     7697     +2144     
+ Misses       3007      890     -2117     
Flag Coverage Δ
total 89.63% <75.86%> (?)
unit 64.84% <34.48%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LasNikas LasNikas merged commit 4725885 into trixi-framework:main Nov 18, 2025
33 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants