Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Leo-Smith committed Jan 6, 2025
1 parent e68c5d9 commit 251d64e
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions src/backends/fallback/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 ()
Expand Down

0 comments on commit 251d64e

Please sign in to comment.