CUDA Networks
Functions
matrix_sigmoid_derivative.cu File Reference

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

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

Go to the source code of this file.

Functions

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

Detailed Description

Implementation of the sigmoid derivative function for matrices.

Definition in file matrix_sigmoid_derivative.cu.

Function Documentation

◆ sigmoidDerivativeKernel()

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

CUDA kernel for applying the sigmoid 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_sigmoid_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  // Compute sigmoid activation
22  double sigmoid_x = 1.0 / (1.0 + exp(-input[idx]));
23 
24  // Apply sigmoid derivative: sigmoid(x) * (1 - sigmoid(x))
25  output[idx] = sigmoid_x * (1.0 - sigmoid_x);
26  }
27 }