forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MSECriterion.cu
62 lines (51 loc) · 1.35 KB
/
MSECriterion.cu
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "THCUNN.h"
#include "common.h"
#include "TH/THHalf.h"
#include "THCHalfAutoNumerics.cuh"
#include "THCThrustAllocator.cuh"
#include "THCApply.cuh"
#include <thrust/fill.h>
#include <thrust/functional.h>
#include <thrust/device_ptr.h>
#include <thrust/reduce.h>
#include <thrust/inner_product.h>
#if CUDA_VERSION >= 7000
#include <thrust/system/cuda/execution_policy.h>
#endif
template <typename Dtype, typename Acctype>
struct mse_functor
{
mse_functor() {}
__host__ __device__ Acctype operator()(const Dtype &x, const Dtype &y) const
{
Acctype z = ScalarConvert<Dtype, Acctype>::to(x)-y;
return z*z;
}
};
template <typename Dtype>
struct mse_updateOutput_functor
{
mse_updateOutput_functor() {}
__device__ void operator()(
const Dtype *input,
const Dtype *target,
Dtype *output)
{
Dtype diff = THCNumerics<Dtype>::sub(*input, *target);
*output = THCNumerics<Dtype>::mul(diff, diff);
}
};
template <typename Dtype, typename Acctype>
struct mse_updateGradInput_functor
{
const Acctype norm;
mse_updateGradInput_functor(Acctype norm_)
: norm(norm_)
{}
__host__ __device__ Dtype operator()(const Dtype &x, const Dtype &y) const
{
return ScalarConvert<Acctype, Dtype>::to(norm * (ScalarConvert<Dtype, Acctype>::to(x) - y));
}
};
#include "generic/MSECriterion.cu"
#include "THCGenerateFloatTypes.h"