From 55b8fc718a378423cd4b6d93258779e201877b1d Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 5 Oct 2021 13:08:44 +0200 Subject: Cycles: improve detection of HIP compiler for buildbot And fix various broken things in the HIP kernel compilation. --- CMakeLists.txt | 1 + build_files/cmake/Modules/FindHIP.cmake | 79 +++++++++++++++++++++++++++++++++ intern/cycles/cmake/external_libs.cmake | 12 ++++- intern/cycles/kernel/CMakeLists.txt | 39 +++++++--------- 4 files changed, 106 insertions(+), 25 deletions(-) create mode 100644 build_files/cmake/Modules/FindHIP.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c4b8bf6dcd4..16842f3134b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -406,6 +406,7 @@ mark_as_advanced(WITH_CYCLES_CUDA_BUILD_SERIAL) set(CYCLES_TEST_DEVICES CPU CACHE STRING "Run regression tests on the specified device types (CPU CUDA OPTIX)" ) set(CYCLES_CUDA_BINARIES_ARCH sm_30 sm_35 sm_37 sm_50 sm_52 sm_60 sm_61 sm_70 sm_75 sm_86 compute_75 CACHE STRING "CUDA architectures to build binaries for") mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH) +option(WITH_CYCLES_HIP_BINARIES "Build Cycles HIP binaries" OFF) unset(PLATFORM_DEFAULT) option(WITH_CYCLES_LOGGING "Build Cycles with logging support" ON) option(WITH_CYCLES_DEBUG_NAN "Build Cycles with additional asserts for detecting NaNs and invalid values" OFF) diff --git a/build_files/cmake/Modules/FindHIP.cmake b/build_files/cmake/Modules/FindHIP.cmake new file mode 100644 index 00000000000..c68d78e5796 --- /dev/null +++ b/build_files/cmake/Modules/FindHIP.cmake @@ -0,0 +1,79 @@ +# - Find HIP compiler +# +# This module defines +# HIP_HIPCC_EXECUTABLE, the full path to the hipcc executable +# HIP_VERSION, the HIP compiler version +# +# HIP_FOUND, if the HIP toolkit is found. + +#============================================================================= +# Copyright 2021 Blender Foundation. +# +# Distributed under the OSI-approved BSD 3-Clause License, +# see accompanying file BSD-3-Clause-license.txt for details. +#============================================================================= + +# If HIP_ROOT_DIR was defined in the environment, use it. +if(NOT HIP_ROOT_DIR AND NOT $ENV{HIP_ROOT_DIR} STREQUAL "") + set(HIP_ROOT_DIR $ENV{HIP_ROOT_DIR}) +endif() + +set(_hip_SEARCH_DIRS + ${HIP_ROOT_DIR} +) + +find_program(HIP_HIPCC_EXECUTABLE + NAMES + hipcc + HINTS + ${_hip_SEARCH_DIRS} +) + +if(HIP_HIPCC_EXECUTABLE AND NOT EXISTS ${HIP_HIPCC_EXECUTABLE}) + message(WARNING "Cached or directly specified hipcc executable does not exist.") + set(HIP_FOUND FALSE) +elseif(HIP_HIPCC_EXECUTABLE) + set(HIP_FOUND TRUE) + + set(HIP_VERSION_MAJOR 0) + set(HIP_VERSION_MINOR 0) + set(HIP_VERSION_PATCH 0) + + # Get version from the output. + execute_process(COMMAND ${HIP_HIPCC_EXECUTABLE} --version + OUTPUT_VARIABLE HIP_VERSION_RAW + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + + # Parse parts. + if(HIP_VERSION_RAW MATCHES "HIP version: .*") + # Strip the HIP prefix and get list of individual version components. + string(REGEX REPLACE + ".*HIP version: ([.0-9]+).*" "\\1" + HIP_SEMANTIC_VERSION "${HIP_VERSION_RAW}") + string(REPLACE "." ";" HIP_VERSION_PARTS "${HIP_SEMANTIC_VERSION}") + list(LENGTH HIP_VERSION_PARTS NUM_HIP_VERSION_PARTS) + + # Extract components into corresponding variables. + if(NUM_HIP_VERSION_PARTS GREATER 0) + list(GET HIP_VERSION_PARTS 0 HIP_VERSION_MAJOR) + endif() + if(NUM_HIP_VERSION_PARTS GREATER 1) + list(GET HIP_VERSION_PARTS 1 HIP_VERSION_MINOR) + endif() + if(NUM_HIP_VERSION_PARTS GREATER 2) + list(GET HIP_VERSION_PARTS 2 HIP_VERSION_PATCH) + endif() + + # Unset temp variables. + unset(NUM_HIP_VERSION_PARTS) + unset(HIP_SEMANTIC_VERSION) + unset(HIP_VERSION_PARTS) + endif() + + # Construct full semantic version. + set(HIP_VERSION "${HIP_VERSION_MAJOR}.${HIP_VERSION_MINOR}.${HIP_VERSION_PATCH}") + unset(HIP_VERSION_RAW) +else() + set(HIP_FOUND FALSE) +endif() diff --git a/intern/cycles/cmake/external_libs.cmake b/intern/cycles/cmake/external_libs.cmake index b966edd4298..c1244ab740b 100644 --- a/intern/cycles/cmake/external_libs.cmake +++ b/intern/cycles/cmake/external_libs.cmake @@ -521,7 +521,7 @@ endif() if(WITH_CYCLES_CUDA_BINARIES OR NOT WITH_CUDA_DYNLOAD) find_package(CUDA) # Try to auto locate CUDA toolkit if(CUDA_FOUND) - message(STATUS "CUDA nvcc = ${CUDA_NVCC_EXECUTABLE}") + message(STATUS "Found CUDA ${CUDA_NVCC_EXECUTABLE} (${CUDA_VERSION})") else() message(STATUS "CUDA compiler not found, disabling WITH_CYCLES_CUDA_BINARIES") set(WITH_CYCLES_CUDA_BINARIES OFF) @@ -537,6 +537,16 @@ endif() # HIP ########################################################################### +if(WITH_CYCLES_HIP_BINARIES AND WITH_CYCLES_DEVICE_HIP) + find_package(HIP) + if(HIP_FOUND) + message(STATUS "Found HIP ${HIP_HIPCC_EXECUTABLE} (${HIP_VERSION})") + else() + message(STATUS "HIP compiler not found, disabling WITH_CYCLES_HIP_BINARIES") + set(WITH_CYCLES_HIP_BINARIES OFF) + endif() +endif() + if(NOT WITH_HIP_DYNLOAD) set(WITH_HIP_DYNLOAD ON) endif() diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt index 7b56216e887..514b7f8263c 100644 --- a/intern/cycles/kernel/CMakeLists.txt +++ b/intern/cycles/kernel/CMakeLists.txt @@ -472,20 +472,10 @@ endif() # HIP module -if(WITH_CYCLES_HIP_BINARIES) +if(WITH_CYCLES_HIP_BINARIES AND WITH_CYCLES_DEVICE_HIP) # 64 bit only set(HIP_BITS 64) - # HIP version - execute_process(COMMAND ${HIP_HIPCC_EXECUTABLE} "--version" OUTPUT_VARIABLE HIPCC_OUT) - string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" HIP_VERSION_MAJOR "${HIPCC_OUT}") - string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" HIP_VERSION_MINOR "${HIPCC_OUT}") - set(HIP_VERSION "${HIP_VERSION_MAJOR}${HIP_VERSION_MINOR}") - - - message(WARNING - "HIP version ${HIP_VERSION_MAJOR}.${HIP_VERSION_MINOR} detected") - # build for each arch set(hip_sources device/hip/kernel.cpp ${SRC_HEADERS} @@ -542,23 +532,24 @@ if(WITH_CYCLES_HIP_BINARIES) -D WITH_NANOVDB -I "${NANOVDB_INCLUDE_DIR}") endif() + + add_custom_command( + OUTPUT ${hip_file} + COMMAND ${HIP_HIPCC_EXECUTABLE} + -arch=${arch} + ${HIP_HIPCC_FLAGS} + --${format} + ${CMAKE_CURRENT_SOURCE_DIR}${hip_kernel_src} + ${hip_flags} + DEPENDS ${kernel_sources}) + delayed_install("${CMAKE_CURRENT_BINARY_DIR}" "${hip_file}" ${CYCLES_INSTALL_PATH}/lib) + list(APPEND hip_fatbins ${hip_file}) endmacro() set(prev_arch "none") foreach(arch ${CYCLES_HIP_BINARIES_ARCH}) - set(hip_hipcc_executable ${HIP_HIPCC_EXECUTABLE}) - set(hip_toolkit_root_dir ${HIP_TOOLKIT_ROOT_DIR}) - if(DEFINED hip_hipcc_executable AND DEFINED hip_toolkit_root_dir) - # Compile regular kernel - CYCLES_HIP_KERNEL_ADD(${arch} ${prev_arch} kernel "" "${hip_sources}" FALSE) - - if(WITH_CYCLES_HIP_BUILD_SERIAL) - set(prev_arch ${arch}) - endif() - - unset(hip_hipcc_executable) - unset(hip_toolkit_root_dir) - endif() + # Compile regular kernel + CYCLES_HIP_KERNEL_ADD(${arch} ${prev_arch} kernel "" "${hip_sources}" FALSE) endforeach() add_custom_target(cycles_kernel_hip ALL DEPENDS ${hip_fatbins}) -- cgit v1.2.3