Repository navigation
Mirror pyccel modules as CUDA namespaces - #722
Draft
max-models wants to merge 4 commits into
Draft
max-models wants to merge 4 commits into
max-models wants to merge 4 commits into
Conversation
Every device helper in struphy's .cuh headers now lives in struphy_cuda::<pyccel module> (bsplines_kernels, evaluation_kernels_3d, evaluation_kernels, linalg_kernels, cuboid_kernels, ...). Calls into another module are qualified with the module name, as in pyccel; .cu files write `using namespace struphy_cuda;` and qualify every helper call. The three namespace blocks of evaluation_kernels_3d.cuh are merged into one, which also moves eval_spline_mpi (previously global) into its module namespace. Solves #672. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stack the PR on #723. Conflicts: eval_spline_mpi_{markers,matrix,sparse_meshgrid}_cuda.cu (SplineArgs of #721 with the qualified evaluation_kernels_3d::eval_spline_mpi), linalg_kernels.cuh, filler_kernels.cuh, particle_to_mat_kernels.cuh (helpers of #705/#713 moved into their module namespaces). Semantic fixes: the struphy_cuda::<pyccel module> rule applied to the CUDA code of the PRs below: linear_vlasov_ampere (#705), vlasov_maxwell (#713), bstar_parallel_3form (#718) and eval_spline_mpi_tensor_product_fixed (#724) use 'using namespace struphy_cuda;' and qualified helper calls; m_v_fill_b_v1_symm calls filler_kernels:: and evaluation_kernels_3d::; the fill_v1_symm test wrapper calls particle_to_mat_kernels::m_v_fill_b_v1_symm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 8, 2026
Draft
max-models
added this pull request to stack #728
October 8, 2026 05:45
max-models
removed this pull request from stack #728
October 8, 2026 06:00
max-models
marked this pull request as draft
October 8, 2026 09:13
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack: part 14 of 14, based on #723 (merge that first), top of the stack. Full order: #709 → #708 → #711 → #712 → #705 → #713 → #714 → #718 → #720 → #721 → #724 → #725 → #723 → #722.
Stack fixes: applied the
struphy_cuda::<pyccel module>rule to the CUDA code of the PRs below:linear_vlasov_ampere(#705),vlasov_maxwell(#713),bstar_parallel_3form(#718),eval_spline_mpi_tensor_product_fixed(#724) and theSplineArgsversions ofeval_spline_mpi_*(#721). Each of them hasusing namespace struphy_cuda;and qualified helper calls. The helpersouter,fill_mat,fill_mat_vecandm_v_fill_b_v1_symm(#705/#713) are inside their module namespaces, andm_v_fill_b_v1_symmcallsfiller_kernels::/evaluation_kernels_3d::. Thefill_v1_symmtest wrapper is qualified. The "open PRs that need the same treatment" below are therefore covered by this stack. Local re-run on the stacked branch:test_cuda_parity.py,test_kernel_backends.py,test_evaluation_cuda.py,test_device_helpers.py(59 passed, 419 skipped),test_cuda_emulation.py(74 passed; it compiles every.cu/.cuhwith the host C++ compiler).Solves the following issue(s):
Closes #672, tracked in #650. The CUDA device helpers now live in C++ namespaces that mirror the pyccel modules they port. A pyccel call
linalg_kernels.matrix_inv(...)becomeslinalg_kernels::matrix_inv(...)in CUDA, so the 1:1 correspondence is visible at every call site and two helpers with the same name in different modules (det/det_df,f/df,push/pull) can no longer clash.Core changes:
struphy_cudaas proposed in the issue (struphy_cuda::linalg_kernels::matrix_inv). The namespace is named after the module the header ports:bsplines_kernels,evaluation_kernels_2d,evaluation_kernels_3d(bsplines/)evaluation_kernels,spline_mappings_kernels,transform_kernels(geometry/)cuboid_kernels,orthogonal_kernels,colella_kernels,hollow_cylinder_kernels,powered_elliptic_cylinder_kernels,hollow_torus_kernels,shafranov_shift_cylinder_kernels,shafranov_sqrt_cylinder_kernels,shafranov_dshaped_cylinder_kernels(geometry/domains/<name>/<name>_cuda.cuh)linalg_kernels,filler_kernels,particle_to_mat_kernels,pusher_utilities_kernelsbsplines_kernels::MAX_SPLINE_DEGREE,evaluation_kernels_3d::SplineScratch,spline_mappings_kernels::spline_index_row/first_plane,transform_kernels::column_norm,pusher_utilities_kernels::reflect_velocity.linalg_kernels::det(...)inevaluation_kernels::det_df). Calls within the same module are not, as in pyccel..cufile writesusing namespace struphy_cuda;after its includes and qualifies every helper call (evaluation_kernels_3d::get_spans(...),evaluation_kernels::df(...)).test_device_helpers.pyandgeometry/tests/spline_mapping_cases.pyuse fully qualified names.struphy_cuda::pi(geometry/domains/constants_cuda.cuh). It stands in fornumpy.pi, not for a struphy module.MarkerArgs,DerhamArgs,DomainArgsandLocalProjectorsArgs(kernel_arguments/*.cuh, written by cunumpy'swrite_cuda_header). cunumpy matches theextern "C" __global__signatures against the struct names, and the CPU emulation (pic/tests/cuda_emulation.py) rebuilds the structs by name, so the generators and the emulation are unchanged.evaluation_kernels_3d.cuh: it had threenamespace struphy_cudablocks with an#includein between. It now has one block.eval_spline_mpiwas outside the namespace and is nowevaluation_kernels_3d::eval_spline_mpi, like its pyccel counterpart.Open PRs that need the same treatment after merge: #705, #713 and #718 add
.cu/.cuhcode that still callsstruphy_cuda::<name>. Whichever of them and this PR merges second needs the rule applied:using namespace struphy_cuda;in new.cufiles, and new helpers in their module's namespace. Their branches were not touched.Model-specific changes:
None.
Documentation changes:
CUDA_STRATEGY.md: a new convention bullet under "Target layout" documents the rule: the namespace isstruphy_cuda::<pyccel module>, CUDA-only helpers go into their module, cross-module calls are qualified,.cufiles useusing namespace struphy_cuda;, and the exceptions arepiand the generated structs.Local tests (macOS, no GPU; pyccel kernels compiled with GNU/Fortran; GPU tests not run, so nothing was compiled with NVRTC). The CPU emulation compiles every
.cufile and every helper header as C++17 with the host compiler. That is the syntax check for the namespaces; it caught one misplaced brace while I was working on this.src/struphy/pic/tests/test_cuda_parity.pysrc/struphy/pic/tests/test_cuda_emulation.pysrc/struphy/pic/tests/test_device_helpers.pysrc/struphy/bsplines/tests/test_evaluation_cuda.pysrc/struphy/pic/tests/test_kernel_backends.pyResult: 107 passed, 392 skipped (the GPU-only tests).
develgives the same counts.One open point for the GPU run: the nested namespace definition (
namespace struphy_cuda::bsplines_kernels {) needs C++17. NVRTC uses C++17 by default since CUDA 11, and the emulation compiles with-std=c++17.🤖 Generated with Claude Code