CUDA Networks
Functions
matrix_relu_derivative.cu File Reference

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

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

Go to the source code of this file.

Functions

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

Detailed Description

Implementation of the ReLU derivative function for matrices.

Definition in file matrix_relu_derivative.cu.

Function Documentation

◆ reluDerivativeKernel()

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

CUDA kernel for applying the ReLU derivative 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_derivative.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 derivative: 1 if x > 0, 0 otherwise
22  output[idx] = (input[idx] > 0.0) ? 1.0 : 0.0;
23  }
24 }