[Bf-blender-cvs] [3714d3c3ce8] master: Cycles: link oneAPI backend with debug version of sycl when in Debug

Xavier Hallade noreply at git.blender.org
Fri Oct 7 16:16:43 CEST 2022


Commit: 3714d3c3ce8a64a027012653ee8372617f0ce3f8
Author: Xavier Hallade
Date:   Thu Oct 6 20:49:53 2022 +0200
Branches: master
https://developer.blender.org/rB3714d3c3ce8a64a027012653ee8372617f0ce3f8

Cycles: link oneAPI backend with debug version of sycl when in Debug

It fixes SYCL runtime issues in Debug builds that were due to mixing
Release and Debug MSVC runtimes.
This commit also removes specific handling of dpcpp compiler executable
to simplify the CMake implementation. Using it like clang++ works and
clang++ executable is also available from Intel oneAPI DPC++ compiler in
case it doesn't.

===================================================================

M	build_files/cmake/Modules/FindSYCL.cmake
M	build_files/cmake/platform/platform_win32.cmake
M	intern/cycles/device/CMakeLists.txt
M	intern/cycles/kernel/CMakeLists.txt

===================================================================

diff --git a/build_files/cmake/Modules/FindSYCL.cmake b/build_files/cmake/Modules/FindSYCL.cmake
index 7aead43dd2a..139ebad46b1 100644
--- a/build_files/cmake/Modules/FindSYCL.cmake
+++ b/build_files/cmake/Modules/FindSYCL.cmake
@@ -62,6 +62,13 @@ FIND_LIBRARY(SYCL_LIBRARY
     lib64 lib
 )
 
+if(WIN32)
+  string(REPLACE ".lib" "d.lib" SYCL_LIBRARY_DEBUG ${SYCL_LIBRARY})
+  set(SYCL_LIBRARY_DEBUG ${SYCL_LIBRARY_DEBUG} CACHE FILEPATH "Path to SYCL debug library")
+else()
+  set(SYCL_LIBRARY_DEBUG ${SYCL_LIBRARY} CACHE FILEPATH "Path to SYCL debug library")
+endif()
+
 FIND_PATH(SYCL_INCLUDE_DIR
   NAMES
     CL/sycl.hpp
@@ -85,4 +92,5 @@ ENDIF()
 
 MARK_AS_ADVANCED(
   _SYCL_INCLUDE_PARENT_DIR
+  SYCL_LIBRARY_DEBUG
 )
diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake
index 0f7f04203c6..7031b1faac4 100644
--- a/build_files/cmake/platform/platform_win32.cmake
+++ b/build_files/cmake/platform/platform_win32.cmake
@@ -958,11 +958,17 @@ if(WITH_CYCLES_DEVICE_ONEAPI)
   if(EXISTS ${CYCLES_SYCL} AND NOT SYCL_ROOT_DIR)
     set(SYCL_ROOT_DIR ${CYCLES_SYCL})
   endif()
-  file(GLOB _sycl_runtime_libraries
+  file(GLOB _sycl_runtime_libraries_glob
     ${SYCL_ROOT_DIR}/bin/sycl.dll
     ${SYCL_ROOT_DIR}/bin/sycl[0-9].dll
-    ${SYCL_ROOT_DIR}/bin/pi_level_zero.dll
   )
+  foreach(sycl_runtime_library IN LISTS _sycl_runtime_libraries_glob)
+    string(REPLACE ".dll" "$<$<CONFIG:Debug>:d>.dll" sycl_runtime_library ${sycl_runtime_library})
+    list(APPEND _sycl_runtime_libraries ${sycl_runtime_library})
+  endforeach()
+  unset(_sycl_runtime_libraries_glob)
+
+  list(APPEND _sycl_runtime_libraries ${SYCL_ROOT_DIR}/bin/pi_level_zero.dll)
   list(APPEND PLATFORM_BUNDLED_LIBRARIES ${_sycl_runtime_libraries})
   unset(_sycl_runtime_libraries)
 endif()
diff --git a/intern/cycles/device/CMakeLists.txt b/intern/cycles/device/CMakeLists.txt
index e5467121497..5516e97f34f 100644
--- a/intern/cycles/device/CMakeLists.txt
+++ b/intern/cycles/device/CMakeLists.txt
@@ -193,8 +193,11 @@ if (WITH_CYCLES_DEVICE_ONEAPI)
     set(cycles_kernel_oneapi_lib ${CMAKE_CURRENT_BINARY_DIR}/../kernel/libcycles_kernel_oneapi.so)
   endif()
   list(APPEND LIB
-    ${SYCL_LIBRARY}
     ${cycles_kernel_oneapi_lib}
+    "$<$<CONFIG:Debug>:${SYCL_LIBRARY_DEBUG}>"
+    "$<$<CONFIG:Release>:${SYCL_LIBRARY}>"
+    "$<$<CONFIG:RelWithDebInfo>:${SYCL_LIBRARY}>"
+    "$<$<CONFIG:MinSizeRel>:${SYCL_LIBRARY}>"
   )
   add_definitions(-DWITH_ONEAPI)
   list(APPEND SRC
diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index bbf8fb8682b..d678351e69b 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -758,7 +758,6 @@ if(WITH_CYCLES_DEVICE_ONEAPI)
       ${SYCL_CPP_FLAGS}
       )
 
-
   if (WITH_CYCLES_ONEAPI_SYCL_HOST_ENABLED)
     list(APPEND sycl_compiler_flags -DWITH_ONEAPI_SYCL_HOST_ENABLED)
   endif()
@@ -826,36 +825,43 @@ if(WITH_CYCLES_DEVICE_ONEAPI)
     -D_CRT_SECURE_NO_DEPRECATE
     -DONEAPI_EXPORT)
 
-    if(sycl_compiler_compiler_name MATCHES "dpcpp")
-      # The oneAPI distribution calls the compiler "dpcpp" and comes with a script that sets environment variables.
-      add_custom_command(
-        OUTPUT ${cycles_kernel_oneapi_lib}
-        COMMAND "${sycl_compiler_root}/../../env/vars.bat"
-        COMMAND ${SYCL_COMPILER} $<$<CONFIG:Debug>:-g>$<$<CONFIG:RelWithDebInfo>:-g> ${sycl_compiler_flags}
-        DEPENDS ${cycles_oneapi_kernel_sources})
+    string(REPLACE /Redist/ /Tools/ MSVC_TOOLS_DIR ${MSVC_REDIST_DIR})
+    if(NOT CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) # case for Ninja on Windows
+      get_filename_component(cmake_mt_dir ${CMAKE_MT} DIRECTORY)
+      string(REPLACE /bin/ /Lib/ WINDOWS_KIT_DIR ${cmake_mt_dir})
+      get_filename_component(WINDOWS_KIT_DIR "${WINDOWS_KIT_DIR}/../" ABSOLUTE)
     else()
-      # The open source SYCL compiler just goes by clang++ and does not have such a script.
-      # Set the variables manually.
-      string(REPLACE /Redist/ /Tools/ MSVC_TOOLS_DIR ${MSVC_REDIST_DIR})
-      if(NOT CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) # case for Ninja on Windows
-        get_filename_component(cmake_mt_dir ${CMAKE_MT} DIRECTORY)
-        string(REPLACE /bin/ /Lib/ WINDOWS_KIT_DIR ${cmake_mt_dir})
-        get_filename_component(WINDOWS_KIT_DIR "${WINDOWS_KIT_DIR}/../" ABSOLUTE)
-      else()
-        set(WINDOWS_KIT_DIR ${WINDOWS_KITS_DIR}/Lib/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION})
-      endif()
-      list(APPEND sycl_compiler_flags
-                  -L "${MSVC_TOOLS_DIR}/lib/x64"
-                  -L "${WINDOWS_KIT_DIR}/um/x64"
-                  -L "${WINDOWS_KIT_DIR}/ucrt/x64")
-      add_custom_command(
-        OUTPUT ${cycles_kernel_oneapi_lib}
-        COMMAND ${CMAKE_COMMAND} -E env
-                "LIB=${sycl_compiler_root}/../lib" # for compiler to find sycl.lib
-                "PATH=${OCLOC_INSTALL_DIR};${sycl_compiler_root}"
-                ${SYCL_COMPILER} $<$<CONFIG:Debug>:-g>$<$<CONFIG:RelWithDebInfo>:-g> ${sycl_compiler_flags}
-        DEPENDS ${cycles_oneapi_kernel_sources})
+      set(WINDOWS_KIT_DIR ${WINDOWS_KITS_DIR}/Lib/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION})
     endif()
+    list(APPEND sycl_compiler_flags
+                -L "${MSVC_TOOLS_DIR}/lib/x64"
+                -L "${WINDOWS_KIT_DIR}/um/x64"
+                -L "${WINDOWS_KIT_DIR}/ucrt/x64")
+
+    set(sycl_compiler_flags_Release ${sycl_compiler_flags})
+    set(sycl_compiler_flags_Debug ${sycl_compiler_flags})
+    set(sycl_compiler_flags_RelWithDebInfo ${sycl_compiler_flags})
+    set(sycl_compiler_flags_MinSizeRel ${sycl_compiler_flags})
+    list(APPEND sycl_compiler_flags_RelWithDebInfo -g)
+    get_filename_component(sycl_library_debug_name ${SYCL_LIBRARY_DEBUG} NAME_WE)
+    list(APPEND sycl_compiler_flags_Debug
+                -g
+                -D_DEBUG
+                -nostdlib -Xclang --dependent-lib=msvcrtd
+                -Xclang --dependent-lib=${sycl_library_debug_name})
+
+    add_custom_command(
+      OUTPUT ${cycles_kernel_oneapi_lib}
+      COMMAND ${CMAKE_COMMAND} -E env
+              "LIB=${sycl_compiler_root}/../lib" # for compiler to find sycl.lib
+              "PATH=${OCLOC_INSTALL_DIR}\;${sycl_compiler_root}"
+              ${SYCL_COMPILER}
+              "$<$<CONFIG:Release>:${sycl_compiler_flags_Releas}>"
+              "$<$<CONFIG:RelWithDebInfo>:${sycl_compiler_flags_RelWithDebInfo}>"
+              "$<$<CONFIG:Debug>:${sycl_compiler_flags_Debug}>"
+              "$<$<CONFIG:MinSizeRel>:${sycl_compiler_flags_Release}>"
+              COMMAND_EXPAND_LISTS
+              DEPENDS ${cycles_oneapi_kernel_sources})
   else()
     list(APPEND sycl_compiler_flags -fPIC)
 
@@ -867,26 +873,16 @@ if(WITH_CYCLES_DEVICE_ONEAPI)
     # libpi_level_zero.so can be placed next to it and get found.
     list(APPEND sycl_compiler_flags -Wl,-rpath,'$$ORIGIN')
 
-    # The oneAPI distribution calls the compiler "dpcpp" and comes with a script that sets environment variables.
-    if(sycl_compiler_compiler_name MATCHES "dpcpp")
-      add_custom_command(
-        OUTPUT ${cycles_kernel_oneapi_lib}
-        COMMAND bash -c \"source ${sycl_compiler_root}/../../env/vars.sh&&${SYCL_COMPILER} $<$<CONFIG:Debug>:-g>$<$<CONFIG:RelWithDebInfo>:-g> ${sycl_compiler_flags}\"
-        DEPENDS ${cycles_oneapi_kernel_sources})
-    else()
-      # The open source SYCL compiler just goes by clang++ and does not have such a script.
-      # Set the variables manually.
-      if(NOT IGC_INSTALL_DIR)
-        get_filename_component(IGC_INSTALL_DIR "${sycl_compiler_root}/../lib/igc" ABSOLUTE)
-      endif()
-      add_custom_command(
-        OUTPUT ${cycles_kernel_oneapi_lib}
-        COMMAND ${CMAKE_COMMAND} -E env
-                "LD_LIBRARY_PATH=${sycl_compiler_root}/../lib:${OCLOC_INSTALL_DIR}/lib:${IGC_INSTALL_DIR}/lib"
-                "PATH=${OCLOC_INSTALL_DIR}/bin:${sycl_compiler_root}:$ENV{PATH}" # env PATH is for compiler to find ld
-                ${SYCL_COMPILER} $<$<CONFIG:Debug>:-g>$<$<CONFIG:RelWithDebInfo>:-g> ${sycl_compiler_flags}
-        DEPENDS ${cycles_oneapi_kernel_sources})
+    if(NOT IGC_INSTALL_DIR)
+      get_filename_component(IGC_INSTALL_DIR "${sycl_compiler_root}/../lib/igc" ABSOLUTE)
     endif()
+    add_custom_command(
+      OUTPUT ${cycles_kernel_oneapi_lib}
+      COMMAND ${CMAKE_COMMAND} -E env
+              "LD_LIBRARY_PATH=${sycl_compiler_root}/../lib:${OCLOC_INSTALL_DIR}/lib:${IGC_INSTALL_DIR}/lib"
+              "PATH=${OCLOC_INSTALL_DIR}/bin:${sycl_compiler_root}:$ENV{PATH}" # env PATH is for compiler to find ld
+              ${SYCL_COMPILER} $<$<CONFIG:Debug>:-g>$<$<CONFIG:RelWithDebInfo>:-g> ${sycl_compiler_flags}
+      DEPENDS ${cycles_oneapi_kernel_sources})
   endif()
 
   if(NOT WITH_BLENDER)



More information about the Bf-blender-cvs mailing list