-
Notifications
You must be signed in to change notification settings - Fork 1.1k
cpu: rv64: cmake: fix gcc ice bug when specifying arch opt flags #4466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cpu: rv64: cmake: fix gcc ice bug when specifying arch opt flags #4466
Conversation
|
If the user sets If the user does not provide compiler flags, we detect extension support via CMake; however, if the user explicitly specifies flags, we should compile using those specified flags. What do you think about this approach? |
Thank you for pointing this out @zhangfeiv0 . Updated in the new commit. Now we can:
See cmake logs:
I think a detection is still required even if the user specifies any custom flags. This PR addresses the issue where a user wants fewer extensions than the compiler's default capabilities by specifying |
dzarukin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you, please, elaborate why CMake changes are required and what's the verbose purpose of RV64_MARCH_FLAG? Dealing with compiler options in CMake doesn't look like a promising path to me as it's extremely hard to keep all existing and future options in harmony over oneDNN versions esp. when it comes to inspecting a string value.
I'd assume that changes to pooling file should be enough to address the issue.
|
Thank you for the feedback @dzarukin. Clarify why CMake changes are necessaryYou're right that changing However, the purpose of CMake changes are to support documented The real issue is that CMake detection happens before
Without the CMake fix:
About string inspection concernsI totally understand your concern about string parsing being fragile. Let me propose a cleaner alternative: Alternative Approach: Re-test compiler capabilities after applying user flagsInstead of parsing the if (DNNL_TARGET_ARCH STREQUAL "RV64")
if (NOT DNNL_ARCH_OPT_FLAGS STREQUAL "HostOpts")
message(STATUS "Testing Arch Opt Flags for RV64: ${DNNL_ARCH_OPT_FLAGS}")
set(ARCH_SIMD_TEST_FLAGS "${DNNL_ARCH_OPT_FLAGS}")
endif()
# Check if the RVV Intrinsics can be compiled with the current toolchain and flags
if (DNNL_ARCH_OPT_FLAGS STREQUAL "HostOpts")
set(ARCH_SIMD_TEST_FLAGS "-march=rv64gcv")
endif()
set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "${ARCH_SIMD_TEST_FLAGS}")
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("#if !defined(__riscv) || !defined(__riscv_v)
#error \"RISC-V or vector extension(RVV) is not supported by the compiler\"
#endif
#if defined(__riscv_v_intrinsic) && __riscv_v_intrinsic < 12000
#error \"RISC-V intrinsics v0.12 or higher is required\"
#endif
#include <riscv_vector.h>
int main() {
return 0;
};"
CAN_COMPILE_RVV_INTRINSICS
)See logs:zhangjian@localhost:~/oneDNN/build_rvv (main) $ rm -rf * && cmake .. -DDNNL_TARGET_ARCH="RV64"
-- CMAKE_BUILD_TYPE is unset, defaulting to Release
-- The C compiler identification is GNU 14.2.0
-- The CXX compiler identification is GNU 14.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/zhangjian/tools/tool-gcc14.2/bin/riscv64-unknown-linux-gnu-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/zhangjian/tools/tool-gcc14.2/bin/riscv64-unknown-linux-gnu-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- DNNL_TARGET_ARCH: RV64
-- DNNL_LIBRARY_NAME: dnnl
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Performing Test CAN_COMPILE_RVV_INTRINSICS
-- Performing Test CAN_COMPILE_RVV_INTRINSICS - Success
-- Performing Test CAN_COMPILE_ZVFH_INTRINSICS
-- Performing Test CAN_COMPILE_ZVFH_INTRINSICS - Success
-- Can compile RVV Intrinsics: TRUE
-- Can compile Zvfh Intrinsics: TRUE
-- DNNL_RISCV_USE_RVV_INTRINSICS: TRUE
-- DNNL_RISCV_USE_ZVFH_INTRINSICS: TRUE
-- Using RV64 march flag: -march=rv64gcv_zvfh
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Could NOT find Doxyrest (missing: DOXYREST_EXECUTABLE)
-- Found Python: /usr/bin/python3.11 (found suitable version "3.11.7", minimum required is "3.7") found components: Interpreter
-- Could NOT find Sphinx (missing: SPHINX_EXECUTABLE)
-- Found Git: /usr/bin/git (found version "2.43.0")
-- Enabled testing coverage: CI
-- Enabled workload: TRAINING
-- Enabled primitives: ALL
-- Enabled primitive CPU ISA: ALL
-- Enabled primitive GPU ISA: ALL
-- Enabled GeMM kernels ISA: ALL
-- Primitive cache is enabled
-- Graph component is enabled
-- Configuring done (1.8s)
-- Generating done (0.2s)
-- Build files have been written to: /home/zhangjian/oneDNN/build_rvv
zhangjian@localhost:~/oneDNN/build_rvv (main) $ rm -rf * && cmake .. -DDNNL_TARGET_ARCH="RV64" -DDNNL_ARCH_OPT_FLAGS="-march=rv64gc"
-- CMAKE_BUILD_TYPE is unset, defaulting to Release
-- The C compiler identification is GNU 14.2.0
-- The CXX compiler identification is GNU 14.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/zhangjian/tools/tool-gcc14.2/bin/riscv64-unknown-linux-gnu-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/zhangjian/tools/tool-gcc14.2/bin/riscv64-unknown-linux-gnu-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- DNNL_TARGET_ARCH: RV64
-- DNNL_LIBRARY_NAME: dnnl
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Testing Arch Opt Flags for RV64: -march=rv64gc
-- Performing Test CAN_COMPILE_RVV_INTRINSICS
-- Performing Test CAN_COMPILE_RVV_INTRINSICS - Failed
-- Can compile RVV Intrinsics: FALSE
-- Can compile Zvfh Intrinsics: FALSE
-- DNNL_RISCV_USE_RVV_INTRINSICS: FALSE
-- DNNL_RISCV_USE_ZVFH_INTRINSICS: FALSE
-- Using RV64 march flag: -march=rv64gc
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Could NOT find Doxyrest (missing: DOXYREST_EXECUTABLE)
-- Found Python: /usr/bin/python3.11 (found suitable version "3.11.7", minimum required is "3.7") found components: Interpreter
-- Could NOT find Sphinx (missing: SPHINX_EXECUTABLE)
-- Found Git: /usr/bin/git (found version "2.43.0")
-- Enabled testing coverage: CI
-- Enabled workload: TRAINING
-- Enabled primitives: ALL
-- Enabled primitive CPU ISA: ALL
-- Enabled primitive GPU ISA: ALL
-- Enabled GeMM kernels ISA: ALL
-- Primitive cache is enabled
-- Graph component is enabled
-- Configuring done (1.4s)
-- Generating done (0.2s)
-- Build files have been written to: /home/zhangjian/oneDNN/build_rvv
zhangjian@localhost:~/oneDNN/build_rvv (main) $ rm -rf * && cmake .. -DDNNL_TARGET_ARCH="RV64" -DDNNL_ARCH_OPT_FLAGS="-march=rv64gcv"
-- CMAKE_BUILD_TYPE is unset, defaulting to Release
-- The C compiler identification is GNU 14.2.0
-- The CXX compiler identification is GNU 14.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/zhangjian/tools/tool-gcc14.2/bin/riscv64-unknown-linux-gnu-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/zhangjian/tools/tool-gcc14.2/bin/riscv64-unknown-linux-gnu-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- DNNL_TARGET_ARCH: RV64
-- DNNL_LIBRARY_NAME: dnnl
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Testing Arch Opt Flags for RV64: -march=rv64gcv
-- Performing Test CAN_COMPILE_RVV_INTRINSICS
-- Performing Test CAN_COMPILE_RVV_INTRINSICS - Success
-- Performing Test CAN_COMPILE_ZVFH_INTRINSICS
-- Performing Test CAN_COMPILE_ZVFH_INTRINSICS - Failed
-- Can compile RVV Intrinsics: TRUE
-- Can compile Zvfh Intrinsics: FALSE
-- DNNL_RISCV_USE_RVV_INTRINSICS: TRUE
-- DNNL_RISCV_USE_ZVFH_INTRINSICS: FALSE
-- Using RV64 march flag: -march=rv64gcv
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Could NOT find Doxyrest (missing: DOXYREST_EXECUTABLE)
-- Found Python: /usr/bin/python3.11 (found suitable version "3.11.7", minimum required is "3.7") found components: Interpreter
-- Could NOT find Sphinx (missing: SPHINX_EXECUTABLE)
-- Found Git: /usr/bin/git (found version "2.43.0")
-- Enabled testing coverage: CI
-- Enabled workload: TRAINING
-- Enabled primitives: ALL
-- Enabled primitive CPU ISA: ALL
-- Enabled primitive GPU ISA: ALL
-- Enabled GeMM kernels ISA: ALL
-- Primitive cache is enabled
-- Graph component is enabled
-- Configuring done (1.7s)
-- Generating done (0.2s)
-- Build files have been written to: /home/zhangjian/oneDNN/build_rvv
zhangjian@localhost:~/oneDNN/build_rvv (main) $ rm -rf * && cmake .. -DDNNL_TARGET_ARCH="RV64" -DDNNL_ARCH_OPT_FLAGS="-march=rv64gcv_zvfh"
-- CMAKE_BUILD_TYPE is unset, defaulting to Release
-- The C compiler identification is GNU 14.2.0
-- The CXX compiler identification is GNU 14.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/zhangjian/tools/tool-gcc14.2/bin/riscv64-unknown-linux-gnu-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/zhangjian/tools/tool-gcc14.2/bin/riscv64-unknown-linux-gnu-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- DNNL_TARGET_ARCH: RV64
-- DNNL_LIBRARY_NAME: dnnl
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Testing Arch Opt Flags for RV64: -march=rv64gcv_zvfh
-- Performing Test CAN_COMPILE_RVV_INTRINSICS
-- Performing Test CAN_COMPILE_RVV_INTRINSICS - Success
-- Performing Test CAN_COMPILE_ZVFH_INTRINSICS
-- Performing Test CAN_COMPILE_ZVFH_INTRINSICS - Success
-- Can compile RVV Intrinsics: TRUE
-- Can compile Zvfh Intrinsics: TRUE
-- DNNL_RISCV_USE_RVV_INTRINSICS: TRUE
-- DNNL_RISCV_USE_ZVFH_INTRINSICS: TRUE
-- Using RV64 march flag: -march=rv64gcv_zvfh
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Could NOT find Doxyrest (missing: DOXYREST_EXECUTABLE)
-- Found Python: /usr/bin/python3.11 (found suitable version "3.11.7", minimum required is "3.7") found components: Interpreter
-- Could NOT find Sphinx (missing: SPHINX_EXECUTABLE)
-- Found Git: /usr/bin/git (found version "2.43.0")
-- Enabled testing coverage: CI
-- Enabled workload: TRAINING
-- Enabled primitives: ALL
-- Enabled primitive CPU ISA: ALL
-- Enabled primitive GPU ISA: ALL
-- Enabled GeMM kernels ISA: ALL
-- Primitive cache is enabled
-- Graph component is enabled
-- Configuring done (1.8s)
-- Generating done (0.2s)
-- Build files have been written to: /home/zhangjian/oneDNN/build_rvvThis approach reaches the point where |
I got the part about user controlling behavior of extensions which is fine with me. Before jumping into a proposal, could you, please, expand on why CMake detection is needed at all given that there's XByak support for RISC-V now and all supported extensions can be verified at runtime through With data type support tucked behind the extension I can see two options:
If this understanding is correct, CMake can safely discard feature detection code unless this vision misses some important pieces... |
|
Thank you for the clarification @dzarukin. You're absolutely right. I will drop all CMake detection changes and keep the pooling file fix |
Description
This PR fixes the gcc14.2 internal compiler error (ICE) bug that occurs when specifying
-DDNNL_ARCH_OPT_FLAGS="-march=rv64gcv"to disablezvfhextension.I attempted to disable
zvfhextension by adding-DDNNL_ARCH_OPT_FLAGS="-march=rv64gcv"in the cmake options. However, I found two bugs:platform.cmake, the test that setsDNNL_RISCV_USE_ZVFH_INTRINSICStotruepassed beforeDDNNL_ARCH_OPT_FLAGSoverried theCMAKE_CCXX_FLAGS.rvv_nhwc_pooling.hppusesDNNL_RISCV_USE_ZVFH_INTRINSICSflag for dispatch, but this flag can be undefined.These issues together cause a GCC ICE during compilation.
See Log
Bug Fix
We fix these bugs by:
DNNL_ARCH_OPT_FLAGSto correctly determine theCAN_COMPILE_ZVFH_INTRINSICSflag.zvfhruntime check by using thecpu_isa_traitsfor RV64.Tests
After this PR:
DNNL_RISCV_USE_ZVFH_INTRINSICSflag is set correctly and there are no compilation errors.See log
f16tests are skipped on therv64gcvplatform as excepted.See log