You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by ka...@apache.org on 2015/11/16 07:09:03 UTC
[17/19] incubator-singa git commit: SINGA-80 New Blob Level and
Address Level Math Operation Interface
SINGA-80 New Blob Level and Address Level Math Operation Interface
fix some bugs may happen in template deduction
Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/86284f1a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/86284f1a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/86284f1a
Branch: refs/heads/master
Commit: 86284f1af7adeb42661a8d381d8a01f98197920d
Parents: 32e0921
Author: Wei Wang <wa...@comp.nus.edu.sg>
Authored: Tue Nov 10 22:20:52 2015 +0800
Committer: ijingo <ij...@gmail.com>
Committed: Thu Nov 12 21:24:24 2015 +0800
----------------------------------------------------------------------
include/singa/utils/math_addr.h | 4 ++--
include/singa/utils/math_blob.h | 26 +++++++++++++-------------
2 files changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/86284f1a/include/singa/utils/math_addr.h
----------------------------------------------------------------------
diff --git a/include/singa/utils/math_addr.h b/include/singa/utils/math_addr.h
index 4a610a9..fe19f14 100644
--- a/include/singa/utils/math_addr.h
+++ b/include/singa/utils/math_addr.h
@@ -78,14 +78,14 @@ Dtype cpu_dot(const Dtype * A, const Dtype * B, const int n) {
// element-wise
template<typename Op, typename Dtype>
-void cpu_e_f(const int n, Dtype * A, Dtype * B) {
+void cpu_e_f(const int n, const Dtype * A, Dtype * B) {
for (int i = 0 ; i < n ; i++) {
Op::Map(A[i], &B[i]);
}
}
template<typename Op, typename Dtype>
-void cpu_e_f(const int n, Dtype * A, Dtype * B, Dtype * C) {
+void cpu_e_f(const int n, const Dtype * A, const Dtype * B, Dtype * C) {
for (int i = 0 ; i < n ; i++) {
Op::Map(A[i], B[i], &C[i]);
}
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/86284f1a/include/singa/utils/math_blob.h
----------------------------------------------------------------------
diff --git a/include/singa/utils/math_blob.h b/include/singa/utils/math_blob.h
index 4b71715..6428117 100644
--- a/include/singa/utils/math_blob.h
+++ b/include/singa/utils/math_blob.h
@@ -52,7 +52,7 @@ void Scale(XPU xpu, Dtype alpha, const Blob<Dtype> & A, Blob<Dtype> * B) {
*/
template<typename Dtype>
void AXPY(XPU xpu, Dtype alpha, const Blob<Dtype> & A, Blob<Dtype> * B) {
- CHECK_EQ(A.count(), B.count());
+ CHECK_EQ(A.count(), B->count());
if (xpu == cpu) {
cpu_axpy(A.cpu_data(), A.count(),
alpha, B->mutable_cpu_data());
@@ -141,7 +141,7 @@ void GEMM(XPU xpu, Dtype alpha, Dtype beta, const Blob<Dtype>& A,
const Blob<Dtype> & B, Blob<Dtype> * C) {
CHECK_EQ(A.shape().size(), 2);
CHECK_EQ(B.shape().size(), 2);
- CHECK_EQ(C.shape().size(), 2);
+ CHECK_EQ(C->shape().size(), 2);
int a1, a2, b1, b2, m, n;
CHECK(!C->transpose());
a1 = A.transpose() ? A.shape(1) : A.shape(0);
@@ -223,7 +223,7 @@ Dtype VVDot(XPU xpu, const Blob<Dtype> & A, const Blob<Dtype> & B) {
template <typename Dtype>
void OuterProduct(XPU xpu, const Blob<Dtype>& A, const Blob<Dtype>& B,
Blob<Dtype> * C) {
- CHECK(!C.transpose()); // do not support C.T now.
+ CHECK(!C->transpose()); // do not support C.T now.
int m = A.count();
int n = B.count();
@@ -287,7 +287,7 @@ void Map(XPU xpu, const Blob<Dtype> & A, const Blob<Dtype> & B,
* Loose shape checking, A.count() == B.count().
*/
template<typename Op, typename Dtype>
-void Map(XPU xpu, Dtype alpha, const Blob<Dtype>& A, const Blob<Dtype>* B) {
+void Map(XPU xpu, Dtype alpha, const Blob<Dtype>& A, Blob<Dtype>* B) {
CHECK_EQ(A.count(), B->count()) << "Blobs must have the same size";
if (xpu == cpu) {
cpu_e_f<Op>(A.count(), alpha, A.cpu_data(), B->mutable_cpu_data());
@@ -319,7 +319,7 @@ void Map(XPU xpu, Dtype alpha, const Blob<Dtype>& A, const Blob<Dtype>& B,
* Loose shape checking, A.count() == B.count().
*/
template<typename Dtype>
-void Copy(XPU xpu, const Blob<Dtype>& A, const Blob<Dtype>* B) {
+void Copy(XPU xpu, const Blob<Dtype>& A, Blob<Dtype>* B) {
CHECK_EQ(A.count(), B->count()) << "Blobs must have the same size";
if (xpu == cpu) {
std::copy(A.cpu_data(), A.cpu_data() + A.count(), B->mutable_cpu_data());
@@ -357,7 +357,7 @@ void Sub(XPU xpu, const Blob<Dtype> & A, const Blob<Dtype> & B,
template<typename Dtype>
void Mult(XPU xpu, const Blob<Dtype> & A, const Blob<Dtype> & B,
Blob<Dtype> * C) {
- Map<singa::op::Mult>(xpu, A, B, C);
+ Map<singa::op::Mult<Dtype>>(xpu, A, B, C);
// TODO(wangwei) use MKL's vector func
}
@@ -368,7 +368,7 @@ void Mult(XPU xpu, const Blob<Dtype> & A, const Blob<Dtype> & B,
template<typename Dtype>
void Div(XPU xpu, const Blob<Dtype> & A, const Blob<Dtype> & B,
Blob<Dtype> * C) {
- Map<singa::op::Div>(xpu, A, B, C);
+ Map<singa::op::Div<Dtype>>(xpu, A, B, C);
// TODO(wangwei) use MKL's vector func
}
/*************************1D<-->2D op/transform***************************/
@@ -380,12 +380,12 @@ void Div(XPU xpu, const Blob<Dtype> & A, const Blob<Dtype> & B,
template<typename Dtype>
void MVAddCol(XPU xpu, Dtype alpha, Dtype beta, const Blob<Dtype> & A,
Blob<Dtype> * B) {
- if (B.transpose()) {
+ if (B->transpose()) {
Blob<Dtype>* tmp = Transpose(* B);
MVAddRow(xpu, alpha, beta, A, tmp);
delete tmp;
} else {
- CHECK_EQ(B.count() % A.count(), 0) << "#col of B not match length of A";
+ CHECK_EQ(B->count() % A.count(), 0) << "#col of B not match length of A";
int m = A.count(), n = B->count() / m;
if (xpu == cpu) {
Blob<Dtype> one(n);
@@ -420,12 +420,12 @@ void MVAddCol(XPU xpu, const Blob<Dtype> & A, Blob<Dtype>* B) {
template<typename Dtype>
void MVAddRow(XPU xpu, Dtype alpha, Dtype beta, const Blob<Dtype> & A,
Blob<Dtype> * B) {
- if (B.transpose()) {
+ if (B->transpose()) {
Blob<Dtype>* tmp = Transpose(* B);
MVAddCol(xpu, alpha, beta, A, tmp);
delete tmp;
} else {
- CHECK_EQ(B.count() % A.count(), 0) << "#col of B not match length of A";
+ CHECK_EQ(B->count() % A.count(), 0) << "#col of B not match length of A";
int m = A.count(), n = B->count() / m;
if (xpu == cpu) {
Blob<Dtype> one(n);
@@ -529,7 +529,7 @@ void MVSumRow(XPU xpu, Dtype alpha, Dtype beta, const Blob<Dtype> & A,
*/
template<typename Op, typename Dtype>
void Reduce2D(XPU xpu, const Blob<Dtype> & A, Blob<Dtype> * B) {
- CHECK_EQ(A.count() % B.count(), 0) << "Row size not match B length";
+ CHECK_EQ(A.count() % B->count(), 0) << "Row size not match B length";
int m = B->count(), n = A.count() / m;
if (xpu == cpu) {
cpu_reduce_f<Op>(A.cpu_data(), m, n, B->mutable_cpu_data());
@@ -548,7 +548,7 @@ void Reduce2D(XPU xpu, const Blob<Dtype> & A, Blob<Dtype> * B) {
*/
template<typename Op, typename Dtype>
void Expand2D(XPU xpu, const Blob<Dtype> & A, Blob<Dtype> * B) {
- CHECK_EQ(B.count() % A.count(), 0) << "Row size of B not match length of A";
+ CHECK_EQ(B->count() % A.count(), 0) << "Row size of B not match length of A";
int m = A.count(), n = B->count() / m;
if (xpu == cpu) {
cpu_expand_f<Op>(A.cpu_data(), m, n, B->mutable_cpu_data());