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:07 UTC

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

Repository: incubator-singa
Updated Branches:
  refs/heads/master 80555151a -> e9b2c964c


SINGA-247 Add windows support for singa

Fix some warnings, most of which are type transferring.
Add a target named "singa_static" to generate static libs.


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

Branch: refs/heads/master
Commit: d0317a75c3dd7bd8e878ead0ea2b7a44273d07bd
Parents: 350bdf4
Author: xiezl <xi...@comp.nus.edu.sg>
Authored: Tue Sep 20 01:47:05 2016 +0800
Committer: Wei Wang <wa...@comp.nus.edu.sg>
Committed: Mon Oct 10 17:41:28 2016 +0800

----------------------------------------------------------------------
 src/CMakeLists.txt                      | 9 ++++++---
 src/core/tensor/sparse_tensor.cc        | 2 ++
 src/core/tensor/tensor.cc               | 2 +-
 src/io/image_transformer.cc             | 2 +-
 src/model/feed_forward_net.cc           | 2 +-
 src/model/layer/batchnorm.cc            | 2 +-
 src/model/layer/pooling.cc              | 2 +-
 src/model/optimizer/local_all_reduce.cc | 2 ++
 8 files changed, 15 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d0317a75/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7b94580..adafdf2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -81,15 +81,18 @@ 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")
+	#SET_TARGET_PROPERTIES(singa_objects 
+	#  PROPERTIES COMPILE_FLAGS "/wd4244 /wd4267 /wd4018 /wd4005 /wd4804 /wd4800")
   ENDIF()
 ENDIF()
-#ADD_DEPENDENCIES(singa_objects copy_protobuf)
+ADD_DEPENDENCIES(singa_objects copy_protobuf)
 
 ADD_LIBRARY(singa SHARED $<TARGET_OBJECTS:singa_objects> ${cuda_objs})
 TARGET_LINK_LIBRARIES(singa ${SINGA_LINKER_LIBS})
 
+ADD_LIBRARY(singa_static STATIC $<TARGET_OBJECTS:singa_objects> ${cuda_objs})
+TARGET_LINK_LIBRARIES(singa ${SINGA_LINKER_LIBS})
+
 #pass configure infor to swig 
 FILE(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/api/config.i")
 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/api/config.i.in" "${CMAKE_CURRENT_SOURCE_DIR}/api/config.i")

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d0317a75/src/core/tensor/sparse_tensor.cc
----------------------------------------------------------------------
diff --git a/src/core/tensor/sparse_tensor.cc b/src/core/tensor/sparse_tensor.cc
index 46ea850..68021d1 100644
--- a/src/core/tensor/sparse_tensor.cc
+++ b/src/core/tensor/sparse_tensor.cc
@@ -15,6 +15,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "singa/singa_config.h"
+
 #ifndef DISABLE_WARNINGS
 
 #include "singa/core/tensor.h"

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d0317a75/src/core/tensor/tensor.cc
----------------------------------------------------------------------
diff --git a/src/core/tensor/tensor.cc b/src/core/tensor/tensor.cc
index 516a088..40d85a2 100644
--- a/src/core/tensor/tensor.cc
+++ b/src/core/tensor/tensor.cc
@@ -282,7 +282,7 @@ Tensor Tensor::T() const {
   Tensor t;
   t.device_ = device_;
   t.data_type_ = data_type_;
-  t.transpose_ = ~transpose_;
+  t.transpose_ = !transpose_;
   t.shape_.push_back(shape_[1]);
   t.shape_.push_back(shape_[0]);
   t.block_ = block_;

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d0317a75/src/io/image_transformer.cc
----------------------------------------------------------------------
diff --git a/src/io/image_transformer.cc b/src/io/image_transformer.cc
index f233ad3..6e5567d 100644
--- a/src/io/image_transformer.cc
+++ b/src/io/image_transformer.cc
@@ -31,7 +31,7 @@ namespace singa {
     CHECK_GE(input.nDim(), 2u);
     CHECK_EQ(input.data_type(), kFloat32) << "Data type " << input.data_type()
       << " is invalid for an raw image";
-    srand(time(NULL));
+    srand((unsigned int)time(NULL));
     /// TODO
     /// currently only consider one sample each time
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d0317a75/src/model/feed_forward_net.cc
----------------------------------------------------------------------
diff --git a/src/model/feed_forward_net.cc b/src/model/feed_forward_net.cc
index 3875430..c5c894e 100644
--- a/src/model/feed_forward_net.cc
+++ b/src/model/feed_forward_net.cc
@@ -129,7 +129,7 @@ void FeedForwardNet::AsType(DataType dtype) {
 void FeedForwardNet::Train(size_t batchsize, int nb_epoch, const Tensor& x,
                            const Tensor& y, float val_split) {
   CHECK_EQ(x.shape(0), y.shape(0)) << "Diff num of sampels in x and y";
-  size_t num_train = x.shape(0) * val_split;
+  size_t num_train = (size_t) (x.shape(0) * val_split);
   if (val_split == 0.0f) {
     Tensor dummy;
     Train(batchsize, nb_epoch, x, y, dummy, dummy);

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d0317a75/src/model/layer/batchnorm.cc
----------------------------------------------------------------------
diff --git a/src/model/layer/batchnorm.cc b/src/model/layer/batchnorm.cc
index 2ca7742..ad7b2b3 100644
--- a/src/model/layer/batchnorm.cc
+++ b/src/model/layer/batchnorm.cc
@@ -28,7 +28,7 @@ RegisterLayerClass(singacl_batchnorm, BatchNorm);
 void BatchNorm::Setup(const Shape& in_sample, const LayerConf& conf) {
   Layer::Setup(in_sample, conf);
   out_sample_shape_ = in_sample;
-  factor_ = conf.batchnorm_conf().factor();
+  factor_ = (float) conf.batchnorm_conf().factor();
   channels_ = in_sample.at(0);
   if (in_sample.size() == 3u)
     height_ = in_sample.at(1);

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d0317a75/src/model/layer/pooling.cc
----------------------------------------------------------------------
diff --git a/src/model/layer/pooling.cc b/src/model/layer/pooling.cc
index ff8d58e..cf42891 100644
--- a/src/model/layer/pooling.cc
+++ b/src/model/layer/pooling.cc
@@ -173,7 +173,7 @@ void Pooling::ForwardMaxPooling(const float* bottom, const int num,
               const int index = h * width + w;
               if (bottom[index] > top[top_index]) {
                 top[top_index] = bottom[index];
-                mask[top_index] = index;
+                mask[top_index] = (float) index;
               }
             }
           }

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d0317a75/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 9cda321..e496efa 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.
  */
+#include "singa/singa_config.h"
+
 #ifndef DISABLE_WARNINGS
 
 #ifndef SRC_MODEL_OPTIMIZER_LOCAL_ALL_REDUCE_H_


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

Posted by wa...@apache.org.
SINGA-247 Add windows support for singa.

Fix an error on max function and a warning due to improper conversion.
Link the static libs to the test target.


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

Branch: refs/heads/master
Commit: af30903f421984ecb64a816138ab6a601ba060d7
Parents: 37d3b39
Author: xiezl <xi...@comp.nus.edu.sg>
Authored: Thu Sep 22 17:26:52 2016 +0800
Committer: Wei Wang <wa...@comp.nus.edu.sg>
Committed: Mon Oct 10 17:44:53 2016 +0800

----------------------------------------------------------------------
 src/CMakeLists.txt                | 2 +-
 src/core/tensor/tensor_math_cpp.h | 4 ++--
 src/io/binfile_reader.cc          | 2 +-
 test/CMakeLists.txt               | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/af30903f/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6704960..7493ffb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -92,7 +92,7 @@ ADD_LIBRARY(singa SHARED $<TARGET_OBJECTS:singa_objects> ${cuda_objs})
 TARGET_LINK_LIBRARIES(singa ${SINGA_LINKER_LIBS})
 
 ADD_LIBRARY(singa_static STATIC $<TARGET_OBJECTS:singa_objects> ${cuda_objs})
-TARGET_LINK_LIBRARIES(singa ${SINGA_LINKER_LIBS})
+TARGET_LINK_LIBRARIES(singa_static ${SINGA_LINKER_LIBS})
 
 #pass configure infor to swig 
 FILE(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/api/config.i")

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/af30903f/src/core/tensor/tensor_math_cpp.h
----------------------------------------------------------------------
diff --git a/src/core/tensor/tensor_math_cpp.h b/src/core/tensor/tensor_math_cpp.h
index e978e8e..edae209 100644
--- a/src/core/tensor/tensor_math_cpp.h
+++ b/src/core/tensor/tensor_math_cpp.h
@@ -570,7 +570,7 @@ void ComputeCrossEntropy<float, lang::Cpp>(const size_t batchsize,
     int truth_idx = tPtr[i];
     CHECK_GE(truth_idx, 0);
     float prob_of_truth = pPtr[i * dim + truth_idx];
-    lossPtr[i] = -std::log(std::max(prob_of_truth, FLT_MIN));
+    lossPtr[i] = -std::log((std::max)(prob_of_truth, FLT_MIN));
   }
 }
 
@@ -600,7 +600,7 @@ void RowMax<float, lang::Cpp>(const size_t nrow, const size_t ncol,
     int offset = (int)(r * ncol);
     float maxval = inPtr[offset];
     for (size_t c = 1; c < ncol; c++)
-      maxval = std::max(maxval, inPtr[offset + c]);
+      maxval = (std::max)(maxval, inPtr[offset + c]);
     outPtr[r] = maxval;
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/af30903f/src/io/binfile_reader.cc
----------------------------------------------------------------------
diff --git a/src/io/binfile_reader.cc b/src/io/binfile_reader.cc
index 9167451..a6081e3 100644
--- a/src/io/binfile_reader.cc
+++ b/src/io/binfile_reader.cc
@@ -105,7 +105,7 @@ bool BinFileReader::ReadField(std::string* content) {
   content->clear();
   int ssize = sizeof(size_t);
   if (!PrepareNextField(ssize)) return false;
-  int len = *reinterpret_cast<size_t*>(buf_ + offset_);
+  int len = *reinterpret_cast<int*>(buf_ + offset_);
   offset_ += ssize;
   if (!PrepareNextField(len)) return false;
   content->reserve(len);

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/af30903f/test/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index e1487d2..a996413 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -31,9 +31,9 @@ AUX_SOURCE_DIRECTORY(singa singa_test_source)
 LIST(REMOVE_ITEM singa_test_source "singa/test_ep.cc")
 
 ADD_EXECUTABLE(test_singa "gtest/gtest_main.cc" ${singa_test_source})
-ADD_DEPENDENCIES(test_singa singa)
+ADD_DEPENDENCIES(test_singa singa_static)
 #MESSAGE(STATUS "link libs" ${singa_linker_libs})
-TARGET_LINK_LIBRARIES(test_singa gtest singa ${SINGA_LINKER_LIBS})
+TARGET_LINK_LIBRARIES(test_singa gtest singa_static ${SINGA_LINKER_LIBS})
 IF(UNIX AND (NOT APPLE))
     LIST(APPEND LINK_FLAGS "-pthread")
 ENDIF()


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

Posted by wa...@apache.org.
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_;


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

Posted by wa...@apache.org.
SINGA-247 Add windows support for singa

Fix warnings.


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

Branch: refs/heads/master
Commit: 37d3b39e942d9e1d03344524a2e958a9d7aa83c3
Parents: d0317a7
Author: xiezl <xi...@comp.nus.edu.sg>
Authored: Tue Sep 20 14:02:47 2016 +0800
Committer: Wei Wang <wa...@comp.nus.edu.sg>
Committed: Mon Oct 10 17:44:53 2016 +0800

----------------------------------------------------------------------
 include/singa/core/tensor.h       |  2 +-
 include/singa/utils/string.h      |  2 +-
 src/CMakeLists.txt                |  1 +
 src/core/tensor/tensor.cc         | 32 ++++++++++++++++----------------
 src/core/tensor/tensor_math_cpp.h |  4 ++--
 src/io/binfile_reader.cc          |  2 +-
 src/io/binfile_writer.cc          |  8 ++++----
 src/model/feed_forward_net.cc     | 22 +++++++++++-----------
 src/model/layer/convolution.cc    |  8 +++-----
 src/model/layer/pooling.cc        | 12 ++++++------
 src/utils/logging.cc              |  5 ++++-
 11 files changed, 50 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/37d3b39e/include/singa/core/tensor.h
----------------------------------------------------------------------
diff --git a/include/singa/core/tensor.h b/include/singa/core/tensor.h
index 00df60b..a41afbc 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/37d3b39e/include/singa/utils/string.h
----------------------------------------------------------------------
diff --git a/include/singa/utils/string.h b/include/singa/utils/string.h
index b4c7c24..35177e2 100644
--- a/include/singa/utils/string.h
+++ b/include/singa/utils/string.h
@@ -84,7 +84,7 @@ class Tokenizer {
     auto pos = buf_.find_first_of(sep_, start);
     if (pos == std::string::npos)
       pos = buf_.length();
-    start_ = pos + 1;
+    start_ = (unsigned int)(pos + 1);
     out = buf_.substr(start, pos);
     return *this;
   }

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/37d3b39e/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index adafdf2..6704960 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -81,6 +81,7 @@ ENDFOREACH()
 ADD_LIBRARY(singa_objects OBJECT ${singa_sources})
 IF(WIN32) 
   IF (MSVC)
+	ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
 	#SET_TARGET_PROPERTIES(singa_objects 
 	#  PROPERTIES COMPILE_FLAGS "/wd4244 /wd4267 /wd4018 /wd4005 /wd4804 /wd4800")
   ENDIF()

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/37d3b39e/src/core/tensor/tensor.cc
----------------------------------------------------------------------
diff --git a/src/core/tensor/tensor.cc b/src/core/tensor/tensor.cc
index 40d85a2..d96b2ec 100644
--- a/src/core/tensor/tensor.cc
+++ b/src/core/tensor/tensor.cc
@@ -36,26 +36,26 @@ Tensor::Tensor(const Shape &shape, DataType dtype)
     : data_type_(dtype), device_(defaultDevice), shape_(shape) {
   size_t size = Product(shape_) * SizeOf(data_type_);
   if (size)
-    block_ = device_->NewBlock(size);
+    block_ = device_->NewBlock((int)size);
 }
 Tensor::Tensor(Shape &&shape, DataType dtype)
     : data_type_(dtype), device_(defaultDevice), shape_(shape) {
   size_t size = Product(shape_) * SizeOf(data_type_);
   if (size)
-    block_ = device_->NewBlock(size);
+    block_ = device_->NewBlock((int)size);
 }
 Tensor::Tensor(const Shape &shape, std::shared_ptr<Device> device,
                DataType dtype)
     : data_type_(dtype), device_(device), shape_(shape) {
   size_t size = Product(shape_) * SizeOf(data_type_);
   if (size)
-    block_ = device_->NewBlock(size);
+    block_ = device_->NewBlock((int)size);
 }
 Tensor::Tensor(Shape &&shape, std::shared_ptr<Device> device, DataType dtype)
     : data_type_(dtype), device_(device), shape_(shape) {
   size_t size = Product(shape_) * SizeOf(data_type_);
   if (size)
-    block_ = device_->NewBlock(size);
+    block_ = device_->NewBlock((int)size);
 }
 Tensor::Tensor(const Tensor &in)
     : transpose_(in.transpose_),
@@ -89,7 +89,7 @@ void Tensor::ResetLike(const Tensor &in) {
       device_->FreeBlock(block_);
     device_ = in.device_;
     data_type_ = in.data_type_;
-    block_ = device_->NewBlock(in.MemSize());
+    block_ = device_->NewBlock((int)in.MemSize());
   }
   shape_ = in.shape_;
 }
@@ -98,7 +98,7 @@ void Tensor::Reshape(const Shape &shape) {
   if (Product(shape_) != Product(shape)) {
     if (block_ != nullptr && block_->DecRefCount() == 0)
       device_->FreeBlock(block_);
-    block_ = device_->NewBlock(Product(shape) * SizeOf(data_type_));
+    block_ = device_->NewBlock((int)(Product(shape) * SizeOf(data_type_)));
   }
   shape_ = shape;
 }
@@ -107,7 +107,7 @@ void Tensor::Reshape(Shape &&shape) {
   if (Product(shape_) != Product(shape)) {
     if (block_ != nullptr && block_->DecRefCount() == 0)
       device_->FreeBlock(block_);
-    block_ = device_->NewBlock(Product(shape) * SizeOf(data_type_));
+    block_ = device_->NewBlock((int)(Product(shape) * SizeOf(data_type_)));
   }
   shape_ = std::move(shape);
 }
@@ -116,7 +116,7 @@ void Tensor::AsType(const DataType type) {
   if (data_type_ != type) {
     if (block_ != nullptr && block_->DecRefCount() == 0)
       device_->FreeBlock(block_);
-    block_ = device_->NewBlock(Product(shape_) * SizeOf(type));
+    block_ = device_->NewBlock((int)(Product(shape_) * SizeOf(type)));
     data_type_ = type;
   }
 }
@@ -182,20 +182,20 @@ void Tensor::FromProto(const singa::TensorProto &proto) {
     case kFloat32: {
       std::unique_ptr<float[]> data_ptr(new float[Product(shape_)]);
       for (size_t i = 0; i < Product(shape_); ++i)
-        data_ptr[i] = static_cast<float>(proto.float_data(i));
+        data_ptr[i] = static_cast<float>(proto.float_data((int)i));
       CopyDataFromHostPtr<float>(data_ptr.get(), Product(shape_));
       break;
     }
     case kDouble: {
       std::unique_ptr<double[]> data(new double[Product(shape_)]);
       for (size_t i = 0; i < Product(shape_); ++i)
-        data[i] = proto.double_data(i);
+        data[i] = proto.double_data((int)i);
       CopyDataFromHostPtr<double>(data.get(), Product(shape_));
       break;
     }
     case kInt: {
       std::unique_ptr<int[]> data(new int[Product(shape_)]);
-      for (size_t i = 0; i < Product(shape_); ++i) data[i] = proto.int_data(i);
+      for (size_t i = 0; i < Product(shape_); ++i) data[i] = proto.int_data((int)i);
       CopyDataFromHostPtr<int>(data.get(), Product(shape_));
       break;
     }
@@ -369,17 +369,17 @@ void CopyDataToFrom(Tensor *dst, const Tensor &src, const size_t num,
   if (dst_dev->lang() != src_dev->lang()) {
     // let the none cpp device conduct copy op
     if (dst_dev->lang() == kCpp) {
-      src_dev->CopyDataToFrom(to, from, nBytes, kDeviceToHost, d_offset,
-                              s_offset);
+      src_dev->CopyDataToFrom(to, from, nBytes, kDeviceToHost, (int)d_offset,
+                              (int)s_offset);
     } else if (src_dev->lang() == kCpp) {
-      dst_dev->CopyDataToFrom(to, from, nBytes, kHostToDevice, d_offset,
-                              s_offset);
+      dst_dev->CopyDataToFrom(to, from, nBytes, kHostToDevice, (int)d_offset,
+							  (int)s_offset);
     } else {
       LOG(FATAL) << "Not support mem copy betwee Cuda and OpenCL device";
     }
   } else {
     auto direct = src_dev->lang() == kCpp ? kHostToHost : kDeviceToDevice;
-    src_dev->CopyDataToFrom(to, from, nBytes, direct, d_offset, s_offset);
+    src_dev->CopyDataToFrom(to, from, nBytes, direct, (int)d_offset, (int)s_offset);
   }
 }
 //============================================================================

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/37d3b39e/src/core/tensor/tensor_math_cpp.h
----------------------------------------------------------------------
diff --git a/src/core/tensor/tensor_math_cpp.h b/src/core/tensor/tensor_math_cpp.h
index 8c8a40a..e978e8e 100644
--- a/src/core/tensor/tensor_math_cpp.h
+++ b/src/core/tensor/tensor_math_cpp.h
@@ -462,7 +462,7 @@ void GEMM<float, lang::Cpp>(const bool transA, const bool transB,
   const float *BPtr = static_cast<const float *>(B->data());
   float *CPtr = static_cast<float *>(C->mutable_data());
   cblas_sgemm(CblasRowMajor, transa, transb, nrowA, ncolB, ncolA, alpha, APtr,
-              lda, BPtr, ldb, beta, CPtr, ldc);
+	  lda, BPtr, ldb, beta, CPtr, ldc);
 }
 
 #else
@@ -597,7 +597,7 @@ void RowMax<float, lang::Cpp>(const size_t nrow, const size_t ncol,
   const float *inPtr = static_cast<const float *>(in->data());
   float *outPtr = static_cast<float *>(out->mutable_data());
   for (size_t r = 0; r < nrow; r++) {
-    int offset = r * ncol;
+    int offset = (int)(r * ncol);
     float maxval = inPtr[offset];
     for (size_t c = 1; c < ncol; c++)
       maxval = std::max(maxval, inPtr[offset + c]);

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/37d3b39e/src/io/binfile_reader.cc
----------------------------------------------------------------------
diff --git a/src/io/binfile_reader.cc b/src/io/binfile_reader.cc
index 9b52a5d..9167451 100644
--- a/src/io/binfile_reader.cc
+++ b/src/io/binfile_reader.cc
@@ -125,7 +125,7 @@ bool BinFileReader::PrepareNextField(int size) {
       return false;
     } else {
       fdat_.read(buf_ + bufsize_, capacity_ - bufsize_);
-      bufsize_ += fdat_.gcount();
+      bufsize_ += (int) fdat_.gcount();
       CHECK_LE(size, bufsize_) << "Field size is too large: " << size;
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/37d3b39e/src/io/binfile_writer.cc
----------------------------------------------------------------------
diff --git a/src/io/binfile_writer.cc b/src/io/binfile_writer.cc
index adc910e..1231c45 100644
--- a/src/io/binfile_writer.cc
+++ b/src/io/binfile_writer.cc
@@ -54,10 +54,10 @@ bool BinFileWriter::Write(const std::string& key, const std::string& value) {
   magic[3] = 0;
   if (key.size() == 0) {
     magic[2] = 0;
-    size = sizeof(magic) + sizeof(size_t) + value.size();
+    size = (int) (sizeof(magic) + sizeof(size_t) + value.size());
   } else {
     magic[2] = 1;
-    size = sizeof(magic) + 2 * sizeof(size_t) + key.size() + value.size();
+    size = (int) (sizeof(magic) + 2 * sizeof(size_t) + key.size() + value.size());
   }
 
   if (bufsize_ + size > capacity_) {
@@ -73,12 +73,12 @@ bool BinFileWriter::Write(const std::string& key, const std::string& value) {
     *reinterpret_cast<size_t*>(buf_ + bufsize_) = key.size();
     bufsize_ += sizeof(size_t);
     std::memcpy(buf_ + bufsize_, key.data(), key.size());
-    bufsize_ += key.size();
+    bufsize_ += (int) key.size();
   }
   *reinterpret_cast<size_t*>(buf_ + bufsize_) = value.size();
   bufsize_ += sizeof(size_t);
   std::memcpy(buf_ + bufsize_, value.data(), value.size());
-  bufsize_ += value.size();
+  bufsize_ += (int) value.size();
   return true;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/37d3b39e/src/model/feed_forward_net.cc
----------------------------------------------------------------------
diff --git a/src/model/feed_forward_net.cc b/src/model/feed_forward_net.cc
index c5c894e..ff781d5 100644
--- a/src/model/feed_forward_net.cc
+++ b/src/model/feed_forward_net.cc
@@ -146,7 +146,7 @@ void FeedForwardNet::Train(size_t batchsize, int nb_epoch, const Tensor& x,
                            const Tensor& y, const Tensor& val_x,
                            const Tensor& val_y) {
   CHECK_EQ(x.shape(0), y.shape(0)) << "Diff num of sampels in x and y";
-  int num_extra_samples = x.shape(0) % batchsize;
+  int num_extra_samples = (int)x.shape(0) % batchsize;
   if (num_extra_samples != 0)
     LOG(WARNING) << "Pls set batchsize to make num_total_samples "
                  << "% batchsize == 0. Otherwise, the last "
@@ -219,12 +219,12 @@ const vector<Tensor> FeedForwardNet::Backward(int flag, const Tensor& grad) {
   vector<Tensor> param_grads;
   std::stack<Tensor> buf;
   Tensor tmp = grad;
-  for (int i = layers_.size() - 1; i >= 0; i--) {
+  for (int i = (int)layers_.size() - 1; i >= 0; i--) {
     // LOG(INFO) << layers_.at(i)->name() << " : " << tmp.L1();
     auto ret = layers_.at(i)->Backward(flag, tmp);
     tmp = ret.first;
     if (ret.second.size()) {
-      for (int k = ret.second.size() - 1; k >= 0; k--) {
+      for (int k = (int)ret.second.size() - 1; k >= 0; k--) {
         buf.push(ret.second[k]);
         // LOG(INFO) <<  "      " << buf.top().L1();
       }
@@ -242,10 +242,10 @@ std::pair<Tensor, Tensor> FeedForwardNet::Evaluate(const Tensor& x,
                                                    size_t batchsize) {
   CHECK_EQ(x.shape(0), y.shape(0)) << "Diff num of sampels in x and y";
   CHECK_GE(x.shape(0), batchsize);
-  int num_extra_samples = x.shape(0) % batchsize;
+  int num_extra_samples = (int)x.shape(0) % batchsize;
   Tensor loss(Shape{x.shape(0)}), metric(Shape{x.shape(0)});
   for (size_t b = 0; b < x.shape(0) / batchsize; b++) {
-    int start = b * batchsize, end = start + batchsize;
+    int start = (int)(b * batchsize), end = (int)(start + batchsize);
     const Tensor bx = CopyRows(x, start, end);
     const Tensor by = CopyRows(y, start, end);
     const auto ret = EvaluateOnBatch(bx, by);
@@ -253,12 +253,12 @@ std::pair<Tensor, Tensor> FeedForwardNet::Evaluate(const Tensor& x,
     CopyDataToFrom(&metric, ret.second, batchsize, start, 0);
   }
   {
-    int start = x.shape(0) - batchsize, end = x.shape(0);
+    int start = (int)(x.shape(0) - batchsize), end = (int)x.shape(0);
     const Tensor bx = CopyRows(x, start, end);
     const Tensor by = CopyRows(y, start, end);
     const auto ret = EvaluateOnBatch(bx, by);
-    int dst_offset = x.shape(0) - num_extra_samples;
-    int src_offset = batchsize - num_extra_samples;
+    int dst_offset = (int)(x.shape(0) - num_extra_samples);
+    int src_offset = (int)(batchsize - num_extra_samples);
     CopyDataToFrom(&loss, ret.first, num_extra_samples, dst_offset, src_offset);
     CopyDataToFrom(&metric, ret.second, num_extra_samples, dst_offset,
                    src_offset);
@@ -277,17 +277,17 @@ std::pair<Tensor, Tensor> FeedForwardNet::EvaluateOnBatch(const Tensor& x,
 
 const Tensor FeedForwardNet::Predict(const Tensor& x, size_t batchsize) {
   CHECK_GE(x.shape(0), batchsize);
-  int num_extra_samples = x.shape(0) % batchsize;
+  int num_extra_samples = (int)(x.shape(0) % batchsize);
   const auto outshape = layers_.back()->GetOutputSampleShape();
   Tensor y(Shape{x.shape(0), Product(outshape)}, x.device());
   for (size_t b = 0; b < x.shape(0) / batchsize; b++) {
-    int start = b * batchsize, end = start + batchsize;
+    int start = (int)(b * batchsize), end = (int)(start + batchsize);
     const Tensor bx = CopyRows(x, start, end);
     CopyDataToFrom(&y, PredictOnBatch(bx), batchsize * y.shape(1),
                    start * y.shape(1), 0);
   }
   if (num_extra_samples > 0) {
-    int start = x.shape(0) - batchsize, end = x.shape(0);
+    int start = (int)(x.shape(0) - batchsize), end = (int)(x.shape(0));
     const Tensor bx = CopyRows(x, start, end);
     CopyDataToFrom(&y, PredictOnBatch(bx), num_extra_samples * y.shape(1),
                    (x.shape(0) - num_extra_samples) * y.shape(1),

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/37d3b39e/src/model/layer/convolution.cc
----------------------------------------------------------------------
diff --git a/src/model/layer/convolution.cc b/src/model/layer/convolution.cc
index bd7cc00..327d018 100644
--- a/src/model/layer/convolution.cc
+++ b/src/model/layer/convolution.cc
@@ -112,7 +112,7 @@ const Tensor Convolution::Forward(int flag, const Tensor &input) {
   auto in_data = input.data<float>();
   for (size_t b = 0; b < batchsize; b++) {
     Im2col(in_data + b * imagesize, channels_, height_, width_, kernel_h_,
-           kernel_w_, pad_h_, pad_w_, stride_h_, stride_w_, data_col);
+        kernel_w_, pad_h_, pad_w_, stride_h_, stride_w_, data_col);
     col_data.CopyDataFromHostPtr(data_col, col_height_ * col_width_);
     Tensor each = Mult(weight_, col_data);
     if (bias_term_) {
@@ -151,7 +151,7 @@ const std::pair<Tensor, vector<Tensor>> Convolution::Backward(
 
     SumRows(tmp3, &db);
   }
-  
+
   auto in_data = src_data.data<float>();
   Tensor col_data(Shape{col_height_, col_width_});
   float *data_col = new float[col_height_ * col_width_];
@@ -159,17 +159,15 @@ const std::pair<Tensor, vector<Tensor>> Convolution::Backward(
   for (size_t b = 0; b < batchsize; b++) {
     Im2col(in_data + b * imagesize, channels_, height_, width_, kernel_h_,
            kernel_w_, pad_h_, pad_w_, stride_h_, stride_w_, data_col);
-    
+
     col_data.CopyDataFromHostPtr(data_col, col_height_ * col_width_);
     Tensor grad_b(Shape{num_filters_, conv_height_ * conv_width_});
     CopyDataToFrom(&grad_b, grad, grad_b.Size(), 0, b * grad_b.Size());
     dw += Mult(grad_b, col_data.T());
     Tensor dcol_b = Mult(weight_.T(), grad_b);
     auto dcol_data = dcol_b.data<float>();
-    
     Col2im(dcol_data, channels_, height_, width_, kernel_h_, kernel_w_, pad_h_,
            pad_w_, stride_h_, stride_w_, dx_b);
-    
     dx.CopyDataFromHostPtr(dx_b, imagesize, b * imagesize);
   }
   param_grad.push_back(dw);

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/37d3b39e/src/model/layer/pooling.cc
----------------------------------------------------------------------
diff --git a/src/model/layer/pooling.cc b/src/model/layer/pooling.cc
index cf42891..2ddfc1c 100644
--- a/src/model/layer/pooling.cc
+++ b/src/model/layer/pooling.cc
@@ -108,14 +108,14 @@ const std::pair<Tensor, vector<Tensor>>
 Pooling::Backward(int flag, const Tensor& grad) {
   CHECK_EQ(grad.device()->lang(), kCpp);
   CHECK_EQ(grad.nDim(), 4u);
-  
+
   vector<Tensor> param_grad;
-  
+
   auto batchsize = grad.shape(0);
   auto dtype = grad.data_type();
   auto dev = grad.device();
   Shape shape{batchsize, channels_, height_, width_};
-  
+
   Tensor dx(shape, dev, dtype);
   auto gradptr = grad.data<float>();
   float* dxptr = new float[dx.Size()];
@@ -190,7 +190,7 @@ void Pooling::ForwardMaxPooling(const float* bottom, const int num,
 void Pooling::BackwardMaxPooling(const float* top, const float* mask,
                                  const int num, const int channels,
                                  const int height, const int width,
-                                 const int pooled_h, const int pooled_w, 
+                                 const int pooled_h, const int pooled_w,
                                  const int kernel_h, const int kernel_w,
                                  const int pad_h, const int pad_w,
                                  const int stride_h, const int stride_w,
@@ -215,7 +215,7 @@ void Pooling::BackwardMaxPooling(const float* top, const float* mask,
 }
 
 void Pooling::ForwardAvgPooling(const float* bottom, const int num,
-                                const int channels, 
+                                const int channels,
                                 const int height, const int width,
                                 const int pooled_h, const int pooled_w,
                                 const int kernel_h, const int kernel_w,
@@ -261,7 +261,7 @@ void Pooling::ForwardAvgPooling(const float* bottom, const int num,
 
 void Pooling::BackwardAvgPooling(const float* top, const int num,
                                  const int channels,
-                                 const int height, const int width, 
+                                 const int height, const int width,
                                  const int pooled_h, const int pooled_w,
                                  const int kernel_h, const int kernel_w,
                                  const int pad_h, const int pad_w,

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/37d3b39e/src/utils/logging.cc
----------------------------------------------------------------------
diff --git a/src/utils/logging.cc b/src/utils/logging.cc
index 50fa7dc..304d431 100644
--- a/src/utils/logging.cc
+++ b/src/utils/logging.cc
@@ -23,8 +23,11 @@
 
 #include <stdlib.h>
 #include <sys/types.h>
-//#include <unistd.h>
+#ifdef _MSC_VER
 #include <io.h>
+#else
+#include <unistd.h>
+#endif
 
 namespace singa {
 


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

Posted by wa...@apache.org.
SINGA-247 Add windows support for singa.

Update installation.md to guide the user in Windows platform.


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

Branch: refs/heads/master
Commit: 6c9e0b4a3a3a33f178c554722856c29eb926fba4
Parents: af30903
Author: xiezl <xi...@comp.nus.edu.sg>
Authored: Thu Sep 22 17:29:50 2016 +0800
Committer: Wei Wang <wa...@comp.nus.edu.sg>
Committed: Mon Oct 10 17:44:53 2016 +0800

----------------------------------------------------------------------
 doc/en/docs/installation.md | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/6c9e0b4a/doc/en/docs/installation.md
----------------------------------------------------------------------
diff --git a/doc/en/docs/installation.md b/doc/en/docs/installation.md
index e4b76c0..a797c57 100755
--- a/doc/en/docs/installation.md
+++ b/doc/en/docs/installation.md
@@ -215,8 +215,45 @@ To build SINGA with OpenCL support, you need to pass the flag during cmake:
     cmake .. -DUSE_OPENCL=ON
 
 ### Windows
-To be added.
 
+The compiler used for windows can ONLY be 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](doc/en/docs/dependencies.md).
+After all the
+dependencies are successfully installed, just run the following commands to
+generate the VS project in cmd under singa folder:
+
+    $ md build && cd build
+    $ 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
+specify a 64-bit version project by:
+
+    $ md build && cd build
+    $ cmake -G "Visual Studio 14 Win64" -DUSE_CUDA=OFF -DUSE_PYTHON=OFF ..
+
+If you get error outputs like "Could NOT find xxxxx" indicating a dependent
+library missing, please configure your library file and include path for cmake or the system.
+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"
+
+To find out the parameters you need to specify for some special libraries, you
+can run the following command:
+
+    $ cmake -LAH
+
+After generating the VS project, please open the "singa.sln" project file under
+the "build" folder and compile it via a normal VS project. You will find the
+unit tests file named "test_singa" in the project binary folder.
 
 ## FAQ
 


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

Posted by wa...@apache.org.
SINGA-247 Add windows support for singa

Remove dynamic lib generation on windows.
Fix some warnings and a typo in instructions.


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

Branch: refs/heads/master
Commit: 901e885b18f430205397a79e740d72cffb63712c
Parents: 8531af5
Author: xiezl <xi...@comp.nus.edu.sg>
Authored: Wed Oct 5 21:04:32 2016 +0800
Committer: Wei Wang <wa...@comp.nus.edu.sg>
Committed: Mon Oct 10 17:44:54 2016 +0800

----------------------------------------------------------------------
 cmake/Templates/singa_config.h.in       |  2 --
 doc/en/docs/dependencies.md             |  2 +-
 src/CMakeLists.txt                      | 18 +++++++++++-------
 src/core/device/opencl_device.cc        |  6 ++++--
 src/core/device/platform.cc             |  6 +++++-
 src/core/memory/memory.cc               |  5 +++--
 src/core/tensor/sparse_tensor.cc        |  2 --
 src/io/jpg_decoder.cc                   |  6 +++++-
 src/io/jpg_encoder.cc                   |  6 +++++-
 src/io/lmdb_reader.cc                   |  6 +++++-
 src/io/lmdb_writer.cc                   |  7 +++++--
 src/model/optimizer/local_all_reduce.cc |  2 --
 test/CMakeLists.txt                     |  4 ++--
 test/singa/test_accuracy.cc             |  2 +-
 test/singa/test_activation.cc           |  2 +-
 test/singa/test_adagrad.cc              |  4 ++--
 test/singa/test_batchnorm.cc            |  2 +-
 test/singa/test_cross_entropy.cc        |  2 +-
 test/singa/test_csv.cc                  |  2 +-
 test/singa/test_dropout.cc              |  2 +-
 test/singa/test_image_transformer.cc    |  8 ++++----
 test/singa/test_lrn.cc                  | 16 ++++++++--------
 test/singa/test_mse.cc                  |  2 +-
 test/singa/test_nesterov.cc             |  4 ++--
 test/singa/test_rmsprop.cc              |  8 ++++----
 test/singa/test_sgd.cc                  |  8 ++++----
 test/singa/test_snapshot.cc             |  4 ++--
 test/singa/test_tensor_math.cc          |  2 +-
 28 files changed, 80 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


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

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/doc/en/docs/dependencies.md
----------------------------------------------------------------------
diff --git a/doc/en/docs/dependencies.md b/doc/en/docs/dependencies.md
index d7da27d..5216900 100644
--- a/doc/en/docs/dependencies.md
+++ b/doc/en/docs/dependencies.md
@@ -56,7 +56,7 @@ Step 5: Done.
 ### CBLAS
 
 There are ready-to-use binary packages online
-([link](https://sourceforge.net/projects/openblas/files/). However, we still install
+([link](https://sourceforge.net/projects/openblas/files/)). However, we still install
 OpenBLAS with version 0.2.18 as test:
 
 Step 1: Download and decompress the source code.

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ce3e792..b9526a3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -79,19 +79,23 @@ ENDFOREACH()
 
 ADD_LIBRARY(singa_objects OBJECT ${singa_sources})
 IF(WIN32) 
+  ADD_LIBRARY(singa STATIC $<TARGET_OBJECTS:singa_objects> ${cuda_objs})
+  TARGET_LINK_LIBRARIES(singa ${SINGA_LINKER_LIBS})
   IF (MSVC)
 	ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
-	#SET_TARGET_PROPERTIES(singa_objects 
-	#  PROPERTIES COMPILE_FLAGS "/wd4244 /wd4267 /wd4018 /wd4005 /wd4804 /wd4800")
+	IF(DISABLE_WARNINGS)
+	  ADD_DEFINITIONS(-DDISABLE_WARNINGS)
+	  SET_TARGET_PROPERTIES(singa_objects 
+	    PROPERTIES COMPILE_FLAGS "/wd4244 /wd4267 /wd4018 /wd4005 /wd4804 /wd4800")
+	ENDIF()
   ENDIF()
 ENDIF()
 ADD_DEPENDENCIES(singa_objects copy_protobuf)
 
-ADD_LIBRARY(singa SHARED $<TARGET_OBJECTS:singa_objects> ${cuda_objs})
-TARGET_LINK_LIBRARIES(singa ${SINGA_LINKER_LIBS})
-
-ADD_LIBRARY(singa_static STATIC $<TARGET_OBJECTS:singa_objects> ${cuda_objs})
-TARGET_LINK_LIBRARIES(singa_static ${SINGA_LINKER_LIBS})
+IF(UNIX OR APPLE)
+  ADD_LIBRARY(singa SHARED $<TARGET_OBJECTS:singa_objects> ${cuda_objs})
+  TARGET_LINK_LIBRARIES(singa ${SINGA_LINKER_LIBS})
+ENDIF()
 
 #pass configure infor to swig 
 FILE(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/api/config.i")

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/src/core/device/opencl_device.cc
----------------------------------------------------------------------
diff --git a/src/core/device/opencl_device.cc b/src/core/device/opencl_device.cc
index c9c2211..e0d4ff3 100644
--- a/src/core/device/opencl_device.cc
+++ b/src/core/device/opencl_device.cc
@@ -15,8 +15,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-#ifdef USE_OPENCL
+#ifndef DISABLE_WARNINGS
 
 #include <iostream>
 #include <fstream>
@@ -27,6 +26,7 @@
 #include "singa/utils/tinydir.h"
 #include "singa/utils/opencl_utils.h"
 
+#ifdef USE_OPENCL
 
 using namespace viennacl;
 using namespace viennacl::backend::opencl;
@@ -170,3 +170,5 @@ void OpenclDevice::Free(void* p) {
 } // namespace singa
 
 #endif // USE_OPENCL
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/src/core/device/platform.cc
----------------------------------------------------------------------
diff --git a/src/core/device/platform.cc b/src/core/device/platform.cc
index 3392492..eb02c5b 100644
--- a/src/core/device/platform.cc
+++ b/src/core/device/platform.cc
@@ -15,11 +15,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifdef USE_CUDA
+#ifndef DISABLE_WARNINGS
 
 #include "singa/core/device.h"
 #include "singa/singa_config.h"
 
+#ifdef USE_CUDA
+
 namespace singa {
 
 int Platform::GetNumGPUs() {
@@ -138,3 +140,5 @@ Platform::CreateCudaGPUsOn(const vector<int> &devices, size_t init_size) {
 }  // namespace singa
 
 #endif  // USE_CUDA
+
+#endif
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/src/core/memory/memory.cc
----------------------------------------------------------------------
diff --git a/src/core/memory/memory.cc b/src/core/memory/memory.cc
index 2dd1cbe..0fb8511 100644
--- a/src/core/memory/memory.cc
+++ b/src/core/memory/memory.cc
@@ -17,12 +17,13 @@
  */
 #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() {
@@ -111,4 +112,4 @@ void CudaMemPool::Free(void *ptr) {
 }
 #endif
 
-#endif
\ No newline at end of file
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/src/core/tensor/sparse_tensor.cc
----------------------------------------------------------------------
diff --git a/src/core/tensor/sparse_tensor.cc b/src/core/tensor/sparse_tensor.cc
index 68021d1..46ea850 100644
--- a/src/core/tensor/sparse_tensor.cc
+++ b/src/core/tensor/sparse_tensor.cc
@@ -15,8 +15,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "singa/singa_config.h"
-
 #ifndef DISABLE_WARNINGS
 
 #include "singa/core/tensor.h"

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/src/io/jpg_decoder.cc
----------------------------------------------------------------------
diff --git a/src/io/jpg_decoder.cc b/src/io/jpg_decoder.cc
index e0d458c..c6aca19 100644
--- a/src/io/jpg_decoder.cc
+++ b/src/io/jpg_decoder.cc
@@ -15,10 +15,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifdef USE_OPENCV
+#ifndef DISABLE_WARNINGS
 
 #include "singa/io/decoder.h"
 
+#ifdef USE_OPENCV
+
 #include <opencv2/highgui/highgui.hpp>
 #include <opencv2/imgproc/imgproc.hpp>
 
@@ -72,3 +74,5 @@ std::vector<Tensor> JPGDecoder::Decode(std::string value) {
 }
 }  // namespace singa
 #endif
+
+#endif
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/src/io/jpg_encoder.cc
----------------------------------------------------------------------
diff --git a/src/io/jpg_encoder.cc b/src/io/jpg_encoder.cc
index 4a4ee85..e4ab144 100644
--- a/src/io/jpg_encoder.cc
+++ b/src/io/jpg_encoder.cc
@@ -15,10 +15,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifdef USE_OPENCV
+#ifndef DISABLE_WARNINGS
 
 #include "singa/io/encoder.h"
 
+#ifdef USE_OPENCV
+
 #include <opencv2/highgui/highgui.hpp>
 #include <opencv2/imgproc/imgproc.hpp>
 
@@ -81,3 +83,5 @@ std::string JPGEncoder::Encode(vector<Tensor>& data) {
 }
 }  // namespace singa
 #endif  // USE_OPENCV
+
+#endif
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/src/io/lmdb_reader.cc
----------------------------------------------------------------------
diff --git a/src/io/lmdb_reader.cc b/src/io/lmdb_reader.cc
index 8bb82c0..44b097c 100644
--- a/src/io/lmdb_reader.cc
+++ b/src/io/lmdb_reader.cc
@@ -15,11 +15,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifdef USE_LMDB
+#ifndef DISABLE_WARNINGS
 
 #include "singa/io/reader.h"
 #include "singa/utils/logging.h"
 
+#ifdef USE_LMDB
+
 namespace singa {
 namespace io {
 bool LMDBReader::Open(const std::string& path) {
@@ -116,3 +118,5 @@ inline void LMDBReader::MDB_CHECK(int mdb_status) {
 }  // namespace io
 }  // namespace singa
 #endif  // USE_LMDB
+
+#endif
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/src/io/lmdb_writer.cc
----------------------------------------------------------------------
diff --git a/src/io/lmdb_writer.cc b/src/io/lmdb_writer.cc
index 3e6d5f8..ec0e002 100644
--- a/src/io/lmdb_writer.cc
+++ b/src/io/lmdb_writer.cc
@@ -15,12 +15,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-#ifdef USE_LMDB
+#ifndef DISABLE_WARNINGS
 
 #include "singa/io/writer.h"
 #include "singa/utils/logging.h"
 
+#ifdef USE_LMDB
+
 namespace singa {
 namespace io {
 bool LMDBWriter::Open(const std::string& path, Mode mode) {
@@ -132,3 +133,5 @@ inline void LMDBWriter::MDB_CHECK(int mdb_status) {
 }  // namespace io
 }  // namespace singa
 #endif  // USE_LMDB
+
+#endif
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/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 e496efa..9cda321 100644
--- a/src/model/optimizer/local_all_reduce.cc
+++ b/src/model/optimizer/local_all_reduce.cc
@@ -15,8 +15,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "singa/singa_config.h"
-
 #ifndef DISABLE_WARNINGS
 
 #ifndef SRC_MODEL_OPTIMIZER_LOCAL_ALL_REDUCE_H_

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index a996413..e1487d2 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -31,9 +31,9 @@ AUX_SOURCE_DIRECTORY(singa singa_test_source)
 LIST(REMOVE_ITEM singa_test_source "singa/test_ep.cc")
 
 ADD_EXECUTABLE(test_singa "gtest/gtest_main.cc" ${singa_test_source})
-ADD_DEPENDENCIES(test_singa singa_static)
+ADD_DEPENDENCIES(test_singa singa)
 #MESSAGE(STATUS "link libs" ${singa_linker_libs})
-TARGET_LINK_LIBRARIES(test_singa gtest singa_static ${SINGA_LINKER_LIBS})
+TARGET_LINK_LIBRARIES(test_singa gtest singa ${SINGA_LINKER_LIBS})
 IF(UNIX AND (NOT APPLE))
     LIST(APPEND LINK_FLAGS "-pthread")
 ENDIF()

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_accuracy.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_accuracy.cc b/test/singa/test_accuracy.cc
index 5d337fb..5b8067d 100644
--- a/test/singa/test_accuracy.cc
+++ b/test/singa/test_accuracy.cc
@@ -26,7 +26,7 @@ TEST(Accuracy, Compute) {
   singa::Accuracy acc;
   singa::Tensor p(singa::Shape{2, 3});
   singa::Tensor t(singa::Shape{2}, singa::kInt);
-  const float pdat[6] = {0.1, 0.3, 0.6, 0.3, 0.2, 0.5};
+  const float pdat[6] = {0.1f, 0.3f, 0.6f, 0.3f, 0.2f, 0.5f};
   const int tdat[2] = {1, 2};  // one wrong, one correct
   p.CopyDataFromHostPtr(pdat, sizeof(pdat) / sizeof(float));
   t.CopyDataFromHostPtr(tdat, sizeof(tdat) / sizeof(int));

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_activation.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_activation.cc b/test/singa/test_activation.cc
index bb8ad84..ee7a44e 100644
--- a/test/singa/test_activation.cc
+++ b/test/singa/test_activation.cc
@@ -116,7 +116,7 @@ TEST(Activation, Backward) {
     float* dx = new float[n];
     if (acti.Mode() == "sigmoid") {
       for (size_t i = 0; i < n; i++)
-        dx[i] = grad[i] * yptr[i] * (1. - yptr[i]);
+        dx[i] = grad[i] * yptr[i] * (1.0f - yptr[i]);
     }
     else if (acti.Mode() == "tanh") {
       for (size_t i = 0; i < n; i++)

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_adagrad.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_adagrad.cc b/test/singa/test_adagrad.cc
index f12ec68..7408411 100644
--- a/test/singa/test_adagrad.cc
+++ b/test/singa/test_adagrad.cc
@@ -27,8 +27,8 @@
 TEST(AdaGrad, ApplyCPU) {
   singa::AdaGrad adagrad;
   float lr = 0.1f;
-  const float v[4] = {0.1, 0.2, 0.3, 0.4};
-  const float g[4] = {0.01, 0.02, 0.03, 0.04};
+  const float v[4] = {0.1f, 0.2f, 0.3f, 0.4f};
+  const float g[4] = {0.01f, 0.02f, 0.03f, 0.04f};
 
   singa::Tensor value(singa::Shape{4}), grad(singa::Shape{4});
   value.CopyDataFromHostPtr(v, 4);

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_batchnorm.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_batchnorm.cc b/test/singa/test_batchnorm.cc
index a61f6f3..c8efbf9 100644
--- a/test/singa/test_batchnorm.cc
+++ b/test/singa/test_batchnorm.cc
@@ -34,7 +34,7 @@ TEST(BatchNorm, Setup) {
   batchnorm_conf->set_factor(0.01);
   batchnorm.Setup(Shape{2, 4, 4}, conf);
 
-  EXPECT_FLOAT_EQ(0.01, batchnorm.factor());
+  EXPECT_FLOAT_EQ(0.01f, batchnorm.factor());
   EXPECT_EQ(2u, batchnorm.channels());
   EXPECT_EQ(4u, batchnorm.height());
   EXPECT_EQ(4u, batchnorm.width());

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_cross_entropy.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_cross_entropy.cc b/test/singa/test_cross_entropy.cc
index 8235766..d63695e 100644
--- a/test/singa/test_cross_entropy.cc
+++ b/test/singa/test_cross_entropy.cc
@@ -47,7 +47,7 @@ TEST_F(TestSoftmaxCrossEntropy, CppForward) {
   const Tensor& loss = cross_entropy.Forward(singa::kEval, p, t);
   auto ldat = loss.data<float>();
 
-  const float result_test = -log(0.25);
+  const float result_test = (float) -log(0.25);
   EXPECT_FLOAT_EQ(ldat[0], result_test);
   EXPECT_FLOAT_EQ(ldat[1], result_test);
 }

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_csv.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_csv.cc b/test/singa/test_csv.cc
index d8dbe69..77f5baa 100644
--- a/test/singa/test_csv.cc
+++ b/test/singa/test_csv.cc
@@ -36,7 +36,7 @@ TEST(CSV, EncoderDecode) {
   decoder.Setup(decoder_conf);
   EXPECT_EQ(true, decoder.has_label());
 
-  float in_data[] = {1.23, 4.5, 5.1, 3.33, 0.44};
+  float in_data[] = {1.23f, 4.5f, 5.1f, 3.33f, 0.44f};
   std::string in_str = "2, 1.23, 4.5, 5.1, 3.33, 0.44";
   int in_label = 2;
   size_t size = 5;

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_dropout.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_dropout.cc b/test/singa/test_dropout.cc
index b0c34a3..047762e 100644
--- a/test/singa/test_dropout.cc
+++ b/test/singa/test_dropout.cc
@@ -30,7 +30,7 @@ TEST(Dropout, Setup) {
 
   singa::LayerConf conf;
   singa::DropoutConf* dropconf = conf.mutable_dropout_conf();
-  dropconf->set_dropout_ratio(0.8);
+  dropconf->set_dropout_ratio(0.8f);
 
   drop.Setup(Shape{3}, conf);
   EXPECT_EQ(0.8f, drop.dropout_ratio());

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_image_transformer.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_image_transformer.cc b/test/singa/test_image_transformer.cc
index 4540aa8..016da72 100644
--- a/test/singa/test_image_transformer.cc
+++ b/test/singa/test_image_transformer.cc
@@ -58,7 +58,7 @@ TEST(ImageTransformer, Apply3D) {
   float* x = new float[n];
   size_t channel = 3, height = 6, width = 10;
   singa::Tensor in(singa::Shape{height, width, channel});
-  srand(time(NULL));
+  srand((unsigned int)time(NULL));
   for (size_t i = 0; i < n; i++) x[i] = (float)(rand() % 256);
   in.CopyDataFromHostPtr<float>(x, n);
   int resize_height = 4, resize_width = 6;
@@ -125,7 +125,7 @@ TEST(ImageTransformer, Apply2D) {
   float* x = new float[n];
   size_t height = 6, width = 10;
   singa::Tensor in(singa::Shape{height, width});
-  srand(time(NULL));
+  srand((unsigned int)time(NULL));
   for (size_t i = 0; i < n; i++) x[i] = (float)(rand() % 256);
   in.CopyDataFromHostPtr<float>(x, n);
   int resize_height = 4, resize_width = 6;
@@ -219,7 +219,7 @@ TEST(ImageTransformer, Crop) {
   float* x = new float[n];
   size_t channel = 3, height = 6, width = 10;
   singa::Tensor in(singa::Shape{channel, height, width});
-  srand(time(NULL));
+  srand((unsigned int)time(NULL));
   for (size_t i = 0; i < n; i++) x[i] = (float)(rand() % 256);
   in.CopyDataFromHostPtr<float>(x, n);
   size_t crop_height = 3, crop_width = 4,
@@ -244,7 +244,7 @@ TEST(ImageTransformer, Mirror) {
   float* x = new float[n];
   size_t channel = 3, height = 2, width = 5;
   singa::Tensor in(singa::Shape{height, width, channel});
-  srand(time(NULL));
+  srand((unsigned int)time(NULL));
   for (size_t i = 0; i < n; i++) x[i] = (float)(rand() % 256);
   in.CopyDataFromHostPtr<float>(x, n);
   singa::Tensor out = singa::mirror(in, true, false, "HWC");

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_lrn.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_lrn.cc b/test/singa/test_lrn.cc
index 454e1a9..6a389e1 100644
--- a/test/singa/test_lrn.cc
+++ b/test/singa/test_lrn.cc
@@ -32,14 +32,14 @@ TEST(LRN, Setup) {
   LRNConf *lrn_conf = conf.mutable_lrn_conf();
   lrn_conf->set_k(1.0);
   lrn_conf->set_local_size(3);
-  lrn_conf->set_alpha(0.1);
-  lrn_conf->set_beta(0.75);
+  lrn_conf->set_alpha(0.1f);
+  lrn_conf->set_beta(0.75f);
   lrn.Setup(Shape{1}, conf);
 
   EXPECT_FLOAT_EQ(1.0, lrn.k());
   EXPECT_EQ(3, lrn.local_size());
-  EXPECT_FLOAT_EQ(0.1, lrn.alpha());
-  EXPECT_FLOAT_EQ(0.75, lrn.beta());
+  EXPECT_FLOAT_EQ(0.1f, lrn.alpha());
+  EXPECT_FLOAT_EQ(0.75f, lrn.beta());
 }
 
 TEST(LRN, Forward) {
@@ -52,8 +52,8 @@ TEST(LRN, Forward) {
   singa::LRNConf *lrn_conf = conf.mutable_lrn_conf();
   lrn_conf->set_k(1.0);
   lrn_conf->set_local_size(3);
-  lrn_conf->set_alpha(0.1);
-  lrn_conf->set_beta(0.75);
+  lrn_conf->set_alpha(0.1f);
+  lrn_conf->set_beta(0.75f);
   lrn.Setup(Shape{4, 1, 1}, conf);
 
   Tensor out = lrn.Forward(kTrain, in);
@@ -85,8 +85,8 @@ TEST(LRN, Backward) {
   singa::LRNConf *lrn_conf = conf.mutable_lrn_conf();
   lrn_conf->set_k(1.0);
   lrn_conf->set_local_size(3);
-  lrn_conf->set_alpha(0.1);
-  lrn_conf->set_beta(0.75);
+  lrn_conf->set_alpha(0.1f);
+  lrn_conf->set_beta(0.75f);
   lrn.Setup(Shape{4, 1, 1}, conf);
 
   Tensor out = lrn.Forward(kTrain, in);

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_mse.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_mse.cc b/test/singa/test_mse.cc
index 9cf0e9c..7aa3326 100644
--- a/test/singa/test_mse.cc
+++ b/test/singa/test_mse.cc
@@ -51,7 +51,7 @@ TEST_F(TestMSE, CppForward) {
       l += (pdat[k] - tdat[k]) * (pdat[k] - tdat[k]);
       k++;
     }
-    EXPECT_FLOAT_EQ(ldat[i], 0.5 * l);
+    EXPECT_FLOAT_EQ(ldat[i], 0.5f * l);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_nesterov.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_nesterov.cc b/test/singa/test_nesterov.cc
index 7c76784..3ae3181 100644
--- a/test/singa/test_nesterov.cc
+++ b/test/singa/test_nesterov.cc
@@ -28,8 +28,8 @@ TEST(Nesterov, ApplyCPU) {
   float lr = 0.1f;
   auto func = [](int step) { return step <= 5 ? 0.5f : 0.9f; };
   nesterov.SetMomentumGenerator(func);
-  const float v[4] = {0.1, 0.2, 0.3, 0.4};
-  const float g[4] = {0.01, 0.02, 0.03, 0.04};
+  const float v[4] = {0.1f, 0.2f, 0.3f, 0.4f};
+  const float g[4] = {0.01f, 0.02f, 0.03f, 0.04f};
 
   singa::Tensor value(singa::Shape{4}), grad(singa::Shape{4});
   value.CopyDataFromHostPtr(v, 4);

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_rmsprop.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_rmsprop.cc b/test/singa/test_rmsprop.cc
index d259592..f398355 100644
--- a/test/singa/test_rmsprop.cc
+++ b/test/singa/test_rmsprop.cc
@@ -26,13 +26,13 @@
 TEST(RMSProp, ApplyCPU) {
   singa::RMSProp rmsprop;
   float lr = 0.1f;
-  float rho = 0.9;
-  const float v[4] = {0.1, 0.2, 0.3, 0.4};
-  const float g[4] = {0.01, 0.02, 0.03, 0.04};
+  float rho = 0.9f;
+  const float v[4] = {0.1f, 0.2f, 0.3f, 0.4f};
+  const float g[4] = {0.01f, 0.02f, 0.03f, 0.04f};
 
   singa::OptimizerConf conf;
   conf.set_rho(rho);
-  conf.set_delta(1E-8);
+  conf.set_delta(1E-8f);
 
   singa::Tensor value(singa::Shape{4}), grad(singa::Shape{4});
   value.CopyDataFromHostPtr(v, 4);

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_sgd.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_sgd.cc b/test/singa/test_sgd.cc
index e6ed9bf..c25dfbd 100644
--- a/test/singa/test_sgd.cc
+++ b/test/singa/test_sgd.cc
@@ -25,8 +25,8 @@
 
 TEST(SGD, ApplyWithoutMomentum) {
   singa::SGD sgd;
-  const float v[4] = {0.1, 0.2, 0.3, 0.4};
-  const float g[4] = {0.1, 0.1, 0.1, 0.1};
+  const float v[4] = {0.1f, 0.2f, 0.3f, 0.4f};
+  const float g[4] = {0.1f, 0.1f, 0.1f, 0.1f};
 
   singa::Tensor value(singa::Shape{4}), grad(singa::Shape{4});
   value.CopyDataFromHostPtr(v, 4);
@@ -58,8 +58,8 @@ TEST(SGD, ApplyWithMomentum) {
   float lr = 0.1f;
   auto func = [](int step) { return step <=5 ? 0.5f: 0.9f;};
   sgd.SetMomentumGenerator(func);
-  const float v[4] = {0.1, 0.2, 0.3, 0.4};
-  const float g[4] = {0.01, 0.02, 0.03, 0.04};
+  const float v[4] = {0.1f, 0.2f, 0.3f, 0.4f};
+  const float g[4] = {0.01f, 0.02f, 0.03f, 0.04f};
 
   singa::Tensor value(singa::Shape{4}), grad(singa::Shape{4});
   value.CopyDataFromHostPtr(v, 4);

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_snapshot.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_snapshot.cc b/test/singa/test_snapshot.cc
index 33b57b9..a9e8ee6 100644
--- a/test/singa/test_snapshot.cc
+++ b/test/singa/test_snapshot.cc
@@ -28,8 +28,8 @@
 #include <fstream>
 
 const std::string prefix = "./snapshot_test";
-const float param_1_data[] = {0.1, 0.2, 0.3, 0.4};
-const float param_2_data[] = {0.2, 0.1, 0.4, 0.3};
+const float param_1_data[] = {0.1f, 0.2f, 0.3f, 0.4f};
+const float param_2_data[] = {0.2f, 0.1f, 0.4f, 0.3f};
 const std::string desc_1 =
     "parameter name: Param_1\tdata type: 0\tdim: 1\tshape: 4";
 const std::string desc_2 =

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/901e885b/test/singa/test_tensor_math.cc
----------------------------------------------------------------------
diff --git a/test/singa/test_tensor_math.cc b/test/singa/test_tensor_math.cc
index 267905d..c3a1039 100644
--- a/test/singa/test_tensor_math.cc
+++ b/test/singa/test_tensor_math.cc
@@ -152,7 +152,7 @@ TEST_F(TestTensorMath, SoftMax) {
   Tensor p1 = SoftMax(Reshape(e, Shape{1, 6}));
   const float *dptr1 = p1.data<float>();
   float sum = 0;
-  for (int i = 0; i < 6; i++) sum += exp(i + 1);
+  for (int i = 0; i < 6; i++) sum += (float)exp(i + 1);
   EXPECT_NEAR(exp(1) / sum, dptr1[0], 1e-5);
   EXPECT_NEAR(exp(3) / sum, dptr1[2], 1e-5);
   EXPECT_NEAR(exp(5) / sum, dptr1[4], 1e-5);


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

Posted by wa...@apache.org.
SINGA-247 Add windows support for singa

Update instructions.


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

Branch: refs/heads/master
Commit: 8531af5723cbc917af9f6378178fea39fb258f95
Parents: 6c9e0b4
Author: xiezl <xi...@comp.nus.edu.sg>
Authored: Fri Sep 23 23:51:26 2016 +0800
Committer: Wei Wang <wa...@comp.nus.edu.sg>
Committed: Mon Oct 10 17:44:53 2016 +0800

----------------------------------------------------------------------
 cmake/Dependencies.cmake    |  1 +
 doc/en/docs/dependencies.md | 79 ++++++++++++++++++++++++++++++++++++++++
 doc/en/docs/installation.md | 13 ++++---
 src/CMakeLists.txt          |  1 -
 4 files changed, 87 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/8531af57/cmake/Dependencies.cmake
----------------------------------------------------------------------
diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
index 5f3d6a7..d9dbae7 100644
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -31,6 +31,7 @@ IF(GLOG_FOUND)
     MESSAGE(STATUS "GLOG FOUND at ${GLOG_INCLUDE_DIR}")
     ADD_DEFINITIONS("-DUSE_GLOG")
     LIST(APPEND SINGA_LINKER_LIBS ${GLOG_LIBRARIES})
+	INCLUDE_DIRECTORIES(${GLOG_INCLUDE_DIR})
 ENDIF()
 
 IF(USE_LMDB)

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/8531af57/doc/en/docs/dependencies.md
----------------------------------------------------------------------
diff --git a/doc/en/docs/dependencies.md b/doc/en/docs/dependencies.md
new file mode 100644
index 0000000..d7da27d
--- /dev/null
+++ b/doc/en/docs/dependencies.md
@@ -0,0 +1,79 @@
+# Dependent library installation
+
+## 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
+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
+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). 
+
+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. 
+
+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).
+Copy all the generated library files into the installation library folder (or
+system folder).
+
+Step 4: Done.
+
+### Google protobuf 
+
+Tested on version 2.6.1:
+
+Step 1: Download and decompress the source code.
+
+Step 2: Open "protobuf.sln" file under "vsprojects" 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 "libprotobuf", "libprotobuf-lite", "libprotoc" and
+"protoc" projects.
+
+Step 3: Run "extract_includes.bat" script under "vsprojects" folder, you will
+get a new "include" folder with all the headers.
+
+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).
+
+Step 5: Done.
+
+### CBLAS
+
+There are ready-to-use binary packages online
+([link](https://sourceforge.net/projects/openblas/files/). However, we still install
+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: 
+
+    $ md build $$ cd build
+    $ cmake -G "Visual Studio 14" ..
+
+Or run `cmake -G "Visual Studio 14 Win64"` as you wish.
+
+Step 3: Install Perl into your system and put perl.exe on your path. Open "OpenBlas.sln" and build the solution, especially "libopenblas"
+project.
+
+Step 4: Copy the library files under "build\lib" folder and all header files
+under OpenBLAS folder into installation library and include folders (or system
+folders).
+
+Step 5: Done.

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/8531af57/doc/en/docs/installation.md
----------------------------------------------------------------------
diff --git a/doc/en/docs/installation.md b/doc/en/docs/installation.md
index a797c57..47aa245 100755
--- a/doc/en/docs/installation.md
+++ b/doc/en/docs/installation.md
@@ -216,16 +216,16 @@ To build SINGA with OpenCL support, you need to pass the flag during cmake:
 
 ### Windows
 
-The compiler used for windows can ONLY be Visual Studio 2015 as some c++11
+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
+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](doc/en/docs/dependencies.md).
+[Dependencies](dependencies.md).
 After all the
 dependencies are successfully installed, just run the following commands to
-generate the VS project in cmd under singa folder:
+generate the VS solution in cmd under singa folder:
 
     $ md build && cd build
     $ cmake -G "Visual Studio 14" -DUSE_CUDA=OFF -DUSE_PYTHON=OFF .. 
@@ -251,8 +251,9 @@ can run the following command:
 
     $ cmake -LAH
 
-After generating the VS project, please open the "singa.sln" project file under
-the "build" folder and compile it via a normal VS project. You will find the
+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
+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.
 
 ## FAQ

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/8531af57/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7493ffb..ce3e792 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -17,7 +17,6 @@
 #
 
 # generate protobuf sources
-
 FILE(GLOB proto_files proto/*.proto)
 protobuf_generate_cpp(proto_srcs proto_hdrs ${proto_files})
 #MESSAGE(STATUS "proto_srcs: ${proto_srcs}")


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

Posted by wa...@apache.org.
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 <xi...@comp.nus.edu.sg>
Authored: Mon Sep 19 01:59:44 2016 +0800
Committer: Wei Wang <wa...@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);
 }