Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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:
# 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)
# Copy arrays on the GPU for the field
# gathering and the particle push
self.Ex = cuda.to_device(self.Ex)
self.Ey = cuda.to_device(self.Ey)
self.Ez = cuda.to_device(self.Ez)
self.Bx = cuda.to_device(self.Bx)
self.By = cuda.to_device(self.By)
self.Bz = cuda.to_device(self.Bz)
The z index in the full-size array, that corresponds to index 0
in the small-size array (i.e. position at which to add the
small-size array into the full-size one)
grid: a list of InterpolationGrid objects
Contains the full-size array rho
"""
Nm = len(grid)
if type(grid[0].rho) is np.ndarray:
# The large-size array rho is on the CPU
for m in range( Nm ):
grid[m].rho[ iz_min:iz_min+2 ] += self.rho_buffer[m]
else:
# The large-size array rho is on the GPU
# Copy the small-size buffer to the GPU
cuda.to_device( self.rho_buffer, to=self.d_rho_buffer )
# On the GPU: add the small-size buffers to the large-size array
dim_grid_1d, dim_block_1d = cuda_tpb_bpg_1d( grid[0].Nr, TPB=64 )
for m in range( Nm ):
add_rho_to_gpu_array[dim_grid_1d, dim_block_1d]( iz_min,
self.d_rho_buffer, grid[m].rho, m )
small-size array into the full-size one)
grid: a list of InterpolationGrid objects
Contains the full-size array Jr, Jt, Jz
"""
Nm = len(grid)
if type(grid[0].Jr) is np.ndarray:
# The large-size arrays for J are on the CPU
for m in range( Nm ):
grid[m].Jr[ iz_min:iz_min+2 ] += self.Jr_buffer[m]
grid[m].Jt[ iz_min:iz_min+2 ] += self.Jt_buffer[m]
grid[m].Jz[ iz_min:iz_min+2 ] += self.Jz_buffer[m]
else:
# The large-size arrays for J are on the GPU
# Copy the small-size buffers to the GPU
cuda.to_device( self.Jr_buffer, to=self.d_Jr_buffer )
cuda.to_device( self.Jt_buffer, to=self.d_Jt_buffer )
cuda.to_device( self.Jz_buffer, to=self.d_Jz_buffer )
# On the GPU: add the small-size buffers to the large-size array
dim_grid_1d, dim_block_1d = cuda_tpb_bpg_1d( grid[0].Nr, TPB=64 )
for m in range( Nm ):
add_J_to_gpu_array[dim_grid_1d, dim_block_1d]( iz_min,
self.d_Jr_buffer, self.d_Jt_buffer, self.d_Jz_buffer,
grid[m].Jr, grid[m].Jt, grid[m].Jz, m )
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:
# 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)
# Copy arrays on the GPU for the field
# gathering and the particle push
self.Ex = cuda.to_device(self.Ex)
self.Ey = cuda.to_device(self.Ey)
self.Ez = cuda.to_device(self.Ez)
self.Bx = cuda.to_device(self.Bx)
self.By = cuda.to_device(self.By)
self.Bz = cuda.to_device(self.Bz)
# Copy sorting buffers on the GPU
self.sorting_buffer = cuda.to_device(self.sorting_buffer)
grid: a list of InterpolationGrid objects
Contains the full-size array Jr, Jt, Jz
"""
Nm = len(grid)
if type(grid[0].Jr) is np.ndarray:
# The large-size arrays for J are on the CPU
for m in range( Nm ):
grid[m].Jr[ iz_min:iz_min+2 ] += self.Jr_buffer[m]
grid[m].Jt[ iz_min:iz_min+2 ] += self.Jt_buffer[m]
grid[m].Jz[ iz_min:iz_min+2 ] += self.Jz_buffer[m]
else:
# The large-size arrays for J are on the GPU
# Copy the small-size buffers to the GPU
cuda.to_device( self.Jr_buffer, to=self.d_Jr_buffer )
cuda.to_device( self.Jt_buffer, to=self.d_Jt_buffer )
cuda.to_device( self.Jz_buffer, to=self.d_Jz_buffer )
# On the GPU: add the small-size buffers to the large-size array
dim_grid_1d, dim_block_1d = cuda_tpb_bpg_1d( grid[0].Nr, TPB=64 )
for m in range( Nm ):
add_J_to_gpu_array[dim_grid_1d, dim_block_1d]( iz_min,
self.d_Jr_buffer, self.d_Jt_buffer, self.d_Jz_buffer,
grid[m].Jr, grid[m].Jt, grid[m].Jz, m )
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:
# 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)
# Copy arrays on the GPU for the field
# gathering and the particle push
self.Ex = cuda.to_device(self.Ex)
self.Ey = cuda.to_device(self.Ey)
self.Ez = cuda.to_device(self.Ez)
self.Bx = cuda.to_device(self.Bx)
self.By = cuda.to_device(self.By)
self.Bz = cuda.to_device(self.Bz)
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:
# 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)
# Copy arrays on the GPU for the field
# gathering and the particle push
self.Ex = cuda.to_device(self.Ex)
self.Ey = cuda.to_device(self.Ey)
self.Ez = cuda.to_device(self.Ez)
self.Bx = cuda.to_device(self.Bx)
self.By = cuda.to_device(self.By)
self.Bz = cuda.to_device(self.Bz)
# Copy sorting buffers on the GPU
self.sorting_buffer = cuda.to_device(self.sorting_buffer)
if self.n_integer_quantities > 0:
self.int_sorting_buffer = cuda.to_device(self.int_sorting_buffer)
# Copy particle tracker data
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:
# 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)
# Copy arrays on the GPU for the field
# gathering and the particle push
self.Ex = cuda.to_device(self.Ex)
self.Ey = cuda.to_device(self.Ey)
self.Ez = cuda.to_device(self.Ez)
self.Bx = cuda.to_device(self.Bx)
self.By = cuda.to_device(self.By)
self.Bz = cuda.to_device(self.Bz)
# Copy sorting buffers on the GPU
self.sorting_buffer = cuda.to_device(self.sorting_buffer)
if self.n_integer_quantities > 0:
self.int_sorting_buffer = cuda.to_device(self.int_sorting_buffer)
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:
# 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)
# Copy arrays on the GPU for the field
# gathering and the particle push
self.Ex = cuda.to_device(self.Ex)
self.Ey = cuda.to_device(self.Ey)
self.Ez = cuda.to_device(self.Ez)
self.Bx = cuda.to_device(self.Bx)
self.By = cuda.to_device(self.By)
self.Bz = cuda.to_device(self.Bz)
# Copy sorting buffers on the GPU
self.sorting_buffer = cuda.to_device(self.sorting_buffer)
if self.n_integer_quantities > 0: