You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by cj...@apache.org on 2017/12/14 16:25:30 UTC
[incubator-mxnet] branch master updated: Add googletest as a
3rdparty library (#9016)
This is an automated email from the ASF dual-hosted git repository.
cjolivier01 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/master by this push:
new fdd41a8 Add googletest as a 3rdparty library (#9016)
fdd41a8 is described below
commit fdd41a84b5aee6870707fc53cfe1ee343c5c66e9
Author: Pedro Larroy <92...@users.noreply.github.com>
AuthorDate: Thu Dec 14 17:25:26 2017 +0100
Add googletest as a 3rdparty library (#9016)
* [CMake] Compile with gtest
* [Make] Use gtest from 3rdparty in Make build
* [Clang] Fix warning
* [Windows] Misc test fixes
* [rebase] update mshadow...
* Add googletest as submodule
* googletest -> release-1.8.0
---
.gitmodules | 7 +++++--
3rdparty/googletest | 1 +
CMakeLists.txt | 9 +++++++++
dmlc-core | 2 +-
mshadow | 2 +-
tests/CMakeLists.txt | 4 ++--
tests/cpp/engine/threaded_engine_test.cc | 3 +--
tests/cpp/include/test_op.h | 5 ++++-
tests/cpp/include/test_perf.h | 4 ++++
tests/cpp/include/test_tune.h | 5 +++++
tests/cpp/include/test_util.h | 7 ++++++-
tests/cpp/operator/batchnorm_test.cc | 12 +++++++++++-
tests/cpp/operator/tune/operator_tune_test.cc | 1 +
tests/cpp/unittest.mk | 17 +++++++++++++----
14 files changed, 64 insertions(+), 15 deletions(-)
diff --git a/.gitmodules b/.gitmodules
index 4ad3e40..8a5521a 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,9 +1,9 @@
[submodule "mshadow"]
path = mshadow
- url = https://github.com/dmlc/mshadow.git
+ url = https://github.com/larroy/mshadow.git
[submodule "dmlc-core"]
path = dmlc-core
- url = https://github.com/dmlc/dmlc-core.git
+ url = https://github.com/larroy/dmlc-core.git
[submodule "ps-lite"]
path = ps-lite
url = https://github.com/dmlc/ps-lite
@@ -19,3 +19,6 @@
[submodule "3rdparty/openmp"]
path = 3rdparty/openmp
url = https://github.com/llvm-mirror/openmp
+[submodule "3rdparty/googletest"]
+ path = 3rdparty/googletest
+ url = https://github.com/google/googletest.git
diff --git a/3rdparty/googletest b/3rdparty/googletest
new file mode 160000
index 0000000..ec44c6c
--- /dev/null
+++ b/3rdparty/googletest
@@ -0,0 +1 @@
+Subproject commit ec44c6c1675c25b9827aacd08c02433cccde7780
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8211624..6e6b178 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -315,6 +315,15 @@ if(USE_JEMALLOC)
endif()
include(CTest)
+set(GTEST_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/googletest/googletest")
+set(GTEST_INCLUDE_DIR ${GTEST_ROOT}/include)
+#set(GTEST_BOTH_LIBRARIES gtest gtest_main)
+set(GTEST_LIBRARIES gtest gtest_main)
+set(GTEST_MAIN_LIBRARY gtest_main)
+set(GTEST_LIBRARY gtest)
+
+add_subdirectory(${GTEST_ROOT})
+find_package(GTest REQUIRED)
# cudnn detection
if(USE_CUDNN AND USE_CUDA)
diff --git a/dmlc-core b/dmlc-core
index ebbda66..2320e7c 160000
--- a/dmlc-core
+++ b/dmlc-core
@@ -1 +1 @@
-Subproject commit ebbda66217efd5f7e16ace68cae0128a7117d081
+Subproject commit 2320e7c897d5c2c8e7fdd91c44b0696f0a346e53
diff --git a/mshadow b/mshadow
index 2d7780c..eeafe88 160000
--- a/mshadow
+++ b/mshadow
@@ -1 +1 @@
-Subproject commit 2d7780c3f2eefe4453fa419862d1b2089bedb8d5
+Subproject commit eeafe8854104b8cf2a15e77d2591f1f6107d7bf9
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index f2758c4..8a85c09 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -20,8 +20,8 @@ if(NOT MSVC)
set(UNITTEST_STATIC_LINK ON)
endif()
-if(GTEST_FOUND)
-
+# FIXME MSVC unit test linking issue
+if(GTEST_FOUND AND NOT MSVC)
enable_testing()
file(GLOB_RECURSE UNIT_TEST_SOURCE "cpp/*.cc" "cpp/*.h")
diff --git a/tests/cpp/engine/threaded_engine_test.cc b/tests/cpp/engine/threaded_engine_test.cc
index be60ecf..3007285 100644
--- a/tests/cpp/engine/threaded_engine_test.cc
+++ b/tests/cpp/engine/threaded_engine_test.cc
@@ -23,7 +23,6 @@
* \brief threaded engine tests
*/
#include <time.h>
-#include <unistd.h>
#include <dmlc/logging.h>
#include <gtest/gtest.h>
#include <mxnet/engine.h>
@@ -47,7 +46,7 @@ struct Workload {
int time;
};
-static u_int32_t seed_ = 0xdeadbeef;
+static uint32_t seed_ = 0xdeadbeef;
/**
* generate a list of workloads
diff --git a/tests/cpp/include/test_op.h b/tests/cpp/include/test_op.h
index af83969..066168e 100644
--- a/tests/cpp/include/test_op.h
+++ b/tests/cpp/include/test_op.h
@@ -101,6 +101,8 @@ class OperatorDataInitializer {
* \param blob Blob which to fill with random values
*/
void FillRandom(const TBlob& blob) const {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wabsolute-value"
std::uniform_real_distribution<> dis_real(-5.0, 5.0);
std::uniform_int_distribution<> dis_int(-128, 127);
test::patternFill<DType>(&blob, [this, &dis_real, &dis_int]() -> DType {
@@ -108,7 +110,7 @@ class OperatorDataInitializer {
DType val;
do {
val = static_cast<DType>(dis_real(this->generator()));
- } while (fabs(val) < 1e-5); // If too close to zero, try again
+ } while (std::abs(val) < 1e-5); // If too close to zero, try again
return val;
} else {
DType val;
@@ -118,6 +120,7 @@ class OperatorDataInitializer {
return val;
}
});
+#pragma clang diagnostic pop
}
void FillZero(const TBlob& blob) const {
diff --git a/tests/cpp/include/test_perf.h b/tests/cpp/include/test_perf.h
index 597b87f..8d2a264 100644
--- a/tests/cpp/include/test_perf.h
+++ b/tests/cpp/include/test_perf.h
@@ -27,7 +27,11 @@
#ifndef TEST_PERF_H_
#define TEST_PERF_H_
+#ifndef _WIN32
#include <sys/time.h>
+#else
+#include <Windows.h>
+#endif
#include <dmlc/logging.h>
#include <iomanip>
#include <iostream>
diff --git a/tests/cpp/include/test_tune.h b/tests/cpp/include/test_tune.h
index 9cf4a2e..f5e15cc 100644
--- a/tests/cpp/include/test_tune.h
+++ b/tests/cpp/include/test_tune.h
@@ -26,7 +26,12 @@
#ifndef TEST_TUNE_H_
#define TEST_TUNE_H_
+#ifndef _WIN32
#include <sys/time.h>
+#else
+#include <Windows.h>
+#endif
+
#include <dmlc/logging.h>
#include <iomanip>
#include <iostream>
diff --git a/tests/cpp/include/test_util.h b/tests/cpp/include/test_util.h
index 8347a8a..a41e623 100644
--- a/tests/cpp/include/test_util.h
+++ b/tests/cpp/include/test_util.h
@@ -32,6 +32,7 @@
#include <string>
#include <vector>
#include <sstream>
+#include <random>
#if MXNET_USE_VTUNE
#include <ittnotify.h>
@@ -512,12 +513,16 @@ inline void print(const RunContext& ctx,
}
inline std::string demangle(const char *name) {
+#if defined(__GLIBCXX__) || defined(_LIBCPP_VERSION)
int status = -4; // some arbitrary value to eliminate the compiler warning
std::unique_ptr<char, void(*)(void*)> res {
abi::__cxa_demangle(name, nullptr, nullptr, &status),
&std::free
};
return status ? name : res.get();
+#else
+ return name;
+#endif
}
template<typename T>
@@ -605,7 +610,7 @@ inline ScalarType rangedRand(const ScalarType min, const ScalarType max) {
defect = num_rand % num_bins;
ScalarType x;
do {
- x = random();
+ x = std::rand();
} while (num_rand - defect <= (uint64_t)x);
return static_cast<ScalarType>(x / bin_size + min);
diff --git a/tests/cpp/operator/batchnorm_test.cc b/tests/cpp/operator/batchnorm_test.cc
index b66dc75..d9b426a 100644
--- a/tests/cpp/operator/batchnorm_test.cc
+++ b/tests/cpp/operator/batchnorm_test.cc
@@ -845,6 +845,7 @@ TEST(BATCH_NORM, TestStochasticTiming_2D) {
}
/*! \brief Performance tests */
+#ifndef _WIN32
TEST(BATCH_NORM, TestTiming_2D) {
#ifdef NDEBUG
size_t THISCOUNT = 10;
@@ -861,7 +862,7 @@ MSHADOW_REAL_TYPE_SWITCH_EX(
false, false,
blank_kwargs,
2, THISCOUNT);
-#if MXNET_USE_MKL2017 == 1
+#if defined(MXNET_USE_MKL2017) && (MXNET_USE_MKL2017 == 1)
timingTest<op::BatchNormProp, BNOperatorExecutor<DType, AccReal>>(
"MKL BatchNormProp<cpu> 2D",
false, false,
@@ -897,6 +898,7 @@ MSHADOW_REAL_TYPE_SWITCH_EX(
#endif
});
}
+#endif // _WIN32
/**
* Backward tests (generally include forward tests as well)
@@ -1150,6 +1152,8 @@ void compare(const bool isGPU,
typename OperatorExecutor::AccRealType>::compare(object, info_checkLoad);
}
+
+#ifndef _WIN32
TEST(BATCH_NORM, TestBackward1D_Simple) {
MSHADOW_REAL_TYPE_SWITCH_EX(
mshadow::kFloat32, DTypeX, AccReal,
@@ -1195,7 +1199,9 @@ TEST(BATCH_NORM, TestBackward1D_Simple) {
compare(false, info, ___BN_TestBackward1D_Simple_data_shape_1_1_2___);
});
}
+#endif // _WIN32
+#ifndef _WIN32
TEST(BATCH_NORM, TestBackward3D) {
MSHADOW_REAL_TYPE_SWITCH_EX(
mshadow::kFloat32, DType, AccReal,
@@ -1211,6 +1217,7 @@ TEST(BATCH_NORM, TestBackward3D) {
#endif
});
}
+#endif // _WIN32
// nonfixgamma_kwargs
TEST(BATCH_NORM, Test2DBackwardMixed_cpu_cpu_nfg) {
@@ -1343,6 +1350,7 @@ static void compare(const TBlob& blob, const std::vector<DType>& vals) {
}
}
+#ifndef _WIN32
template<typename DType, typename AccReal>
static void compare(const std::vector<std::vector<float>>& d1,
const std::vector<std::vector<float>>& d2) {
@@ -1435,6 +1443,7 @@ static TShape MakeShape(const std::vector<index_t>& shape,
return newShape;
}
+
/*! \brief Create and arrange equivalent data with different channel axes, then compare
* normalized results */
static void runChannelAxisTest(
@@ -1626,6 +1635,7 @@ TEST(BATCH_NORM, TestChannelAxis) {
kwargs.pop_back();
}
}
+#endif
#if MXNET_USE_CUDA
diff --git a/tests/cpp/operator/tune/operator_tune_test.cc b/tests/cpp/operator/tune/operator_tune_test.cc
index 2a37d0c..60096d3 100644
--- a/tests/cpp/operator/tune/operator_tune_test.cc
+++ b/tests/cpp/operator/tune/operator_tune_test.cc
@@ -18,6 +18,7 @@
*/
#include <gtest/gtest.h>
#include <mxnet/tensor_blob.h>
+#include <numeric>
#include "../../src/operator/nn/activation-inl.h"
#include "../../src/operator/operator_tune-inl.h"
#include "../include/test_op_runner.h"
diff --git a/tests/cpp/unittest.mk b/tests/cpp/unittest.mk
index 030b240..4e88c64 100644
--- a/tests/cpp/unittest.mk
+++ b/tests/cpp/unittest.mk
@@ -2,8 +2,11 @@ TEST_SRC = $(shell find tests/cpp/ -name "*.cc")
TEST_OBJ = $(patsubst %.cc, build/%.o, $(TEST_SRC))
TEST = build/tests/cpp/mxnet_unit_tests
-GTEST_LIB=$(GTEST_PATH)/lib/
-GTEST_INC=$(GTEST_PATH)/include/
+GTEST_DIR=3rdparty/googletest/googletest/
+GTEST_INC=3rdparty/googletest/googletest/include/
+GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
+GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
+ $(GTEST_DIR)/include/gtest/internal/*.h
TEST_CFLAGS = -Itests/cpp/include -Isrc $(CFLAGS)
TEST_LDFLAGS = $(LDFLAGS) -Llib -lmxnet
@@ -15,6 +18,12 @@ endif
.PHONY: runtest testclean
+gtest-all.o : $(GTEST_SRCS_)
+ $(CXX) $(CPPFLAGS) -I$(GTEST_INC) -I$(GTEST_DIR) $(CXXFLAGS) -c $(GTEST_DIR)/src/gtest-all.cc
+
+gtest.a : gtest-all.o
+ $(AR) $(ARFLAGS) $@ $^
+
build/tests/cpp/%.o : tests/cpp/%.cc
@mkdir -p $(@D)
$(CXX) -std=c++11 $(TEST_CFLAGS) -I$(GTEST_INC) -MM -MT tests/cpp/$* $< > build/tests/cpp/$*.d
@@ -35,8 +44,8 @@ build/tests/cpp/engine/%.o : tests/cpp/engine/%.cc
$(CXX) -std=c++11 $(TEST_CFLAGS) -I$(GTEST_INC) -MM -MT tests/cpp/engine/$* $< > build/tests/cpp/engine/$*.d
$(CXX) -c -std=c++11 $(TEST_CFLAGS) -I$(GTEST_INC) -o build/tests/cpp/engine/$*.o $(filter %.cc %.a, $^)
-$(TEST): $(TEST_OBJ) lib/libmxnet.so
- $(CXX) -std=c++11 $(TEST_CFLAGS) -I$(GTEST_INC) -o $@ $^ $(TEST_LDFLAGS) -L$(GTEST_LIB) -lgtest
+$(TEST): $(TEST_OBJ) lib/libmxnet.so gtest.a
+ $(CXX) -std=c++11 $(TEST_CFLAGS) -I$(GTEST_INC) -o $@ $^ $(TEST_LDFLAGS)
runtest: $(TEST)
LD_LIBRARY_PATH=$(shell pwd)/lib:$(LD_LIBRARY_PATH) $(TEST)
--
To stop receiving notification emails like this one, please contact
['"commits@mxnet.apache.org" <co...@mxnet.apache.org>'].