822ef31be74acea4ed4a53851229c67bf32fbfed
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_copy(const int N, const Dtype *X, Dtype *Y);
45 template <typename Dtype>
46 void caffe_scal(const int N, const Dtype alpha, Dtype *X);
48 template <typename Dtype>
49 void caffe_sqr(const int N, const Dtype* a, Dtype* y);
51 template <typename Dtype>
52 void caffe_mul(const int N, const Dtype* a, const Dtype* b, Dtype* y);
54 template <typename Dtype>
55 void caffe_div(const int N, const Dtype* a, const Dtype* b, Dtype* y);
57 template <typename Dtype>
58 void caffe_powx(const int n, const Dtype* a, const Dtype b, Dtype* y);
60 template <typename Dtype>
61 void caffe_vRngUniform(const int n, Dtype* r, const Dtype a, const Dtype b);
63 template <typename Dtype>
64 void caffe_vRngGaussian(const int n, Dtype* r, const Dtype a,
65 const Dtype sigma);
67 template <typename Dtype>
68 void caffe_exp(const int n, const Dtype* a, Dtype* y);
70 template <typename Dtype>
71 Dtype caffe_cpu_dot(const int n, const Dtype* x, const Dtype* y);
73 } // namespace caffe
76 #endif // CAFFE_UTIL_MATH_FUNCTIONS_H_