SortingBoxes cannot be created on the CuPy backend, so any species with SortingParameters(boxes_per_dim=...) fails during setup on the GPU.
Found in: #719 (end-to-end GPU test for LinearVlasovAmpereOneSpecies). The CuPy run was probed on cunumpy's fake CuPy with CUDA launches emulated on the CPU. With sorting boxes enabled it stops in SortingBoxes, so the test in #719 runs without sorting boxes.
What fails (src/struphy/pic/sorting.py, SortingBoxes._set_boxes, devel 25688c5):
sorting.py:228-230: n_cols = round(n_mkr * (1 + 1 / xp.sqrt(n_mkr) + self._box_bufsize)). On CuPy, xp.sqrt of a Python int returns a 0-d device array, and Python's round() does not accept it.
sorting.py:239: initialize_neighbours(self._neighbours, ...). This is the pyccel kernel from pic/sorting_kernels.py:68, called with the device array self._neighbours created by xp.zeros a few lines above.
SortingBoxes is created in Particles at src/struphy/pic/base.py:2597, so the failure happens at setup, before any box sorting in the time loop.
Suggested fix:
- Compute
n_cols with math.sqrt (it is host-side bookkeeping, not device data).
- Build
_neighbours on the host with the pyccel initialize_neighbours and copy it to the device once (setup data). Alternatively, add a CUDA version in its own folder, following CUDA_STRATEGY.md.
- Add a fake-CuPy test that creates
Particles with boxes_per_dim on CuPy.
This only fixes setup. Sorting the markers into boxes on the device (Particles.put_particles_in_boxes, assign_box_to_each_particle, sort_boxed_particles) is still part of #694, and the SPH models need it.
Related: #694, #719. Part of #650 (see CUDA_STRATEGY.md).
🤖 Generated with Claude Code
SortingBoxescannot be created on the CuPy backend, so any species withSortingParameters(boxes_per_dim=...)fails during setup on the GPU.Found in: #719 (end-to-end GPU test for
LinearVlasovAmpereOneSpecies). The CuPy run was probed on cunumpy's fake CuPy with CUDA launches emulated on the CPU. With sorting boxes enabled it stops inSortingBoxes, so the test in #719 runs without sorting boxes.What fails (
src/struphy/pic/sorting.py,SortingBoxes._set_boxes, devel 25688c5):sorting.py:228-230:n_cols = round(n_mkr * (1 + 1 / xp.sqrt(n_mkr) + self._box_bufsize)). On CuPy,xp.sqrtof a Python int returns a 0-d device array, and Python'sround()does not accept it.sorting.py:239:initialize_neighbours(self._neighbours, ...). This is the pyccel kernel frompic/sorting_kernels.py:68, called with the device arrayself._neighbourscreated byxp.zerosa few lines above.SortingBoxesis created inParticlesatsrc/struphy/pic/base.py:2597, so the failure happens at setup, before any box sorting in the time loop.Suggested fix:
n_colswithmath.sqrt(it is host-side bookkeeping, not device data)._neighbourson the host with the pyccelinitialize_neighboursand copy it to the device once (setup data). Alternatively, add a CUDA version in its own folder, followingCUDA_STRATEGY.md.Particleswithboxes_per_dimon CuPy.This only fixes setup. Sorting the markers into boxes on the device (
Particles.put_particles_in_boxes,assign_box_to_each_particle,sort_boxed_particles) is still part of #694, and the SPH models need it.Related: #694, #719. Part of #650 (see
CUDA_STRATEGY.md).🤖 Generated with Claude Code