Fix vs2022 caused AVX512 illegal instruction issue. (#153480)

Fixes #145702

Add `/d2implyavx512upperregs-` to disable compiler over-aggressive optimization, which caused involeved AVX512 register on AVX2 machine.

Reference to: https://github.com/pytorch/pytorch/issues/145702#issuecomment-2874029459

Local test passed:
<img width="1208" alt="image" src="https://github.com/user-attachments/assets/26f4cb91-6bb5-416f-aa35-c899eb1489b2" />

Pull Request resolved: https://github.com/pytorch/pytorch/pull/153480
Approved by: https://github.com/Blackhex, https://github.com/cyyever, https://github.com/atalman
This commit is contained in:
Xu Han
2025-05-20 20:36:58 +00:00
committed by PyTorch MergeBot
parent 996c4d803d
commit 179e7d8624
5 changed files with 16 additions and 4 deletions

View File

@ -3,6 +3,8 @@ if "%VC_YEAR%" == "2022" powershell windows/internal/vs2022_install.ps1
set VC_VERSION_LOWER=17
set VC_VERSION_UPPER=18
:: Please don't delete VS2019 as an alternative, in case some Windows compiler issue.
:: Reference: https://github.com/pytorch/pytorch/issues/145702#issuecomment-2858693930
if "%VC_YEAR%" == "2019" (
set VC_VERSION_LOWER=16
set VC_VERSION_UPPER=17

View File

@ -9,7 +9,7 @@ if [[ "$OS" != "windows-arm64" ]]; then
export USE_SCCACHE=1
export SCCACHE_BUCKET=ossci-compiler-cache
export SCCACHE_IGNORE_SERVER_IO_ERROR=1
export VC_YEAR=2019
export VC_YEAR=2022
fi
if [[ "$DESIRED_CUDA" == 'xpu' ]]; then

View File

@ -4,7 +4,7 @@ set -eux -o pipefail
source "${BINARY_ENV_FILE:-/c/w/env}"
export CUDA_VERSION="${DESIRED_CUDA/cu/}"
export VC_YEAR=2019
export VC_YEAR=2022
if [[ "$DESIRED_CUDA" == 'xpu' ]]; then
export VC_YEAR=2022

View File

@ -5,7 +5,7 @@ title: "DISABLED [WORKFLOW_NAME] / [PLATFORM_NAME] / [JOB_NAME]"
labels: "module: ci"
---
> For example, DISABLED pull / win-vs2019-cpu-py3 / test (default). Once
> For example, DISABLED pull / win-vs2022-cpu-py3 / test (default). Once
> created, the job will be disabled within 15 minutes. You can check the
> list of disabled jobs at https://ossci-metrics.s3.amazonaws.com/disabled-jobs.json

View File

@ -353,6 +353,8 @@ function(torch_compile_options libname)
set(MSVC_DEBINFO_OPTION "/Zi")
endif()
set(MSVC_APPEND_OPTION)
if(${MSVC_TOOLSET_VERSION} GREATER_EQUAL 142)
# Add /permissive- flag for conformance mode to the compiler.
# This will force more strict check to the code standard.
@ -360,9 +362,17 @@ function(torch_compile_options libname)
# By default, the /permissive- option is set in new projects created by Visual Studio 2017 version 15.5 and later versions.
# We set the /permissive- flag from VS 2019 (MSVC_TOOLSET_VERSION 142) to avoid compiling issues for old toolkit.
# 2. For MSVC VERSION: https://cmake.org/cmake/help/latest/variable/MSVC_TOOLSET_VERSION.html
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-" PARENT_SCOPE)
target_compile_options(${libname} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
endif()
if(${MSVC_TOOLSET_VERSION} GREATER_EQUAL 143)
# Add /d2implyavx512upperregs- to disable compiler over-aggressive optimization, which caused involeved AVX512 register on AVX2 machine.
# Reference: https://github.com/pytorch/pytorch/issues/145702#issuecomment-2874029459
target_compile_options(${libname} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:/d2implyavx512upperregs->)
endif()
target_compile_options(${libname} PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:
${MSVC_RUNTIME_LIBRARY_OPTION}