You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2016/10/10 15:46:14 UTC

[8/8] incubator-singa git commit: SINGA-247 Add windows support for singa

SINGA-247 Add windows support for singa

Update the alexnet.cc and cmake file to enable the compilation for CPU only environment.
Update the documentations to include more instruction/hints.


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

Branch: refs/heads/master
Commit: e9b2c964c37dbcbbacf502649c17d50ec1608978
Parents: 901e885
Author: U-wangwei-PC\wangwei <wangwei>
Authored: Sun Oct 9 23:25:30 2016 +0800
Committer: Wei Wang <wa...@comp.nus.edu.sg>
Committed: Mon Oct 10 23:41:07 2016 +0800

----------------------------------------------------------------------
 doc/en/docs/dependencies.md     | 37 ++++++++++++++++++++++++------------
 doc/en/docs/installation.md     | 25 ++++++++++--------------
 examples/cifar10/CMakeLists.txt |  9 ++++++---
 examples/cifar10/alexnet.cc     |  8 ++++++--
 examples/cifar10/cifar10.h      |  6 +++---
 5 files changed, 50 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e9b2c964/doc/en/docs/dependencies.md
----------------------------------------------------------------------
diff --git a/doc/en/docs/dependencies.md b/doc/en/docs/dependencies.md
index 5216900..a812c05 100644
--- a/doc/en/docs/dependencies.md
+++ b/doc/en/docs/dependencies.md
@@ -3,26 +3,25 @@
 ## Windows
 
 This section is used to compile and install the dependent libraries under
-windows system from source codes. The ONLY compiler used is Visual Studio 2015.
-If you intend to generate a 32-bit/64-bit singa solution, please configure all the
+windows system from source codes. The following instructions ONLY work for Visual Studio 2015 as
+previous VS does not support [C++11 features](https://msdn.microsoft.com/en-us/library/hh567368.aspx) well (including generic lambdas, auto, non-static
+data member initializers). If you intend to generate a 32-bit/64-bit singa solution, please configure all the
 VS projects for the dependent libraries as 32-bit/64-bit. This can be done by
-"Configuration Manager" in VS 2015 or use coresponding generator in cmake. When compiling the following libraries, you
+"Configuration Manager" in VS 2015 or use corresponding generator in cmake. When compiling the following libraries, you
 may get system-specific warnings/errors. Please fix them according to the
 prompts by VS.
 
 ### Google Logging
-
-The glog library is an optional library for singa project. But it is needed for
-protobuf check on cmake. Since the latest release version of glog will encounter error C2084 on sprintf function
-under VS2015, we test the compilation and installation with the
-latest codes of glog. The code is from [git](https://github.com/google/glog). 
+The glog library is an optional library for singa project. But it is currently necessary for Window compilation.
+Since the latest release version of glog will encounter error C2084 on sprintf function
+under VS2015, we test the compilation and installation using the master branch from [github](https://github.com/google/glog).
 
 Step 1: Download and decompress the source code. Or use `git clone
 https://github.com/google/glog` to get the code.
 
 Step 2: Open "glog.sln" file under project folder. You will get a conversion
 dialog and please finish it by the prompts. Compile all the projects in the solution after
-proper configuration, especially "libglog" and "libglog_static" projects. 
+proper configuration, especially "libglog" and "libglog_static" projects.
 
 Step 3: Copy all the header files and the entire directory named "glog" under
 "src\windows\" folder into the installation include folder (or system folder).
@@ -31,7 +30,8 @@ system folder).
 
 Step 4: Done.
 
-### Google protobuf 
+
+### Google protobuf
 
 Tested on version 2.6.1:
 
@@ -49,7 +49,7 @@ Step 4: Copy the library files, such as "libprotobuf.lib",
 "libprotobuf-lite.lib", "libprotoc.lib", etc., into your installation library folder (or
 system folder). Copy the binary file "protoc" into your installation binary
 folder (or system folder). Copy all the headers and folders in "include" folder into your
-installation include foder (or system folder).
+installation include folder (or system folder).
 
 Step 5: Done.
 
@@ -62,7 +62,7 @@ OpenBLAS with version 0.2.18 as test:
 Step 1: Download and decompress the source code.
 
 Step 2: Start a cmd window under the OpenBLAS folder then run the following
-commands to generate the solution: 
+commands to generate the solution:
 
     $ md build $$ cd build
     $ cmake -G "Visual Studio 14" ..
@@ -77,3 +77,16 @@ under OpenBLAS folder into installation library and include folders (or system
 folders).
 
 Step 5: Done.
+
+
+## FAQ
+
+1. Error C2375 'snprintf': redefinition; different linkage
+
+    Add \u201cHAVE_SNPRINTF\u201d to \u201cC/C++ - Preprocessor - Preprocessor definitions\u201d
+
+2. Error due to hash map
+
+    Add "_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS" to Preprocessor Definitions.
+
+

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e9b2c964/doc/en/docs/installation.md
----------------------------------------------------------------------
diff --git a/doc/en/docs/installation.md b/doc/en/docs/installation.md
index 47aa245..069cf6a 100755
--- a/doc/en/docs/installation.md
+++ b/doc/en/docs/installation.md
@@ -216,22 +216,14 @@ To build SINGA with OpenCL support, you need to pass the flag during cmake:
 
 ### Windows
 
-The ONLY compiler used for windows is Visual Studio 2015 as some c++11
-features (Generic lambdas, auto, non-static data member intitializers, etc.)
-followed by singa are only supported in this version (details can be found
-[here](https://msdn.microsoft.com/en-us/library/hh567368.aspx)). 
-
-For the dependent library installation, please refer to
-[Dependencies](dependencies.md).
-After all the
-dependencies are successfully installed, just run the following commands to
+For the dependent library installation, please refer to [Dependencies](dependencies.md).
+After all the dependencies are successfully installed, just run the following commands to
 generate the VS solution in cmd under singa folder:
 
     $ md build && cd build
-    $ cmake -G "Visual Studio 14" -DUSE_CUDA=OFF -DUSE_PYTHON=OFF .. 
+    $ cmake -G "Visual Studio 14" -DUSE_CUDA=OFF -DUSE_PYTHON=OFF ..
 
-Current version of singa cannot support neither cuda/cudnn compiling nor python
-wrappers. The default project generated by the command is 32-bit version. You can also
+The default project generated by the command is 32-bit version. You can also
 specify a 64-bit version project by:
 
     $ md build && cd build
@@ -243,8 +235,8 @@ For example, you get an error "Could NOT find CBLAS" and suppose you installed
 openblas header files at "d:\include" and openblas library at "d:\lib". You should run the
 following command to specify your cblas parameters in cmake:
 
-    $ cmake -G "Visual Studio 14" -DUSE_CUDA=OFF -DUSE_PYTHON=OFF
-    -DCBLAS_INCLUDE_DIR="d:\include" -DCBLAS_LIBRARIES="d:\lib\libopenblas.lib"
+    $ cmake -G "Visual Studio 14" -DUSE_CUDA=OFF -DUSE_PYTHON=OFF -DCBLAS_INCLUDE_DIR="d:\include" -DCBLAS_LIBRARIES="d:\lib\libopenblas.lib" -DProtobuf_INCLUDE_DIR=<include dir of protobuf> -DProtobuf_LIBRARIES=<path to libprotobuf.lib> -DProtobuf_PROTOC_EXECUTABLE=<path to protoc.exe> -DGLOG_INCLUDE_DIR=<include dir of glog> -DGLOG_LIBRARIES=<path to libglog.lib> ..
+    
 
 To find out the parameters you need to specify for some special libraries, you
 can run the following command:
@@ -252,9 +244,12 @@ can run the following command:
     $ cmake -LAH
 
 If you use cmake GUI tool in windows, please make sure you configure the right
-parameters for the singa solution by select "Advanced" box. After generating the VS project, please open the "singa.sln" project file under
+parameters for the singa solution by select "Advanced" box. After generating the VS project,
+please open the "singa.sln" project file under
 the "build" folder and compile it as a normal VS solution. You will find the
 unit tests file named "test_singa" in the project binary folder.
+If you get errors when running test_singa.exe due to libglog.dll/libopenblas.dll missing,
+please just copy the dll files into the same folder as test_singa.exe
 
 ## FAQ
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e9b2c964/examples/cifar10/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/examples/cifar10/CMakeLists.txt b/examples/cifar10/CMakeLists.txt
index 1f29f2f..5708c29 100644
--- a/examples/cifar10/CMakeLists.txt
+++ b/examples/cifar10/CMakeLists.txt
@@ -19,10 +19,12 @@
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
 INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include)
 
-IF(USE_CUDNN)
+
 ADD_EXECUTABLE(alexnet alexnet.cc)
 ADD_DEPENDENCIES(alexnet singa)
-TARGET_LINK_LIBRARIES(alexnet singa protobuf ${SINGA_LIBKER_LIBS})
+TARGET_LINK_LIBRARIES(alexnet singa ${SINGA_LIBKER_LIBS})
+
+IF(USE_CUDNN)
 
 ADD_EXECUTABLE(alexnet-parallel alexnet-parallel.cc)
 ADD_DEPENDENCIES(alexnet-parallel singa)
@@ -33,4 +35,5 @@ ADD_EXECUTABLE(vgg-parallel vgg-parallel.cc)
 ADD_DEPENDENCIES(vgg-parallel singa)
 TARGET_LINK_LIBRARIES(vgg-parallel singa protobuf ${SINGA_LIBKER_LIBS})
 SET_TARGET_PROPERTIES(vgg-parallel PROPERTIES LINK_FLAGS "${LINK_FLAGS} -pthread")
-ENDIF(USE_CUDNN)
+
+ENDIF(USE_CUDNN)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e9b2c964/examples/cifar10/alexnet.cc
----------------------------------------------------------------------
diff --git a/examples/cifar10/alexnet.cc b/examples/cifar10/alexnet.cc
index 8a506d2..61097b6 100644
--- a/examples/cifar10/alexnet.cc
+++ b/examples/cifar10/alexnet.cc
@@ -22,13 +22,16 @@
 #include "./cifar10.h"
 #include "singa/model/feed_forward_net.h"
 #include "singa/model/optimizer.h"
-#include "singa/model/initializer.h"
 #include "singa/model/metric.h"
 #include "singa/utils/channel.h"
 #include "singa/utils/string.h"
 namespace singa {
 // currently supports 'cudnn' and 'singacpp'
+#ifdef USE_CUDNN
 const std::string engine = "cudnn";
+#else
+const std::string engine = "singacpp";
+#endif  // USE_CUDNN
 LayerConf GenConvConf(string name, int nb_filter, int kernel, int stride,
                       int pad, float std) {
   LayerConf conf;
@@ -177,13 +180,14 @@ void Train(int num_epoch, string data_dir) {
   SoftmaxCrossEntropy loss;
   Accuracy acc;
   net.Compile(true, &sgd, &loss, &acc);
-
+#ifdef USE_CUDNN
   auto dev = std::make_shared<CudaGPU>();
   net.ToDevice(dev);
   train_x.ToDevice(dev);
   train_y.ToDevice(dev);
   test_x.ToDevice(dev);
   test_y.ToDevice(dev);
+#endif  // USE_CUDNN
   net.Train(100, num_epoch, train_x, train_y, test_x, test_y);
 }
 }

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e9b2c964/examples/cifar10/cifar10.h
----------------------------------------------------------------------
diff --git a/examples/cifar10/cifar10.h b/examples/cifar10/cifar10.h
index d2b9225..11cc55d 100644
--- a/examples/cifar10/cifar10.h
+++ b/examples/cifar10/cifar10.h
@@ -41,9 +41,9 @@ class Cifar10 {
   void ReadImage(std::ifstream* file, int* label, char* buffer);
 
  private:
-  const size_t kImageSize = 32;
-  const size_t kImageVol = 3072;
-  const size_t kBatchSize = 10000;
+  static const size_t kImageSize = 32;
+  static const size_t kImageVol = 3072;
+  static const size_t kBatchSize = 10000;
   const size_t kTrainFiles = 5;
 
   string dir_path_;