未验证 提交 0ad363b1 编写于 作者: S Sing_chan 提交者: GitHub

support vs2019 compilation in windows (#38719)

* support vs2019 compilation in windows

* not modify pow_op's original compute logic
上级 e91f7c02
...@@ -207,6 +207,10 @@ FUNCTION(build_protobuf TARGET_NAME BUILD_FOR_HOST) ...@@ -207,6 +207,10 @@ FUNCTION(build_protobuf TARGET_NAME BUILD_FOR_HOST)
elseif(WITH_IPU) elseif(WITH_IPU)
SET(PROTOBUF_REPOSITORY ${GIT_URL}/protocolbuffers/protobuf.git) SET(PROTOBUF_REPOSITORY ${GIT_URL}/protocolbuffers/protobuf.git)
SET(PROTOBUF_TAG d750fbf648256c7c631f51ffdbf67d7c18b0114e) SET(PROTOBUF_TAG d750fbf648256c7c631f51ffdbf67d7c18b0114e)
elseif(WIN32)
SET(PROTOBUF_REPOSITORY ${GIT_URL}/protocolbuffers/protobuf.git)
# Change the tag to support building with vs2019
SET(PROTOBUF_TAG 01a05a53f40ca2ac5f0af10c6cc0810bee39b792)
else() else()
SET(PROTOBUF_REPOSITORY ${GIT_URL}/protocolbuffers/protobuf.git) SET(PROTOBUF_REPOSITORY ${GIT_URL}/protocolbuffers/protobuf.git)
SET(PROTOBUF_TAG 9f75c5aa851cd877fb0d93ccc31b8567a6706546) SET(PROTOBUF_TAG 9f75c5aa851cd877fb0d93ccc31b8567a6706546)
......
...@@ -174,6 +174,27 @@ struct FMaxFunctor<paddle::platform::float16> { ...@@ -174,6 +174,27 @@ struct FMaxFunctor<paddle::platform::float16> {
} }
}; };
template <>
struct FMaxFunctor<int> {
inline HOSTDEVICE int operator()(const int& a, const int& b) const {
float float_a = static_cast<float>(a);
float float_b = static_cast<float>(b);
auto result = std::fmax(float_a, float_b);
return std::lrint(result);
}
};
template <>
struct FMaxFunctor<int64_t> {
inline HOSTDEVICE int64_t operator()(const int64_t& a,
const int64_t& b) const {
double double_a = static_cast<double>(a);
double double_b = static_cast<double>(b);
auto result = std::fmax(double_a, double_b);
return std::llrint(result);
}
};
// Fmin // Fmin
template <typename T> template <typename T>
struct FMinFunctor { struct FMinFunctor {
...@@ -194,6 +215,27 @@ struct FMinFunctor<paddle::platform::float16> { ...@@ -194,6 +215,27 @@ struct FMinFunctor<paddle::platform::float16> {
} }
}; };
template <>
struct FMinFunctor<int> {
inline HOSTDEVICE int operator()(const int& a, const int& b) const {
float float_a = static_cast<float>(a);
float float_b = static_cast<float>(b);
auto result = std::fmin(float_a, float_b);
return std::lrint(result);
}
};
template <>
struct FMinFunctor<int64_t> {
inline HOSTDEVICE int64_t operator()(const int64_t& a,
const int64_t& b) const {
double double_a = static_cast<double>(a);
double double_b = static_cast<double>(b);
auto result = std::fmin(double_a, double_b);
return std::llrint(result);
}
};
template <typename T> template <typename T>
struct MulGradFunctor { struct MulGradFunctor {
inline HOSTDEVICE T operator()(const T& a, const T& b) const { return a * b; } inline HOSTDEVICE T operator()(const T& a, const T& b) const { return a * b; }
......
...@@ -31,7 +31,8 @@ struct CudaPowFunctor< ...@@ -31,7 +31,8 @@ struct CudaPowFunctor<
// when cast to int by default and it is wrong. // when cast to int by default and it is wrong.
// Use llrint to cast it to the nearest integer, which is 3. // Use llrint to cast it to the nearest integer, which is 3.
inline HOSTDEVICE T operator()(const T args[]) const { inline HOSTDEVICE T operator()(const T args[]) const {
return std::llrint(std::pow(args[0], args[1])); return std::llrint(
std::pow(static_cast<double>(args[0]), static_cast<double>(args[1])));
} }
}; };
......
...@@ -31,7 +31,8 @@ struct PowFunctor { ...@@ -31,7 +31,8 @@ struct PowFunctor {
// when cast to int by default and it is wrong. // when cast to int by default and it is wrong.
// Use llrint to cast it to the nearest integer, which is 3. // Use llrint to cast it to the nearest integer, which is 3.
if (std::is_integral<T>::value) { if (std::is_integral<T>::value) {
return std::llrint(std::pow(a, b)); return std::llrint(
std::pow(static_cast<double>(a), static_cast<double>(b)));
} }
#endif #endif
return std::pow(a, b); return std::pow(a, b);
...@@ -60,13 +61,25 @@ class ElementwisePowKernel : public framework::OpKernel<T> { ...@@ -60,13 +61,25 @@ class ElementwisePowKernel : public framework::OpKernel<T> {
template <typename T> template <typename T>
struct PowGradDX { struct PowGradDX {
HOSTDEVICE T operator()(T x, T y, T out, T dout) const { HOSTDEVICE T operator()(T x, T y, T out, T dout) const {
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
if (std::is_integral<T>::value) {
return dout * y *
std::pow(static_cast<double>(x), static_cast<double>(y - 1));
}
#endif
return dout * y * std::pow(x, y - 1); return dout * y * std::pow(x, y - 1);
} }
}; };
template <typename T> template <typename T, typename Enable = void>
struct PowGradDY { struct PowGradDY {
HOSTDEVICE T operator()(T x, T y, T out, T dout) const { HOSTDEVICE T operator()(T x, T y, T out, T dout) const {
#if defined(__CUDA_ARCH__) || defined(__HIPCC__)
if (std::is_integral<T>::value) {
return dout * std::log(static_cast<double>(x)) *
std::pow(static_cast<double>(x), static_cast<double>(y));
}
#endif
return dout * std::log(x) * std::pow(x, y); return dout * std::log(x) * std::pow(x, y);
} }
}; };
......
...@@ -84,7 +84,7 @@ void BatchSvd(const T* X, T* U, T* VH, T* S, int rows, int cols, int batches, ...@@ -84,7 +84,7 @@ void BatchSvd(const T* X, T* U, T* VH, T* S, int rows, int cols, int batches,
template <typename T> template <typename T>
struct PowFunctor { struct PowFunctor {
PowFunctor(const T* input, T* output, int64_t numel, float exp) PowFunctor(const T* input, T* output, int64_t numel, T exp)
: input_(input), output_(output), numel_(numel), exp_(exp) {} : input_(input), output_(output), numel_(numel), exp_(exp) {}
HOSTDEVICE void operator()(int64_t idx) const { HOSTDEVICE void operator()(int64_t idx) const {
...@@ -93,7 +93,7 @@ struct PowFunctor { ...@@ -93,7 +93,7 @@ struct PowFunctor {
const T* input_; const T* input_;
T* output_; T* output_;
int64_t numel_; int64_t numel_;
float exp_; T exp_;
}; };
template <typename T> template <typename T>
...@@ -297,7 +297,7 @@ struct DeviceIndependenceTensorOperations { ...@@ -297,7 +297,7 @@ struct DeviceIndependenceTensorOperations {
const framework::ExecutionContext& context) const framework::ExecutionContext& context)
: context(context) {} : context(context) {}
framework::Tensor Pow(const framework::Tensor& x, float exp) { framework::Tensor Pow(const framework::Tensor& x, T exp) {
framework::Tensor out; framework::Tensor out;
auto for_range = GetForRange(x.numel()); auto for_range = GetForRange(x.numel());
int numel = x.numel(); int numel = x.numel();
......
...@@ -261,6 +261,7 @@ set ON_INFER=ON ...@@ -261,6 +261,7 @@ set ON_INFER=ON
set WITH_TESTING=ON set WITH_TESTING=ON
set WITH_TENSORRT=ON set WITH_TENSORRT=ON
set WITH_INFERENCE_API_TEST=ON set WITH_INFERENCE_API_TEST=ON
set WITH_TPCACHE=OFF
call :cmake || goto cmake_error call :cmake || goto cmake_error
call :build || goto build_error call :build || goto build_error
...@@ -325,7 +326,11 @@ echo ======================================== ...@@ -325,7 +326,11 @@ echo ========================================
rem set vs language to english to block showIncludes, this need vs has installed English language package. rem set vs language to english to block showIncludes, this need vs has installed English language package.
set VSLANG=1033 set VSLANG=1033
rem Configure the environment for 64-bit builds. 'DISTUTILS_USE_SDK' indicates that the user has selected the compiler. rem Configure the environment for 64-bit builds. 'DISTUTILS_USE_SDK' indicates that the user has selected the compiler.
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" echo %task_name%|findstr wincheck_inference >nul && (
call "D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
) || (
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
)
set DISTUTILS_USE_SDK=1 set DISTUTILS_USE_SDK=1
rem Windows 10 Kit bin dir rem Windows 10 Kit bin dir
set PATH=C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64;%PATH% set PATH=C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64;%PATH%
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <limits> #include <limits>
#include <memory> #include <memory>
#include <new> #include <new>
#include <stdexcept>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册