CUDA Networks
Functions
matrix_select_batch.cu File Reference

Implementation of the Matrix::select_batch method for selecting a subset of the matrix. More...

#include "matrix.h"
#include <cuda_runtime.h>
#include <stdexcept>
Include dependency graph for matrix_select_batch.cu:

Go to the source code of this file.

Functions

__global__ void selectBatchKernel (const double *src, double *dst, int src_cols, int dst_cols, int start_row, int start_col, int num_rows, int num_cols)
 CUDA kernel for selecting a subset of the matrix. More...
 

Detailed Description

Implementation of the Matrix::select_batch method for selecting a subset of the matrix.

Definition in file matrix_select_batch.cu.

Function Documentation

◆ selectBatchKernel()

__global__ void selectBatchKernel ( const double *  src,
double *  dst,
int  src_cols,
int  dst_cols,
int  start_row,
int  start_col,
int  num_rows,
int  num_cols 
)

CUDA kernel for selecting a subset of the matrix.

Parameters
srcPointer to the source matrix data.
dstPointer to the destination matrix data.
src_colsNumber of columns in the source matrix.
dst_colsNumber of columns in the destination matrix.
start_rowStarting row index.
start_colStarting column index.
num_rowsNumber of rows to select.
num_colsNumber of columns to select.

Definition at line 21 of file matrix_select_batch.cu.

22  {
23  // Calculate global thread indices
24  int row = blockIdx.y * blockDim.y + threadIdx.y;
25  int col = blockIdx.x * blockDim.x + threadIdx.x;
26 
27  // Check if thread is within the selected subset bounds
28  if (row < num_rows && col < num_cols) {
29  // Calculate source and destination indices
30  int src_idx = (start_row + row) * src_cols + (start_col + col);
31  int dst_idx = row * dst_cols + col;
32 
33  // Copy the element from source to destination
34  dst[dst_idx] = src[src_idx];
35  }
36 }