Evaluation of performance portability frameworks for the implementation of a particle-in-cell code
Paper · 2019 · Victor Artigues, Katharina Kormann, Markus Rampp et al.
Summary
A scientific program can run on different processors and still leave much of their computing power unused. The authors examine that problem for a particle-in-cell simulation, in which moving particles interact with electromagnetic fields represented on a grid. They take a computationally expensive part of the simulation and ask how well it carries over from multicore CPUs to GPU parallel computing. Their comparison focuses on Kokkos and RAJA, C++ frameworks that let programmers express parallel work and select an execution backend when building the program. Plain OpenMP and CUDA serve as the CPU and GPU references, and OpenACC provides another route to both types of processor.
The routine moves particles, uses the magnetic field along their paths to change their velocities, and deposits their contributions to the electric current on the grid. The particle updates can run concurrently, but particles can contribute to the same grid entry. Each implementation therefore needs a way to combine those contributions safely. On CPUs, that can mean giving threads private copies of the current array and summing them afterwards. On GPUs, several implementations use atomic additions, which let concurrent workers update a shared entry without losing contributions. The way each version handles these updates, and the temporary memory needed to calculate them, matters to both performance and implementation effort.
OpenACC and plain OpenMP achieved speedups of about 19 and 18, respectively, on 20 Skylake CPU cores. The paper summarizes the Kokkos CPU overhead relative to OpenMP as about 14%. A hybrid using OpenMP loops and Kokkos array views recovered essentially the performance of plain OpenMP. RAJA scaled less well on the CPU even after the authors reorganized thread-local memory. OpenACC led on the K40m GPU, while CUDA led on the P100 and V100. Kokkos was faster than RAJA on the P100, and RAJA was faster on the K40m and V100. Separate measurements of computation and data transfer showed how the connection between the CPU and GPU could change the practical significance of those rankings.
The authors judged both C++ frameworks usable for complex scientific code and favored Kokkos for the planned full simulation. Its defaults, scratch-memory support, and facilities for accumulating current reduced the amount of platform-specific work they had to do. That judgment combines timing results with the experience of implementing the routine. The measured workload is a node-local part of the particle-in-cell calculation, so the study supports a choice for further development while leaving full-simulation performance open.
Deep dive: Evaluation of performance portability frameworks for the implementation of a particle-in-cell code
A particle-in-cell benchmark compares Kokkos and RAJA with OpenMP, OpenACC and CUDA, measuring speed and implementation effort on CPUs and GPUs. · about 39 minutes to read
The problem and its context
Why running the same code is only part of the job
The paper begins with a distinction between distributing work across a supercomputer and deciding how to execute it inside a node. For communication between nodes, the authors describe the Message Passing Interface, or MPI, as a stable and well-supported choice. Inside a node, a program may encounter a multicore CPU, a GPU, or both. The expression “MPI + X” captures the division. MPI handles communication across nodes, while the choice represented by X determines how the program gets useful work out of the hardware at each node.
The rise of accelerators made that second choice especially consequential for the application the authors wanted to build. In the November 2018 Top 500 ranking, accelerated systems represented about 40% of the total when weighted by peak performance. For some of the high-end systems discussed in the paper, GPUs supplied a large share of nominal computing power. A program developed exclusively around CPU threads could consequently leave an important part of the intended machine unused. Supporting accelerators meant deciding how to express the same numerical calculation for hardware with different ways of organizing threads and accessing memory.
The authors describe OpenMP as an established way to parallelize CPU work. Its specifications also covered accelerators, but compiler support for those targets was limited at the time, and some aspects of behavior differed across processor types. OpenACC offered a directive-based approach designed with GPU programming in mind and could also target multicore CPUs. Its compiler choices were limited as well. With either directive-based approach, the authors expected complex programs to need changes in data layout or control flow to get good performance across both kinds of hardware. A compiler directive can expose a loop to parallel execution, but the organization of the data that loop uses still matters.
OpenCL addressed heterogeneous hardware too. The paper describes it as exposing more of the organization of parallel hardware through kernels, the routines mapped onto the available processing threads. An application built around ordinary loops or task graphs could require substantial restructuring to express its work that way. For existing Fortran programs, the authors also point to the need to construct C interfaces. CUDA gave the study a way to write directly for NVIDIA GPUs, with explicit decisions about how the particle loop maps onto threads and thread blocks.
C++ portability frameworks offered a different division of labor. An application could describe the work to run in parallel, the data it needs, and some requirements on how it should run. The framework would then generate code for a selected backend, such as OpenMP on the CPU or CUDA on the GPU. C++ templates allow many of those choices to be resolved at compile time. The benefit the paper investigates is the prospect of keeping the numerical calculation in a common source while letting specialists maintain the machinery that connects it to each platform. This still leaves an application programmer with real decisions about memory, scheduling, and synchronization.
Why this particle calculation was a different test
The authors were preparing for a substantial development effort. Their goal was a full parallel C++ implementation of a particle-in-cell approach to the Vlasov–Maxwell equations, but the large implementation had yet to be built and tuned for the target systems. A pilot study gave them a way to investigate framework choices before committing to an application-wide design. They started from a routine in the Fortran implementation in SeLaLib, extracted the relevant computation, and used it as the basis for a standalone C++ program.
The routine gives the frameworks more to handle than a parallel loop with a single output per iteration. Each particle has its own position and velocity, so workers can update different particles independently. The same particle can contribute to several current coefficients on the grid, and different particles can contribute to the same coefficient. The benchmark therefore combines independent work on particle records with a shared accumulation. Calculating the contribution also requires temporary storage, whose placement can affect CPU caches or the resources available to a GPU kernel.
There is a further complication inside each loop iteration. The current in this scheme depends on the path a particle takes during the timestep. Each particle can travel a different distance in the direction being advanced. The number of grid basis functions involved in a contribution can vary accordingly. That variation is relevant to the paper's choice of workload. A framework must let the programmer organize a substantial per-particle calculation, supply its temporary memory, and handle irregular work within the loop as well as collisions in the output array.
What earlier comparisons had established
The closest earlier studies in the paper addressed different scientific calculations. Martineau and colleagues used TeaLeaf, a small heat-conduction application based on finite differences, to compare several approaches to portable parallel programming. The authors report that Kokkos and RAJA incurred penalties of 5% to 30% relative to architecture-specific implementations in that study. This provided a precedent for measuring a framework against code written for the target platform. The magnitude of the penalty in a loop that deposits a particle current remained a separate question.
The work by Sunderland and colleagues on the Uintah turbulent-combustion code illustrated another possible outcome. Introducing Kokkos views with appropriate layouts improved some kernels by making memory access and vectorization more effective. A view is an array interface that maps logical indices onto physical storage. That earlier experience made layout part of the portability question. Changing the software interface can change how effectively a processor reads the array, so the resulting timing can reflect a better storage arrangement as well as the cost of executing through a framework.
The Albany study described by the authors focused on refactoring portions of a finite-element application with Kokkos. It compared performance across CPU, GPU, and KNL targets. The paper points out that the study lacked a performance baseline from the original code before the port. The present evaluation builds CPU and GPU reference implementations for the extracted routine and compares them with versions that use portable interfaces. It also adds a hybrid CPU implementation so that the role of Kokkos array views can be investigated separately from the full Kokkos execution path.
These precedents explain the scope of the paper. The authors study a common scientific computing pattern through an application with different demands from the heat-conduction, combustion, and finite-element cases they discuss. Their questions concern both the speed obtained from the implementation and the work needed to express it. In particular, they want to know what a framework supplies for grid accumulation, thread-private storage, and target selection, because those details will recur when developing the larger simulation.
The method, step by step
From a plasma distribution to a particle loop
The physical starting point is a distribution over position and velocity. At any location, particles of a given plasma species can have a range of velocities. Keeping track of that distribution directly would give the numerical scheme a six-dimensional phase space to represent, including the spatial and velocity coordinates. The particle-in-cell method instead uses weighted computational particles to represent the distribution. The position and velocity of a computational particle change over time, and its weight specifies its contribution to the representation.
The electromagnetic fields are represented on a spatial grid. The particle calculation uses the field representation to determine what happens along a trajectory. In the other direction, the particles supply information about charge and current to the field equations. This exchange explains the name particle-in-cell. At each particle's position or along its path, the algorithm identifies the relevant grid cells and basis functions. A basis function is one of the functions used to reconstruct a field from its grid coefficients. A particle contributes to the coefficients whose basis functions are involved in the path calculation.
The authors use a building block from the geometric electromagnetic particle-in-cell scheme, GEMPIC. The operation they selected uses the magnetic field to update the other velocity components while advancing the first position component and accumulating the first current component. The particle loop combines geometry, numerical evaluation, and parallel bookkeeping. The stages below follow that loop from loading particle data to assembling its grid output.
Particle movement and current deposition in the benchmark
The steps in order.
The last step describes the accumulation at the algorithmic level. In code that uses private arrays, it is a separate pass that adds those arrays together. Where the implementation deposits through atomic additions directly into a common array, the contributions are combined during the particle loop. Both choices produce the grid quantity needed by the field calculation. The organization differs because the processor can make one method more practical than the other.
The governing equations
The Vlasov equation describes how the distribution changes as particles move and accelerate in the fields. In the paper's notation, its transport terms distinguish motion through space from motion through velocity space.
∂ₜ fₛ(x, v, t) + v · ∇ₓ fₛ(x, v, t) + (qₛ/mₛ)(E(x, t) + v × B(x, t)) · ∇ᵥ fₛ(x, v, t) = 0
Here fₛ is the distribution of species s, x is spatial position, v is velocity, and t is time. E and B are the electric and magnetic fields at the position and time shown. qₛ and mₛ are the charge and mass for that species. ∂ₜ is the time derivative, while ∇ₓ and ∇ᵥ differentiate the distribution with respect to position and velocity. The dot denotes an inner product and × is the vector cross product. The sum being zero expresses constancy of the distribution along the corresponding trajectories.
The particle distribution and the fields are coupled. The paper gives the time evolution of the electric and magnetic fields as follows.
∂ₜ E − ∇ × B = −j
∂ₜ E is the time derivative of the electric field. ∇ × B is the spatial curl of the magnetic field, and j is the current density. Here the cross notation with ∇ denotes a differential operator on the field.
∂ₜ B + ∇ × E = 0
∂ₜ B is the time derivative of the magnetic field and ∇ × E is the spatial curl of the electric field. The zero on the right means those terms sum to zero. The paper also gives divergence conditions for the fields.
∇ · E = ρ
∇ · E denotes the spatial divergence of the electric field and ρ is the charge density.
∇ · B = 0
∇ · B denotes the spatial divergence of the magnetic field, which the equation sets to zero.
Charge and current are velocity moments, meaning they are obtained by integrating the distribution over velocities with different factors in the integrand. Position and time stay fixed during the integration.
ρ(x, t) = Σₛ qₛ ∫ fₛ(x, v, t) dv
ρ(x, t) is the charge density at x and t. Σₛ denotes a sum over species. For each species, the integral adds its distribution fₛ over velocity v, with dv indicating the variable of integration. The factor qₛ gives that species' charge.
j(x, t) = Σₛ qₛ ∫ v fₛ(x, v, t) dv
j(x, t) is the current density at that position and time. Σₛ sums over species and qₛ is the corresponding charge. Inside the integral, the velocity vector v weights the distribution fₛ, so the result includes the direction of motion. dv again indicates integration over velocities. The benchmark assembles a contribution to a component of this current in the grid representation.
Particles and fields in the numerical representation
The appendix presents the characteristic equations behind the particle method. Along a characteristic, the evolution of position is given by the trajectory's velocity.
dX/dt = V
X and V are the position and velocity along a characteristic, and d/dt is differentiation with respect to time t. The same equation serves in the semi-discrete system when X and V collect the positions and velocities of all computational particles.
dV/dt = E(X, t) + V × B(X, t)
Here V is the trajectory velocity, E(X, t) and B(X, t) are the fields at trajectory position X and time t, and × is the cross product. This is the appendix's displayed characteristic equation, where the force terms appear without a separate species factor. The governing Vlasov equation and the explicit particle updates show the charge-to-mass factor for the corresponding species.
A computational particle has a position, a velocity, and a weight. The weight stays fixed in the scheme considered here. The appendix gives a general particle representation in which a spatial shape function specifies how the particle contributes at positions around its location.
fₛ(x, v, t) = Σₚ₌₁ᴺᵖˢ wₚ S(x − xₚ) δ(v − vₚ)
fₛ is the distribution of species s at position x, velocity v, and time t. The sum enumerates the Nᵖˢ computational particles for that species using index p, beginning at 1. wₚ is the particle's weight, and xₚ and vₚ are its position and velocity at time t. S is the spatial shape function and δ is the Dirac distribution, which places the velocity contribution at vₚ. The appendix allows the spatial shape to be a Dirac distribution or a smoothing kernel in this general expression. The GEMPIC scheme studied here takes S to be a Dirac distribution.
The field representation is separate. Each component of a field is reconstructed from time-dependent coefficients and spatial basis functions. The electric and magnetic fields use different spline bases. A spline is polynomial within each of its pieces, and the basis functions used here have compact support, meaning that they are non-zero only on a limited portion of the grid.
Ẽₖ(x, t) = Σᵢ₌₁ᴺᵍ eₖ,ᵢ(t) Λᵢ¹,ᵏ(x)
Ẽₖ is the discretized electric field component indexed by k, evaluated at x and t. The grid index i runs from 1 through Nᵍ, the number of grid points used for that component's basis. eₖ,ᵢ(t) is the coefficient at index i and time t. Λᵢ¹,ᵏ(x) is the corresponding electric basis function at x, with 1 identifying the electric basis family.
B̃ₖ(x, t) = Σᵢ₌₁ᴺᵍ bₖ,ᵢ(t) Λᵢ²,ᵏ(x)
B̃ₖ is the discretized magnetic field component indexed by k. x and t are position and time, and i ranges from 1 to the grid count Nᵍ. bₖ,ᵢ(t) is the magnetic coefficient at index i, while Λᵢ²,ᵏ(x) is the associated spatial function in magnetic basis family 2.
For the electric component in a given direction, the basis uses a spline of degree p − 1 in that direction and degree p in the transverse directions. The magnetic component reverses that arrangement, using degree p in its own direction and degree p − 1 in the transverse directions. Here p is the base spline degree. It is separate from the particle index, also written p in the paper. Each basis function is a tensor product. Its value is found by multiplying the univariate spline values for the respective spatial coordinates. This is the structure the implementation exploits when it reuses calculations across grid entries.
Where the benchmark fits in the time step
In the semi-discrete system, space has been represented by particles and grid coefficients, while time is still continuous. In addition to the position equation, the paper gives the velocity equations by component. The following notation uses ⊙ to make explicit that products between particle vectors act entry by entry.
dV₁/dt = (q/m)[Λ¹,¹(X)e₁ + V₂ ⊙ (M_q Λ²,³(X)b₃) − V₃ ⊙ (M_q Λ²,²(X)b₂)]
V₁, V₂, and V₃ are vectors containing the first, second, and third velocity components across the particles. d/dt gives their rate of change in time. q/m is the species charge q divided by its mass m. X holds the particle positions. A matrix Λʲ,ᵏ(X) evaluates basis family j, electric for 1 and magnetic for 2, for field component k at those positions. Multiplying by the electric coefficients e₁ or magnetic coefficients b₂ and b₃ evaluates the indicated field component across particles. M_q is the diagonal matrix specified in the appendix, with entries given by particle weight times charge. ⊙ multiplies the resulting entries by the corresponding velocity entries.
dV₂/dt = (q/m)[Λ¹,²(X)e₂ + V₃ ⊙ (M_q Λ²,¹(X)b₁) − V₁ ⊙ (M_q Λ²,³(X)b₃)]
Here dV₂/dt is the change of the second velocity component across all particles, and V₃ and V₁ supply the other velocity components for the entrywise products ⊙. q and m are species charge and mass. Λ¹,²(X) evaluates the second electric basis component at particle positions X, and e₂ contains its coefficients. Λ²,¹(X) and Λ²,³(X) evaluate the first and third magnetic basis components whose coefficients are b₁ and b₃. M_q carries the particle charge and weight on its diagonal. The opposing magnetic terms come from the component structure of the cross product.
dV₃/dt = (q/m)[Λ¹,³(X)e₃ + V₁ ⊙ (M_q Λ²,²(X)b₂) − V₂ ⊙ (M_q Λ²,¹(X)b₁)]
dV₃/dt is the time rate of change of the vector of third velocity components. q/m is charge over mass. The electric coefficient vector e₃ multiplies the third electric basis evaluation Λ¹,³(X). Magnetic coefficient vectors b₂ and b₁ multiply their respective magnetic basis evaluations Λ²,²(X) and Λ²,¹(X) at positions X. The diagonal matrix M_q holds charge times weight, and ⊙ applies multiplication by the particle velocities V₁ and V₂ entry by entry.
The field equations operate on coefficient vectors. The paper treats the electric evolution in weak form, using the finite-element mass matrices, and the magnetic evolution in strong form, using the discrete curl.
de/dt = M₁⁻¹[Cᵀ M₂ b(t) − Λ¹(X)ᵀ M_q V]
e and b collect the electric and magnetic coefficient vectors across components. de/dt is the time derivative of the electric coefficients, and b(t) is the magnetic coefficient vector at time t. M₁ and M₂ are the finite-element mass matrices for the electric and magnetic bases, and M₁⁻¹ is the inverse electric mass matrix. C is the discrete curl and ᵀ denotes transpose. Λ¹(X) collects the electric basis evaluations at the particle positions X, with the component grouping understood in the product with the velocity vector V. M_q weights particle velocities by charge and particle weight. The term involving its product with V is the grid source supplied by the particles.
db/dt = −C e(t)
db/dt is the time derivative of the magnetic coefficient vector. C is the discrete curl matrix and e(t) is the electric coefficient vector at time t. The minus sign gives the sign of the magnetic evolution in the field equation.
The time integration in GEMPIC can be organized by Hamiltonian splitting. Splitting divides the system into pieces that act on different terms and can be integrated explicitly in succession. The benchmark uses the part in which the first velocity component drives the motion along the first coordinate. The first velocity component stays fixed during this part. Of the full equations for the transverse velocities, the operation retains the terms in which that fixed velocity multiplies the corresponding magnetic component.
dX₁/dt = V₁
X₁ contains the first position component for every particle, V₁ contains the corresponding velocities, and d/dt denotes the derivative with respect to time. This equation gives a straight segment in that coordinate during the substep.
dV₂/dt = −(q/m) V₁ ⊙ (M_q Λ²,³(X)b₃)
V₂ is the vector of second velocity components and dV₂/dt is its time derivative. q and m are charge and mass, and V₁ supplies the velocity entry for the elementwise product ⊙. Λ²,³(X) evaluates the third magnetic basis component at particle positions X, b₃ contains its coefficients, and M_q denotes the diagonal charge-and-weight matrix in the displayed semi-discrete equations.
dV₃/dt = (q/m) V₁ ⊙ (M_q Λ²,²(X)b₂)
dV₃/dt is the time derivative of the third velocity component across particles. q/m is the charge-to-mass factor, V₁ supplies the first velocity component in the entrywise product ⊙, and M_q is diagonal with the charge-and-weight factors. Λ²,²(X) evaluates the second magnetic basis component at X, and b₂ contains the associated coefficients. This contribution has the opposite sign from the one in the second velocity equation.
M₁,₁ de₁/dt = −Λ¹,¹(X)ᵀ M_q V₁
M₁,₁ is the electric mass matrix block for the first component and de₁/dt is the time derivative of that component's coefficient vector. Λ¹,¹(X) evaluates the first electric basis component at the positions X. Its transpose ᵀ maps the values weighted by M_q V₁, the first particle velocities with charge and weight applied, into the grid representation.
Calculating one particle's path and its contributions
The explicit calculation starts by reading the particle's current state. The position update uses the first velocity component during the substep. In the equations below, tₘ and tₘ₊₁ name the starting and ending times, and the mass in a charge-to-mass factor is written as plain m. The subscripts on the times serve as step indices.
x₁,ₚ(tₘ₊₁) = x₁,ₚ(tₘ) + Δt v₁,ₚ(tₘ)
x₁,ₚ is the first coordinate of particle p, evaluated at the end or start time as shown. Δt is the timestep and v₁,ₚ(tₘ) is that particle's first velocity component at the start. The transverse coordinates stay at their starting values during the segment.
The authors express the velocity changes as integrals over this trajectory. For a non-zero first velocity component they change the integration variable from time to the first spatial coordinate. The velocity factor is then absorbed into the change of variable. The spatial integral runs from the old position to the new one in the order the particle travels. A particle traveling in the opposite direction therefore reverses the orientation of the integral. The transverse coordinates remain fixed, so their spline factors can be taken outside the integral.
For clarity, the next equations write out the tensor-product factors using N for a univariate spline and use the abbreviated endpoint names a and b. Both refer to the first coordinate of the same particle, with a at tₘ and b at tₘ₊₁. In the spline superscripts d is the base degree, called p in the paper.
v₂,ₚ(tₘ₊₁) = v₂,ₚ(tₘ) − (q/m) Σᵢ₌₁ᴺᵍ b₃,ᵢ(tₘ) [∫ₐᵇ Nᵢ₁ᵈ⁻¹(σ) dσ] Nᵢ₂ᵈ⁻¹(x₂,ₚ(tₘ)) Nᵢ₃ᵈ(x₃,ₚ(tₘ))
v₂,ₚ is particle p's second velocity component at the indicated time. q/m is charge divided by mass. The sum uses grid index i from 1 through Nᵍ. b₃,ᵢ(tₘ) is the coefficient of the third magnetic component at grid index i and the start time. The subscripts i₁, i₂, and i₃ are the coordinate indices associated with i. Nᵢ₁ᵈ⁻¹ is a spline of degree d − 1 integrated in the first coordinate σ from a to b. The other N factors are the transverse splines of the indicated degrees at the second and third starting coordinates x₂,ₚ(tₘ) and x₃,ₚ(tₘ).
v₃,ₚ(tₘ₊₁) = v₃,ₚ(tₘ) + (q/m) Σᵢ₌₁ᴺᵍ b₂,ᵢ(tₘ) [∫ₐᵇ Nᵢ₁ᵈ⁻¹(σ) dσ] Nᵢ₂ᵈ(x₂,ₚ(tₘ)) Nᵢ₃ᵈ⁻¹(x₃,ₚ(tₘ))
v₃,ₚ is the third velocity component of particle p, first at the end and then at the start of the step. q/m is the charge-to-mass factor. i again ranges from 1 to the grid count Nᵍ, and b₂,ᵢ(tₘ) is the second magnetic component's coefficient at index i and the start time. The first-direction spline of degree d − 1 is integrated in σ between endpoints a and b. The other spline factors use the second and third grid indices i₂ and i₃ and the unchanged transverse particle coordinates. The higher transverse degree is now in the second direction, in accordance with the basis for the second magnetic component.
jᵢ ← jᵢ + q wₚ [∫ₐᵇ Nᵢ₁ᵈ⁻¹(σ) dσ] Nᵢ₂ᵈ(x₂,ₚ(tₘ)) Nᵢ₃ᵈ(x₃,ₚ(tₘ))
jᵢ is coefficient i of the integrated current for the first field component. The arrow means adding the contribution on the right to the current value. q wₚ is particle charge times weight. The integral uses longitudinal spline index i₁ and degree d − 1 along spatial coordinate σ between the particle's endpoints a and b. i₂ and i₃ select transverse splines of degree d at the second and third starting coordinates of particle p. These are the transverse degrees for the first electric component. In the split field equation, the mass-matrix-weighted electric coefficient vector at the next time is its old value with the integrated current subtracted.
The longitudinal integral appears in the velocity and deposition calculations. This common factor is why the implementation computes a set of path integrals and then reuses them within the grid loops. The paper evaluates the integral by taking the difference of a primitive spline at the path endpoints. A primitive is a function whose derivative is the spline being integrated.
∫ₐᵇ Nᵢ₁ᵈ⁻¹(σ) dσ = Fᵢ₁(b) − Fᵢ₁(a)
Nᵢ₁ᵈ⁻¹ is the longitudinal spline of degree d − 1 associated with grid index i₁. σ is the spatial integration variable. a and b are the particle's old and new first coordinates, and Fᵢ₁ is the primitive of that spline. Evaluating both endpoint values gives the signed contribution along the path.
In practice, the code first finds the old and new grid cells and the local coordinates within them. For a point evaluation, compact support restricts the work to the splines active in the corresponding cell. For the path integral, the portion of the grid involved depends on how far the particle moves. The code uses piecewise polynomial representations for both the splines and their primitives. It evaluates the relevant polynomials with Horner's algorithm, which evaluates coefficients by nesting multiplications and additions. The code listing also shows reuse of products of transverse spline factors inside the grid loops.
This procedure connects the numerical operation to the shape of the workload. Temporary values include the particle's old and new coordinates, the local spline evaluations, and the indices used to address the relevant grid coefficients. Thread-private storage keeps those temporary values independent while many particles are being processed. The integrated current has different ownership. A given entry can receive a contribution from any particle whose path involves the corresponding basis function. Its implementation requires coordination even though each particle's new state can be written back to its own record.
Giving the same operation several implementations
The standalone C++ reference includes the driver, input and output, timing, and verification. The authors use it as the starting point for the parallel versions. The first CPU version uses OpenMP directives to distribute the particle loop and to combine partial currents. Threads have private temporary variables and private current storage. A separate work-sharing loop combines the thread results by grid entry. The plain CUDA version serves as the GPU reference. It maps particle work onto blocks of threads and uses atomic additions to a shared current array.
The Kokkos port uses views to describe arrays and manage their allocation. A view carries a pointer and information about how indices map to elements. Kokkos also associates its views with a memory space, which determines where data is allocated. A host mirror provides a host-side view when needed, and the implementation explicitly copies data between the mirror and the view used for computation. This arrangement lets code express where a set of data is needed without reproducing all of the allocation logic for each backend.
Kokkos distinguishes the operation itself, such as a parallel loop, from the execution policy and execution space. The execution space selects where the work runs. The policy describes how the work is organized there. Its range policy specifies index bounds, while its team policy offers hierarchical execution and scratch memory. The scratch memory holds temporary data for the routine and has to be sized before the loop is dispatched. The authors use a functor, a C++ object that can be called like a function, to hold the state needed by the loop. An execution tag selects the relevant operation within that object at compile time.
The grid accumulation in Kokkos uses ScatterView. On the CPU it supplies private copies of the current array, and the program calls a contribution operation to combine them afterwards. On the GPU it uses atomics without duplicating the view. In the implementation discussed by the authors, choosing the two modes required a small conditional template setting. Kokkos could otherwise supply defaults for execution and memory spaces, and its build configuration could select the hardware-specific optimization flags. The code was developed with Kokkos version 2.7.00.
The RAJA port also wraps array data in views and expresses the parallel loop through a framework call. RAJA views describe access to storage allocated by the program. The application is responsible for allocation and transfers, and RAJA policies explicitly specify the execution target and organization of the loop. A range segment describes the particle indices that the loop processes. The authors use lambda functions, function bodies defined where they are passed to the framework, to hold the work associated with a particle. The study used RAJA version 0.6.0.
The CPU accumulation in RAJA uses a separately implemented reduction. Each thread has a view of its partial current array, and a later loop sums the entries across threads. On the GPU, the code uses RAJA atomic updates to the shared current array. Temporary data also requires different handling on the two targets. The CPU implementation uses views over per-thread memory, while the GPU path uses local storage appropriate to that implementation. The authors specify target choices through conditional compilation where needed. The common calculation is still visible in the code, but more of the work of connecting it to each backend is handled in the application.
The OpenACC implementation takes a further approach to combining current. It creates a current array for each gang, a group of workers in the OpenACC execution structure, and uses atomic updates within a gang. It then sums the gang arrays. This scheme reduces the number of workers competing to update the same array. It also introduces an additional stage and extra storage. The paper explains the choice through comparisons with a shared array, which are discussed below.
The hybrid uses Kokkos views for the arrays and OpenMP directives for execution. Accesses in the OpenMP section use unmanaged views, which refer to the underlying allocation without participating in Kokkos reference counting. The arrangement was designed to test whether arrays accessed through Kokkos views could retain plain OpenMP performance. Its construction is important to interpreting the result, because it changes the operation of the views inside the OpenMP region along with the way the loop is launched.
Experiments and results
The workload and what the timings measure
The experiments use simulation data. A run processes 10 million particles on a 16 by 8 by 8 mesh with splines of degree 3 and 2. The particle count, mesh, and spline degrees define the workload held constant across the main comparisons. The particle records use an array of structures. In this representation a particle's position, velocity, and weight are stored together, and the array contains a succession of those records. Framework versions change the interfaces through which code works with that storage, while the overall particle organization remains fixed.
The authors first examined serial performance using a single process and 3 iterations. On a single IvyBridge core, the plain C++ routine took about 7.5 seconds per iteration with these settings. In the preparation described alongside that measurement, they identified repeated modulo operations in the mapping from particle positions to the mesh. Across the implementations, saving intermediate computations for reuse within the same iteration roughly halved processing time. The authors present this as an optimization of the common calculation. The main parallel comparisons then show how the resulting implementations behave as the execution framework or target processor changes.
The study distinguishes the hardware used during development from the systems used to obtain the principal results. Much of the development took place on an IvyBridge node with Kepler GPUs. The GPU comparison includes the K40m from this generation, the P100 from a POWER8-Pascal system, and the V100 from a Skylake-Volta system. The CPU scaling experiment uses a 20-core Intel Xeon Gold 6148 2.4GHz Skylake processor. The unit of comparison for the benchmarks is a single multicore CPU socket or a single GPU, even though the machines themselves contain additional processors or devices.
The compilation setup is another part of the experimental conditions. The authors used GCC 6.3 and CUDA 9.1 for the relevant builds of the C++ reference, direct parallel implementations, and framework versions. OpenACC was compiled with PGI 19. The builds used aggressive optimization and hardware-specific settings. Kokkos could generate suitable compiler settings from its target specification, while the other builds required the equivalent choices to be set explicitly. The authors report spending comparable amounts of time analyzing and optimizing the various ports, with particular intervention when they found a CPU memory issue in RAJA.
The principal CPU metric is wall-clock time per iteration as the number of cores changes. Speedup expresses that change relative to the single-core run of an implementation. This matters when reading the scaling results. Two implementations can have similar speedups and different absolute times if they start from different single-core times. The CPU figure averages the reported times over 10 runs. On GPUs, the paper measures computation and data-transfer time separately with NVIDIA's profiler and averages the GPU figure over 200 runs.
CPU scaling and elapsed time
On the Skylake socket, OpenACC recorded the shortest time and scaled nearly ideally up to 20 cores, with a speedup of about 19. Plain OpenMP followed with a speedup of about 18. Its elapsed time on 20 cores was about 2.8% longer than OpenACC's. The closeness of those elapsed times matters more for the ordering on that machine than the rounded speedup figures alone. The compilers differ across these implementations, so the comparison is between tested builds using their respective toolchains.
The paper gives two summaries of the Kokkos CPU cost with different reference points. Averaged across the tested core counts, the Kokkos implementation was about a factor of 1.21 slower than OpenACC. In the conclusion, the authors describe about 14% overhead relative to plain OpenMP and say that Kokkos scaled almost as well as that baseline. These figures answer different questions because their comparison points differ. Together they show that Kokkos followed a similar scaling trend and paid a measurable elapsed-time cost for this workload.
The hybrid achieved a speedup of 19.18 on 20 cores and virtually the same elapsed performance as plain OpenMP. The reported speedup is specific to the hybrid's own scaling curve. The close elapsed times support the finding about data access. The views used by the hybrid could be retained while the computation ran with the OpenMP loop and reduction organization.
RAJA was the slowest CPU implementation and showed the weakest scaling in the comparison. This is the result after the authors improved the arrangement of thread-local memory. The paper considers further improvement possible with additional tuning. Its evaluation of portability includes the time such tuning would require, so the amount of effort already spent is material to the authors' choice. The study records the performance that came out of the tested implementation process and optimization budget.
GPU computation across hardware generations
The compute-time ranking changed across GPU generations. On the K40m, OpenACC came first, followed by CUDA, RAJA, and Kokkos. CUDA was about 67% slower than OpenACC. RAJA took a factor of 2.02 as long as OpenACC, and Kokkos took a factor of 2.30 as long. The three comparisons use the same OpenACC reference, though the paper expresses the CUDA comparison as a percentage and the framework comparisons as multiplicative factors.
On the P100, CUDA was fastest. OpenACC took 1.23 times the CUDA compute time, Kokkos took 1.95 times, and RAJA took 2.18 times. The chart shows the alternatives for which the paper explicitly gives those factors, all relative to the same CUDA run.
P100 PIC benchmark compute time relative to CUDA for 10 million particles
OpenACC comes closest to CUDA, and Kokkos finishes ahead of RAJA.
The numbers
| System or setting | compute-time factor relative to CUDA |
|---|---|
| OpenACC (this paper) | 1.23 |
| Kokkos | 1.95 |
| RAJA | 2.18 |
CUDA also led on the V100. OpenACC took 1.20 times the CUDA compute time, RAJA took 2.51 times, and Kokkos took 3.53 times. The frameworks change places between the P100 and the V100. The single fastest portable alternative in these GPU comparisons was OpenACC on each of those devices when the ranking is expressed relative to native CUDA on the same device.
V100 PIC benchmark compute time relative to CUDA for 10 million particles
OpenACC stays closest to CUDA, while RAJA finishes ahead of Kokkos.
The numbers
| System or setting | compute-time factor relative to CUDA |
|---|---|
| OpenACC (this paper) | 1.20 |
| RAJA | 2.51 |
| Kokkos | 3.53 |
The ratio to CUDA is a comparison within a device. A larger ratio on another device can result from a much faster CUDA reference there. The ratios alone therefore leave open how a given framework's absolute runtime changes across devices. The paper supplies a cross-architecture comparison of a different kind by placing the best Skylake result on its GPU timing figure. For the V100, each tested GPU implementation computed the routine significantly faster than the best time on the 20-core Skylake CPU.
The per-device order is also important when interpreting the authors' overall framework preference. Kokkos led RAJA on the P100, whereas RAJA led Kokkos on the K40m and V100. The preference for Kokkos in the full project came from looking at CPU scaling and implementation experience alongside those GPU timings. On the GPU itself, the measurement gives a conditional result tied to the device and the particular way each version implements the routine.
How transfers alter the comparison
Moving particle data between host memory and device memory can take longer than part of the calculation it enables. The authors therefore measured computation and transfer individually, synchronizing host and device data each timestep in the benchmark. The figure for the GPU reports both computation time and the duration of a single data transfer. This lets a reader consider the effect of a transfer separately from the cost of executing the routine.
The hardware link is part of that measurement. On the tested P100 system, the NVLink connection had a transfer rate of 20 gigatransfers per second. The K40m and V100 systems used PCIe 3.0 with a transfer rate of 8 GT/s. The transfers over NVLink took roughly 2 times less time in the reported comparison. These figures characterize the interconnects and the measured transfers, respectively. The GPU's ability to calculate the particle update is a separate quantity.
For OpenACC, the transfer took longer on the V100 system than on the P100 system. The paper reports that this made the P100 the fastest overall for the OpenACC implementation under the measured compute-and-transfer arrangement. The shortest pure compute result was CUDA on the V100, where the transfer took about a factor of 2.3 longer than the computation. A faster GPU kernel can thus expose the importance of a transfer that previously represented a smaller share of the elapsed time.
The authors expect a full PIC program to exchange the large particle state less often than the benchmark synchronizes it. They identify initial setup, checkpointing, and particle redistribution associated with sorting for data locality as occasions for particle transfers. Field data has to be synchronized at each step, but the paper describes it as small relative to the particle data. This is the basis for their expectation that a realistic run would often be closer to the compute-only cost. The relative importance of transfers in such a run depends on the frequency and size of exchanges in the final application.
What the ablations show
Keeping Kokkos arrays while changing loop execution
The paper offers implementation comparisons and controlled changes to the routine, with the hybrid providing the clearest test of an overhead hypothesis. The authors wanted to know whether Kokkos views imposed the observed CPU cost simply because the program accessed its data through them. They retained the views, substituted conventional OpenMP execution for the Kokkos parallel loops, and accessed the allocations using unmanaged views in the parallel regions. With that arrangement the hybrid ran at virtually the same speed as plain OpenMP.
The result establishes that the portable array interface can coexist with the performance of the plain OpenMP implementation under the tested conditions. It also gives the authors a practical way to tune a portion of a larger Kokkos program. The views can remain in use while a critical CPU routine takes over its own loop scheduling and current accumulation. Because the hybrid also changes the access traits and uses the OpenMP reduction structure, it localizes the problem to a broader execution arrangement. The comparison leaves the individual costs of dispatch, scratch handling, and reduction inside full Kokkos unresolved.
The unmanaged view choice has a concrete motivation. Kokkos can manage the lifetime of its allocations through reference counting. The authors explain that ordinary managed views in the OpenMP region would create atomic-operation overhead. An unmanaged view avoids that lifetime bookkeeping in the region while providing access to storage whose lifetime is handled elsewhere. The favorable hybrid timing is evidence for the specific combination of the OpenMP organization and unmanaged access, which is more precise than a claim that every use of a Kokkos view carries the same CPU cost. There was no corresponding hybrid experiment for RAJA.
Changing the placement of RAJA scratch data
The RAJA CPU investigation starts from an observation about scaling. A parallel loop can have private variables at the level of the program and still force threads to interact through the cache. A processor cache moves and tracks data in blocks called cache lines. If neighboring threads write different variables on the same line, their writes can repeatedly cause that line to move or be invalidated across cores. This is false sharing. The apparent sharing comes from the physical placement of separate variables, rather than from a numerical requirement for the threads to exchange those variables.
The authors used the LIKWID performance tool to diagnose the early implementation. At 10 cores, the OpenMP-based code had about 200 MB on the last-level-cache measure used for the analysis, and the Kokkos code had about 10 MB. For the early RAJA CPU code, the reported value was 18 GB. The paper describes this measure as traffic associated with data that had to be synchronized between cores through the last-level cache. The figures concern cache activity in the diagnostic. They measure a different aspect of execution from the wall-clock iteration times.
Early RAJA scratch storage grouped local values in short neighboring slices of a view, with 3 entries per thread in the authors' example. The logical separation between slices was enough for each thread to have its own values. It left different threads' slices close enough to occupy the same cache line. The authors tried expanding a slice to 8 entries, retaining the first 3 as useful values and leaving the next 5 unused as padding. They identify 8 doubles as a typical cache-line width for the relevant x86 setting. With the added spacing, scaling improved substantially, at the cost of allocating and moving more memory.
The final change grouped the scratch data used by each thread into its own contiguous block. OpenMP already used private local variables, and Kokkos used per-thread scratch allocation. Regrouping brought the RAJA version closer to those arrangements while preserving the storage and view machinery needed by the RAJA code. This was the best of the layouts the authors tried. The final RAJA CPU version still scaled less well than the other CPU implementations. The diagnostic therefore identifies a concrete source of avoidable cost in the early code, while the remaining gap is left without a complete breakdown.
The cache problem and the current reduction are related to thread organization, but they concern different kinds of memory access. The false-sharing investigation addresses scratch data used during the particle calculation, where each thread is meant to have its own values. The current deposition has a genuine requirement to combine results across workers. Improving separation of scratch memory can remove incidental traffic while leaving the cost of assembling the current in place. This distinction helps explain why a successful memory-layout fix could improve scaling without fully closing the elapsed-time gap.
Varying reuse and the organization of current updates
Caching modulo calculations was a change to the shared numerical work. The code uses modulo operations while locating or addressing the mesh in the course of processing a particle. Once a result has been computed, it can be stored and reused during that iteration. The reported improvement of about a factor of 2 across implementations shows how much repeated mesh-address calculation mattered in this particular routine. It applies to the common workload and does not establish a special advantage for a framework.
The GPU discussion identifies another implementation choice with a different effect on performance. The direct CUDA code adds particle contributions through atomics on one global current array. The OpenACC code uses a separate array per gang and an additional reduction across gangs. The authors tried a shared-array approach in OpenACC as well. They report that the per-gang approach was much faster on the multicore CPU and that the two approaches performed fairly similarly on the GPUs. That comparison explains why the chosen OpenACC implementation used per-gang arrays on both targets.
Across the GPU generations, the authors attribute CUDA's improvement relative to OpenACC to stronger hardware support for atomic additions on recent devices. The shared-array approach can have many workers competing for the same locations. The per-gang arrays limit sharing to a smaller group before combining the partial results, a choice the authors connect to OpenACC's stronger relative performance on the older K40m. The change in ranking across devices is consistent with that explanation. Hardware generation, compiler, and implementation all vary in the broader comparison, so it captures the effect of those tested combinations.
These comparisons answer different questions about the same loop. The hybrid shows what can happen when data access through views is retained and the CPU execution path is replaced. The RAJA scratch changes show how thread-private values can interfere at cache-line granularity and how regrouping them helps. The OpenACC comparison shows a target-dependent effect of organizing real contention on the current array. Together they explain why the portability decision involved how easily an implementation could express a suitable memory and reduction strategy as well as which parallel loop interface it used.
Limitations
Scope identified by the authors
The study covers a single building block of the GEMPIC scheme. It represents the interplay of particle movement, field evaluation, and current deposition that the authors consider characteristic of the larger application. Full simulation performance would also depend on the other substeps, the field solution, and the management of distributed particle and grid data. The paper confines the experiment to shared-memory parallelism within a node, with the principal comparison using one CPU socket or one GPU. Its results give a basis for choosing an implementation framework for further development.
The authors keep the particle layout fixed. An array of particle records was a common starting point for the comparison, and it limited the work needed to produce the parallel versions. The paper identifies alternative arrangements, including storing the fields of particle records in separate arrays or combining the two organizations. It also explains that this particular deposition loop poses a challenge for vectorization because the relevant path length, and therefore the loop over longitudinal contributions, varies among particles. Data layouts tailored to address that problem remain outside the experiment.
Optimization effort was deliberately limited. The authors aimed to spend comparable time on the implementations to reflect what a team might obtain by starting from the sequential C++ routine and making a port. That criterion is appropriate to a decision in which developer time matters. It also leaves room for different performance with a larger tuning effort. The authors explicitly discuss this possibility for RAJA on the CPU, where the final version still showed a scaling gap after false-sharing mitigation.
Framework features and build options are tied to the tested versions. Kokkos's vector accumulation facility was in its experimental namespace, and the tested RAJA code needed its own CPU vector reduction. The paper notes limits to inspecting the generated code at the high-level C++ or C++/CUDA stage, describing assembly as the available level for examining what the templates produce. These points characterize the authors' development experience with the versions they used. They are historically specific observations about the tools available for the project.
Limits that follow from the experimental design
The fixed particle count, mesh, and spline degrees make comparisons easier to interpret within the benchmark. They also set the balance among per-particle arithmetic, scratch storage, and contention for grid entries. Another particle workload could spend a different share of its time in those activities. Different trajectory lengths would change how much path integration and deposition work is required. A broader claim about all particle-in-cell workloads would require evidence across those conditions. The authors present the possible relevance to other schemes as a judgment based on shared computational patterns.
GPU timing includes several hardware and software choices at once. The K40m, P100, and V100 come from different systems, and the device links differ. When the question is computation on the GPU, the profiler's separate compute measurement is the relevant quantity. When the question is operation within a particular host system, the transfer measurement becomes relevant too. A full application would introduce its own transfer schedule. The paper's expectation about infrequent particle transfers is a reason to examine the compute figure closely, and its full impact depends on the implementation of the larger simulation.
The CPU comparison also includes a compiler distinction. OpenACC uses PGI and the other CPU versions use GCC. The reported 2.8% difference between OpenACC and OpenMP on 20 cores is consequently a comparison of those implementations with their respective toolchains. The same applies to framework overhead more broadly. Measured time comes from the combination of the framework, how its API is used, the backend compiler, and the hardware. The hybrid and memory-layout investigations help narrow the explanations for particular results, while a decomposition of every runtime difference would require additional tests.
The paper verifies the parallel framework implementations against the reference as part of the development process. Its benchmark emphasis is elapsed time and usability for a specified routine. Questions about numerical behavior over a complete simulation would require evidence from the full sequence of substeps. Likewise, the reported timing averages characterize the runs the authors performed. The quantitative prose gives selected speedups, compute-time factors, and cache measurements, while the figures provide the trends across CPU core counts and GPU targets.
How to read the usability judgment
The usability assessment reflects the experience of the programmers who implemented the routine. They found that OpenMP and OpenACC required relatively little intrusion into existing loop code. The Kokkos and RAJA versions required restructuring to express parallel dispatch and arrange data. Kokkos supplied useful defaults and scratch-memory support, while RAJA gave the application programmer more direct responsibility for resource management and target selection. The authors regarded both frameworks as practical and preferred the balance they obtained with Kokkos.
Learning time in the study followed a particular order. The graduate-level C++ programmer learned and applied Kokkos first and brought that experience to RAJA. The programmers also had prior familiarity with OpenMP and CUDA. Thus the reported effort reflects prior experience and the order of implementation as well as the frameworks themselves. The strongest evidence for the usability preference lies in concrete features of the resulting code, such as how the implementation obtains scratch space, switches reduction strategies, and selects a target. Productivity across teams with other experience remains a separate question.
The preference for Kokkos also assumes that the project's requirements extend beyond achieving the shortest possible runtime for this one routine on a particular accelerator. Native CUDA led on the P100 and V100, and OpenACC performed strongly on both CPU and GPU. The authors gave weight to the prospect of maintaining the larger C++ application, its need for portable memory and parallel abstractions, and the ability to recover CPU performance with a hybrid where needed. That is the scope of their recommendation.
What came after
Later uptake of the study is unestablished. The paper's own forward-looking conclusion is a choice of Kokkos for the planned full particle-in-cell implementation. Its evidence for that choice came from the pilot routine, where both CPU and GPU execution were demonstrated and the authors could identify which features they would need again. They also left a concrete path for CPU optimization in the hybrid experiment and recorded where OpenACC and CUDA produced shorter times.
The question left open at the end of the study is how those findings carry into the full simulation. The benchmark makes the costs of particle computation, current accumulation, and host–device transfer visible individually. A complete implementation would bring those costs together with field solves, the other particle substeps, and communication across nodes. The paper establishes the properties of a candidate foundation for that work. Whether its measured tradeoffs persist at full scale remains an open outcome.
Cite
Cite as Victor Artigues, Katharina Kormann, Markus Rampp and Klaus Reuter. 2019. Evaluation of performance portability frameworks for the implementation of a particle-in-cell code. arXiv:1911.08394.
@misc{artigues2019evaluation,
title = {{Evaluation of performance portability frameworks for the implementation of a particle-in-cell code}},
author = {Victor Artigues, Katharina Kormann, Markus Rampp and Klaus Reuter},
year = {2019},
doi = {10.48550/arxiv.1911.08394},
eprint = {1911.08394},
archivePrefix = {arXiv},
url = {https://doi.org/10.48550/arxiv.1911.08394}
}This page in Markdown https://md.research.elamur.ai/free/en/papers/artigues-2019-evaluation-performance-portability-frameworks-implementation/