From 2a6cbfaccf32f53b171c36fb5f6e995c297c0b4f Mon Sep 17 00:00:00 2001 From: peterjc123 Date: Wed, 20 Mar 2019 09:16:28 -0700 Subject: [PATCH] Enable 32 bit CPU build on Windows Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/18176 Differential Revision: D14539884 Pulled By: ezyang fbshipit-source-id: 0e4bd9c1ef1830cd9bcc40df36b87534f61def08 --- tools/build_pytorch_libs.py | 10 +++++++--- tools/setup_helpers/env.py | 3 +++ torch/csrc/jit/pybind_utils.h | 6 +++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tools/build_pytorch_libs.py b/tools/build_pytorch_libs.py index 840abb5..5a0c416 100644 --- a/tools/build_pytorch_libs.py +++ b/tools/build_pytorch_libs.py @@ -1,4 +1,4 @@ -from .setup_helpers.env import (IS_ARM, IS_DARWIN, IS_LINUX, IS_PPC, IS_WINDOWS, +from .setup_helpers.env import (IS_64BIT, IS_ARM, IS_DARWIN, IS_LINUX, IS_PPC, IS_WINDOWS, DEBUG, REL_WITH_DEB_INFO, USE_MKLDNN, check_env_flag, check_negative_env_flag, hotpatch_build_env_vars) @@ -84,7 +84,8 @@ elif REL_WITH_DEB_INFO: def overlay_windows_vcvars(env): from distutils._msvccompiler import _get_vc_env - vc_env = _get_vc_env('x64') + vc_arch = 'x64' if IS_64BIT else 'x86' + vc_env = _get_vc_env(vc_arch) for k, v in env.items(): lk = k.lower() if lk not in vc_env: @@ -128,7 +129,10 @@ def run_cmake(version, if USE_NINJA: cmake_args.append('-GNinja') elif IS_WINDOWS: - cmake_args.append('-GVisual Studio 15 2017 Win64') + if IS_64BIT: + cmake_args.append('-GVisual Studio 15 2017 Win64') + else: + cmake_args.append('-GVisual Studio 15 2017') try: import numpy as np NUMPY_INCLUDE_DIR = np.get_include() diff --git a/tools/setup_helpers/env.py b/tools/setup_helpers/env.py index e9c69af..2900f6b 100644 --- a/tools/setup_helpers/env.py +++ b/tools/setup_helpers/env.py @@ -1,5 +1,6 @@ import os import platform +import struct import sys from itertools import chain @@ -13,6 +14,8 @@ IS_ARM = (platform.machine() == 'aarch64') IS_CONDA = 'conda' in sys.version or 'Continuum' in sys.version or any([x.startswith('CONDA') for x in os.environ]) CONDA_DIR = os.path.join(os.path.dirname(sys.executable), '..') +IS_64BIT = (struct.calcsize("P") == 8) + def check_env_flag(name, default=''): return os.getenv(name, default).upper() in ['ON', '1', 'YES', 'TRUE', 'Y'] diff --git a/torch/csrc/jit/pybind_utils.h b/torch/csrc/jit/pybind_utils.h index 5ff0447..f72ed15 100644 --- a/torch/csrc/jit/pybind_utils.h +++ b/torch/csrc/jit/pybind_utils.h @@ -336,16 +336,16 @@ struct VISIBILITY_HIDDEN tuple_slice { tuple_slice(py::tuple tup_, int64_t b_, int64_t e_) : tup(std::move(tup_)), b(b_), e(e_) {} py::detail::tuple_iterator begin() const { - return {tup, b}; + return {tup, static_cast(b)}; } py::detail::tuple_iterator end() const { - return {tup, e}; + return {tup, static_cast(e)}; } size_t size() const { return e - b; } py::detail::tuple_accessor operator[](size_t index) const { - return {tup, b + index}; + return {tup, static_cast(b + index)}; } private: -- 2.7.4