From 0eb449a86e6d48ba5a4a3a828f45a97a447292e9 Mon Sep 17 00:00:00 2001 From: Robin Kuzmin <9372582+kuzminrobin@users.noreply.github.com> Date: Mon, 6 Dec 2021 12:06:49 -0800 Subject: [PATCH] Reverting the PR #881 to investigate the QDK Release failures. (#888) --- build/ci-codecheck.yml | 2 +- build/ci.yml | 2 +- build/steps-codecheck.yml | 2 +- src/Qir/Common/cmake/unit_test_include.cmake | 2 +- .../lib/Simulators/FullstateSimulator.cpp | 12 +-- src/Qir/Runtime/public/QubitManager.hpp | 4 +- src/Qir/Runtime/test-qir-runtime.ps1 | 4 +- .../StandaloneInputReference/CMakeLists.txt | 2 +- src/Qir/Samples/test-qir-samples.ps1 | 4 +- src/Qir/Tests/test-qir-tests.ps1 | 12 ++- src/Simulation/Native/CMakeLists.txt | 77 ++++--------------- .../Native/build-native-simulator.ps1 | 53 ++----------- src/Simulation/Native/prerequisites.ps1 | 32 +++----- src/Simulation/Native/src/CMakeLists.txt | 22 ++++-- .../Native/src/simulator/CMakeLists.txt | 3 - .../Native/src/simulator/kernels.hpp | 2 - 16 files changed, 68 insertions(+), 167 deletions(-) diff --git a/build/ci-codecheck.yml b/build/ci-codecheck.yml index 4b4545f31e8..9e2427cb7e8 100644 --- a/build/ci-codecheck.yml +++ b/build/ci-codecheck.yml @@ -27,7 +27,7 @@ jobs: linux: imageName: 'ubuntu-latest' mac: - imageName: 'macOS-latest' + imageName: 'macOS-10.15' #windows: # No sanitizers supported on Win at the moment. # imageName: 'windows-latest' pool: diff --git a/build/ci.yml b/build/ci.yml index 4e60039fd26..48ca8e7e740 100644 --- a/build/ci.yml +++ b/build/ci.yml @@ -31,7 +31,7 @@ jobs: linux: imageName: 'ubuntu-latest' mac: - imageName: 'macOS-latest' + imageName: 'macOS-10.15' windows: imageName: 'windows-latest' pool: diff --git a/build/steps-codecheck.yml b/build/steps-codecheck.yml index fe474e3ccbf..8a25efe684f 100644 --- a/build/steps-codecheck.yml +++ b/build/steps-codecheck.yml @@ -10,7 +10,7 @@ steps: # QIR Runtime: - pwsh: src/Qir/Runtime/prerequisites.ps1 - displayName: "Install QIR Runtime Prerequisites" + displayName: "Install QIR Runtime Prerequisistes" workingDirectory: $(System.DefaultWorkingDirectory) - pwsh: src/Qir/Runtime/build-qir-runtime.ps1 diff --git a/src/Qir/Common/cmake/unit_test_include.cmake b/src/Qir/Common/cmake/unit_test_include.cmake index 93701f563b0..5c29fc114c7 100644 --- a/src/Qir/Common/cmake/unit_test_include.cmake +++ b/src/Qir/Common/cmake/unit_test_include.cmake @@ -9,7 +9,7 @@ macro(add_unit_test target) if(DEFINED ENV{NATIVE_SIMULATOR}) set(TEST_DEPS1 $ENV{NATIVE_SIMULATOR}) else() - set(TEST_DEPS1 "${PROJECT_SOURCE_DIR}/../../Simulation/native/build/drop") + set(TEST_DEPS1 "${PROJECT_SOURCE_DIR}/../../Simulation/native/build/$ENV{BUILD_CONFIGURATION}") endif() set(TEST_DEPS2 "${CMAKE_BINARY_DIR}/bin") diff --git a/src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp b/src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp index 93836936317..c077f826643 100644 --- a/src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp +++ b/src/Qir/Runtime/lib/Simulators/FullstateSimulator.cpp @@ -211,7 +211,7 @@ namespace Quantum { if (this->simulatorId != NULL_SIMULATORID) { - typedef void (*TDestroy)(unsigned); + typedef unsigned (*TDestroy)(unsigned); static TDestroy destroySimulatorInstance = reinterpret_cast(LoadProc(this->handle, "destroy")); assert(destroySimulatorInstance); @@ -226,7 +226,7 @@ namespace Quantum // Deprecated, use `DumpMachine()` and `DumpRegister()` instead. void GetState(TGetStateCallback callback) override { - typedef void (*TDump)(unsigned, TGetStateCallback); + typedef bool (*TDump)(unsigned, TGetStateCallback); static TDump dump = reinterpret_cast(this->GetProc("Dump")); dump(this->simulatorId, callback); } @@ -462,7 +462,7 @@ namespace Quantum void R(PauliId axis, QubitIdType target, double theta) override { - typedef void (*TR)(unsigned, unsigned, double, unsigned); + typedef unsigned (*TR)(unsigned, unsigned, double, unsigned); static TR r = reinterpret_cast(this->GetProc("R")); r(this->simulatorId, GetBasis(axis), theta, GetQubitId(target)); @@ -472,7 +472,7 @@ namespace Quantum void ControlledR(long numControls, QubitIdType controls[], PauliId axis, QubitIdType target, double theta) override { - typedef void (*TMCR)(unsigned, unsigned, double, unsigned, unsigned*, unsigned); + typedef unsigned (*TMCR)(unsigned, unsigned, double, unsigned, unsigned*, unsigned); static TMCR cr = reinterpret_cast(this->GetProc("MCR")); std::vector ids = GetQubitIds(numControls, controls); @@ -483,7 +483,7 @@ namespace Quantum void Exp(long numTargets, PauliId paulis[], QubitIdType targets[], double theta) override { - typedef void (*TExp)(unsigned, unsigned, unsigned*, double, unsigned*); + typedef unsigned (*TExp)(unsigned, unsigned, unsigned*, double, unsigned*); static TExp exp = reinterpret_cast(this->GetProc("Exp")); std::vector ids = GetQubitIds(numTargets, targets); std::vector convertedBases = GetBases(numTargets, paulis); @@ -494,7 +494,7 @@ namespace Quantum void ControlledExp(long numControls, QubitIdType controls[], long numTargets, PauliId paulis[], QubitIdType targets[], double theta) override { - typedef void (*TMCExp)(unsigned, unsigned, unsigned*, double, unsigned, unsigned*, unsigned*); + typedef unsigned (*TMCExp)(unsigned, unsigned, unsigned*, double, unsigned, unsigned*, unsigned*); static TMCExp cexp = reinterpret_cast(this->GetProc("MCExp")); std::vector idsTargets = GetQubitIds(numTargets, targets); std::vector idsControls = GetQubitIds(numControls, controls); diff --git a/src/Qir/Runtime/public/QubitManager.hpp b/src/Qir/Runtime/public/QubitManager.hpp index f1ff2afb3b3..1d1bda589db 100644 --- a/src/Qir/Runtime/public/QubitManager.hpp +++ b/src/Qir/Runtime/public/QubitManager.hpp @@ -40,9 +40,7 @@ namespace Quantum // No complex scenarios for now. Don't need to support copying/moving. CQubitManager(const CQubitManager&) = delete; CQubitManager& operator=(const CQubitManager&) = delete; - ~CQubitManager(); // If this dtor is made _virtual_ then the QIR RT tests crash (at least in Debug config) - // if the native simulator is compiled with Clang (as opposed to GCC). Nothing wrong found in - // the code, probably is the compiler bug. + virtual ~CQubitManager(); // Restricted reuse area control void StartRestrictedReuseArea(); diff --git a/src/Qir/Runtime/test-qir-runtime.ps1 b/src/Qir/Runtime/test-qir-runtime.ps1 index 377ee141411..68a09d7b990 100644 --- a/src/Qir/Runtime/test-qir-runtime.ps1 +++ b/src/Qir/Runtime/test-qir-runtime.ps1 @@ -3,10 +3,8 @@ . (Join-Path $PSScriptRoot .. qir-utils.ps1) +# TODO: `ASAN_OPTIONS=check_initialization_order=1` (https://clang.llvm.org/docs/AddressSanitizer.html#initialization-order-checking). # TODO: macOS: `ASAN_OPTIONS=detect_leaks=1` (https://clang.llvm.org/docs/AddressSanitizer.html#memory-leak-detection). -$env:ASAN_OPTIONS = "check_initialization_order=true:detect_stack_use_after_return=true:" ` - + "alloc_dealloc_mismatch=true:new_delete_type_mismatch=true:strict_init_order=true:strict_string_checks=true:" ` - + "detect_invalid_pointer_pairs=2" if (-not (Test-CTest (Join-Path $PSScriptRoot bin $Env:BUILD_CONFIGURATION unittests) "QIR Runtime")) { throw "At least one project failed testing. Check the logs." diff --git a/src/Qir/Samples/StandaloneInputReference/CMakeLists.txt b/src/Qir/Samples/StandaloneInputReference/CMakeLists.txt index 8006d3a5694..5f994b1dc24 100644 --- a/src/Qir/Samples/StandaloneInputReference/CMakeLists.txt +++ b/src/Qir/Samples/StandaloneInputReference/CMakeLists.txt @@ -34,7 +34,7 @@ add_test( if(DEFINED ENV{NATIVE_SIMULATOR}) set(TEST_DEPS1 $ENV{NATIVE_SIMULATOR}) else() - set(TEST_DEPS1 "${PROJECT_SOURCE_DIR}/../../Simulation/native/build/drop") + set(TEST_DEPS1 "${PROJECT_SOURCE_DIR}/../../Simulation/native/build/$ENV{BUILD_CONFIGURATION}") endif() set(TEST_DEPS2 "${PROJECT_SOURCE_DIR}/../Runtime/bin/$ENV{BUILD_CONFIGURATION}/bin") diff --git a/src/Qir/Samples/test-qir-samples.ps1 b/src/Qir/Samples/test-qir-samples.ps1 index a5bbef65a84..1a1246cb732 100644 --- a/src/Qir/Samples/test-qir-samples.ps1 +++ b/src/Qir/Samples/test-qir-samples.ps1 @@ -3,10 +3,8 @@ . (Join-Path $PSScriptRoot .. qir-utils.ps1) +# TODO: `ASAN_OPTIONS=check_initialization_order=1` (https://clang.llvm.org/docs/AddressSanitizer.html#initialization-order-checking). # TODO: macOS: `ASAN_OPTIONS=detect_leaks=1` (https://clang.llvm.org/docs/AddressSanitizer.html#memory-leak-detection). -$env:ASAN_OPTIONS = "check_initialization_order=true:detect_stack_use_after_return=true:" ` - + "alloc_dealloc_mismatch=true:new_delete_type_mismatch=true:strict_init_order=true:strict_string_checks=true:" ` - + "detect_invalid_pointer_pairs=2" if (-not (Test-CTest (Join-Path $PSScriptRoot bin $Env:BUILD_CONFIGURATION StandaloneInputReference) "QIR Samples (StandaloneInputReference)")) { throw "At least one project failed testing. Check the logs." diff --git a/src/Qir/Tests/test-qir-tests.ps1 b/src/Qir/Tests/test-qir-tests.ps1 index fef566d1b62..f6ad54463b5 100644 --- a/src/Qir/Tests/test-qir-tests.ps1 +++ b/src/Qir/Tests/test-qir-tests.ps1 @@ -16,10 +16,14 @@ if ($Env:BUILD_CONFIGURATION -eq "Debug") if (-not ($IsWindows)) { $env:LSAN_OPTIONS += "suppressions=../../../../LSan.ignore" # https://clang.llvm.org/docs/AddressSanitizer.html#suppressing-memory-leaks - # TODO: macOS: `ASAN_OPTIONS=detect_leaks=1` (https://clang.llvm.org/docs/AddressSanitizer.html#memory-leak-detection). - $env:ASAN_OPTIONS = "check_initialization_order=true:detect_stack_use_after_return=true:" ` - + "alloc_dealloc_mismatch=true:new_delete_type_mismatch=true:strict_init_order=true:strict_string_checks=true" - # + ":detect_invalid_pointer_pairs=2" TODO(rokuzmin, #883): ==8218==ERROR: AddressSanitizer: invalid-pointer-pair: 0x602000000af4 0x602000000af0 + if (-not ($IsMacOS)) + { + $env:ASAN_OPTIONS += "check_initialization_order=1" # https://clang.llvm.org/docs/AddressSanitizer.html#initialization-order-checking + } + #else # AddressSanitizer: detect_leaks is not supported on this platform. Re-enable this once supported. + #{ + # $env:ASAN_OPTIONS += "detect_leaks=1" # https://clang.llvm.org/docs/AddressSanitizer.html#memory-leak-detection + #} } } diff --git a/src/Simulation/Native/CMakeLists.txt b/src/Simulation/Native/CMakeLists.txt index 1029f69e1f7..06b27fd43de 100644 --- a/src/Simulation/Native/CMakeLists.txt +++ b/src/Simulation/Native/CMakeLists.txt @@ -32,75 +32,26 @@ option(USE_SINGLE_PRECISION "Use single-precision floating point operations" OFF option(HAVE_INTRINSICS "Have AVX intrinsics" OFF) option(USE_GATE_FUSION "Use gate fusion" ON) -# Always use Spectre mitigations where available -if (WIN32) - # Enforce use of static runtime (avoids target machine needing msvcrt installed). - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - - # Locate the vswhere application, which will provide paths to any installed Visual Studio instances. - # By invoking it with "-find **/lib/spectre/x64" we will find any Spectre mitigated libaries that - # have been installed. - find_program(_vswhere_tool - NAMES vswhere - PATHS "$ENV{ProgramFiles\(x86\)}/Microsoft Visual Studio/Installer") - if (NOT ${vswhere}) - message(FATAL_ERROR "Could not locate vswhere.exe - unable to source vc redistributable") - endif() - execute_process( - COMMAND "${_vswhere_tool}" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -find **/14.29.*/**/lib/spectre/x64 -sort - OUTPUT_VARIABLE _vs_install_loc_out - RESULT_VARIABLE _vs_where_exitcode - OUTPUT_STRIP_TRAILING_WHITESPACE) - file(TO_CMAKE_PATH "${_vs_install_loc_out}" SPECTRE_LIB_PATH_OUT) - string(REGEX REPLACE "[\r\n]+" ";" SPECTRE_LIB_PATH ${SPECTRE_LIB_PATH_OUT}) - message(INFO "*** install loc: ${SPECTRE_LIB_PATH}") - - # Locate the spectre mitigated runtime libraries and fail if they can't be found. Targets in this - # cmake project can use the variables to explicitly link these libraries rather than using the - # non-mitigated libraries that are found by default. - find_library(LIBCMT_SPECTRE_REL libcmt PATHS ${SPECTRE_LIB_PATH} REQUIRED) - find_library(LIBCMT_SPECTRE_DEB libcmtd PATHS ${SPECTRE_LIB_PATH} REQUIRED) - set(LIBCMT_SPECTRE debug ${LIBCMT_SPECTRE_DEB} optimized ${LIBCMT_SPECTRE_REL}) - message(INFO "*** using spectre lib: ${LIBCMT_SPECTRE}") - find_library(LIBCPMT_SPECTRE_REL libcpmt PATHS ${SPECTRE_LIB_PATH} REQUIRED) - find_library(LIBCPMT_SPECTRE_DEB libcpmtd PATHS ${SPECTRE_LIB_PATH} REQUIRED) - set(LIBCPMT_SPECTRE debug ${LIBCPMT_SPECTRE_DEB} optimized ${LIBCPMT_SPECTRE_REL}) - message(INFO "*** using spectre lib: ${LIBCPMT_SPECTRE}") - find_library(LIBVCRUNTIME_SPECTRE_REL libvcruntime PATHS ${SPECTRE_LIB_PATH} REQUIRED) - find_library(LIBVCRUNTIME_SPECTRE_DEB libvcruntimed PATHS ${SPECTRE_LIB_PATH} REQUIRED) - set(LIBVCRUNTIME_SPECTRE debug ${LIBVCRUNTIME_SPECTRE_DEB} optimized ${LIBVCRUNTIME_SPECTRE_REL}) - message(INFO "*** using spectre lib: ${LIBVCRUNTIME_SPECTRE}") - set(SPECTRE_LIBS - ${LIBCMT_SPECTRE} - ${LIBCPMT_SPECTRE} - ${LIBVCRUNTIME_SPECTRE}) - - add_link_options("LINKER:/guard:cf") -endif() - -if (NOT APPLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mspeculative-load-hardening -mretpoline") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mspeculative-load-hardening -mretpoline") -endif() +# windows specific flags +if (MSVC) + # always create debug info + add_definitions("/Zi") + add_definitions("/Z7") + + # build with no VC runtime depedencies: + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /Qspectre /guard:cf /Zi /Z7") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /Qspectre /guard:cf") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG") +else (MSVC) + set(CMAKE_CXX_FLAGS "-static-libgcc") +endif (MSVC) + include_directories(${PROJECT_BINARY_DIR}/src) include_directories(${PROJECT_SOURCE_DIR}/src) # OpenMP if(ENABLE_OPENMP) - -if (APPLE) - set(OPENMP_PATH "/usr/local/opt/libomp") - set(OPENMP_COMPILER_FLAGS "-Xpreprocessor -fopenmp -I${OPENMP_PATH}/include -lomp -L${OPENMP_PATH}/lib") - set(OPENMP_LIB_NAME "omp") - - set(OpenMP_CXX_FLAGS "${OPENMP_COMPILER_FLAGS}") - set(OpenMP_C_FLAGS "${OPENMP_COMPILER_FLAGS}") - set(OpenMP_CXX_LIB_NAMES "${OPENMP_LIB_NAME}") - set(OpenMP_C_LIB_NAMES "${OPENMP_LIB_NAME}") - set(OpenMP_omp_LIBRARY "${OPENMP_PATH}/lib/libomp.dylib") -endif() - find_package(OpenMP) if(OPENMP_FOUND) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") diff --git a/src/Simulation/Native/build-native-simulator.ps1 b/src/Simulation/Native/build-native-simulator.ps1 index 625112a0b1a..3908c7df01c 100644 --- a/src/Simulation/Native/build-native-simulator.ps1 +++ b/src/Simulation/Native/build-native-simulator.ps1 @@ -10,62 +10,25 @@ if (-not (Test-Path $nativeBuild)) { } Push-Location $nativeBuild -# Search for "sanitize" in -# https://clang.llvm.org/docs/ClangCommandLineReference.html -# https://man7.org/linux/man-pages/man1/gcc.1.html -$SANITIZE_FLAGS=` - "-fsanitize=undefined " ` - + "-fsanitize=shift -fsanitize=shift-base " ` - + "-fsanitize=integer-divide-by-zero -fsanitize=float-divide-by-zero " ` - + "-fsanitize=unreachable " ` - + "-fsanitize=vla-bound -fsanitize=null -fsanitize=return " ` - + "-fsanitize=signed-integer-overflow -fsanitize=bounds -fsanitize=alignment -fsanitize=object-size " ` - + "-fsanitize=float-cast-overflow -fsanitize=nonnull-attribute -fsanitize=returns-nonnull-attribute -fsanitize=bool -fsanitize=enum " ` - + "-fsanitize=vptr -fsanitize=pointer-overflow -fsanitize=builtin " ` - + "-fsanitize=implicit-conversion -fsanitize=local-bounds -fsanitize=nullability " ` - ` - + "-fsanitize=address " ` - + "-fsanitize=pointer-compare -fsanitize=pointer-subtract " ` - + "-fsanitize-address-use-after-scope " ` - + "-fno-omit-frame-pointer -fno-optimize-sibling-calls" - - #+ "-fsanitize=unsigned-integer-overflow " # TODO(rokuzmin, #884): Disable this option for _specific_ lines - # of code, but not for the whole binary. - # There should be no space after -D CMAKE_BUILD_TYPE= but if we provide the environment variable inline, without # the space it doesn't seem to get substituted... With invalid -D CMAKE_BUILD_TYPE argument cmake silently produces # a DEBUG build. if (($IsWindows) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Win")))) { - $CMAKE_C_COMPILER = "-DCMAKE_C_COMPILER=clang.exe" - $CMAKE_CXX_COMPILER = "-DCMAKE_CXX_COMPILER=clang++.exe" - - if ((!(Get-Command clang -ErrorAction SilentlyContinue) -and (choco find --idonly -l llvm) -contains "llvm") -or ` - (Test-Path Env:/AGENT_OS)) { - # LLVM was installed by Chocolatey, so add the install location to the path. - $env:PATH = "$($env:SystemDrive)\Program Files\LLVM\bin;$env:Path" - } - - cmake -G Ninja -D BUILD_SHARED_LIBS:BOOL="1" $CMAKE_C_COMPILER $CMAKE_CXX_COMPILER ` - -D CMAKE_BUILD_TYPE="$Env:BUILD_CONFIGURATION" .. - # Without `-G Ninja` we fail to switch from MSVC to Clang. - # Sanitizers are not supported on Windows at the moment. Check again after migrating from Clang-11. + Write-Host "On Windows build native simulator using the default C/C++ compiler (should be MSVC)" + cmake -D BUILD_SHARED_LIBS:BOOL="1" -D CMAKE_BUILD_TYPE="$Env:BUILD_CONFIGURATION" .. } elseif (($IsLinux) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Lin")))) { - cmake -D BUILD_SHARED_LIBS:BOOL="1" -D CMAKE_C_COMPILER=clang-11 -D CMAKE_CXX_COMPILER=clang++-11 ` - -D CMAKE_C_FLAGS_DEBUG="$SANITIZE_FLAGS" ` - -D CMAKE_CXX_FLAGS_DEBUG="$SANITIZE_FLAGS" ` - -D CMAKE_BUILD_TYPE="$Env:BUILD_CONFIGURATION" .. + Write-Host "On Linux build native simulator using gcc (needed for OpenMP)" + cmake -D BUILD_SHARED_LIBS:BOOL="1" -D CMAKE_C_COMPILER=gcc -D CMAKE_CXX_COMPILER=g++ -D CMAKE_BUILD_TYPE="$Env:BUILD_CONFIGURATION" .. } elseif (($IsMacOS) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Darwin")))) { - Write-Host "On MacOS build using the default C/C++ compiler (should be AppleClang)" - - cmake -D BUILD_SHARED_LIBS:BOOL="1" ` - -D CMAKE_C_FLAGS_DEBUG="$SANITIZE_FLAGS" ` - -D CMAKE_CXX_FLAGS_DEBUG="$SANITIZE_FLAGS" ` - -D CMAKE_BUILD_TYPE="$Env:BUILD_CONFIGURATION" .. + Write-Host "On MacOS build native simulator using gcc (needed for OpenMP)" + # `gcc`on Darwin seems to be a shim that redirects to AppleClang, to get real gcc, must point to the specific + # version of gcc we've installed. + cmake -D BUILD_SHARED_LIBS:BOOL="1" -D CMAKE_C_COMPILER=gcc-7 -D CMAKE_CXX_COMPILER=g++-7 -D CMAKE_BUILD_TYPE="$Env:BUILD_CONFIGURATION" .. } else { cmake -D BUILD_SHARED_LIBS:BOOL="1" -D CMAKE_BUILD_TYPE="$Env:BUILD_CONFIGURATION" .. diff --git a/src/Simulation/Native/prerequisites.ps1 b/src/Simulation/Native/prerequisites.ps1 index 4b7c2a72fc4..3f1272ffa84 100644 --- a/src/Simulation/Native/prerequisites.ps1 +++ b/src/Simulation/Native/prerequisites.ps1 @@ -2,29 +2,15 @@ # Licensed under the MIT License. if (($IsMacOS) -or ((Test-Path Env:AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Darwin")))) { - brew install libomp -} elseif (($IsWindows) -or ((Test-Path Env:/AGENT_OS) -and ($Env:AGENT_OS.StartsWith("Win")))) { - if (!(Get-Command clang -ErrorAction SilentlyContinue) -or ` - (Test-Path Env:/AGENT_OS)) { - choco install llvm --version=11.1.0 --allow-downgrade - Write-Host "##vso[task.setvariable variable=PATH;]$($env:SystemDrive)\Program Files\LLVM\bin;$Env:PATH" - } - if (!(Get-Command ninja -ErrorAction SilentlyContinue)) { - choco install ninja - } - if (!(Get-Command cmake -ErrorAction SilentlyContinue)) { - choco install cmake - } - refreshenv -} -else { - if (Get-Command sudo -ErrorAction SilentlyContinue) { - sudo apt update - sudo apt-get install -y clang-11 - } else { - apt update - apt-get install -y clang-11 - } + # building with gcc-9 succeeds but some of the unit tests fail + Write-Host "Install gcc-7 as pre-req for building native simulator on MacOS" + # temporary workaround for Bintray sunset + # remove this after Homebrew is updated to 3.1.1 on MacOS image, see: + # https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md + brew update + brew install gcc@7 +} else { + Write-Host "No pre-reqs for building native simulator on platforms other than MacOS" } diff --git a/src/Simulation/Native/src/CMakeLists.txt b/src/Simulation/Native/src/CMakeLists.txt index 81a510f7e9e..dbbda28611f 100644 --- a/src/Simulation/Native/src/CMakeLists.txt +++ b/src/Simulation/Native/src/CMakeLists.txt @@ -2,10 +2,17 @@ # Licensed under the MIT License. # AVX -set(AVXFLAGS "-mavx") +if (MSVC) +set(AVXFLAGS "/arch:AVX" ) +set(AVX2FLAGS "/arch:AVX2" ) +set(AVX512FLAGS "/arch:AVX512" ) +set(FMAFLAGS "") +else(MSVC) +SET(AVXFLAGS "-mavx") set(AVX2FLAGS "-mfma -mavx2") set(AVX512FLAGS "-mfma -mavx512f -mavx512cd") set(FMAFLAGS ) +endif(MSVC) configure_file(config.hpp.in ${PROJECT_BINARY_DIR}/src/config.hpp) configure_file(version.hpp.in ${PROJECT_BINARY_DIR}/src/version.hpp) @@ -16,19 +23,20 @@ add_subdirectory(simulator) set(SOURCES simulator/factory.cpp simulator/capi.cpp simulator/simulator.cpp util/openmp.cpp simulator/simulatoravx.cpp simulator/simulatoravx2.cpp simulator/simulatoravx512.cpp ) if(BUILD_SHARED_LIBS) add_library(Microsoft.Quantum.Simulator.Runtime SHARED ${SOURCES}) - set_source_files_properties(simulator/capi.cpp PROPERTIES COMPILE_FLAGS ${AVXFLAGS}) - set_source_files_properties(simulator/simulator.cpp PROPERTIES COMPILE_FLAGS ${AVXFLAGS}) set_source_files_properties(simulator/simulatoravx.cpp PROPERTIES COMPILE_FLAGS ${AVXFLAGS}) - set_source_files_properties(simulator/simulatoravx2.cpp PROPERTIES COMPILE_FLAGS -mfma COMPILE_FLAGS ${AVX2FLAGS}) - set_source_files_properties(simulator/simulatoravx512.cpp PROPERTIES COMPILE_FLAGS -mfma COMPILE_FLAGS ${AVX512FLAGS}) +if (MSVC) +set_source_files_properties(simulator/simulatoravx2.cpp PROPERTIES COMPILE_FLAGS -mfma COMPILE_FLAGS ${AVX2FLAGS}) +set_source_files_properties(simulator/simulatoravx512.cpp PROPERTIES COMPILE_FLAGS -mfma COMPILE_FLAGS ${AVX512FLAGS}) +else(MSVC) +set_source_files_properties(simulator/simulatoravx2.cpp PROPERTIES COMPILE_FLAGS -mfma COMPILE_FLAGS ${AVX2FLAGS}) +set_source_files_properties(simulator/simulatoravx512.cpp PROPERTIES COMPILE_FLAGS -mfma COMPILE_FLAGS ${AVX512FLAGS}) +endif(MSVC) message (STATUS "Building shared library") target_compile_definitions(Microsoft.Quantum.Simulator.Runtime PRIVATE BUILD_DLL=1) set_target_properties(Microsoft.Quantum.Simulator.Runtime PROPERTIES POSITION_INDEPENDENT_CODE TRUE) else(BUILD_SHARED_LIBS) message (STATUS "Building static library") add_library(Microsoft.Quantum.Simulator.Runtime STATIC ${SOURCES}) - set_source_files_properties(simulator/capi.cpp PROPERTIES COMPILE_FLAGS ${AVXFLAGS}) - set_source_files_properties(simulator/simulator.cpp PROPERTIES COMPILE_FLAGS ${AVXFLAGS}) set_source_files_properties(simulator/simulatoravx.cpp PROPERTIES COMPILE_FLAGS ${AVXFLAGS}) set_source_files_properties(simulator/simulatoravx2.cpp PROPERTIES COMPILE_FLAGS ${AVX2FLAGS}) set_source_files_properties(simulator/simulatoravx512.cpp PROPERTIES COMPILE_FLAGS ${AVX512FLAGS}) diff --git a/src/Simulation/Native/src/simulator/CMakeLists.txt b/src/Simulation/Native/src/simulator/CMakeLists.txt index d838c545bea..d8b7a391013 100644 --- a/src/Simulation/Native/src/simulator/CMakeLists.txt +++ b/src/Simulation/Native/src/simulator/CMakeLists.txt @@ -1,8 +1,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -set(AVXFLAGS "-mavx") - add_executable(factory_test factory_test.cpp) target_link_libraries(factory_test Microsoft.Quantum.Simulator.Runtime) add_test(NAME factory_test COMMAND ./factory_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) @@ -21,7 +19,6 @@ add_executable(quantum_simulator_unittests "${PROJECT_SOURCE_DIR}/src/catch2/catch_driver.cpp" local_test.cpp ) -set_source_files_properties(local_test.cpp PROPERTIES COMPILE_FLAGS ${AVXFLAGS}) target_link_libraries(quantum_simulator_unittests PUBLIC Microsoft.Quantum.Simulator.Runtime diff --git a/src/Simulation/Native/src/simulator/kernels.hpp b/src/Simulation/Native/src/simulator/kernels.hpp index dbf406dd862..3311bb27f8c 100644 --- a/src/Simulation/Native/src/simulator/kernels.hpp +++ b/src/Simulation/Native/src/simulator/kernels.hpp @@ -75,8 +75,6 @@ unsigned getvalue( std::vector, A> const& wfn, unsigned q, double eps = 100. * std::numeric_limits::epsilon()) - __attribute__((noinline)) // TODO(rokuzmin, #885): Try to remove `__attribute__((noinline))` after migrating - // to clang-13 on Win and Linux. { std::size_t mask = 1ull << q; for (std::size_t i = 0; i < wfn.size(); ++i)