singa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wang...@apache.org
Subject [2/8] incubator-singa git commit: SINGA-247 Add windows support for singa
Date Mon, 10 Oct 2016 15:46:08 GMT
SINGA-247 Add windows support for singa

Add MSVC codes in cmake files.
Add DISABLE_WARNINGS into configure files.
Fix incompatible codes and add some definitions.


Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/350bdf41
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/350bdf41
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/350bdf41

Branch: refs/heads/master
Commit: 350bdf41487221a692b8c335b54e9034a71c1834
Parents: 8055515
Author: xiezl <xiezhongle@comp.nus.edu.sg>
Authored: Mon Sep 19 01:59:44 2016 +0800
Committer: Wei Wang <wangwei@comp.nus.edu.sg>
Committed: Mon Oct 10 17:41:28 2016 +0800

----------------------------------------------------------------------
 CMakeLists.txt                          | 12 ++++++++++--
 cmake/Templates/singa_config.h.in       |  2 ++
 include/singa/core/tensor.h             |  2 +-
 src/CMakeLists.txt                      | 13 ++++++++++---
 src/core/device/opencl_device.cc        |  3 ++-
 src/core/device/platform.cc             |  3 +--
 src/core/memory/memory.cc               |  5 ++++-
 src/core/tensor/sparse_tensor.cc        |  4 ++++
 src/core/tensor/tensor.cc               |  2 +-
 src/io/jpg_decoder.cc                   |  3 +--
 src/io/jpg_encoder.cc                   |  2 +-
 src/io/lmdb_reader.cc                   |  2 +-
 src/io/lmdb_writer.cc                   |  3 ++-
 src/model/optimizer/local_all_reduce.cc |  4 ++++
 src/utils/logging.cc                    |  3 ++-
 test/singa/test_cross_entropy.cc        |  2 +-
 test/singa/test_mse.cc                  |  4 ++--
 test/singa/test_timer.cc                |  4 ++--
 18 files changed, 51 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e799348..2e9f27a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,14 +20,21 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 
 PROJECT(singa)
 SET(PACKAGE_VERSION "1.0.0")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -O2 ")
+MESSAGE(STATUS "CMAKE paths: ${CMAKE_PREFIX_PATH} test ${CMAKE_SYSTEM_PREFIX_PATH}")
 
 LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Thirdparty)
 #message(STATUS "module path: ${CMAKE_MODULE_PATH}")
 
 # Flags
 IF(UNIX OR APPLE)
-  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
+  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -O2 -fPIC -Wall")
+ENDIF()
+IF(WIN32) 
+  IF (MSVC)
+	MESSAGE(STATUS "Using msvc compiler")
+    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_SCL_SECURE_NO_WARNINGS")
+	MESSAGE(STATUS "Using msvc compiler ${CMAKE_CXX_FLAGS}")
+  ENDIF()
 ENDIF()
 IF(CMAKE_BUILD_TYPE=Debug)
   SET(NVCC_FLAG "${NVCC_FLAG} -g -G ")
@@ -46,6 +53,7 @@ OPTION(USE_PYTHON "Generate py wrappers" ON)
 OPTION(USE_JAVA "Generate java wrappers" OFF)
 OPTION(USE_OPENCL "Use OpenCL" OFF)
 OPTION(ENABLE_DIST "enable distributed training" OFF)
+OPTION(DISABLE_WARNINGS "disable warnings under windows" ON)
 
 INCLUDE("cmake/Dependencies.cmake")
 #INCLUDE("cmake/Utils.cmake")

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/cmake/Templates/singa_config.h.in
----------------------------------------------------------------------
diff --git a/cmake/Templates/singa_config.h.in b/cmake/Templates/singa_config.h.in
index f3500d0..324f7a3 100644
--- a/cmake/Templates/singa_config.h.in
+++ b/cmake/Templates/singa_config.h.in
@@ -40,6 +40,8 @@
 
 #cmakedefine ENABLE_DIST
 
+#cmakedefine DISABLE_WARNINGS
+
 // lmdb
 #cmakedefine USE_LMDB
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/include/singa/core/tensor.h
----------------------------------------------------------------------
diff --git a/include/singa/core/tensor.h b/include/singa/core/tensor.h
index a41afbc..00df60b 100644
--- a/include/singa/core/tensor.h
+++ b/include/singa/core/tensor.h
@@ -211,7 +211,7 @@ class Tensor {
   /// Note: block_ is allocated in lazy manner to avoid frequent malloc/free.
   /// If you want to get an allocated Block, use block() instead of block_.
   Block *block_ = nullptr;
-  Shape shape_ = {};
+  Shape shape_;// = {};
 };
 
 typedef Shape::iterator ShapeIter;

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5f70204..7b94580 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -27,6 +27,10 @@ LIST(APPEND singa_sources ${proto_hdrs} ${proto_srcs})
 AUX_SOURCE_DIRECTORY(utils utils_source)
 LIST(APPEND singa_sources ${utils_source})
 
+AUX_SOURCE_DIRECTORY(io io_source)
+AUX_SOURCE_DIRECTORY(io/network io_source)
+LIST(APPEND singa_sources ${io_source})
+
 AUX_SOURCE_DIRECTORY(core/device core_source)
 AUX_SOURCE_DIRECTORY(core/memory core_source)
 AUX_SOURCE_DIRECTORY(core/scheduler core_source)
@@ -57,9 +61,6 @@ AUX_SOURCE_DIRECTORY(model/metric model_source)
 AUX_SOURCE_DIRECTORY(model/updater model_source)
 LIST(APPEND singa_sources ${model_source})
 
-AUX_SOURCE_DIRECTORY(io io_source)
-AUX_SOURCE_DIRECTORY(io/network io_source)
-LIST(APPEND singa_sources ${io_source})
 
 ADD_CUSTOM_TARGET(
   copy_protobuf ALL
@@ -78,6 +79,12 @@ FOREACH(fil ${proto_hdrs})
 ENDFOREACH()
 
 ADD_LIBRARY(singa_objects OBJECT ${singa_sources})
+IF(WIN32) 
+  IF (MSVC)
+	SET_TARGET_PROPERTIES(singa_objects 
+	  PROPERTIES COMPILE_FLAGS "/wd4244 /wd4267 /wd4018 /wd4005 /wd4804 /wd4800")
+  ENDIF()
+ENDIF()
 #ADD_DEPENDENCIES(singa_objects copy_protobuf)
 
 ADD_LIBRARY(singa SHARED $<TARGET_OBJECTS:singa_objects> ${cuda_objs})

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/src/core/device/opencl_device.cc
----------------------------------------------------------------------
diff --git a/src/core/device/opencl_device.cc b/src/core/device/opencl_device.cc
index 0c8f010..c9c2211 100644
--- a/src/core/device/opencl_device.cc
+++ b/src/core/device/opencl_device.cc
@@ -16,6 +16,8 @@
  * limitations under the License.
  */
 
+#ifdef USE_OPENCL
+
 #include <iostream>
 #include <fstream>
 #include <sstream>
@@ -25,7 +27,6 @@
 #include "singa/utils/tinydir.h"
 #include "singa/utils/opencl_utils.h"
 
-#ifdef USE_OPENCL
 
 using namespace viennacl;
 using namespace viennacl::backend::opencl;

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/src/core/device/platform.cc
----------------------------------------------------------------------
diff --git a/src/core/device/platform.cc b/src/core/device/platform.cc
index a3661f2..3392492 100644
--- a/src/core/device/platform.cc
+++ b/src/core/device/platform.cc
@@ -15,12 +15,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#ifdef USE_CUDA
 
 #include "singa/core/device.h"
 #include "singa/singa_config.h"
 
-#ifdef USE_CUDA
-
 namespace singa {
 
 int Platform::GetNumGPUs() {

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/src/core/memory/memory.cc
----------------------------------------------------------------------
diff --git a/src/core/memory/memory.cc b/src/core/memory/memory.cc
index cb33a48..2dd1cbe 100644
--- a/src/core/memory/memory.cc
+++ b/src/core/memory/memory.cc
@@ -15,13 +15,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#ifndef DISABLE_WARNINGS
 
+#ifdef USE_CUDA
 #include "singa/core/memory.h"
 #include "singa/utils/logging.h"
 #include "singa/proto/core.pb.h"
 #include <iostream>
 
-#ifdef USE_CUDA
 namespace singa {
 std::atomic<int> CnMemPool::pool_count(0);
 std::pair<size_t, size_t> CnMemPool::GetMemUsage() {
@@ -109,3 +110,5 @@ void CudaMemPool::Free(void *ptr) {
 }
 }
 #endif
+
+#endif
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/src/core/tensor/sparse_tensor.cc
----------------------------------------------------------------------
diff --git a/src/core/tensor/sparse_tensor.cc b/src/core/tensor/sparse_tensor.cc
index a8ae973..46ea850 100644
--- a/src/core/tensor/sparse_tensor.cc
+++ b/src/core/tensor/sparse_tensor.cc
@@ -15,5 +15,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#ifndef DISABLE_WARNINGS
+
 #include "singa/core/tensor.h"
 namespace singa {}
+
+#endif
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/src/core/tensor/tensor.cc
----------------------------------------------------------------------
diff --git a/src/core/tensor/tensor.cc b/src/core/tensor/tensor.cc
index d7e8f86..516a088 100644
--- a/src/core/tensor/tensor.cc
+++ b/src/core/tensor/tensor.cc
@@ -567,7 +567,7 @@ GenBinaryTensorFn(operator>=, GE);
   void fn(const Tensor &in, const SType x, Tensor *ret) {     \
     EltwiseTensorScalarFn(fn, in, x, ret);                    \
   }                                                           \
-  template Tensor op<float>(const Tensor &in, const float x); \
+  template Tensor op <float>(const Tensor &in, const float x); \
   template void fn<float>(const Tensor &in, const float x, Tensor *ret)
 
 GenTensorScalarFn(operator+, Add);

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/src/io/jpg_decoder.cc
----------------------------------------------------------------------
diff --git a/src/io/jpg_decoder.cc b/src/io/jpg_decoder.cc
index b778b98..e0d458c 100644
--- a/src/io/jpg_decoder.cc
+++ b/src/io/jpg_decoder.cc
@@ -15,11 +15,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#ifdef USE_OPENCV
 
 #include "singa/io/decoder.h"
 
-#ifdef USE_OPENCV
-
 #include <opencv2/highgui/highgui.hpp>
 #include <opencv2/imgproc/imgproc.hpp>
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/src/io/jpg_encoder.cc
----------------------------------------------------------------------
diff --git a/src/io/jpg_encoder.cc b/src/io/jpg_encoder.cc
index 8335a91..4a4ee85 100644
--- a/src/io/jpg_encoder.cc
+++ b/src/io/jpg_encoder.cc
@@ -15,10 +15,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#ifdef USE_OPENCV
 
 #include "singa/io/encoder.h"
 
-#ifdef USE_OPENCV
 #include <opencv2/highgui/highgui.hpp>
 #include <opencv2/imgproc/imgproc.hpp>
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/src/io/lmdb_reader.cc
----------------------------------------------------------------------
diff --git a/src/io/lmdb_reader.cc b/src/io/lmdb_reader.cc
index 7f78080..8bb82c0 100644
--- a/src/io/lmdb_reader.cc
+++ b/src/io/lmdb_reader.cc
@@ -15,10 +15,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#ifdef USE_LMDB
 
 #include "singa/io/reader.h"
 #include "singa/utils/logging.h"
-#ifdef USE_LMDB
 
 namespace singa {
 namespace io {

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/src/io/lmdb_writer.cc
----------------------------------------------------------------------
diff --git a/src/io/lmdb_writer.cc b/src/io/lmdb_writer.cc
index e89894b..3e6d5f8 100644
--- a/src/io/lmdb_writer.cc
+++ b/src/io/lmdb_writer.cc
@@ -16,9 +16,10 @@
  * limitations under the License.
  */
 
+#ifdef USE_LMDB
+
 #include "singa/io/writer.h"
 #include "singa/utils/logging.h"
-#ifdef USE_LMDB
 
 namespace singa {
 namespace io {

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/src/model/optimizer/local_all_reduce.cc
----------------------------------------------------------------------
diff --git a/src/model/optimizer/local_all_reduce.cc b/src/model/optimizer/local_all_reduce.cc
index ea03e39..9cda321 100644
--- a/src/model/optimizer/local_all_reduce.cc
+++ b/src/model/optimizer/local_all_reduce.cc
@@ -15,6 +15,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#ifndef DISABLE_WARNINGS
+
 #ifndef SRC_MODEL_OPTIMIZER_LOCAL_ALL_REDUCE_H_
 #define SRC_MODEL_OPTIMIZER_LOCAL_ALL_REDUCE_H_
 #include "singa/model/optimizer.h"
@@ -23,3 +25,5 @@ namespace singa {
 }
 
 #endif  // SRC_MODEL_OPTIMIZER_LOCAL_ALL_REDUCE_H_
+
+#endif
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/src/utils/logging.cc
----------------------------------------------------------------------
diff --git a/src/utils/logging.cc b/src/utils/logging.cc
index 3b0916b..50fa7dc 100644
--- a/src/utils/logging.cc
+++ b/src/utils/logging.cc
@@ -23,7 +23,8 @@
 
 #include <stdlib.h>
 #include <sys/types.h>
-#include <unistd.h>
+//#include <unistd.h>
+#include <io.h>
 
 namespace singa {
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/test/singa/test_cross_entropy.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_cross_entropy.cc b/test/singa/test_cross_entropy.cc
index c7fa2fb..8235766 100644
--- a/test/singa/test_cross_entropy.cc
+++ b/test/singa/test_cross_entropy.cc
@@ -32,7 +32,7 @@ class TestSoftmaxCrossEntropy : public ::testing::Test {
     p.Reshape(singa::Shape{2, 4});
     t.Reshape(singa::Shape{2, 1});
   }
-  const float pdat[8] = {0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
+  const float pdat[8] = {0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f };
   const int tdat[2] = {0, 2};
 
   singa::Tensor p, t;

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/test/singa/test_mse.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_mse.cc b/test/singa/test_mse.cc
index a0ab1a1..9cf0e9c 100644
--- a/test/singa/test_mse.cc
+++ b/test/singa/test_mse.cc
@@ -33,8 +33,8 @@ class TestMSE : public ::testing::Test {
     p.CopyDataFromHostPtr(pdat, sizeof(pdat) / sizeof(float));
     t.CopyDataFromHostPtr(tdat, sizeof(pdat) / sizeof(float));
   }
-  const float pdat[6] = {0.1, 1.1, 2.1, 0.3, 2.2, 1.8};
-  const float tdat[6] = {0.1, 1.1, 2.0, 0.3, 2.2, 1.8};
+  const float pdat[6] = { 0.1f, 1.1f, 2.1f, 0.3f, 2.2f, 1.8f};
+  const float tdat[6] = { 0.1f, 1.1f, 2.0f, 0.3f, 2.2f, 1.8f};
 
   singa::Tensor p, t;
 };

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/350bdf41/test/singa/test_timer.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_timer.cc b/test/singa/test_timer.cc
index 76d3597..735b72d 100644
--- a/test/singa/test_timer.cc
+++ b/test/singa/test_timer.cc
@@ -24,7 +24,7 @@
 
 TEST(TimerTest, TestTick) {
   singa::Timer t;
-  std::this_thread::sleep_for(std::chrono::milliseconds(1000));
+  std::this_thread::sleep_for(std::chrono::milliseconds(10));
   int time = t.Elapsed<singa::Timer::Milliseconds>();
-  EXPECT_GE(time, 1000);
+  EXPECT_GE(time, 10);
 }


Mime
View raw message