Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Build] [refactor] Define runtime build target #4838

Merged
merged 14 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,7 @@ if (${CLANG_VERSION_MAJOR} VERSION_GREATER ${CLANG_HIGHEST_VERSION})
endif()
endif()

# Build llvm-runtime for host arch and cuda (if available)
foreach(arch IN LISTS HOST_ARCH CUDA_ARCH)
add_custom_target(
"generate_llvm_runtime_${arch}"
COMMAND ${CLANG_EXECUTABLE} ${CLANG_OSX_FLAGS} -c runtime.cpp -o "runtime_${arch}.bc" -fno-exceptions -emit-llvm -std=c++17 -D "ARCH_${arch}" -I ${PROJECT_SOURCE_DIR};
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/taichi/runtime/llvm"
)
add_dependencies(${CORE_LIBRARY_NAME} "generate_llvm_runtime_${arch}")
install(FILES "${PROJECT_SOURCE_DIR}/taichi/runtime/llvm/runtime_${arch}.bc" DESTINATION ${CMAKE_INSTALL_PREFIX}/python/taichi/_lib/runtime)
endforeach()
add_subdirectory(taichi/runtime/llvm)

configure_file(taichi/common/version.h.in ${CMAKE_SOURCE_DIR}/taichi/common/version.h)
configure_file(taichi/common/commit_hash.h.in ${CMAKE_SOURCE_DIR}/taichi/common/commit_hash.h)
Expand Down
13 changes: 8 additions & 5 deletions cmake/TaichiCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ option(TI_EMSCRIPTENED "Build using emscripten" OFF)
# projects.
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
# Suppress warnings from submodules introduced by the above symbol visibility change
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/python/taichi/_lib)

if(ANDROID)
Expand Down Expand Up @@ -140,10 +143,6 @@ file(GLOB TAICHI_OPENGL_REQUIRED_SOURCE
"taichi/backends/opengl/codegen_opengl.*"
"taichi/backends/opengl/struct_opengl.*"
)
file(GLOB TAICHI_VULKAN_REQUIRED_SOURCE
"taichi/backends/vulkan/runtime.h"
"taichi/backends/vulkan/runtime.cpp"
)

list(REMOVE_ITEM TAICHI_CORE_SOURCE ${TAICHI_BACKEND_SOURCE})

Expand Down Expand Up @@ -198,7 +197,7 @@ if (TI_WITH_VULKAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_VULKAN")
list(APPEND TAICHI_CORE_SOURCE ${TAICHI_VULKAN_SOURCE})
endif()
list(APPEND TAICHI_CORE_SOURCE ${TAICHI_VULKAN_REQUIRED_SOURCE})


if (TI_WITH_DX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_WITH_DX11")
Expand Down Expand Up @@ -389,8 +388,12 @@ if (TI_WITH_VULKAN)
install(FILES ${CMAKE_BINARY_DIR}/libMoltenVK.dylib DESTINATION ${INSTALL_LIB_DIR}/runtime)
endif()
endif()

add_subdirectory(taichi/runtime/vulkan)
target_link_libraries(${CORE_LIBRARY_NAME} vulkan_runtime)
endif ()


# Optional dependencies

if (APPLE)
Expand Down
2 changes: 1 addition & 1 deletion taichi/backends/dx/dx_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifdef TI_WITH_DX11

#include "taichi/backends/dx/dx_device.h"
#include "taichi/backends/vulkan/runtime.h"
#include "taichi/runtime/vulkan/runtime.h"
#include "taichi/backends/vulkan/snode_tree_manager.h"
#include "taichi/program/program_impl.h"

Expand Down
2 changes: 1 addition & 1 deletion taichi/backends/vulkan/aot_module_builder_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "taichi/aot/module_builder.h"
#include "taichi/backends/vulkan/aot_utils.h"
#include "taichi/backends/vulkan/runtime.h"
#include "taichi/runtime/vulkan/runtime.h"
#include "taichi/codegen/spirv/snode_struct_compiler.h"
#include "taichi/codegen/spirv/kernel_utils.h"

Expand Down
2 changes: 1 addition & 1 deletion taichi/backends/vulkan/aot_module_loader_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <fstream>
#include <type_traits>

#include "taichi/backends/vulkan/runtime.h"
#include "taichi/runtime/vulkan/runtime.h"

namespace taichi {
namespace lang {
Expand Down
2 changes: 1 addition & 1 deletion taichi/backends/vulkan/aot_module_loader_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <vector>

#include "taichi/backends/vulkan/aot_utils.h"
#include "taichi/backends/vulkan/runtime.h"
#include "taichi/runtime/vulkan/runtime.h"
#include "taichi/codegen/spirv/kernel_utils.h"

#include "taichi/aot/module_loader.h"
Expand Down
2 changes: 1 addition & 1 deletion taichi/backends/vulkan/snode_tree_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "taichi/backends/vulkan/snode_tree_manager.h"

#include "taichi/backends/vulkan/runtime.h"
#include "taichi/runtime/vulkan/runtime.h"

namespace taichi {
namespace lang {
Expand Down
2 changes: 1 addition & 1 deletion taichi/backends/vulkan/vulkan_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "taichi/backends/vulkan/vulkan_device_creator.h"
#include "taichi/backends/vulkan/vulkan_utils.h"
#include "taichi/backends/vulkan/vulkan_loader.h"
#include "taichi/backends/vulkan/runtime.h"
#include "taichi/runtime/vulkan/runtime.h"
#include "taichi/backends/vulkan/snode_tree_manager.h"
#include "taichi/backends/vulkan/vulkan_device.h"
#include "vk_mem_alloc.h"
Expand Down
2 changes: 1 addition & 1 deletion taichi/python/export_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "taichi/backends/metal/api.h"
#include "taichi/backends/opengl/opengl_api.h"
#include "taichi/backends/vulkan/runtime.h"
#include "taichi/runtime/vulkan/runtime.h"
#include "taichi/backends/dx/dx_api.h"
#include "taichi/common/core.h"
#include "taichi/common/interface.h"
Expand Down
19 changes: 19 additions & 0 deletions taichi/runtime/llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ./taichi/runtime/llvm/CMakeLists.txt

function(COMPILE_LLVM_RUNTIME rtm_arch)
message(STATUS "Compiling LLVM byte code file for arch ${rtm_arch}")
# Keep this for now, as .bc need to be generated.
add_custom_target(
"generate_llvm_runtime_${rtm_arch}"
COMMAND ${CLANG_EXECUTABLE} ${CLANG_OSX_FLAGS} -c runtime.cpp -o "runtime_${rtm_arch}.bc" -fno-exceptions -emit-llvm -std=c++17 -D "ARCH_${rtm_arch}" -I ${PROJECT_SOURCE_DIR};
# TODO, it's better to avoid polluting the source dir, keep in build
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
add_dependencies(${CORE_LIBRARY_NAME} "generate_llvm_runtime_${rtm_arch}")
install(FILES "${CMAKE_SOURCE_DIR}/taichi/runtime/llvm/runtime_${arch}.bc" DESTINATION ${CMAKE_INSTALL_PREFIX}/python/taichi/_lib/runtime)
endfunction()

# Build llvm-runtime for host arch and cuda (if available)
foreach(arch IN LISTS HOST_ARCH CUDA_ARCH)
compile_llvm_runtime(${arch})
endforeach()
13 changes: 13 additions & 0 deletions taichi/runtime/vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ./taichi/runtime/vulkan/CMakeLists.txt

add_library(vulkan_runtime)
target_sources(vulkan_runtime
PRIVATE
runtime.cpp
)
target_include_directories(vulkan_runtime
PRIVATE
${PROJECT_SOURCE_DIR}/external/SPIRV-Tools/include
${PROJECT_SOURCE_DIR}/external/eigen
${PROJECT_SOURCE_DIR}/external/FP16/include
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "taichi/backends/vulkan/runtime.h"
#include "taichi/runtime/vulkan/runtime.h"
#include "taichi/program/program.h"

#include <chrono>
Expand Down
File renamed without changes.