Skip to content

Commit

Permalink
[Refactor]Move llvm runtime build for archs to cmake from C++. (#2524)
Browse files Browse the repository at this point in the history
Co-authored-by: Ailing Zhang <[email protected]>
  • Loading branch information
ailzhang and Ailing Zhang authored Jul 14, 2021
1 parent 286328c commit b08bebf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@ add_custom_target(
)
add_dependencies(${CORE_LIBRARY_NAME} generate_commit_hash)

if (TI_WITH_CUDA)
set(CUDA_ARCH "cuda")
endif()

find_program(CLANG_EXECUTABLE NAMES clang-7 clang-8 clang-9 clang-10 clang)
if (NOT CLANG_EXECUTABLE)
message(FATAL_ERROR "Cannot find any clang executable.")
endif()

find_program(LLVM_AS_EXECUTABLE NAMES llvm-as)
if (NOT LLVM_AS_EXECUTABLE)
message(FATAL_ERROR "Cannot find llvm-as executable.")
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} -S runtime.cpp -o runtime.ll -fno-exceptions -emit-llvm -std=c++17 -D "ARCH_${arch}" -I ${PROJECT_SOURCE_DIR};
COMMAND ${LLVM_AS_EXECUTABLE} runtime.ll -o "runtime_${arch}.bc"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/taichi/runtime/llvm"
)
add_dependencies(${CORE_LIBRARY_NAME} "generate_llvm_runtime_${arch}")
endforeach()

FILE(WRITE ${CMAKE_CURRENT_LIST_DIR}/taichi/common/version.h
"#pragma once\n"
"#define TI_VERSION_MAJOR \"${TI_VERSION_MAJOR}\"\n"
Expand Down
3 changes: 3 additions & 0 deletions cmake/TaichiCXXFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}"
message("Setting -march=nehalem for x86_64 processors")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=nehalem -DTI_ARCH_x64")
endif()
set(ARCH "x64")
elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTI_ARCH_ARM")
set(ARCH "arm64")
else()
message(FATAL_ERROR "Unknown processor type ${CMAKE_SYSTEM_PROCESSOR}")
endif()
set(HOST_ARCH ${ARCH} CACHE INTERNAL "Host arch")

if (USE_STDCPP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
Expand Down
1 change: 0 additions & 1 deletion python/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def build(project_name):
assert os.path.exists(libdevice_path)
shutil.copy(libdevice_path, 'taichi/lib/slim_libdevice.10.bc')

ti.core.compile_runtimes()
runtime_dir = ti.core.get_runtime_dir()
for f in os.listdir(runtime_dir):
if f.startswith('runtime_') and f.endswith('.bc'):
Expand Down
7 changes: 0 additions & 7 deletions taichi/llvm/llvm_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,6 @@ void compile_runtime_bitcode(Arch arch) {
}
}

void compile_runtimes() {
compile_runtime_bitcode(host_arch());
#if defined(TI_WITH_CUDA)
compile_runtime_bitcode(Arch::cuda);
#endif
}

std::string libdevice_path() {
std::string folder;
if (is_release()) {
Expand Down
2 changes: 0 additions & 2 deletions taichi/python/export_lang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void expr_assign(const Expr &lhs_, const Expr &rhs, std::string tb) {

std::vector<std::unique_ptr<ASTBuilder::ScopeGuard>> scope_stack;

void compile_runtimes();
std::string libdevice_path();
std::string get_runtime_dir();

Expand Down Expand Up @@ -743,7 +742,6 @@ void export_lang(py::module &m) {
m.def("test_throw", [] { throw IRModified(); });
m.def("needs_grad", needs_grad);

m.def("compile_runtimes", compile_runtimes);
m.def("libdevice_path", libdevice_path);

m.def("host_arch", host_arch);
Expand Down

0 comments on commit b08bebf

Please sign in to comment.