1 // Copyright 2013 Yangqing Jia
3 #ifndef CAFFE_UTIL_MATH_FUNCTIONS_H_
4 #define CAFFE_UTIL_MATH_FUNCTIONS_H_
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,
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,
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,
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,
38 template <typename Dtype>
39 void caffe_axpy(const int N, const Dtype alpha, const Dtype* X,
42 template <typename Dtype>
43 void caffe_gpu_axpy(const int N, const Dtype alpha, const Dtype* X,
46 template <typename Dtype>
47 void caffe_axpby(const int N, const Dtype alpha, const Dtype* X,
48 const Dtype beta, Dtype* Y);
50 template <typename Dtype>
51 void caffe_gpu_axpby(const int N, const Dtype alpha, const Dtype* X,
52 const Dtype beta, Dtype* Y);
54 template <typename Dtype>
55 void caffe_copy(const int N, const Dtype *X, Dtype *Y);
57 template <typename Dtype>
58 void caffe_gpu_copy(const int N, const Dtype *X, Dtype *Y);
60 template <typename Dtype>
61 void caffe_scal(const int N, const Dtype alpha, Dtype *X);
63 template <typename Dtype>
64 void caffe_gpu_scal(const int N, const Dtype alpha, Dtype *X);
66 template <typename Dtype>
67 void caffe_sqr(const int N, const Dtype* a, Dtype* y);
69 template <typename Dtype>
70 void caffe_add(const int N, const Dtype* a, const Dtype* b, Dtype* y);
72 template <typename Dtype>
73 void caffe_sub(const int N, const Dtype* a, const Dtype* b, Dtype* y);
75 template <typename Dtype>
76 void caffe_mul(const int N, const Dtype* a, const Dtype* b, Dtype* y);
78 template <typename Dtype>
79 void caffe_gpu_mul(const int N, const Dtype* a, const Dtype* b, Dtype* y);
81 template <typename Dtype>
82 void caffe_div(const int N, const Dtype* a, const Dtype* b, Dtype* y);
84 template <typename Dtype>
85 void caffe_powx(const int n, const Dtype* a, const Dtype b, Dtype* y);
87 template <typename Dtype>
88 void caffe_vRngUniform(const int n, Dtype* r, const Dtype a, const Dtype b);
90 template <typename Dtype>
91 void caffe_vRngGaussian(const int n, Dtype* r, const Dtype a,
94 template <typename Dtype>
95 void caffe_exp(const int n, const Dtype* a, Dtype* y);
97 template <typename Dtype>
98 Dtype caffe_cpu_dot(const int n, const Dtype* x, const Dtype* y);
100 template <typename Dtype>
101 void caffe_gpu_dot(const int n, const Dtype* x, const Dtype* y, Dtype* out);
106 #endif // CAFFE_UTIL_MATH_FUNCTIONS_H_