How to use the fbpic.cuda_utils.cuda.to_device function in fbpic

To help you get started, we’ve selected a few fbpic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fbpic / fbpic / fbpic / boundaries / field_buffer_handling.py View on Github external
# - 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
github fbpic / fbpic / fbpic / boundaries / field_buffer_handling.py View on Github external
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 )
github fbpic / fbpic / fbpic / particles / particles.py View on Github external
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)
github fbpic / fbpic / fbpic / boundaries / field_buffer_handling.py View on Github external
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 )
github fbpic / fbpic / fbpic / boundaries / field_buffer_handling.py View on Github external
# (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 )
github fbpic / fbpic / fbpic / particles / particles.py View on Github external
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)
github fbpic / fbpic / fbpic / boundaries / field_buffer_handling.py View on Github external
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)
github fbpic / fbpic / fbpic / particles / particles.py View on Github external
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)
github fbpic / fbpic / fbpic / boundaries / guard_cell_damping.py View on Github external
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 )