pytorch/caffe2/core/common_test.cc
ArutyunovG 8e91da4cb3 Windows shared build (#13550)
Summary:
Hi guys,

I'd like to build Caffe2 with more supported options in Windows with Microsoft Visual Studios.
This is the first pull request.
Running scripts/build_windows_shared.bat is able to build Caffe2 with both CMAKE_BUILD_TYPE=Debug and CMAKE_BUILD_TYPE=Release with Visual Studio 14 2015.
CUDA is 9.0, cudnn is 7.0.5, glog, gflags and lmdb are supported on my system.
Python is 3.5, Detectron works from python interface as well.
It was even possible to debug detectron code and step into caffe2_gpu.dll with pdbs built.

What is disappointing, that c10/experimental ops don't build with this Visual Studio generator, I added special option INCLUDE_EXPERIMENTAL_C10_OPS (default ON) to deal with it in build_windows_shared.bat.

After this pull request the next step is to add Visual Studio 2017 support in the script.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/13550

Reviewed By: ezyang

Differential Revision: D13042597

Pulled By: orionr

fbshipit-source-id: f313f909f599cd582a1d000eff766eef3a9fc4fc
2018-11-16 12:16:28 -08:00

46 lines
1.1 KiB
C++

#include <iostream>
#include <memory>
#define CAFFE2_TESTONLY_FORCE_STD_STRING_TEST
#include "caffe2/core/common.h"
#include <gtest/gtest.h>
namespace caffe2 {
#ifndef __ANDROID__
// Simple tests to make sure that our stoi and stod implementations are
// matching the std implementations, but not testing it very extensively
// as one should be using the std version most of the time.
TEST(CommonTest, TestStoi) {
EXPECT_TRUE(CAFFE2_TESTONLY_WE_ARE_USING_CUSTOM_STRING_FUNCTIONS);
string s = "1234";
int i_std = std::stoi(s);
int i_caffe2 = ::c10::stoi(s);
EXPECT_EQ(i_std, i_caffe2);
}
TEST(CommonTest, TestStod) {
// Full string is parsed.
string s = "1.234";
std::size_t p_std = 0, p_caffe2 = 0;
double d_std = std::stod(s, &p_std);
double d_caffe2 = ::c10::stod(s, &p_caffe2);
EXPECT_EQ(d_std, d_caffe2);
EXPECT_EQ(p_std, p_caffe2);
// Only part of the string is parsed.
s = "1.234 5.678";
d_std = std::stod(s, &p_std);
d_caffe2 = ::c10::stod(s, &p_caffe2);
EXPECT_EQ(d_std, d_caffe2);
EXPECT_EQ(p_std, p_caffe2);
}
#endif // __ANDROID__
} // namespace caffe2