Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# - Adding scalar field buffers
self.scal_add_send_l = np.empty((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_send_r = np.empty((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_recv_l = np.empty((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_recv_r = np.empty((2, 2*ng, Nr), dtype=np.complex128)
else:
# Allocate buffers on the CPU and GPU
# Use cuda.pinned_array so that CPU array is pagelocked.
# (cannot be swapped out to disk and GPU can access it via DMA)
pin_ary = cuda.pinned_array
# - Replacing vector field buffers
self.vec_rep_send_l = pin_ary((6, ng, Nr), dtype=np.complex128)
self.vec_rep_send_r = pin_ary((6, ng, Nr), dtype=np.complex128)
self.vec_rep_recv_l = pin_ary((6, ng, Nr), dtype=np.complex128)
self.vec_rep_recv_r = pin_ary((6, ng, Nr), dtype=np.complex128)
self.d_vec_rep_buffer_l = cuda.to_device( self.vec_rep_send_l )
self.d_vec_rep_buffer_r = cuda.to_device( self.vec_rep_send_r )
# - Adding vector field buffers
self.vec_add_send_l = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_send_r = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_recv_l = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_recv_r = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.d_vec_add_buffer_l = cuda.to_device( self.vec_add_send_l )
self.d_vec_add_buffer_r = cuda.to_device( self.vec_add_send_r )
# - Replacing scalar field buffers
self.scal_rep_send_l = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_send_r = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_recv_l = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_recv_r = pin_ary((2, ng, Nr), dtype=np.complex128)
self.d_scal_rep_buffer_l = cuda.to_device( self.scal_rep_send_l )
self.d_scal_rep_buffer_r = cuda.to_device( self.scal_rep_send_r )
# - Adding scalar field buffers
self.d_vec_rep_buffer_l = cuda.to_device( self.vec_rep_send_l )
self.d_vec_rep_buffer_r = cuda.to_device( self.vec_rep_send_r )
# - Adding vector field buffers
self.vec_add_send_l = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_send_r = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_recv_l = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_recv_r = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.d_vec_add_buffer_l = cuda.to_device( self.vec_add_send_l )
self.d_vec_add_buffer_r = cuda.to_device( self.vec_add_send_r )
# - Replacing scalar field buffers
self.scal_rep_send_l = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_send_r = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_recv_l = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_recv_r = pin_ary((2, ng, Nr), dtype=np.complex128)
self.d_scal_rep_buffer_l = cuda.to_device( self.scal_rep_send_l )
self.d_scal_rep_buffer_r = cuda.to_device( self.scal_rep_send_r )
# - Adding scalar field buffers
self.scal_add_send_l = pin_ary((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_send_r = pin_ary((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_recv_l = pin_ary((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_recv_r = pin_ary((2, 2*ng, Nr), dtype=np.complex128)
self.d_scal_add_buffer_l = cuda.to_device( self.scal_add_send_l )
self.d_scal_add_buffer_r = cuda.to_device( self.scal_add_send_r )
def send_particles_to_gpu( self ):
"""
Copy the particles to the GPU.
Particle arrays of self now point to the GPU arrays.
"""
if self.use_cuda_memory:
# Send positions, velocities, inverse gamma and weights
# to the GPU (CUDA)
self.x = cuda.to_device(self.x)
self.y = cuda.to_device(self.y)
self.z = cuda.to_device(self.z)
self.ux = cuda.to_device(self.ux)
self.uy = cuda.to_device(self.uy)
self.uz = cuda.to_device(self.uz)
self.inv_gamma = cuda.to_device(self.inv_gamma)
self.w = cuda.to_device(self.w)
# Initialize empty arrays on the GPU for the field
# gathering and the particle push
self.Ex = cuda.device_array_like(self.Ex)
self.Ey = cuda.device_array_like(self.Ey)
self.Ez = cuda.device_array_like(self.Ez)
self.Bx = cuda.device_array_like(self.Bx)
self.By = cuda.device_array_like(self.By)
self.Bz = cuda.device_array_like(self.Bz)
self.vec_rep_recv_r = pin_ary((6, ng, Nr), dtype=np.complex128)
self.d_vec_rep_buffer_l = cuda.to_device( self.vec_rep_send_l )
self.d_vec_rep_buffer_r = cuda.to_device( self.vec_rep_send_r )
# - Adding vector field buffers
self.vec_add_send_l = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_send_r = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_recv_l = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_recv_r = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.d_vec_add_buffer_l = cuda.to_device( self.vec_add_send_l )
self.d_vec_add_buffer_r = cuda.to_device( self.vec_add_send_r )
# - Replacing scalar field buffers
self.scal_rep_send_l = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_send_r = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_recv_l = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_recv_r = pin_ary((2, ng, Nr), dtype=np.complex128)
self.d_scal_rep_buffer_l = cuda.to_device( self.scal_rep_send_l )
self.d_scal_rep_buffer_r = cuda.to_device( self.scal_rep_send_r )
# - Adding scalar field buffers
self.scal_add_send_l = pin_ary((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_send_r = pin_ary((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_recv_l = pin_ary((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_recv_r = pin_ary((2, 2*ng, Nr), dtype=np.complex128)
self.d_scal_add_buffer_l = cuda.to_device( self.scal_add_send_l )
self.d_scal_add_buffer_r = cuda.to_device( self.scal_add_send_r )
# (cannot be swapped out to disk and GPU can access it via DMA)
pin_ary = cuda.pinned_array
# - Replacing vector field buffers
self.vec_rep_send_l = pin_ary((6, ng, Nr), dtype=np.complex128)
self.vec_rep_send_r = pin_ary((6, ng, Nr), dtype=np.complex128)
self.vec_rep_recv_l = pin_ary((6, ng, Nr), dtype=np.complex128)
self.vec_rep_recv_r = pin_ary((6, ng, Nr), dtype=np.complex128)
self.d_vec_rep_buffer_l = cuda.to_device( self.vec_rep_send_l )
self.d_vec_rep_buffer_r = cuda.to_device( self.vec_rep_send_r )
# - Adding vector field buffers
self.vec_add_send_l = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_send_r = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_recv_l = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_recv_r = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.d_vec_add_buffer_l = cuda.to_device( self.vec_add_send_l )
self.d_vec_add_buffer_r = cuda.to_device( self.vec_add_send_r )
# - Replacing scalar field buffers
self.scal_rep_send_l = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_send_r = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_recv_l = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_recv_r = pin_ary((2, ng, Nr), dtype=np.complex128)
self.d_scal_rep_buffer_l = cuda.to_device( self.scal_rep_send_l )
self.d_scal_rep_buffer_r = cuda.to_device( self.scal_rep_send_r )
# - Adding scalar field buffers
self.scal_add_send_l = pin_ary((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_send_r = pin_ary((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_recv_l = pin_ary((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_recv_r = pin_ary((2, 2*ng, Nr), dtype=np.complex128)
self.d_scal_add_buffer_l = cuda.to_device( self.scal_add_send_l )
self.d_scal_add_buffer_r = cuda.to_device( self.scal_add_send_r )
def send_particles_to_gpu( self ):
"""
Copy the particles to the GPU.
Particle arrays of self now point to the GPU arrays.
"""
if self.use_cuda_memory:
# Send positions, velocities, inverse gamma and weights
# to the GPU (CUDA)
self.x = cuda.to_device(self.x)
self.y = cuda.to_device(self.y)
self.z = cuda.to_device(self.z)
self.ux = cuda.to_device(self.ux)
self.uy = cuda.to_device(self.uy)
self.uz = cuda.to_device(self.uz)
self.inv_gamma = cuda.to_device(self.inv_gamma)
self.w = cuda.to_device(self.w)
# Initialize empty arrays on the GPU for the field
# gathering and the particle push
self.Ex = cuda.device_array_like(self.Ex)
self.Ey = cuda.device_array_like(self.Ey)
self.Ez = cuda.device_array_like(self.Ez)
self.Bx = cuda.device_array_like(self.Bx)
self.By = cuda.device_array_like(self.By)
self.Bz = cuda.device_array_like(self.Bz)
# Initialize empty arrays on the GPU for the sorting
self.cell_idx = cuda.device_array_like(self.cell_idx)
self.sorted_idx = cuda.device_array_like(self.sorted_idx)
self.particle_buffer = cuda.device_array_like(self.particle_buffer)
self.scal_add_send_l = np.empty((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_send_r = np.empty((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_recv_l = np.empty((2, 2*ng, Nr), dtype=np.complex128)
self.scal_add_recv_r = np.empty((2, 2*ng, Nr), dtype=np.complex128)
else:
# Allocate buffers on the CPU and GPU
# Use cuda.pinned_array so that CPU array is pagelocked.
# (cannot be swapped out to disk and GPU can access it via DMA)
pin_ary = cuda.pinned_array
# - Replacing vector field buffers
self.vec_rep_send_l = pin_ary((6, ng, Nr), dtype=np.complex128)
self.vec_rep_send_r = pin_ary((6, ng, Nr), dtype=np.complex128)
self.vec_rep_recv_l = pin_ary((6, ng, Nr), dtype=np.complex128)
self.vec_rep_recv_r = pin_ary((6, ng, Nr), dtype=np.complex128)
self.d_vec_rep_buffer_l = cuda.to_device( self.vec_rep_send_l )
self.d_vec_rep_buffer_r = cuda.to_device( self.vec_rep_send_r )
# - Adding vector field buffers
self.vec_add_send_l = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_send_r = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_recv_l = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.vec_add_recv_r = pin_ary((6, 2*ng, Nr), dtype=np.complex128)
self.d_vec_add_buffer_l = cuda.to_device( self.vec_add_send_l )
self.d_vec_add_buffer_r = cuda.to_device( self.vec_add_send_r )
# - Replacing scalar field buffers
self.scal_rep_send_l = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_send_r = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_recv_l = pin_ary((2, ng, Nr), dtype=np.complex128)
self.scal_rep_recv_r = pin_ary((2, ng, Nr), dtype=np.complex128)
self.d_scal_rep_buffer_l = cuda.to_device( self.scal_rep_send_l )
self.d_scal_rep_buffer_r = cuda.to_device( self.scal_rep_send_r )
# - Adding scalar field buffers
self.scal_add_send_l = pin_ary((2, 2*ng, Nr), dtype=np.complex128)
def send_particles_to_gpu( self ):
"""
Copy the particles to the GPU.
Particle arrays of self now point to the GPU arrays.
"""
if self.use_cuda_memory:
# Send positions, velocities, inverse gamma and weights
# to the GPU (CUDA)
self.x = cuda.to_device(self.x)
self.y = cuda.to_device(self.y)
self.z = cuda.to_device(self.z)
self.ux = cuda.to_device(self.ux)
self.uy = cuda.to_device(self.uy)
self.uz = cuda.to_device(self.uz)
self.inv_gamma = cuda.to_device(self.inv_gamma)
self.w = cuda.to_device(self.w)
# Initialize empty arrays on the GPU for the field
# gathering and the particle push
self.Ex = cuda.device_array_like(self.Ex)
self.Ey = cuda.device_array_like(self.Ey)
self.Ez = cuda.device_array_like(self.Ez)
self.Bx = cuda.device_array_like(self.Bx)
self.By = cuda.device_array_like(self.By)
self.Bz = cuda.device_array_like(self.Bz)
# Initialize empty arrays on the GPU for the sorting
self.cell_idx = cuda.device_array_like(self.cell_idx)
guard cells, no damping is performed, between two processors.
(Damping is still performed in the guard cells that correspond
to open boundaries)
"""
# Register the number of guard cells
self.n_guard = n_guard
# Create the damping arrays
self.left_damp = generate_damp_array(
n_guard, n_order, left_proc, exchange_period )
self.right_damp = generate_damp_array(
n_guard, n_order, right_proc, exchange_period )
# Transfer the damping array to the GPU
if cuda_installed:
self.d_left_damp = cuda.to_device( self.left_damp )
self.d_right_damp = cuda.to_device( self.right_damp )