CUDA Networks
Functions
matrix_sigmoid.cu File Reference

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

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

Go to the source code of this file.

Functions

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

Detailed Description

Implementation of the sigmoid activation function for matrices.

Definition in file matrix_sigmoid.cu.

Function Documentation

◆ sigmoidKernel()

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

CUDA kernel for applying the sigmoid 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 16 of file matrix_sigmoid.cu.

16  {
17  // Calculate the global thread index
18  int idx = blockIdx.x * blockDim.x + threadIdx.x;
19 
20  // Check if the thread is within the matrix bounds
21  if (idx < size) {
22  // Apply sigmoid: 1 / (1 + exp(-x))
23  output[idx] = 1.0 / (1.0 + exp(-input[idx]));
24  }
25 }