From 251d64ebd8b3034c674444ca7a72b0c8a3493305 Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Mon, 6 Jan 2025 13:49:42 +0800 Subject: [PATCH] minor --- src/backends/fallback/CMakeLists.txt | 62 +++++++++++++++++----------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/src/backends/fallback/CMakeLists.txt b/src/backends/fallback/CMakeLists.txt index 787612550..bcfe80672 100644 --- a/src/backends/fallback/CMakeLists.txt +++ b/src/backends/fallback/CMakeLists.txt @@ -10,6 +10,9 @@ if (NOT LLVM_FOUND) endif () if (LLVM_FOUND AND embree_FOUND) + + message(STATUS "Build with fallback backend (LLVM ${LLVM_VERSION}, Embree ${embree_VERSION})") + set(LUISA_COMPUTE_ENABLE_FALLBACK ON) set(LC_BACKEND_FALLBACK_SRC fallback_device.cpp @@ -34,8 +37,38 @@ if (LLVM_FOUND AND embree_FOUND) # exclude codegen from unity build since it's too big set_source_files_properties(fallback_codegen.cpp PROPERTIES UNITY_BUILD OFF) target_link_directories(luisa-compute-backend-fallback PRIVATE ${LLVM_LIBRARY_DIRS}) + target_link_libraries(luisa-compute-backend-fallback PRIVATE + luisa-compute-xir + luisa-compute-vulkan-swapchain + embree) + + # help distinguish between embree 3 and 4 + target_compile_definitions(luisa-compute-backend-fallback PRIVATE + LUISA_COMPUTE_EMBREE_VERSION=${embree_VERSION_MAJOR}) # use libdispatch or TBB for parallel_for on non-Apple Unix systems if available + if (UNIX AND NOT APPLE) + # libdispatch + find_library(DISPATCH_LIB dispatch) + find_path(DISPATCH_INCLUDE_DIR dispatch/dispatch.h) + if (DISPATCH_LIB AND DISPATCH_INCLUDE_DIR) + target_compile_definitions(luisa-compute-backend-fallback PRIVATE LUISA_COMPUTE_ENABLE_LIBDISPATCH=1) + target_link_libraries(luisa-compute-backend-fallback PRIVATE ${DISPATCH_LIB}) + target_include_directories(luisa-compute-backend-fallback PRIVATE ${DISPATCH_INCLUDE_DIR}) + else () + find_package(TBB CONFIG) + if (TBB_FOUND) + target_compile_definitions(luisa-compute-backend-fallback PRIVATE LUISA_COMPUTE_ENABLE_TBB=1) + target_link_libraries(luisa-compute-backend-fallback PRIVATE TBB::tbb) + else () + message(WARNING "TBB and libdispatch not found. Performance of the fallback backend may be affected.") + endif () + endif () + endif () + + # LLVM + target_include_directories(luisa-compute-backend-fallback PRIVATE ${LLVM_INCLUDE_DIRS}) + llvm_map_components_to_libnames(LLVM_LIBS core executionengine support orcjit nativecodegen irreader passes analysis coroutines) if (UNIX AND NOT APPLE) # check if the libraries exist # map library dirs to link directories options @@ -63,37 +96,20 @@ if (LLVM_FOUND AND embree_FOUND) set(LLVM_LIBS ${LLVM_DYLIB}) endif () endif () + # avoid re-exporting symbols from LLVM + target_link_libraries(luisa-compute-backend-fallback PRIVATE "-Wl,--exclude-libs,ALL" ${LLVM_LIBS}) + else () + target_link_libraries(luisa-compute-backend-fallback PRIVATE ${LLVM_LIBS}) endif () - message(STATUS "Build with fallback backend (LLVM ${LLVM_VERSION}, Embree ${embree_VERSION})") - llvm_map_components_to_libnames(LLVM_LIBS core executionengine support orcjit nativecodegen irreader passes analysis coroutines) - if (UNIX AND NOT APPLE) - # check if the libraries exist - try_compile(LLVM_LIBS_EXIST - SOURCE_FROM_CONTENT "try_link_llvm.cpp" "int main() {}" - LINK_LIBRARIES ${LLVM_LIBS}) - if (NOT LLVM_LIBS_EXIST) - message(WARNING "LLVM libraries not found. Trying to link with LLVM shared libraries.") - find_library(LLVM_DYLIB LLVM REQUIRED) - message(STATUS "LLVM libraries found at ${LLVM_DYLIB}") - set(LLVM_LIBS ${LLVM_DYLIB}) - endif () - endif () - target_include_directories(luisa-compute-backend-fallback PRIVATE ${LLVM_INCLUDE_DIRS}) - target_link_libraries(luisa-compute-backend-fallback PRIVATE - embree ${LLVM_LIBS} - luisa-compute-xir - luisa-compute-vulkan-swapchain) if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") target_compile_options(luisa-compute-backend-fallback PRIVATE /wd4624 /wd4996 # do not complain about LLVM - /fp:fast /fp:contract /fp:except-) + /fp:fast /fp:contract /fp:except- /ARCH:AVX2) else () target_compile_options(luisa-compute-backend-fallback PRIVATE -ffast-math) endif () - # help distinguish between embree 3 and 4 - target_compile_definitions(luisa-compute-backend-fallback PRIVATE - LUISA_COMPUTE_EMBREE_VERSION=${embree_VERSION_MAJOR}) + elseif (NOT LUISA_COMPUTE_CHECK_BACKEND_DEPENDENCIES) message(FATAL_ERROR "LLVM or Embree not found for the fallback backend.") else ()