CUDA Networks
Functions
matrix_multiply_elementwise.cu File Reference

Implementation of the Matrix::multiply_elementwise method for GPU-accelerated element-wise matrix multiplication. More...

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

Go to the source code of this file.

Functions

__global__ void matrixMultiplyElementwiseKernel (const double *a, const double *b, double *c, int rows, int cols)
 CUDA kernel for element-wise matrix multiplication. More...
 

Detailed Description

Implementation of the Matrix::multiply_elementwise method for GPU-accelerated element-wise matrix multiplication.

Definition in file matrix_multiply_elementwise.cu.

Function Documentation

◆ matrixMultiplyElementwiseKernel()

__global__ void matrixMultiplyElementwiseKernel ( const double *  a,
const double *  b,
double *  c,
int  rows,
int  cols 
)

CUDA kernel for element-wise matrix multiplication.

Parameters
aPointer to the first input matrix data.
bPointer to the second input matrix data.
cPointer to the output matrix data.
rowsNumber of rows in the matrices.
colsNumber of columns in the matrices.

Definition at line 19 of file matrix_multiply_elementwise.cu.

19  {
20  // Calculate global thread indices
21  int row = blockIdx.y * blockDim.y + threadIdx.y;
22  int col = blockIdx.x * blockDim.x + threadIdx.x;
23 
24  // Check if thread is within matrix bounds
25  if (row < rows && col < cols) {
26  // Calculate index of current element
27  int index = row * cols + col;
28 
29  // Perform element-wise multiplication
30  c[index] = a[index] * b[index];
31  }
32 }