未验证 提交 bd56e040 编写于 作者: M Mihai Maruseac 提交者: GitHub

Merge pull request #35548 from compnerd/r2.1-windows-build

r2.1 cherry-pick request: windows build support
......@@ -160,6 +160,10 @@ build:c++17 --cxxopt=-std=c++1z
build:c++17 --cxxopt=-stdlib=libc++
build:c++1z --config=c++17
# Tensorflow uses M_* math constants that only get defined by MSVC headers if
# _USE_MATH_DEFINES is defined.
build:windows --copt=/D_USE_MATH_DEFINES
# Default paths for TF_SYSTEM_LIBS
build --define=PREFIX=/usr
build --define=LIBDIR=$(PREFIX)/lib
......
......@@ -1233,7 +1233,7 @@ def set_windows_build_flags(environ_cp):
# Fix winsock2.h conflicts
write_to_bazelrc(
'build --copt=-DWIN32_LEAN_AND_MEAN --host_copt=-DWIN32_LEAN_AND_MEAN '
'--copt=-DNOGDI --host_copt=-DNOGDI')
'--copt=-DNOGDI --host_copt=-DNOGDI --copt=-D_USE_MATH_DEFINES')
# Output more verbose information when something goes wrong
write_to_bazelrc('build --verbose_failures')
# The host and target platforms are the same in Windows build. So we don't
......
......@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#define _USE_MATH_DEFINES
#include <cmath>
#include "tensorflow/cc/ops/array_ops_internal.h"
......
......@@ -15,9 +15,7 @@ limitations under the License.
#include "tensorflow/compiler/xla/client/lib/math.h"
// This macro is required to make MSVC defines math constants in math.h
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include "tensorflow/compiler/xla/client/lib/arithmetic.h"
#include "tensorflow/compiler/xla/client/lib/constants.h"
......
......@@ -36,6 +36,8 @@ namespace {
struct TridiagonalSystemShape {
const int64 rank;
const int64 num_equations;
TridiagonalSystemShape(int64 rk, int64 num_eqs)
: rank(rk), num_equations(num_eqs) {}
};
Status CheckSecondToLastDimension(const Shape& op_shape, int64 rank,
......@@ -109,9 +111,7 @@ StatusOr<TridiagonalSystemShape> CheckSystemAndReturnShape(XlaOp lower_diagonal,
TF_RETURN_IF_ERROR(CheckSecondToLastDimension(upper_diagonal_shape, rank, 1,
"upper diagonal"));
TridiagonalSystemShape result = {.rank = rank,
.num_equations = num_equations};
return result;
return TridiagonalSystemShape(rank, num_equations);
}
XlaOp Coefficient(XlaOp operand, int64 i) {
......
......@@ -469,7 +469,7 @@ Status DynamicDimensionInferenceVisitor::HandleSetDimensionSize(
// Propagate dynamic dimension indicated by this set dimension size
// instruction.
parent_->SetDynamicSize(hlo, {}, hlo->dimension(), hlo->mutable_operand(1),
{.stride = 1, .multiple_of = 1});
DimensionConstraint(1, 1));
}
// Also Propagate dynamic dimension already set by operands.
......@@ -813,7 +813,7 @@ Status DynamicDimensionInferenceVisitor::HandleReshape(HloInstruction* hlo) {
parent_->SetDynamicSize(
reshape, {}, output_dynamic_dimension, new_dynamic_size,
{.stride = 1, .multiple_of = constraint.multiple_of / divisor});
DimensionConstraint(1, constraint.multiple_of / divisor));
}
if (input_dim_size < output_dim_size) {
......@@ -850,12 +850,12 @@ Status DynamicDimensionInferenceVisitor::HandleReshape(HloInstruction* hlo) {
hlo->parent()->AddInstruction(HloInstruction::CreateBinary(
output_dynamic_size->shape(), HloOpcode::kMultiply,
new_dynamic_size, operand_dynamic_size));
int64 new_multiple_of_constraint =
constraint.multiple_of * output_dim_size /
operand->shape().dimensions(input_dynamic_dimension);
parent_->SetDynamicSize(
reshape, {}, output_dynamic_dimension, new_dynamic_size,
{.stride = 1,
.multiple_of =
constraint.multiple_of * output_dim_size /
operand->shape().dimensions(input_dynamic_dimension)});
DimensionConstraint(1, new_multiple_of_constraint));
}
return Status::OK();
......@@ -1227,7 +1227,7 @@ Status DynamicDimensionInferenceVisitor::HandleParameter(HloInstruction* hlo) {
parent_->SetDynamicSize(target_parameter,
dynamic_dimension.parameter_index,
dynamic_dimension.dimension, dynamic_size,
{.stride = 1, .multiple_of = 1});
DimensionConstraint(1, 1));
return Status::OK();
});
}
......
......@@ -149,6 +149,9 @@ class DynamicDimensionInference {
//
//
struct DimensionConstraint {
explicit DimensionConstraint(int64 s, int64 m)
: stride(s), multiple_of(m) {}
DimensionConstraint() : stride(1), multiple_of(1) {}
// Stride represents the distance of a newly placed element and the previous
// placed element on this dynamic dimension.
int64 stride;
......
......@@ -2611,18 +2611,37 @@ struct MinMaxFiniteValue<bfloat16> {
static double min() { return -max(); }
};
// MSVC's standard C++ library does not define isnan/isfinite for integer types.
// To work around that we will need to provide our own.
template <typename T>
std::enable_if_t<std::is_floating_point<T>::value, bool> IsFinite(T val) {
return std::isfinite(val);
}
template <typename T>
std::enable_if_t<std::is_floating_point<T>::value, bool> IsNaN(T val) {
return std::isnan(val);
}
template <typename T>
std::enable_if_t<std::is_integral<T>::value, bool> IsFinite(T val) {
return std::isfinite(static_cast<double>(val));
}
template <typename T>
std::enable_if_t<std::is_integral<T>::value, bool> IsNaN(T val) {
return std::isnan(static_cast<double>(val));
}
template <typename LiteralNativeT, typename ParsedElemT>
bool HloParserImpl::CheckParsedValueIsInRange(LocTy loc, ParsedElemT value) {
if (std::is_floating_point<ParsedElemT>::value) {
auto value_as_native_t = static_cast<LiteralNativeT>(value);
auto value_double_converted = static_cast<ParsedElemT>(value_as_native_t);
if (!std::isfinite(value) || std::isfinite(value_double_converted)) {
if (!IsFinite(value) || IsFinite(value_double_converted)) {
value = value_double_converted;
}
}
PrimitiveType literal_ty =
primitive_util::NativeToPrimitiveType<LiteralNativeT>();
if (std::isnan(value) ||
if (IsNaN(value) ||
(std::numeric_limits<ParsedElemT>::has_infinity &&
(std::numeric_limits<ParsedElemT>::infinity() == value ||
-std::numeric_limits<ParsedElemT>::infinity() == value))) {
......
......@@ -18,10 +18,7 @@ limitations under the License.
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#undef _USE_MATH_DEFINES
#include <algorithm>
#include <type_traits>
......
......@@ -15,8 +15,8 @@ limitations under the License.
#include "tensorflow/core/lib/random/random_distributions.h"
#include <math.h>
#include <algorithm>
#include <cmath>
#include <functional>
#include <numeric>
#include <unordered_map>
......
......@@ -14,8 +14,6 @@ limitations under the License.
==============================================================================*/
#include "tensorflow/lite/experimental/microfrontend/lib/window_util.h"
// This macro is required to make MSVC defines math constants in math.h
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
......
......@@ -263,6 +263,8 @@ def get_win_copts(is_external = False):
# "/EHs-c-",
"/wd4577",
"/DNOGDI",
# Also see build:windows lines in tensorflow/opensource_only/.bazelrc
# where we set some other options globally.
]
if is_external:
return WINDOWS_COPTS + ["/UTF_COMPILE_LIBRARY"]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册