Skip to content

Commit 6729c19

Browse files
Chao1Hanfengyuan14
andauthored
Enable fp64 conversion emulation conditionally (#675)
Co-authored-by: Feng Yuan <[email protected]>
1 parent 1d70431 commit 6729c19

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

cmake/BuildFlags.cmake

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# Setup building flags for SYCL device and host codes.
22

3+
function(CHECK_SYCL_FLAG FLAG VARIABLE_NAME)
4+
set(TEMP_DIR "${CMAKE_BINARY_DIR}/temp")
5+
file(MAKE_DIRECTORY ${TEMP_DIR})
6+
set(TEST_SRC_FILE "${TEMP_DIR}/check_options.cpp")
7+
set(TEST_EXE_FILE "${TEMP_DIR}/check_options.out")
8+
file(WRITE ${TEST_SRC_FILE} "#include <iostream>\nint main() { std::cout << \"Checking compiler options ...\" << std::endl; return 0; }\n")
9+
execute_process(
10+
COMMAND ${SYCL_COMPILER} -fsycl ${TEST_SRC_FILE} -o ${TEST_EXE_FILE} ${FLAG}
11+
WORKING_DIRECTORY ${TEMP_DIR}
12+
OUTPUT_VARIABLE output
13+
ERROR_VARIABLE output
14+
RESULT_VARIABLE result
15+
TIMEOUT 60
16+
)
17+
if(result EQUAL 0)
18+
set(${VARIABLE_NAME} TRUE PARENT_SCOPE)
19+
else()
20+
set(${VARIABLE_NAME} FALSE PARENT_SCOPE)
21+
endif()
22+
file(REMOVE_RECURSE ${TEMP_DIR})
23+
endfunction()
24+
325
# Support GCC on Linux and MSVC on Windows at the moment.
426
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
527
# # -- Host flags (SYCL_CXX_FLAGS)
@@ -64,8 +86,16 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"
6486
set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI})
6587
endif()
6688

67-
set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -fsycl-fp64-conv-emu)
68-
89+
CHECK_SYCL_FLAG("-fsycl-fp64-conv-emu" SUPPORTS_FP64_CONV_EMU)
90+
if(SUPPORTS_FP64_CONV_EMU)
91+
set(SYCL_KERNEL_OPTIONS ${SYCL_KERNEL_OPTIONS} -fsycl-fp64-conv-emu)
92+
else()
93+
message(WARNING "The compiler does not support the '-fsycl-fp64-conv-emu' flag, \
94+
will disable it. On some platforms that don't support FP64, \
95+
running operations with the FP64 datatype will raise a Runtime error: Required aspect fp64 is not supported on the device \
96+
or a Native API failed error.")
97+
endif()
98+
6999
set(SYCL_FLAGS ${SYCL_FLAGS} ${SYCL_KERNEL_OPTIONS})
70100

71101
set(TORCH_XPU_OPS_FLAGS ${SYCL_HOST_FLAGS})

0 commit comments

Comments
 (0)