1 // Copyright 2013 Yangqing Jia
3 #ifndef CAFFE_UTIL_MATH_FUNCTIONS_H_
4 #define CAFFE_UTIL_MATH_FUNCTIONS_H_
6 #include <mkl.h>
7 #include <cublas_v2.h>
9 namespace caffe {
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);
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);
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);
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);
38 template <typename Dtype>
39 void caffe_axpy(const int N, const Dtype alpha, const Dtype* X,
40 Dtype* Y);
42 template <typename Dtype>
43 void caffe_axpby(const int N, const Dtype alpha, const Dtype* X,
44 const Dtype beta, Dtype* Y);
46 template <typename Dtype>
47 void caffe_copy(const int N, const Dtype *X, Dtype *Y);
49 template <typename Dtype>
50 void caffe_scal(const int N, const Dtype alpha, Dtype *X);
52 template <typename Dtype>
53 void caffe_gpu_scal(const int N, const Dtype alpha, Dtype *X);
55 template <typename Dtype>
56 void caffe_sqr(const int N, const Dtype* a, Dtype* y);
58 template <typename Dtype>
59 void caffe_add(const int N, const Dtype* a, const Dtype* b, Dtype* y);
61 template <typename Dtype>
62 void caffe_sub(const int N, const Dtype* a, const Dtype* b, Dtype* y);
64 template <typename Dtype>
65 void caffe_mul(const int N, const Dtype* a, const Dtype* b, Dtype* y);
67 template <typename Dtype>
68 void caffe_div(const int N, const Dtype* a, const Dtype* b, Dtype* y);
70 template <typename Dtype>
71 void caffe_powx(const int n, const Dtype* a, const Dtype b, Dtype* y);
73 template <typename Dtype>
74 void caffe_vRngUniform(const int n, Dtype* r, const Dtype a, const Dtype b);
76 template <typename Dtype>
77 void caffe_vRngGaussian(const int n, Dtype* r, const Dtype a,
78 const Dtype sigma);
80 template <typename Dtype>
81 void caffe_exp(const int n, const Dtype* a, Dtype* y);
83 template <typename Dtype>
84 Dtype caffe_cpu_dot(const int n, const Dtype* x, const Dtype* y);
86 } // namespace caffe
89 #endif // CAFFE_UTIL_MATH_FUNCTIONS_H_