Skip to content

Commit

Permalink
[build] [refactor] Rename taichi core and taichi python targets (#5451)
Browse files Browse the repository at this point in the history
* Rename ti_core to ti_python_core

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Rename taichi_core to taichi_python

* Rename taichi_isolated_core to taichi_core

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
qiao-bo and pre-commit-ci[bot] authored Jul 20, 2022
1 parent b38a577 commit ae9bb38
Show file tree
Hide file tree
Showing 28 changed files with 100 additions and 110 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ runtimes/Release
runtimes/Debug
runtimes/RelWithDebInfo
runtimes/*.png
runtimes/taichi_core*
runtimes/libtaichi_core*
runtimes/taichi_python*
runtimes/libtaichi_python*
.pypirc
dist/
python/MANIFEST
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/microbenchmarks/_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from time import perf_counter

from taichi._lib import core as ti_core
from taichi._lib import core as ti_python_core

import taichi as ti

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import warnings

from suite_microbenchmarks import MicroBenchmark
from taichi._lib import core as ti_core
from taichi._lib import core as ti_python_core
from utils import datatime_with_format, dump2json

benchmark_suites = [MicroBenchmark]
Expand All @@ -11,7 +11,7 @@
class BenchmarkInfo:
def __init__(self):
"""init with commit info"""
self.commit_hash = ti_core.get_commit_hash()
self.commit_hash = ti_python_core.get_commit_hash()
self.datetime = datatime_with_format()
self.suites = {}
print(f'commit_hash = {self.commit_hash}')
Expand Down
2 changes: 1 addition & 1 deletion cmake/TaichiCAPI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if(NOT TI_BUILD_TESTS)
endif()

add_library(${TAICHI_C_API_NAME} SHARED ${C_API_SOURCE})
target_link_libraries(${TAICHI_C_API_NAME} PRIVATE taichi_isolated_core)
target_link_libraries(${TAICHI_C_API_NAME} PRIVATE taichi_core)

set(C_API_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build")
set_target_properties(${TAICHI_C_API_NAME} PROPERTIES
Expand Down
21 changes: 4 additions & 17 deletions cmake/TaichiCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ if(NOT TI_WITH_LLVM)
set(TI_WITH_CUDA_TOOLKIT OFF)
endif()


## TODO 4832: Split source per target, do not include everything in taichi_core_source
file(GLOB TAICHI_CORE_SOURCE
"taichi/analysis/*.cpp" "taichi/analysis/*.h" #IR
"taichi/aot/*.cpp" "taichi/aot/*.h" #RT?
Expand Down Expand Up @@ -165,11 +163,11 @@ endif()
# library into a shared lib.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# The short-term goal is to have a sub-library, "taichi_isolated_core", that is
# The short-term goal is to have a sub-library, "taichi_core", that is
# mostly Taichi-focused, free from the "application" layer such as pybind11 or
# GUI. At a minimum, we must decouple from pybind11/python-environment. Then we
# can 1) unit test a major part of Taichi, and 2) integrate a new frontend lang
# with "taichi_isolated_core".
# with "taichi_core".
#
# TODO(#2198): Long-term speaking, we should create a separate library for each
# sub-module. This way we can guarantee that the lib dependencies form a DAG.
Expand All @@ -188,18 +186,7 @@ if (TAICHI_EMBIND_SOURCE)
endif()


# TODO(#2196): Rename these CMAKE variables:
# CORE_LIBRARY_NAME --> TAICHI_ISOLATED_CORE_LIB_NAME
# CORE_WITH_PYBIND_LIBRARY_NAME --> TAICHI_CORE_LIB_NAME
#
# However, the better strategy is probably to rename the actual library:
#
# taichi_core --> taichi_pylib (this requires python-side refactoring...)
# taichi_isolated_core --> taichi_core
#
# But this requires more efforts, because taichi_core is already referenced
# everywhere in python.
set(CORE_LIBRARY_NAME taichi_isolated_core)
set(CORE_LIBRARY_NAME taichi_core)
add_library(${CORE_LIBRARY_NAME} OBJECT ${TAICHI_CORE_SOURCE})

if (APPLE)
Expand Down Expand Up @@ -469,7 +456,7 @@ endforeach ()
message("PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES})

if(TI_WITH_PYTHON AND NOT TI_EMSCRIPTENED)
set(CORE_WITH_PYBIND_LIBRARY_NAME taichi_core)
set(CORE_WITH_PYBIND_LIBRARY_NAME taichi_python)
# Cannot compile Python source code with Android, but TI_EXPORT_CORE should be set and
# Android should only use the isolated library ignoring those source code.
if (NOT ANDROID)
Expand Down
2 changes: 1 addition & 1 deletion cmake/TaichiExamples.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if (WIN32)
set_target_properties(${EXAMPLES_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${EXAMPLES_OUTPUT_DIR})
set_target_properties(${EXAMPLES_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${EXAMPLES_OUTPUT_DIR})
endif()
target_link_libraries(${EXAMPLES_NAME} PRIVATE taichi_isolated_core)
target_link_libraries(${EXAMPLES_NAME} PRIVATE taichi_core)
target_link_libraries(${EXAMPLES_NAME} PRIVATE
metal_program_impl
metal_runtime
Expand Down
2 changes: 1 addition & 1 deletion cmake/TaichiExportCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.0)
set(TAICHI_EXPORT_CORE_NAME taichi_export_core)

add_library(${TAICHI_EXPORT_CORE_NAME} SHARED)
target_link_libraries(${TAICHI_EXPORT_CORE_NAME} PRIVATE taichi_isolated_core)
target_link_libraries(${TAICHI_EXPORT_CORE_NAME} PRIVATE taichi_core)
set_target_properties(${TAICHI_EXPORT_CORE_NAME} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build")
Expand Down
2 changes: 1 addition & 1 deletion cmake/TaichiTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if (WIN32)
set_target_properties(${TESTS_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${TESTS_OUTPUT_DIR})
set_target_properties(${TESTS_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${TESTS_OUTPUT_DIR})
endif()
target_link_libraries(${TESTS_NAME} PRIVATE taichi_isolated_core)
target_link_libraries(${TESTS_NAME} PRIVATE taichi_core)
target_link_libraries(${TESTS_NAME} PRIVATE gtest_main)

target_include_directories(${TESTS_NAME}
Expand Down
6 changes: 3 additions & 3 deletions docs/lang/articles/faqs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ sidebar_position: 2
... (many lines, omitted)
/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: _glfwPlatformCreateWindow
/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: glfwCreateWindow
/lib/python3.8/site-packages/taichi/core/../lib/taichi_core.so: taichi::lang::opengl::initialize_opengl(bool)
/lib/python3.8/site-packages/taichi/core/../lib/taichi_python.so: _glfwPlatformCreateWindow
/lib/python3.8/site-packages/taichi/core/../lib/taichi_python.so: glfwCreateWindow
/lib/python3.8/site-packages/taichi/core/../lib/taichi_python.so: taichi::lang::opengl::initialize_opengl(bool)
... (many lines, omitted)
```
Expand Down
2 changes: 1 addition & 1 deletion python/taichi/_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from taichi._lib.utils import ti_core as core
from taichi._lib.utils import ti_python_core as core
28 changes: 15 additions & 13 deletions python/taichi/_lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_os_name():
assert False, f"Unknown platform name {name}"


def import_ti_core():
def import_ti_python_core():
if get_os_name() != 'win':
# pylint: disable=E1101
old_flags = sys.getdlopenflags()
Expand All @@ -41,10 +41,10 @@ def import_ti_core():
os.environ['PATH'] += os.pathsep + pyddir
try:
from taichi._lib.core import \
taichi_core as core # pylint: disable=C0415
taichi_python as core # pylint: disable=C0415
except Exception as e:
if isinstance(e, ImportError):
print(Fore.YELLOW + "Share object taichi_core import failed, "
print(Fore.YELLOW + "Share object taichi_python import failed, "
"check this page for possible solutions:\n"
"https://docs.taichi-lang.org/docs/install" + Fore.RESET)
if get_os_name() == 'win':
Expand Down Expand Up @@ -83,7 +83,7 @@ def is_ci():

def get_core_shared_object():
directory = os.path.join(package_root, '_lib')
return os.path.join(directory, 'libtaichi_core.so')
return os.path.join(directory, 'libtaichi_python.so')


def print_red_bold(*args, **kwargs):
Expand All @@ -99,13 +99,13 @@ def check_exists(src):
)


ti_core = import_ti_core()
ti_python_core = import_ti_python_core()

ti_core.set_python_package_dir(package_root)
ti_python_core.set_python_package_dir(package_root)

log_level = os.environ.get('TI_LOG_LEVEL', '')
if log_level:
ti_core.set_logging_level(log_level)
ti_python_core.set_logging_level(log_level)


def get_dll_name(name):
Expand All @@ -119,7 +119,7 @@ def get_dll_name(name):


def at_startup():
ti_core.set_core_state_python_imported(True)
ti_python_core.set_core_state_python_imported(True)


at_startup()
Expand All @@ -133,23 +133,25 @@ def compare_version(latest, current):

def _print_taichi_header():
header = '[Taichi] '
header += f'version {ti_core.get_version_string()}, '
header += f'version {ti_python_core.get_version_string()}, '

try:
timestamp_path = os.path.join(ti_core.get_repo_dir(), 'timestamp')
timestamp_path = os.path.join(ti_python_core.get_repo_dir(),
'timestamp')
if os.path.exists(timestamp_path):
latest_version = ''
with open(timestamp_path, 'r') as f:
latest_version = f.readlines()[1].rstrip()
if compare_version(latest_version, ti_core.get_version_string()):
if compare_version(latest_version,
ti_python_core.get_version_string()):
header += f'latest version {latest_version}, '
except:
pass

llvm_target_support = ti_core.get_llvm_target_support()
llvm_target_support = ti_python_core.get_llvm_target_support()
header += f'llvm {llvm_target_support}, '

commit_hash = ti_core.get_commit_hash()
commit_hash = ti_python_core.get_commit_hash()
commit_hash = commit_hash[:8]
header += f'commit {commit_hash}, '

Expand Down
10 changes: 5 additions & 5 deletions python/taichi/_logging.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import inspect
import os

from taichi._lib import core as ti_core
from taichi._lib import core as ti_python_core


def _get_logging(name):
Expand All @@ -16,9 +16,9 @@ def _get_logging(name):
"""
def logger(msg, *args, **kwargs):
# Python inspection takes time (~0.1ms) so avoid it as much as possible
if ti_core.logging_effective(name):
if ti_python_core.logging_effective(name):
msg_formatted = msg.format(*args, **kwargs)
func = getattr(ti_core, name)
func = getattr(ti_python_core, name)
frame = inspect.currentframe().f_back
file_name, lineno, func_name, _, _ = inspect.getframeinfo(frame)
file_name = os.path.basename(file_name)
Expand All @@ -45,7 +45,7 @@ def set_logging_level(level):
>>> set_logging_level('debug')
"""
ti_core.set_logging_level(level)
ti_python_core.set_logging_level(level)


def is_logging_effective(level):
Expand All @@ -72,7 +72,7 @@ def is_logging_effective(level):
>>> print(ti.is_logging_effective("error")) # True
>>> print(ti.is_logging_effective("critical")) # True
"""
return ti_core.logging_effective(level)
return ti_python_core.logging_effective(level)


# ------------------------
Expand Down
4 changes: 2 additions & 2 deletions python/taichi/_snode/snode_tree.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The reason we import just the taichi.core.util module, instead of the ti_core
# object within it, is that ti_core is stateful. While in practice ti_core is
# The reason we import just the taichi.core.util module, instead of the ti_python_core
# object within it, is that ti_python_core is stateful. While in practice ti_python_core is
# loaded during the import procedure, it's probably still good to delay the
# access to it.

Expand Down
8 changes: 4 additions & 4 deletions python/taichi/aot/record.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os

from taichi._lib import core as ti_core
from taichi._lib import core as ti_python_core


def record_action_entry(name, contents):
ti_core.record_action_entry(name, list(contents.items()))
ti_python_core.record_action_entry(name, list(contents.items()))


def record_action_hint(name, content=None):
Expand Down Expand Up @@ -44,15 +44,15 @@ def start_recording(filename):
>>> compute_loss()
>>> do_some_works()
"""
ti_core.start_recording(filename)
ti_python_core.start_recording(filename)


def stop_recording():
"""Stops recording kernel information.
This function should be called in pair with :func:`~ti.aot.start_recording`.
"""
ti_core.stop_recording()
ti_python_core.stop_recording()


class RecordKernelGroup:
Expand Down
6 changes: 3 additions & 3 deletions python/taichi/lang/any_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AnyArray:
"""Class for arbitrary arrays in Python AST.
Args:
ptr (taichi_core.Expr): A taichi_core.Expr wrapping a taichi_core.ExternalTensorExpression.
ptr (taichi_python.Expr): A taichi_python.Expr wrapping a taichi_python.ExternalTensorExpression.
element_shape (Tuple[Int]): () if scalar elements (default), (n) if vector elements, and (n, m) if matrix elements.
layout (Layout): Memory layout.
"""
Expand Down Expand Up @@ -39,12 +39,12 @@ def shape(self):

@taichi_scope
def _loop_range(self):
"""Gets the corresponding taichi_core.Expr to serve as loop range.
"""Gets the corresponding taichi_python.Expr to serve as loop range.
This is not in use now because struct fors on AnyArrays are not supported yet.
Returns:
taichi_core.Expr: See above.
taichi_python.Expr: See above.
"""
return self.ptr

Expand Down
2 changes: 1 addition & 1 deletion python/taichi/lang/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _loop_range(self):
"""Gets representative field member for loop range info.
Returns:
taichi_core.Expr: Representative (first) field member.
taichi_python.Expr: Representative (first) field member.
"""
return self.vars[0].ptr

Expand Down
Loading

0 comments on commit ae9bb38

Please sign in to comment.