e9e2db8f27469a3d915e5d7f6c1803c8cd881154
[platform/upstream/caffeonacl.git] / src / caffe / util / math_functions.hpp
1 // Copyright 2013 Yangqing Jia
2
3 #ifndef CAFFE_UTIL_MATH_FUNCTIONS_H_
4 #define CAFFE_UTIL_MATH_FUNCTIONS_H_
5
6 #include <mkl.h>
7 #include <cublas_v2.h>
8
9 namespace caffe {
10
11 // Decaf gemm provides a simpler interface to the gemm functions, with the
12 // limitation that the data has to be contiguous in memory.
13 template <typename Dtype>
14 void caffe_cpu_gemm(const CBLAS_TRANSPOSE TransA,
15     const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K,
16     const Dtype alpha, const Dtype* A, const Dtype* B, const Dtype beta,
17     Dtype* C);
18
19 // Decaf gpu gemm provides an interface that is almost the same as the cpu
20 // gemm function - following the c convention and calling the fortran-order
21 // gpu code under the hood.
22 template <typename Dtype>
23 void caffe_gpu_gemm(const CBLAS_TRANSPOSE TransA,
24     const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K,
25     const Dtype alpha, const Dtype* A, const Dtype* B, const Dtype beta,
26     Dtype* C);
27
28 template <typename Dtype>
29 void caffe_cpu_gemv(const CBLAS_TRANSPOSE TransA, const int M, const int N,
30     const Dtype alpha, const Dtype* A, const Dtype* x, const Dtype beta,
31     Dtype* y);
32
33 template <typename Dtype>
34 void caffe_gpu_gemv(const CBLAS_TRANSPOSE TransA, const int M, const int N,
35     const Dtype alpha, const Dtype* A, const Dtype* x, const Dtype beta,
36     Dtype* y);
37
38 template <typename Dtype>
39 void caffe_axpy(const int N, const Dtype alpha, const Dtype* X,
40     Dtype* Y);
41
42 template <typename Dtype>
43 void caffe_gpu_axpy(const int N, const Dtype alpha, const Dtype* X,
44     Dtype* Y);
45
46 template <typename Dtype>
47 void caffe_axpby(const int N, const Dtype alpha, const Dtype* X,
48     const Dtype beta, Dtype* Y);
49
50 template <typename Dtype>
51 void caffe_gpu_axpby(const int N, const Dtype alpha, const Dtype* X,
52     const Dtype beta, Dtype* Y);
53
54 template <typename Dtype>
55 void caffe_copy(const int N, const Dtype *X, Dtype *Y);
56
57 template <typename Dtype>
58 void caffe_gpu_copy(const int N, const Dtype *X, Dtype *Y);
59
60 template <typename Dtype>
61 void caffe_scal(const int N, const Dtype alpha, Dtype *X);
62
63 template <typename Dtype>
64 void caffe_gpu_scal(const int N, const Dtype alpha, Dtype *X);
65
66 template <typename Dtype>
67 void caffe_sqr(const int N, const Dtype* a, Dtype* y);
68
69 template <typename Dtype>
70 void caffe_add(const int N, const Dtype* a, const Dtype* b, Dtype* y);
71
72 template <typename Dtype>
73 void caffe_sub(const int N, const Dtype* a, const Dtype* b, Dtype* y);
74
75 template <typename Dtype>
76 void caffe_mul(const int N, const Dtype* a, const Dtype* b, Dtype* y);
77
78 template <typename Dtype>
79 void caffe_gpu_mul(const int N, const Dtype* a, const Dtype* b, Dtype* y);
80
81 template <typename Dtype>
82 void caffe_div(const int N, const Dtype* a, const Dtype* b, Dtype* y);
83
84 template <typename Dtype>
85 void caffe_powx(const int n, const Dtype* a, const Dtype b, Dtype* y);
86
87 template <typename Dtype>
88 void caffe_vRngUniform(const int n, Dtype* r, const Dtype a, const Dtype b);
89
90 template <typename Dtype>
91 void caffe_vRngGaussian(const int n, Dtype* r, const Dtype a,
92     const Dtype sigma);
93
94 template <typename Dtype>
95 void caffe_exp(const int n, const Dtype* a, Dtype* y);
96
97 template <typename Dtype>
98 Dtype caffe_cpu_dot(const int n, const Dtype* x, const Dtype* y);
99
100 template <typename Dtype>
101 void caffe_gpu_dot(const int n, const Dtype* x, const Dtype* y, Dtype* out);
102
103 }  // namespace caffe
104
105
106 #endif  // CAFFE_UTIL_MATH_FUNCTIONS_H_