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

GatedLinearUnit.cu « THCUNN « lib - github.com/torch/cunn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d9f347159b143f7a99330e5ddd2f79d952bc2810 (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
#include "THCUNN.h"
#include "THCHalf.h"
#include "THCHalfAutoNumerics.cuh"
#include "common.h"

template <typename Dtype, typename Acctype>
struct gatedLinearCSigMul_functor
{
  __device__ void operator()(Dtype *target, const Dtype *sigTensor, const Dtype *mulTensor) const
  {
    const Acctype sigNum = Acctype(1)/(Acctype(1)+ exp(ScalarConvert<Dtype, Acctype>::to(-*sigTensor)));
    const Dtype mulNum = *mulTensor;
    *target = ScalarConvert<Acctype, Dtype>::to(sigNum * mulNum);
  }
};

template <typename Dtype, typename Acctype>
struct gatedLinearDerivativeSecondHalf_functor
{
  __device__ void operator()(Dtype *target, const Dtype *sigTensor, const Dtype *mulTensor) const
  {
    const Acctype sigNum = Acctype(1)/(Acctype(1)+ exp(ScalarConvert<Dtype, Acctype>::to(-*sigTensor)));
    const Dtype mulNum = *mulTensor;
    *target *= ScalarConvert<Acctype, Dtype>::to((Acctype(1) - sigNum) * sigNum * mulNum);
  }
};

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