Commit: a02992f1313811c9905e44dc95a0aee31d707f67 Author: Xavier Hallade Date: Wed Jun 29 12:58:04 2022 +0200 Branches: master https://developer.blender.org/rBa02992f1313811c9905e44dc95a0aee31d707f67
Cycles: Add support for rendering on Intel GPUs using oneAPI This patch adds a new Cycles device with similar functionality to the existing GPU devices. Kernel compilation and runtime interaction happen via oneAPI DPC++ compiler and SYCL API. This implementation is primarly focusing on Intel® Arc™ GPUs and other future Intel GPUs. The first supported drivers are 101.1660 on Windows and 22.10.22597 on Linux. The necessary tools for compilation are: - A SYCL compiler such as oneAPI DPC++ compiler or https://github.com/intel/llvm - Intel® oneAPI Level Zero which is used for low level device queries: https://github.com/oneapi-src/level-zero - To optionally generate prebuilt graphics binaries: Intel® Graphics Compiler All are included in Linux precompiled libraries on svn: https://svn.blender.org/svnroot/bf-blender/trunk/lib The same goes for Windows precompiled binaries but for the graphics compiler, available as "Intel® Graphics Offline Compiler for OpenCL™ Code" from https://www.intel.com/content/www/us/en/developer/articles/tool/oneapi-standalone-components.html, for which path can be set as OCLOC_INSTALL_DIR. Being based on the open SYCL standard, this implementation could also be extended to run on other compatible non-Intel hardware in the future. Reviewed By: sergey, brecht Differential Revision: https://developer.blender.org/D15254 Co-authored-by: Nikita Sirgienko <nikita.sirgie...@intel.com> Co-authored-by: Stefan Werner <stefan.wer...@intel.com> =================================================================== M CMakeLists.txt M build_files/build_environment/CMakeLists.txt M build_files/build_environment/cmake/download.cmake A build_files/build_environment/cmake/dpcpp.cmake A build_files/build_environment/cmake/dpcpp_deps.cmake A build_files/build_environment/cmake/gmmlib.cmake M build_files/build_environment/cmake/harvest.cmake A build_files/build_environment/cmake/igc.cmake A build_files/build_environment/cmake/macros.cmake A build_files/build_environment/cmake/ocloc.cmake M build_files/build_environment/cmake/options.cmake M build_files/build_environment/cmake/versions.cmake A build_files/build_environment/patches/dpcpp.diff A build_files/build_environment/patches/igc_opencl_clang.diff A build_files/cmake/Modules/FindLevelZero.cmake A build_files/cmake/Modules/FindSYCL.cmake M build_files/cmake/config/blender_release.cmake M build_files/cmake/platform/platform_unix.cmake M build_files/cmake/platform/platform_win32.cmake M intern/cycles/CMakeLists.txt M intern/cycles/blender/addon/properties.py M intern/cycles/blender/addon/ui.py M intern/cycles/blender/device.cpp M intern/cycles/blender/python.cpp M intern/cycles/cmake/external_libs.cmake M intern/cycles/device/CMakeLists.txt M intern/cycles/device/device.cpp M intern/cycles/device/device.h A intern/cycles/device/oneapi/device.cpp A intern/cycles/device/oneapi/device.h A intern/cycles/device/oneapi/device_impl.cpp A intern/cycles/device/oneapi/device_impl.h A intern/cycles/device/oneapi/dll_interface.h A intern/cycles/device/oneapi/queue.cpp A intern/cycles/device/oneapi/queue.h M intern/cycles/integrator/path_trace.cpp M intern/cycles/kernel/CMakeLists.txt M intern/cycles/kernel/device/gpu/kernel.h M intern/cycles/kernel/device/gpu/parallel_active_index.h A intern/cycles/kernel/device/oneapi/compat.h A intern/cycles/kernel/device/oneapi/context_begin.h A intern/cycles/kernel/device/oneapi/context_end.h A intern/cycles/kernel/device/oneapi/device_id.h A intern/cycles/kernel/device/oneapi/dll_interface_template.h A intern/cycles/kernel/device/oneapi/globals.h A intern/cycles/kernel/device/oneapi/image.h A intern/cycles/kernel/device/oneapi/kernel.cpp A intern/cycles/kernel/device/oneapi/kernel.h A intern/cycles/kernel/device/oneapi/kernel_templates.h M intern/cycles/kernel/types.h M intern/cycles/util/atomic.h M intern/cycles/util/half.h M intern/cycles/util/math.h M intern/cycles/util/types_float2.h M intern/cycles/util/types_float2_impl.h M intern/cycles/util/types_float3.h M intern/cycles/util/types_float3_impl.h M intern/cycles/util/types_float4.h M intern/cycles/util/types_float4_impl.h M intern/cycles/util/types_float8.h M intern/cycles/util/types_float8_impl.h M intern/cycles/util/types_int2.h M intern/cycles/util/types_int2_impl.h M intern/cycles/util/types_int3.h M intern/cycles/util/types_int3_impl.h M intern/cycles/util/types_int4.h M intern/cycles/util/types_int4_impl.h M intern/cycles/util/types_uchar2.h M intern/cycles/util/types_uchar2_impl.h M intern/cycles/util/types_uchar3.h M intern/cycles/util/types_uchar3_impl.h M intern/cycles/util/types_uchar4.h M intern/cycles/util/types_uchar4_impl.h M intern/cycles/util/types_uint2.h M intern/cycles/util/types_uint2_impl.h M intern/cycles/util/types_uint3.h M intern/cycles/util/types_uint3_impl.h M intern/cycles/util/types_uint4.h M intern/cycles/util/types_uint4_impl.h M intern/cycles/util/types_ushort4.h M source/creator/blender.map =================================================================== diff --git a/CMakeLists.txt b/CMakeLists.txt index 02648e87695..b2b8c56001b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -454,6 +454,21 @@ if(APPLE) option(WITH_CYCLES_DEVICE_METAL "Enable Cycles Apple Metal compute support" ON) endif() +# oneAPI +if(NOT APPLE) + option(WITH_CYCLES_DEVICE_ONEAPI "Enable Cycles oneAPI compute support" OFF) + option(WITH_CYCLES_ONEAPI_BINARIES "Enable Ahead-Of-Time compilation for Cycles oneAPI device" OFF) + option(WITH_CYCLES_ONEAPI_SYCL_HOST_ENABLED "Enable use of SYCL host (CPU) device execution by oneAPI implementation. This option is for debugging purposes and impacts GPU execution." OFF) + + # https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compilation/ahead-of-time-compilation.html + SET (CYCLES_ONEAPI_SPIR64_GEN_DEVICES "dg2" CACHE STRING "oneAPI Intel GPU architectures to build binaries for") + SET (CYCLES_ONEAPI_SYCL_TARGETS spir64 spir64_gen CACHE STRING "oneAPI targets to build AOT binaries for") + + mark_as_advanced(WITH_CYCLES_ONEAPI_SYCL_HOST_ENABLED) + mark_as_advanced(CYCLES_ONEAPI_SPIR64_GEN_DEVICES) + mark_as_advanced(CYCLES_ONEAPI_SYCL_TARGETS) +endif() + # Draw Manager option(WITH_DRAW_DEBUG "Add extra debug capabilities to Draw Manager" OFF) mark_as_advanced(WITH_DRAW_DEBUG) diff --git a/build_files/build_environment/CMakeLists.txt b/build_files/build_environment/CMakeLists.txt index 1cf63f2d332..a9ff48b2a9b 100644 --- a/build_files/build_environment/CMakeLists.txt +++ b/build_files/build_environment/CMakeLists.txt @@ -33,6 +33,7 @@ include(cmake/versions.cmake) include(cmake/options.cmake) include(cmake/boost_build_options.cmake) include(cmake/download.cmake) +include(cmake/macros.cmake) if(ENABLE_MINGW64) include(cmake/setup_mingw64.cmake) @@ -96,6 +97,15 @@ include(cmake/fmt.cmake) include(cmake/robinmap.cmake) if(NOT APPLE) include(cmake/xr_openxr.cmake) + if(NOT WIN32 OR BUILD_MODE STREQUAL Release) + include(cmake/dpcpp.cmake) + include(cmake/dpcpp_deps.cmake) + endif() + if(NOT WIN32) + include(cmake/igc.cmake) + include(cmake/gmmlib.cmake) + include(cmake/ocloc.cmake) + endif() endif() # OpenColorIO and dependencies. diff --git a/build_files/build_environment/cmake/download.cmake b/build_files/build_environment/cmake/download.cmake index 81e7f7ab3fe..8b210992ada 100644 --- a/build_files/build_environment/cmake/download.cmake +++ b/build_files/build_environment/cmake/download.cmake @@ -101,3 +101,19 @@ download_source(ROBINMAP) download_source(IMATH) download_source(PYSTRING) download_source(LEVEL_ZERO) +download_source(DPCPP) +download_source(VCINTRINSICS) +download_source(OPENCLHEADERS) +download_source(ICDLOADER) +download_source(MP11) +download_source(SPIRV_HEADERS) +download_source(IGC) +download_source(IGC_LLVM) +download_source(IGC_OPENCL_CLANG) +download_source(IGC_VCINTRINSICS) +download_source(IGC_SPIRV_HEADERS) +download_source(IGC_SPIRV_TOOLS) +download_source(IGC_SPIRV_TRANSLATOR) +download_source(GMMLIB) +download_source(OCLOC) + diff --git a/build_files/build_environment/cmake/dpcpp.cmake b/build_files/build_environment/cmake/dpcpp.cmake new file mode 100644 index 00000000000..563bc7aeff4 --- /dev/null +++ b/build_files/build_environment/cmake/dpcpp.cmake @@ -0,0 +1,107 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + + +if(WIN32) + set(LLVM_GENERATOR "Ninja") +else() + set(LLVM_GENERATOR "Unix Makefiles") +endif() + +set(DPCPP_CONFIGURE_ARGS + # When external deps dpcpp needs are not found it will automatically + # download the during the configure stage using FetchContent. Given + # we need to keep an archive of all source used during build for compliance + # reasons it CANNOT download anything we do not know about. By setting + # this property to ON, all downloads are disabled, and we will have to + # provide the missing deps some other way, a build error beats a compliance + # violation + --cmake-opt FETCHCONTENT_FULLY_DISCONNECTED=ON +) +set(DPCPP_SOURCE_ROOT ${BUILD_DIR}/dpcpp/src/external_dpcpp/) +set(DPCPP_EXTRA_ARGS + # When external deps dpcpp needs are not found it will automatically + # download the during the configure stage using FetchContent. Given + # we need to keep an archive of all source used during build for compliance + # reasons it CANNOT download anything we do not know about. By setting + # this property to ON, all downloads are disabled, and we will have to + # provide the missing deps some other way, a build or configure error + # beats a compliance violation + -DFETCHCONTENT_FULLY_DISCONNECTED=ON + -DLLVMGenXIntrinsics_SOURCE_DIR=${BUILD_DIR}/vcintrinsics/src/external_vcintrinsics/ + -DOpenCL_HEADERS=file://${PACKAGE_DIR}/${OPENCLHEADERS_FILE} + -DOpenCL_LIBRARY_SRC=file://${PACKAGE_DIR}/${ICDLOADER_FILE} + -DBOOST_MP11_SOURCE_DIR=${BUILD_DIR}/mp11/src/external_mp11/ + -DLEVEL_ZERO_LIBRARY=${LIBDIR}/level-zero/lib/${LIBPREFIX}ze_loader${SHAREDLIBEXT} + -DLEVEL_ZERO_INCLUDE_DIR=${LIBDIR}/level-zero/include + -DLLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR=${BUILD_DIR}/spirvheaders/src/external_spirvheaders/ + # Below here is copied from an invocation of buildbot/config.py + -DLLVM_ENABLE_ASSERTIONS=ON + -DLLVM_TARGETS_TO_BUILD=X86 + -DLLVM_EXTERNAL_PROJECTS=sycl^^llvm-spirv^^opencl^^libdevice^^xpti^^xptifw + -DLLVM_EXTERNAL_SYCL_SOURCE_DIR=${DPCPP_SOURCE_ROOT}/sycl + -DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR=${DPCPP_SOURCE_ROOT}/llvm-spirv + -DLLVM_EXTERNAL_XPTI_SOURCE_DIR=${DPCPP_SOURCE_ROOT}/xpti + -DXPTI_SOURCE_DIR=${DPCPP_SOURCE_ROOT}/xpti + -DLLVM_EXTERNAL_XPTIFW_SOURCE_DIR=${DPCPP_SOURCE_ROOT}/xptifw + -DLLVM_EXTERNAL_LIBDEVICE_SOURCE_DIR=${DPCPP_SOURCE_ROOT}/libdevice + -DLLVM_ENABLE_PROJECTS=clang^^sycl^^llvm-spirv^^opencl^^libdevice^^xpti^^xptifw + -DLIBCLC_TARGETS_TO_BUILD= + -DLIBCLC_GENERATE_REMANGLED_VARIANTS=OFF + -DSYCL_BUILD_PI_HIP_PLATFORM=AMD + -DLLVM_BUILD_TOOLS=ON + -DSYCL_ENABLE_WERROR=OFF + -DSYCL_INCLUDE_TESTS=ON + -DLLVM_ENABLE_DOXYGEN=OFF + -DLLVM_ENABLE_SPHINX=OFF + -DBUILD_SHARED_LIBS=OFF + -DSYCL_ENABLE_XPTI_TRACING=ON + -DLLVM_ENABLE_LLD=OFF + -DXPTI_ENABLE_WERROR=OFF + -DSYCL_CLANG_EXTRA_FLAGS= + -DSYCL_ENABLE_PLUGINS=level_zero + -DCMAKE_INSTALL_RPATH=\$ORIGIN + -DPython3_ROOT_DIR=${LIBDIR}/python/ + -DPython3_EXECUTABLE=${PYTHON_BINARY} + -DPYTHON_EXECUTABLE=${PYTHON_BINARY} +) + +if(WIN32) + list(APPEND DPCPP_EXTRA_ARGS -DPython3_FIND_REGISTRY=NEVER) +endif() + +ExternalProject_Add(external_dpcpp + URL file://${PACKAGE_DIR}/${DPCPP_FILE} + DOWNLOAD_DIR ${DOWNLOAD_DIR} + URL_HASH ${DPCPP_HASH_TYPE}=${DPCPP_HASH} + PREFIX ${BUILD_DIR}/dpcpp + CMAKE_GENERATOR ${LLVM_GENERATOR} + SOURCE_SUBDIR llvm + LIST_SEPARATOR ^^ + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${LIBDIR}/dpcpp ${DEFAULT_CMAKE_FLAGS} ${DPCPP_EXTRA_ARGS} + #CONFIGURE_COMMAND ${PYTHON_BINARY} ${BUILD_DIR}/dpcpp/src/external_dpcpp/buildbot/configure.py ${DPCPP_CONFIGURE_ARGS} + #BUILD_COMMAND echo "." #${PYTHON_BINARY} ${BUILD_DIR}/dpcpp/src/external_dpcpp/buildbot/compile.py + INSTALL_COMMAND ${CMAKE_COMMAND} --build . -- deploy-sycl-toolchain + PATCH_COMMAND ${PATCH_CMD} -p 1 -d ${BUILD_DIR}/dpcpp/src/external_dpcpp < ${PATCH_DIR}/dpcpp.diff + INSTALL_DIR ${LIBDIR}/dpcpp +) + +add_dependencies( + external_dpcpp + external_python + external_python_site_packages + external_vcintrinsics + external_openclheaders + external_icdloader + external_mp11 + external_level-zero + external_spirvheaders +) + +if(BUILD_MODE STREQUAL Release AND WIN32) + ExternalProject_Add_Step(external_dpcpp after_install + COMMAND ${CMAKE_COMMAND} -E rm -f ${LIBDIR}/dpcpp/bin/clang-cl.exe + COMMAND ${CMAKE_COMMAND} -E rm -f ${LIBDIR}/dpcpp/bin/clang-cpp.exe + COMMAND ${CMAKE_COMMAND} -E rm -f ${LIBDIR}/dpcpp/bin/clang.exe + COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/dpcpp ${HARVEST_TARGET}/dpcpp + ) +endif() diff --git a/build_files/build_environment/cmake/dpcpp_deps.cmake b/build_files/build_environment/cmake/dpcpp_deps.cmake new file mode 100644 index 00000000000..17cb9de3bf7 --- /dev/null +++ b/build_files/build_environment/cmake/dpcpp_deps.cmake @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +# These are build time requirements for dpcpp +# We only have to unpack these dpcpp will build +# them. + +ExternalProject_Add(external_vcintrinsics + URL file://${PACKAGE_DIR}/${VCINTRINSICS_FILE} + URL_HASH ${VCINTRINSICS_HASH_TYPE}=${VCINTRINSICS_HASH} + DOWNLOAD_DIR ${DOWNLOAD_DIR} + PREFIX ${BUILD_DIR}/vcintrinsics + CONFIGURE_COMMAND echo . + BUILD_COMMAND echo . + INSTALL_COMMAND echo . +) + +# opencl headers do not have to be unpacked, dpcpp will do it +# but it wouldn't hurt to do it anyway as an opertunity to validate +# the hash is correct. +ExternalProject_Add(external_openclheaders + URL file://${PACKAGE_DIR}/${OPENCLHEADERS_FILE} + URL_HASH ${OPENCLHEADERS_HASH_TYPE}=${OPENCLHEADERS_HASH} + DOWNLOAD_DIR ${DOWNLOAD_DIR} + PREFIX ${BUILD_DIR}/openclheaders + CONFIGURE_COMMAND echo . + BUILD_COMMAND echo . + INSTALL_COMMAND echo . +) + +# icdloader does not have to be unpacked, dpcpp will do it +# but it wouldn't hurt to do it anyway as an opertunity to validate +# the hash is correct. +ExternalProject_Add(external_icdloader + URL file://${PACKAGE_DIR}/${ICDLOADER_FILE} + URL_HASH ${ICDLOADER_HASH_TYPE}=${ICDLOADER_HASH} + DOWNLOAD_DIR ${DOWNLOAD_DIR} + PREFIX ${BUILD_DIR}/icdloader + CONFIGURE_COMMAND echo . + BUILD_COMMAND echo . + INSTALL_COMMAND echo . +) + +ExternalProject_Add(external_mp11 + URL file://${PACKAGE_DIR}/${MP11_FILE} + URL_HASH ${MP11_HASH_TYPE}=${MP11_HASH} + DOWNLOAD_DIR ${DOWNLOAD_DIR} + PREFIX ${BUILD_DIR}/mp11 + CONFIGURE_COMMAND echo . + BUILD_COMMAND echo . + INSTALL_COMMAND echo . +) + +ExternalProject_Add(external_spirvheaders + URL file://${PACKAGE_DIR}/${SPIRV_HEADERS_FILE} + URL_HASH ${SPIRV_HEADERS_HASH_TYPE}=${SPIRV_HEADERS_HASH} + DOWNLOAD_DIR ${DOWNLOAD_DIR} + PREFIX ${BUILD_DIR}/spirvheaders + CONFIGURE_COMMAND echo . + BUILD_COMMAND echo . + INSTALL_COMMAND echo . +) + diff --git a/build_files/build_environment/cmake/gmmlib.cmake b/build_files/build_environment/ @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs