From f7d757263881429c02387c05a18dd81c4d40ca70 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Fri, 20 Feb 2026 06:56:37 -0800 Subject: [PATCH 1/9] gpu: don't require specific Thrust version Presumably, this was done to guarantee a certain minimum version of Thrust, but it fails with current (2.x) versions of Thrust. Let's assume that any reasonably recent version of Thrust will work, and don't try to enforce a specific version. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e88b5e850..2d8ab9e0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ if(PSC_GPU STREQUAL "cuda") set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}") enable_language(CUDA) - find_package(Thrust 1.10.0 REQUIRED) + find_package(Thrust REQUIRED) thrust_create_target(Thrust) set(USE_CUDA ON) elseif(PSC_GPU STREQUAL "hip") From 74646de158cfc1ec6f4531860c20a9322f6267ae Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Fri, 20 Feb 2026 07:07:26 -0800 Subject: [PATCH 2/9] gpu: include psc.h in test_bnd_prt_inflow.cxx Without it, the config wasn't included, and `USE_CUDA` wasn not defined. --- src/libpsc/tests/test_bnd_prt_inflow.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libpsc/tests/test_bnd_prt_inflow.cxx b/src/libpsc/tests/test_bnd_prt_inflow.cxx index ff1629340..38f229168 100644 --- a/src/libpsc/tests/test_bnd_prt_inflow.cxx +++ b/src/libpsc/tests/test_bnd_prt_inflow.cxx @@ -3,6 +3,7 @@ #include "test_common.hxx" +#include "psc.h" #include "psc_particles_double.h" #include "psc_particles_single.h" #include "particle_with_id.h" From fd3e6007806b6f68354ce1f526f8223a173a069a Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Fri, 20 Feb 2026 07:08:32 -0800 Subject: [PATCH 3/9] gpu: rename half() to one_half() nvcc was complaining about "half" being redefined. It didn't say anything about where the original definition was, maybe it's a conflict with CUDA's `half` type. In any case, renaming the function to `one_half` seems to fix the issue. --- src/libpsc/tests/test_bnd_prt_inflow.cxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libpsc/tests/test_bnd_prt_inflow.cxx b/src/libpsc/tests/test_bnd_prt_inflow.cxx index 38f229168..670b275fc 100644 --- a/src/libpsc/tests/test_bnd_prt_inflow.cxx +++ b/src/libpsc/tests/test_bnd_prt_inflow.cxx @@ -206,7 +206,7 @@ class TestInjector std::vector prts; }; -static double half() { return 0.5; } +static double one_half() { return 0.5; } TEST(TestSetupParticlesInflow, Advance) { @@ -225,7 +225,7 @@ TEST(TestSetupParticlesInflow, Advance) Double3 T = {0.0, 0.0, 0.0}; psc_particle_npt npt = {0, 1.0, u, T}; - Inflow inflow(grid, npt, *half); + Inflow inflow(grid, npt, *one_half); auto prt = inflow.get_advanced_prt(pos, 1.0); @@ -250,7 +250,7 @@ TEST(TestSetupParticlesInflow, InjectIntoCell) Double3 T = {0.0, 0.0, 0.0}; psc_particle_npt npt = {0, 1.0, u, T}; - Inflow inflow(grid, npt, *half); + Inflow inflow(grid, npt, *one_half); TestInjector injector; inflow.inject_into_boundary_cell(injector, {0, 0, 0}); @@ -281,7 +281,7 @@ TEST(TestSetupParticlesInflow, InjectIntoCellFilter) Double3 T = {0.0, 0.0, 0.0}; psc_particle_npt npt = {0, 1.0, u, T}; - Inflow inflow(grid, npt, *half); + Inflow inflow(grid, npt, *one_half); TestInjector injector; inflow.inject_into_boundary_cell(injector, {0, 0, 0}); @@ -305,7 +305,7 @@ TEST(TestSetupParticlesInflow, InjectIntoPatch) Double3 T = {0.0, 0.0, 0.0}; psc_particle_npt npt = {0, 1.0, u, T}; - Inflow inflow(grid, npt, *half); + Inflow inflow(grid, npt, *one_half); TestInjector injector; inflow.inject_into_boundary_patch(injector, grid.patches[0]); @@ -343,7 +343,7 @@ TEST(TestSetupParticlesInflow, InjectIntoBoundaryY) Double3 T = {0.0, 0.0, 0.0}; psc_particle_npt npt = {0, 1.0, u, T}; - Inflow inflow(grid, npt, *half); + Inflow inflow(grid, npt, *one_half); std::vector injectors = {TestInjector(), TestInjector(), TestInjector(), TestInjector()}; @@ -386,7 +386,7 @@ TEST(TestSetupParticlesInflow, InjectIntoBoundaryZ) Double3 T = {0.0, 0.0, 0.0}; psc_particle_npt npt = {0, 1.0, u, T}; - Inflow inflow(grid, npt, *half); + Inflow inflow(grid, npt, *one_half); std::vector injectors = {TestInjector(), TestInjector(), TestInjector(), TestInjector()}; From e7807fbb82d9be2220574b17e043f48f05b7b094 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Fri, 20 Feb 2026 07:46:36 -0800 Subject: [PATCH 4/9] add missing CENTERING definitions to the 1st moments items --- src/libpsc/cuda/checks_cuda_impl.hxx | 2 +- src/libpsc/cuda/fields_item_moments_1st_cuda.hxx | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libpsc/cuda/checks_cuda_impl.hxx b/src/libpsc/cuda/checks_cuda_impl.hxx index d27278506..f38bb98b9 100644 --- a/src/libpsc/cuda/checks_cuda_impl.hxx +++ b/src/libpsc/cuda/checks_cuda_impl.hxx @@ -5,4 +5,4 @@ template using ChecksCuda = - ChecksCommon>; + ChecksCommon>; diff --git a/src/libpsc/cuda/fields_item_moments_1st_cuda.hxx b/src/libpsc/cuda/fields_item_moments_1st_cuda.hxx index 4ef691f0b..1ddeb029f 100644 --- a/src/libpsc/cuda/fields_item_moments_1st_cuda.hxx +++ b/src/libpsc/cuda/fields_item_moments_1st_cuda.hxx @@ -17,6 +17,7 @@ class moment_rho_1st_nc_cuda { public: using dim_t = D; + static const centering::Centering CENTERING = centering::NC; static std::string name() { return "rho_1st_nc"; } static std::vector comp_names(const Grid_t::Kinds& kinds) @@ -42,6 +43,7 @@ class moment_n_1st_cc_cuda { public: using dim_t = D; + static const centering::Centering CENTERING = centering::CC; static std::string name() { return "n_1st_cc"; } static std::vector comp_names(const Grid_t::Kinds& kinds) @@ -67,6 +69,7 @@ class moments_1st_cc_cuda { public: using dim_t = D; + static const centering::Centering CENTERING = centering::CC; static std::string name() { return "all_1st_cc"; } static std::vector comp_names(const Grid_t::Kinds& kinds) From 9b17699449bb3045afe8f533a127767181483afa Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Fri, 20 Feb 2026 08:16:49 -0800 Subject: [PATCH 5/9] gpu: fixes for Mparticles [p] having gone away This is kinda hacky, since MparticlesCuda hasn't been fully adapted, but it compiles, at least. --- src/libpsc/cuda/psc_particles_cuda.cxx | 2 +- src/psc_flatfoil_yz.cxx | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libpsc/cuda/psc_particles_cuda.cxx b/src/libpsc/cuda/psc_particles_cuda.cxx index 641189d9c..ecf8d4ed9 100644 --- a/src/libpsc/cuda/psc_particles_cuda.cxx +++ b/src/libpsc/cuda/psc_particles_cuda.cxx @@ -53,7 +53,7 @@ static void copy_to(MparticlesBase& mprts_base, for (auto prt : accessor[p]) { using real_t = typename MP::real_t; using Real3 = typename MP::Real3; - mprts_other[p].push_back({Real3(prt.x()), Real3(prt.u()), + mprts_other.push_back(p, {Real3(prt.x()), Real3(prt.u()), real_t(prt.qni_wni()), prt.kind(), prt.id(), prt.tag()}); } diff --git a/src/psc_flatfoil_yz.cxx b/src/psc_flatfoil_yz.cxx index f2de74e21..75eb27d3e 100644 --- a/src/psc_flatfoil_yz.cxx +++ b/src/psc_flatfoil_yz.cxx @@ -436,11 +436,11 @@ void run() // fix up renumbered particle kind auto& mp = mprts.template get_as(); for (int p = 0; p < mp.n_patches(); p++) { - for (int n = 0; n < mprts.size(p); n++) { - if (mprts.at(p, n).kind == 0) { - mprts.at(p, n).kind = MY_ION; - } else if (mprts.at(p, n).kind == 1) { - mprts.at(p, n).kind = MY_ELECTRON; + for (int n = 0; n < mp.size(p); n++) { + if (mp.at(p, n).kind == 0) { + mp.at(p, n).kind = MY_ION; + } else if (mp.at(p, n).kind == 1) { + mp.at(p, n).kind = MY_ELECTRON; } else { assert(0); } From 404a75020488c0a270ca614ab8d07c3879926fdc Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Fri, 20 Feb 2026 17:12:59 -0800 Subject: [PATCH 6/9] gpu: adapt MparticlesCuda::size() to take patch --- src/libpsc/cuda/mparticles_cuda.hxx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libpsc/cuda/mparticles_cuda.hxx b/src/libpsc/cuda/mparticles_cuda.hxx index f784955db..dca3ee237 100644 --- a/src/libpsc/cuda/mparticles_cuda.hxx +++ b/src/libpsc/cuda/mparticles_cuda.hxx @@ -46,6 +46,7 @@ struct MparticlesCuda : MparticlesBase } int size() const override { return cmprts_->size(); } + int size(int p) const { return cmprts_->sizeByPatch()[p]; } std::vector sizeByPatch() const override { From 09bdf21bdd3be601b0957b4bb8bed4241328ebb2 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Fri, 20 Feb 2026 17:14:04 -0800 Subject: [PATCH 7/9] gpu: fix hdf5 output with MparticlesCuda basically, reviving the hacky way it was handled... --- .../psc_output_particles/output_particles_hdf5_impl.hxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libpsc/psc_output_particles/output_particles_hdf5_impl.hxx b/src/libpsc/psc_output_particles/output_particles_hdf5_impl.hxx index a698a0b7d..d01a0c61b 100644 --- a/src/libpsc/psc_output_particles/output_particles_hdf5_impl.hxx +++ b/src/libpsc/psc_output_particles/output_particles_hdf5_impl.hxx @@ -786,7 +786,8 @@ public: void perform_diagnostic(Mparticles& mprts) override { (*this)(mprts); } - void operator()(Mparticles& mprts) + template + void operator()(_Mparticles& mprts) { const auto& grid = mprts.grid(); @@ -794,8 +795,8 @@ public: return; } - detail::OutputParticlesHdf5 impl{grid, - params_}; + detail::OutputParticlesHdf5<_Mparticles, ParticleSelector> impl{grid, + params_}; impl(mprts, writer_); } From 7e4bd23e50fcfc4923c95044d680b03e72ba751c Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Fri, 20 Feb 2026 17:14:36 -0800 Subject: [PATCH 8/9] gpu: fix an unused variable warning --- src/libpsc/psc_output_particles/output_particles_hdf5_impl.hxx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libpsc/psc_output_particles/output_particles_hdf5_impl.hxx b/src/libpsc/psc_output_particles/output_particles_hdf5_impl.hxx index d01a0c61b..a1b41cda8 100644 --- a/src/libpsc/psc_output_particles/output_particles_hdf5_impl.hxx +++ b/src/libpsc/psc_output_particles/output_particles_hdf5_impl.hxx @@ -612,7 +612,6 @@ struct OutputParticlesHdf5 void operator()(Mparticles& mprts, OutputParticlesWriterHDF5& writer) { const Grid_t& grid = mprts.grid(); - herr_t ierr; static int pr_A, pr_B, pr_C; if (!pr_A) { From 4d403f0eb7459d42d0a45dd3c896ffa02d8dcef1 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Fri, 20 Feb 2026 18:02:15 -0800 Subject: [PATCH 9/9] gpu: fix deposition --- src/libpsc/psc_push_particles/inc_curr.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libpsc/psc_push_particles/inc_curr.cxx b/src/libpsc/psc_push_particles/inc_curr.cxx index 781335e05..34d1f5d54 100644 --- a/src/libpsc/psc_push_particles/inc_curr.cxx +++ b/src/libpsc/psc_push_particles/inc_curr.cxx @@ -18,7 +18,7 @@ GT_INLINE void deposit(Curr& curr, const int _i[3], const real_t fnqs[3], { psc::CurrentDeposition1vb deposition{{fnqs[0], fnqs[1], fnqs[2]}}; - int i[3]; + Int3 i; for (int d = 0; d < 3; d++) { i[d] = _i[d] + off[d]; }