From 3889dcf3f816cc1b44a2b4de9cd7c5f4ebb22f70 Mon Sep 17 00:00:00 2001 From: ashadrina Date: Fri, 22 Sep 2023 16:09:58 +0200 Subject: [PATCH] Merge pull request #24286 from ashadrina:intel_icx_compiler_support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add Intel® oneAPI DPC++/C++ Compiler (icx) #24286 Intel® C++ Compiler Classic (icc) is deprecated and will be removed in a oneAPI release in the second half of 2023 ([deprecation notice](https://community.intel.com/t5/Intel-oneAPI-IoT-Toolkit/DEPRECATION-NOTICE-Intel-C-Compiler-Classic/m-p/1412267#:~:text=Intel%C2%AE%20C%2B%2B%20Compiler%20Classic%20(icc)%20is%20deprecated%20and%20will,the%20second%20half%20of%202023.)). This commit is intended to add support for the next-generation compiler, Intel® oneAPI DPC++/C++ Compiler (icx) (the documentation for the compiler is available on the [link](https://www.intel.com/content/www/us/en/docs/dpcpp-cpp-compiler/developer-guide-reference/2023-2/overview.html)). ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- cmake/OpenCVCompilerOptimizations.cmake | 8 ++++---- cmake/OpenCVCompilerOptions.cmake | 17 +++++++++++++++-- cmake/OpenCVDetectCXXCompiler.cmake | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/cmake/OpenCVCompilerOptimizations.cmake b/cmake/OpenCVCompilerOptimizations.cmake index 28929c3890..90ad7d783c 100644 --- a/cmake/OpenCVCompilerOptimizations.cmake +++ b/cmake/OpenCVCompilerOptimizations.cmake @@ -224,7 +224,7 @@ if(X86 OR X86_64) ocv_update(CPU_SSE2_IMPLIES "SSE") endif() - if(CV_ICC) + if(CV_ICC OR CV_ICX) macro(ocv_intel_compiler_optimization_option name unix_flags msvc_flags) ocv_update(CPU_${name}_FLAGS_NAME "${name}") if(MSVC) @@ -260,7 +260,7 @@ if(X86 OR X86_64) ocv_intel_compiler_optimization_option(AVX512_CNL "-xCANNONLAKE" "/Qx:CANNONLAKE") ocv_intel_compiler_optimization_option(AVX512_CLX "-xCASCADELAKE" "/Qx:CASCADELAKE") ocv_intel_compiler_optimization_option(AVX512_ICL "-xICELAKE-CLIENT" "/Qx:ICELAKE-CLIENT") - elseif(CV_GCC OR CV_CLANG) + elseif(CV_GCC OR CV_CLANG OR CV_ICX) ocv_update(CPU_AVX2_FLAGS_ON "-mavx2") ocv_update(CPU_FP16_FLAGS_ON "-mf16c") ocv_update(CPU_AVX_FLAGS_ON "-mavx") @@ -657,7 +657,7 @@ macro(ocv_compiler_optimization_options) endmacro() macro(ocv_compiler_optimization_options_finalize) - if((CV_GCC OR CV_CLANG) AND (X86 OR X86_64)) + if((CV_GCC OR CV_CLANG OR CV_ICX) AND (X86 OR X86_64)) if(NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 4) if(OPENCV_EXTRA_CXX_FLAGS MATCHES "-m(sse2|avx)") add_extra_compiler_option(-mfpmath=sse) # !! important - be on the same wave with x64 compilers @@ -944,7 +944,7 @@ macro(ocv_add_dispatched_file_force_all) endmacro() -if(CV_DISABLE_OPTIMIZATION OR CV_ICC) +if(CV_DISABLE_OPTIMIZATION OR CV_ICC OR CX_ICX) ocv_update(CV_ENABLE_UNROLLED 0) else() ocv_update(CV_ENABLE_UNROLLED 1) diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index 8bd8668130..427189c079 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -105,6 +105,19 @@ elseif(CV_ICC) add_extra_compiler_option("-fp-model precise") endif() endif() +elseif(CV_ICX) + # ICX uses -ffast-math by default. + # use own flags, if no one of the flags provided by user: -fp-model, -ffast-math -fno-fast-math + if(NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " /fp:" + AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -fp-model" + AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -ffast-math" + AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -fno-fast-math" + ) + if(NOT ENABLE_FAST_MATH) + add_extra_compiler_option(-fno-fast-math) + add_extra_compiler_option(-fp-model=precise) + endif() + endif() elseif(CV_GCC OR CV_CLANG) if(ENABLE_FAST_MATH) add_extra_compiler_option(-ffast-math) @@ -112,7 +125,7 @@ elseif(CV_GCC OR CV_CLANG) endif() endif() -if(CV_GCC OR CV_CLANG) +if(CV_GCC OR CV_CLANG OR CV_ICX) # High level of warnings. add_extra_compiler_option(-W) if (NOT MSVC) @@ -336,7 +349,7 @@ if(COMMAND ocv_compiler_optimization_options_finalize) endif() # set default visibility to hidden -if((CV_GCC OR CV_CLANG) +if((CV_GCC OR CV_CLANG OR CV_ICX) AND NOT MSVC AND NOT OPENCV_SKIP_VISIBILITY_HIDDEN AND NOT " ${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}" MATCHES " -fvisibility") diff --git a/cmake/OpenCVDetectCXXCompiler.cmake b/cmake/OpenCVDetectCXXCompiler.cmake index 8fe89b3fe0..4295f96568 100644 --- a/cmake/OpenCVDetectCXXCompiler.cmake +++ b/cmake/OpenCVDetectCXXCompiler.cmake @@ -68,6 +68,23 @@ if(MSVC AND CMAKE_C_COMPILER MATCHES "icc|icl") set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS) endif() +# ---------------------------------------------------------------------------- +# Detect Intel ICXC compiler +# ---------------------------------------------------------------------------- +if(UNIX) + if(__INTEL_COMPILER) + set(CV_ICX __INTEL_LLVM_COMPILER) + elseif(CMAKE_C_COMPILER MATCHES "icx") + set(CV_ICX icx_matches_c_compiler) + elseif(CMAKE_CXX_COMPILER MATCHES "icpx") + set(CV_ICX icpx_matches_cxx_compiler) + endif() +endif() + +if(MSVC AND CMAKE_CXX_COMPILER MATCHES ".*(dpcpp-cl|dpcpp|icx-cl|icpx|icx)(.exe)?$") + set(CV_ICX __INTEL_LLVM_COMPILER_WINDOWS) +endif() + if(NOT DEFINED CMAKE_CXX_COMPILER_VERSION AND NOT OPENCV_SUPPRESS_MESSAGE_MISSING_COMPILER_VERSION) message(WARNING "OpenCV: Compiler version is not available: CMAKE_CXX_COMPILER_VERSION is not set")