CUDA Networks
Functions
matrix_relu.cu File Reference

Implementation of the ReLU activation function for matrices. More...

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

Go to the source code of this file.

Functions

__global__ void reluKernel (const double *input, double *output, int size)
 CUDA kernel for applying the ReLU activation function element-wise. More...
 

Detailed Description

Implementation of the ReLU activation function for matrices.

Definition in file matrix_relu.cu.

Function Documentation

◆ reluKernel()

__global__ void reluKernel ( const double *  input,
double *  output,
int  size 
)

CUDA kernel for applying the ReLU activation function element-wise.

Parameters
inputPointer to the input matrix data.
outputPointer to the output matrix data.
sizeTotal number of elements in the matrix.

Definition at line 15 of file matrix_relu.cu.

15  {
16  // Calculate the global thread index
17  int idx = blockIdx.x * blockDim.x + threadIdx.x;
18 
19  // Check if the thread is within the matrix bounds
20  if (idx < size) {
21  // Apply ReLU: max(0, x)
22  output[idx] = fmax(0.0, input[idx]);
23  }
24 }