Skip to content

Commit

Permalink
chg
Browse files Browse the repository at this point in the history
  • Loading branch information
antinucleon committed Dec 29, 2014
1 parent 86bbf1e commit d7d7ed6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
27 changes: 20 additions & 7 deletions test/test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ int main() {
// print
printf("\n#print batch 0 of cpu tensor:\n");
Print2DTensor(tc[0]);
printf("\n");
Print2DTensor(tc[1]);
printf("\n");
Print2DTensor(tc[2]);
// check
if (Check2DTensor(tg[1], tc[1])) {
printf("batch 1 of gpu & cpu tensor are same.\n");
Expand All @@ -35,12 +39,12 @@ int main() {
}
FreeSpace(&tmp_tc);
FreeSpace(&tmp_tg);
// sumall_except_dim: Waring, random fail!
// sumall_except_dim
printf("\n#sumall_except_dim<0> of batch 0:\n");
Tensor<cpu, 1, float> red_tc = NewTensor<cpu, float>(Shape1(2), 0.0f);
Tensor<gpu, 1, float> red_tg = NewTensor<gpu, float>(Shape1(2), 0.0f);
red_tc = sumall_except_dim<0>(tc[0]);
red_tg = sumall_except_dim<0>(tg[0]);
Tensor<cpu, 1, float> red_tc = NewTensor<cpu, float>(Shape1(tc.size(0)), 0.0f);
Tensor<gpu, 1, float> red_tg = NewTensor<gpu, float>(Shape1(tg.size(0)), 0.0f);
red_tc = sumall_except_dim<0>(tc);
red_tg = sumall_except_dim<0>(tg);
Print1DTensor(red_tc);
if (Check1DTensor(red_tg, red_tc)) {
printf("cpu & gpu result consists\n");
Expand All @@ -53,11 +57,20 @@ int main() {
Tensor<gpu, 2, float> sm_tg = NewTensor<gpu, float>(tg[0].shape_, 0.0f);
Softmax(sm_tc, tc[0]);
Softmax(sm_tg, tg[0]);
FreeSpace(&sm_tc);
FreeSpace(&sm_tg);
if (Check2DTensor(sm_tg, sm_tc)) {
printf("cpu & gpu result consists\n");
}
// mirror
printf("\n#mirror\n");
sm_tc = mirror(tc[0]);
sm_tg = mirror(tg[0]);
if (Check2DTensor(sm_tg, sm_tc)) {
printf("cpu & gpu result consists\n");
}
FreeSpace(&sm_tc);
FreeSpace(&sm_tg);
// reshape

FreeSpace(&tc);
FreeSpace(&tg);
ShutdownTensorEngine();
Expand Down
4 changes: 2 additions & 2 deletions test/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ bool Check2DTensor(Tensor<gpu, 2, float> const &tg, Tensor<cpu, 2, float> const
bool Check1DTensor(Tensor<gpu, 1, float> const &tg, Tensor<cpu, 1, float> const &tc) {
Tensor<cpu, 1, float> tcc = NewTensor<cpu, float>(tc.shape_, 0.0f);
Copy(tcc, tg);
// printf("gpu result:\n");
// Print1DTensor(tcc);
printf("gpu result:\n");
Print1DTensor(tcc);
for (index_t i = 0; i < tc.size(0); ++i) {
assert(abs(tcc[i] - tc[i]) < EPS);
}
Expand Down

0 comments on commit d7d7ed6

Please sign in to comment.