Skip to content

Commit

Permalink
SINGA-51 Improve the convolution and pooling operations
Browse files Browse the repository at this point in the history
merge with pull request apache#64
  • Loading branch information
wangsheng1001 committed Sep 14, 2015
2 parents 6d59eec + 077d380 commit e769142
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 11 deletions.
69 changes: 58 additions & 11 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ AUTOMAKE_OPTIONS = foreign subdir-objects
AM_CPPFLAGS = -I$(top_srcdir)/src

MSHADOW_FLAGS = -DMSHADOW_USE_CUDA=0 -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0
DEFAULT_FLAGS = -Wall -pthread -fPIC -std=c++11 -Wno-unknown-pragmas \
$(MSHADOW_FLAGS) -DCPU_ONLY=1 -funroll-loops -DTHREADED

AC_CXXFLAGS = -O3 -Wall -pthread -fPIC -std=c++11 -Wno-unknown-pragmas \
$(MSHADOW_FLAGS) -DCPU_ONLY=1 -funroll-loops
CFLAGS = -O2 $(DEBUG)
CXXFLAGS = -O2 $(DEBUG)
AC_CXXFLAGS = -O2 $(DEBUG)

INCLUDES = -I$(top_srcdir)/include

Expand Down Expand Up @@ -78,21 +81,38 @@ SINGA_HDRS := include/singa.h \
include/communication/msg.h \
include/communication/socket.h

GTEST_SRCS := include/gtest/gtest-all.cc
GTEST_HRDS := include/gtest/gtest.h
TEST_SRCS := include/gtest/gtest_main.cc \
src/test/test_cluster.cc \
src/test/test_common.cc \
src/test/test_msg.cc \
src/test/test_neuralnet.cc \
src/test/test_paramslicer.cc \
src/test/test_shard.cc

lib_LTLIBRARIES = libsinga.la
#EXTRA_PROGRAMS = $(PROGS)
EXTRA_PROGRAMS = singatest
#EXTRA_LTLIBRARIES = $(LTLIBS)
EXTRA_LTLIBRARIES = libgtest.la

lib_LTLIBRARIES = libsinga.la $(LTLIBS)
bin_PROGRAMS = singa singatool $(PROGS)

#lib_LTLIBRARIES = libsinga.la
libsinga_la_SOURCES = $(PROTO_HDRS) $(PROTO_SRCS) $(SINGA_HDRS) $(SINGA_SRCS)
libsinga_la_CXXFLAGS = -O3 -Wall -pthread -fPIC -std=c++11 -Wno-unknown-pragmas \
$(MSHADOW_FLAGS) -DCPU_ONLY=1 -funroll-loops -gdwarf-2 -msse3 \
-gstrict-dwarf -Woverloaded-virtual -DTHREADED -fpermissive
libsinga_la_CXXFLAGS = $(DEFAULT_FLAGS) -gdwarf-2 -msse3 \
-gstrict-dwarf -Woverloaded-virtual -fpermissive
if LMDB
libsinga_la_CXXFLAGS += -DUSE_LMDB
endif
libsinga_la_LDFLAGS = -I./include

bin_PROGRAMS = singa


#bin_PROGRAMS = singa
singa_SOURCES = src/main.cc
singa_CXXFLAGS = -O3 -Wall -pthread -fPIC -std=c++11 -MMD -Wno-unknown-pragmas \
$(MSHADOW_FLAGS) -DCPU_ONLY=1 -funroll-loops -DTHREADED
singa_CXXFLAGS = $(DEFAULT_FLAGS) -MMD
singa_LDFLAGS = -I./include \
-lsinga \
-lglog \
Expand All @@ -106,16 +126,43 @@ if LMDB
singa_LDFLAGS += -llmdb
endif

bin_PROGRAMS += singatool
#bin_PROGRAMS += singatool
singatool_SOURCES = src/utils/tool.cc
singatool_CXXFLAGS = -O3 -Wall -pthread -fPIC -std=c++11 -MMD -Wno-unknown-pragmas \
singatool_CXXFLAGS = -Wall -pthread -fPIC -std=c++11 -MMD -Wno-unknown-pragmas \
-funroll-loops -DTHREADED
singatool_LDFLAGS = -I./include \
-lsinga \
-lglog \
-lprotobuf \
-lzookeeper_mt

#lib_LTLIBRARIES += libgtest.la
libgtest_la_SOURCES = $(GTEST_HDRS) $(GTEST_SRCS)
libgtest_la_CXXFLAGS = $(DEFAULT_FLAGS) -gdwarf-2 -msse3 \
-gstrict-dwarf -Woverloaded-virtual -fpermissive
if LMDB
libgtest_la_CXXFLAGS += -DUSE_LMDB
endif
libgtest_la_LDFLAGS = -I./include

#bin_PROGRAMS += singatest

singatest_SOURCES = $(GTEST_HDRS) $(TEST_SRCS)
singatest_CXXFLAGS = $(DEFAULT_FLAGS)
singatest_LDFLAGS = -I./include \
-lsinga \
-lglog \
-lprotobuf \
-lrt \
-lopenblas \
-lzmq \
-lczmq \
-lzookeeper_mt \
-lgtest
if LMDB
singatest_LDFLAGS += -llmdb
endif

clean-local:
rm -rf $(PROTO_SRCS) $(PROTO_HDRS)
rm -rf $(PROTO_PYS)
Expand Down
25 changes: 25 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ if test x"$enable_lmdb" = x"yes"; then
AC_DEFINE(LMDB, 1, [Enable Option layer])
fi

AC_ARG_ENABLE(test,
AS_HELP_STRING([--enable-test],[enable singa test]),
[enable_test=yes],[enable_test=no])
AM_CONDITIONAL(SINGATEST, test "$enable_test" = yes)
if test x"$enable_test" != x"no"; then
PROGS='singatest'
LTLIBS='libgtest.la'
else
PROGS=''
LTLIBS=''
fi
AC_SUBST([PROGS])
AC_SUBST([LTLIBS])

AC_ARG_ENABLE(debug,
AS_HELP_STRING([--enable-debug],[enable debug mode]),
[enable_debug=yes],[enable_debug=no])
AM_CONDITIONAL(DEBUG, test "$enable_debug" = yes)
if test x"$enable_debug" != x"no"; then
DEBUG='-g'
else
DEBUG=''
fi
AC_SUBST([DEBUG])

#AC_CHECK_LIB([opencv_imgproc], [main], [], [
# AC_MSG_ERROR([unable to find opencv_imgproc lib])
# ])
Expand Down
113 changes: 113 additions & 0 deletions src/test/test_common.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include "gtest/gtest.h"
#include "utils/common.h"
#include <unordered_map>
#include <string>
#include <vector>

using std::string;
using std::vector;
using namespace singa;

TEST(CommonTest, TestIntVecToString) {

vector<int> num_vec {2, 3, 5, 7, 11};
string str = "(2, 3, 5, 7, 11, )";
ASSERT_EQ(str, IntVecToString(num_vec));
}

TEST(CommonTest, TestStringPrintf) {
const char* str_a = "abc";
const char* str_b = "edfgh";
const char* str_c = " !@#";
const char* str_d = "1";
const char* str_e = "2";
const char* str_f = "3";

string fmt_a = "%s%s%s";
string fmt_b = "[%s] [%s] [%s] ";

string str_d_a = "abcedfgh !@#";
string str_d_b = "[1] [2] [3] ";

ASSERT_EQ(str_d_a, StringPrintf(fmt_a, str_a, str_b, str_c));
ASSERT_EQ(str_d_b, StringPrintf(fmt_b, str_d, str_e, str_f));
}

TEST(CommonTest, TestGCDLCM) {
int a = 2, b = 5, c = 10, d = 15;

ASSERT_EQ(1, gcd(a, b));
ASSERT_EQ(5, gcd(c, d));
ASSERT_EQ(10, LeastCommonMultiple(b, c));
ASSERT_EQ(30, LeastCommonMultiple(c, d));
}

TEST(CommonTest, TestMetric) {
string str, msg;
Metric metric;
metric.Add("a", 0.5);
metric.Add("b", 0.5);
metric.Add("a", 1.5);
str = metric.ToLogString();
msg = metric.ToString();
metric.Reset();
metric.ParseFrom(msg);
ASSERT_EQ(str, metric.ToLogString());
}

TEST(CommonTest, TestSlice) {
vector<vector<int>> slices_0;
vector<int> sizes {14112, 96, 256, 884736, 384};
ASSERT_EQ(slices_0, Slice(0, sizes));

vector<vector<int>> slices_1 {
{ 14112 },
{ 96 },
{ 256 },
{ 884736 },
{ 384 },
};

vector<vector<int>> slices_2 {
{ 14112 },
{ 96 },
{ 256 },
{ 435328, 449408 },
{ 384 },
};

vector<vector<int>> slices_4 {
{ 14112 },
{ 96 },
{ 256 },
{ 210432,224896,224896,224512 },
{ 384 },
};

vector<vector<int>> slices_8 {
{ 14112 },
{ 96 },
{ 256 },
{ 97984,112448,112448,112448,112448,112448,112448,112064 },
{ 384 },
};

ASSERT_EQ(slices_1, Slice(1, sizes));
ASSERT_EQ(slices_2, Slice(2, sizes));
ASSERT_EQ(slices_4, Slice(4, sizes));
ASSERT_EQ(slices_8, Slice(8, sizes));
}

TEST(CommonTest, TestPartitionSlices) {
vector<int> slices {
97984,112448,112448,112448,112448,112448,112448,112064
};
vector<int> box_1 { 0, 0, 0, 0, 0, 0, 0, 0 };
vector<int> box_2 { 0, 0, 0, 0, 1, 1, 1, 1 };
vector<int> box_4 { 0, 0, 1, 1, 2, 2, 3, 3 };
vector<int> box_8 { 0, 1, 2, 3, 4, 5, 6, 7 };
ASSERT_EQ(box_1, PartitionSlices(1, slices));
ASSERT_EQ(box_2, PartitionSlices(2, slices));
ASSERT_EQ(box_4, PartitionSlices(4, slices));
ASSERT_EQ(box_8, PartitionSlices(8, slices));
}

0 comments on commit e769142

Please sign in to comment.