Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SoftPlus.cu « THCUNN « lib - github.com/torch/cunn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cb9ecb7d809b58746d5e631c010f93a42b7f0062 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "THCUNN.h"
#include "THCHalf.h"
#include "THCHalfAutoNumerics.cuh"

template <typename T>
struct softPlusupdateOutput_functor
{
  const T threshold;
  const T beta;

  softPlusupdateOutput_functor(T threshold_, T beta_)
    : threshold(threshold_)
    , beta(beta_)
  {}

  __device__ void operator()(T *output, const T *input) const {
    T betain = beta * (*input);
    *output = ((betain) > threshold) ? *input : (1/beta) * log1p(exp(betain));
  }
};

template <typename T>
struct softPlusupdateGradInput_functor
{
  const T threshold;
  const T beta;

  softPlusupdateGradInput_functor(T threshold_, T beta_)
    : threshold(threshold_)
    , beta(beta_)
  {}

  __device__ void operator()(T *gradInput, const T *output, const T *gradOutput) const
  {
    T betaout = beta * (*output);
    T exp_bo = exp(betaout);
    *gradInput = ((betaout) > threshold) ? *gradOutput : *gradOutput * (exp_bo - 1) / exp_bo;
  }
};

#include "generic/SoftPlus.cu"
#include "THCGenerateFloatTypes.h"