Skip to content

Commit

Permalink
Python: Clean CUDA Shutdown
Browse files Browse the repository at this point in the history
Avoid double finalize and segfaults in CUDA debug runs.
  • Loading branch information
ax3l committed Jan 28, 2024
1 parent ce33709 commit 08ea927
Show file tree
Hide file tree
Showing 42 changed files with 20 additions and 158 deletions.
4 changes: 0 additions & 4 deletions examples/alignment/run_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/aperture/run_aperture.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/apochromatic/run_apochromatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/cfbend/run_cfbend.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/cfbend/run_cfbend_madx.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/cfchannel/run_cfchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/cfchannel/run_cfchannel_10nC.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/chicane/run_chicane.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/chicane/run_chicane_madx.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/compression/run_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/cyclotron/run_cyclotron.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/epac2004_benchmarks/run_bithermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/epac2004_benchmarks/run_fodo_rf_SC.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/epac2004_benchmarks/run_thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/expanding_beam/run_expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/fodo/run_fodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/fodo/run_fodo_madx.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/fodo/run_fodo_programmable.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,3 @@ def my_ref_drift(pge, refpart):

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/fodo_chromatic/run_fodo_chr.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/fodo_rf/run_fodo_rf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/iota_lattice/run_iotalattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/iota_lattice/run_iotalattice_sdep.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/iota_lens/run_iotalens.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/iota_lens/run_iotalens_sdep.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/kicker/run_hvkicker_madx.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/kicker/run_kicker.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/kicker/run_kicker_madx.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/kurth/run_kurth_10nC_periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/kurth/run_kurth_periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/multipole/run_multipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/positron_channel/run_positron.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
1 change: 0 additions & 1 deletion examples/pytorch_surrogate_model/run_ml_surrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,3 @@ def surrogate_push(self, pc, step):
sim.lattice.extend([monitor])

sim.evolve()
del sim
4 changes: 0 additions & 4 deletions examples/quadrupole_softedge/run_quadrupole_softedge.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/rfcavity/run_rfcavity.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/rotation/run_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/solenoid/run_solenoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/solenoid/run_solenoid_madx.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/solenoid_softedge/run_solenoid_softedge.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 0 additions & 4 deletions examples/thin_dipole/run_thin_dipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,3 @@

# run simulation
sim.evolve()

# clean shutdown
del sim
amr.finalize()
4 changes: 4 additions & 0 deletions src/ImpactX.H
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ namespace impactx
void operator= (ImpactX const&) = delete;
void operator= (ImpactX &&) = delete;

/** Destruct the ImpactX simulation object
*/
~ImpactX ();

/** Initialize AMReX blocks/grids for domain decomposition & space charge mesh.
*
* This must come first, before particle beams and lattice elements are
Expand Down
14 changes: 10 additions & 4 deletions src/ImpactX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,22 @@
#include <memory>


namespace impactx
{
ImpactX::ImpactX ()
{
namespace impactx {
ImpactX::ImpactX() {
// todo: if amr.n_cells is provided, overwrite/redefine AmrCore object

// todo: if charge deposition and/or space charge are requested, require
// amr.n_cells from user inputs
}

ImpactX::~ImpactX()
{
m_lattice.clear()

// this one last
amr_data.release();
}

void ImpactX::init_grids ()
{
BL_PROFILE("ImpactX::init_grids");
Expand Down
7 changes: 6 additions & 1 deletion tests/python/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
#
# -*- coding: utf-8 -*-

from impactx import ImpactX, RefPart, distribution, elements
from impactx import ImpactX, RefPart, amr, distribution, elements


def test_df_pandas():
"""
This tests using ImpactX and Pandas Dataframes
"""
if amr.Config.have_gpu:
# pc.to_df copies to/from host memory
pp_amrex = amr.ParmParse("amrex")
pp_amrex.add("the_arena_is_managed", 1)

sim = ImpactX()

sim.particle_shape = 2
Expand Down

0 comments on commit 08ea927

Please sign in to comment.