gstaichi 0.1.25.dev0__cp312-cp312-macosx_15_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gstaichi/__init__.py +40 -0
- gstaichi/__main__.py +5 -0
- gstaichi/_funcs.py +706 -0
- gstaichi/_kernels.py +420 -0
- gstaichi/_lib/__init__.py +3 -0
- gstaichi/_lib/core/__init__.py +0 -0
- gstaichi/_lib/core/gstaichi_python.cpython-312-darwin.so +0 -0
- gstaichi/_lib/core/gstaichi_python.pyi +2939 -0
- gstaichi/_lib/core/py.typed +0 -0
- gstaichi/_lib/runtime/libMoltenVK.dylib +0 -0
- gstaichi/_lib/runtime/runtime_arm64.bc +0 -0
- gstaichi/_lib/utils.py +249 -0
- gstaichi/_logging.py +131 -0
- gstaichi/_main.py +545 -0
- gstaichi/_snode/__init__.py +5 -0
- gstaichi/_snode/fields_builder.py +187 -0
- gstaichi/_snode/snode_tree.py +34 -0
- gstaichi/_test_tools/__init__.py +0 -0
- gstaichi/_test_tools/load_kernel_string.py +30 -0
- gstaichi/_version.py +1 -0
- gstaichi/_version_check.py +103 -0
- gstaichi/ad/__init__.py +3 -0
- gstaichi/ad/_ad.py +530 -0
- gstaichi/algorithms/__init__.py +3 -0
- gstaichi/algorithms/_algorithms.py +117 -0
- gstaichi/assets/.git +1 -0
- gstaichi/assets/Go-Regular.ttf +0 -0
- gstaichi/assets/static/imgs/ti_gallery.png +0 -0
- gstaichi/examples/minimal.py +28 -0
- gstaichi/experimental.py +16 -0
- gstaichi/lang/__init__.py +50 -0
- gstaichi/lang/_ndarray.py +352 -0
- gstaichi/lang/_ndrange.py +152 -0
- gstaichi/lang/_template_mapper.py +199 -0
- gstaichi/lang/_texture.py +172 -0
- gstaichi/lang/_wrap_inspect.py +189 -0
- gstaichi/lang/any_array.py +99 -0
- gstaichi/lang/argpack.py +411 -0
- gstaichi/lang/ast/__init__.py +5 -0
- gstaichi/lang/ast/ast_transformer.py +1318 -0
- gstaichi/lang/ast/ast_transformer_utils.py +341 -0
- gstaichi/lang/ast/ast_transformers/__init__.py +0 -0
- gstaichi/lang/ast/ast_transformers/call_transformer.py +267 -0
- gstaichi/lang/ast/ast_transformers/function_def_transformer.py +320 -0
- gstaichi/lang/ast/checkers.py +106 -0
- gstaichi/lang/ast/symbol_resolver.py +57 -0
- gstaichi/lang/ast/transform.py +9 -0
- gstaichi/lang/common_ops.py +310 -0
- gstaichi/lang/exception.py +80 -0
- gstaichi/lang/expr.py +180 -0
- gstaichi/lang/field.py +466 -0
- gstaichi/lang/impl.py +1241 -0
- gstaichi/lang/kernel_arguments.py +157 -0
- gstaichi/lang/kernel_impl.py +1382 -0
- gstaichi/lang/matrix.py +1881 -0
- gstaichi/lang/matrix_ops.py +341 -0
- gstaichi/lang/matrix_ops_utils.py +190 -0
- gstaichi/lang/mesh.py +687 -0
- gstaichi/lang/misc.py +778 -0
- gstaichi/lang/ops.py +1494 -0
- gstaichi/lang/runtime_ops.py +13 -0
- gstaichi/lang/shell.py +35 -0
- gstaichi/lang/simt/__init__.py +5 -0
- gstaichi/lang/simt/block.py +94 -0
- gstaichi/lang/simt/grid.py +7 -0
- gstaichi/lang/simt/subgroup.py +191 -0
- gstaichi/lang/simt/warp.py +96 -0
- gstaichi/lang/snode.py +489 -0
- gstaichi/lang/source_builder.py +150 -0
- gstaichi/lang/struct.py +855 -0
- gstaichi/lang/util.py +381 -0
- gstaichi/linalg/__init__.py +8 -0
- gstaichi/linalg/matrixfree_cg.py +310 -0
- gstaichi/linalg/sparse_cg.py +59 -0
- gstaichi/linalg/sparse_matrix.py +303 -0
- gstaichi/linalg/sparse_solver.py +123 -0
- gstaichi/math/__init__.py +11 -0
- gstaichi/math/_complex.py +205 -0
- gstaichi/math/mathimpl.py +886 -0
- gstaichi/profiler/__init__.py +6 -0
- gstaichi/profiler/kernel_metrics.py +260 -0
- gstaichi/profiler/kernel_profiler.py +586 -0
- gstaichi/profiler/memory_profiler.py +15 -0
- gstaichi/profiler/scoped_profiler.py +36 -0
- gstaichi/sparse/__init__.py +3 -0
- gstaichi/sparse/_sparse_grid.py +77 -0
- gstaichi/tools/__init__.py +12 -0
- gstaichi/tools/diagnose.py +117 -0
- gstaichi/tools/np2ply.py +364 -0
- gstaichi/tools/vtk.py +38 -0
- gstaichi/types/__init__.py +19 -0
- gstaichi/types/annotations.py +47 -0
- gstaichi/types/compound_types.py +90 -0
- gstaichi/types/enums.py +49 -0
- gstaichi/types/ndarray_type.py +147 -0
- gstaichi/types/primitive_types.py +206 -0
- gstaichi/types/quant.py +88 -0
- gstaichi/types/texture_type.py +85 -0
- gstaichi/types/utils.py +13 -0
- gstaichi-0.1.25.dev0.data/data/include/GLFW/glfw3.h +6389 -0
- gstaichi-0.1.25.dev0.data/data/include/GLFW/glfw3native.h +594 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv-tools/instrument.hpp +268 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv-tools/libspirv.h +907 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv-tools/libspirv.hpp +375 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv-tools/linker.hpp +97 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv-tools/optimizer.hpp +970 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/GLSL.std.450.h +114 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv.h +2568 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv.hpp +2579 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_cfg.hpp +168 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_common.hpp +1920 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_cpp.hpp +93 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_cross.hpp +1171 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_cross_c.h +1074 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_cross_containers.hpp +754 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_cross_error_handling.hpp +94 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_cross_parsed_ir.hpp +256 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_cross_util.hpp +37 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_glsl.hpp +1001 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_hlsl.hpp +406 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_msl.hpp +1273 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_parser.hpp +103 -0
- gstaichi-0.1.25.dev0.data/data/include/spirv_cross/spirv_reflect.hpp +91 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools/SPIRV-ToolsConfig.cmake +5 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools/SPIRV-ToolsTarget-release.cmake +29 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools/SPIRV-ToolsTarget.cmake +114 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-diff/SPIRV-Tools-diffConfig.cmake +5 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-diff/SPIRV-Tools-diffTargets-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-diff/SPIRV-Tools-diffTargets.cmake +123 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-link/SPIRV-Tools-linkConfig.cmake +5 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-link/SPIRV-Tools-linkTargets-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-link/SPIRV-Tools-linkTargets.cmake +123 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-lint/SPIRV-Tools-lintConfig.cmake +5 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-lint/SPIRV-Tools-lintTargets-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-lint/SPIRV-Tools-lintTargets.cmake +123 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-opt/SPIRV-Tools-optConfig.cmake +5 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-opt/SPIRV-Tools-optTargets-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-opt/SPIRV-Tools-optTargets.cmake +123 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-reduce/SPIRV-Tools-reduceConfig.cmake +5 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-reduce/SPIRV-Tools-reduceTarget-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/SPIRV-Tools-reduce/SPIRV-Tools-reduceTarget.cmake +123 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/glfw3/glfw3Config.cmake +3 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/glfw3/glfw3ConfigVersion.cmake +65 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/glfw3/glfw3Targets-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/lib/cmake/glfw3/glfw3Targets.cmake +107 -0
- gstaichi-0.1.25.dev0.data/data/lib/libSPIRV-Tools-shared.dylib +0 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_c/cmake/spirv_cross_cConfig-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_c/cmake/spirv_cross_cConfig.cmake +123 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_core/cmake/spirv_cross_coreConfig-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_core/cmake/spirv_cross_coreConfig.cmake +106 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_cpp/cmake/spirv_cross_cppConfig-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_cpp/cmake/spirv_cross_cppConfig.cmake +123 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_glsl/cmake/spirv_cross_glslConfig-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_glsl/cmake/spirv_cross_glslConfig.cmake +123 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_hlsl/cmake/spirv_cross_hlslConfig-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_hlsl/cmake/spirv_cross_hlslConfig.cmake +123 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_msl/cmake/spirv_cross_mslConfig-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_msl/cmake/spirv_cross_mslConfig.cmake +123 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_reflect/cmake/spirv_cross_reflectConfig-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_reflect/cmake/spirv_cross_reflectConfig.cmake +106 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_util/cmake/spirv_cross_utilConfig-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/share/spirv_cross_util/cmake/spirv_cross_utilConfig.cmake +123 -0
- gstaichi-0.1.25.dev0.dist-info/METADATA +105 -0
- gstaichi-0.1.25.dev0.dist-info/RECORD +168 -0
- gstaichi-0.1.25.dev0.dist-info/WHEEL +5 -0
- gstaichi-0.1.25.dev0.dist-info/entry_points.txt +2 -0
- gstaichi-0.1.25.dev0.dist-info/licenses/LICENSE +201 -0
- gstaichi-0.1.25.dev0.dist-info/top_level.txt +1 -0
File without changes
|
Binary file
|
Binary file
|
gstaichi/_lib/utils.py
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
# type: ignore
|
2
|
+
|
3
|
+
import os
|
4
|
+
import platform
|
5
|
+
import re
|
6
|
+
import sys
|
7
|
+
import warnings
|
8
|
+
|
9
|
+
from colorama import Fore, Style
|
10
|
+
|
11
|
+
if sys.version_info[0] < 3 or sys.version_info[1] <= 5:
|
12
|
+
raise RuntimeError(
|
13
|
+
"\nPlease restart with Python 3.6+\n" + "Current Python version:",
|
14
|
+
sys.version_info,
|
15
|
+
)
|
16
|
+
|
17
|
+
|
18
|
+
def in_docker():
|
19
|
+
if os.environ.get("TI_IN_DOCKER", "") == "":
|
20
|
+
return False
|
21
|
+
return True
|
22
|
+
|
23
|
+
|
24
|
+
def get_os_name():
|
25
|
+
name = platform.platform()
|
26
|
+
# in python 3.8, platform.platform() uses mac_ver() on macOS
|
27
|
+
# it will return 'macOS-XXXX' instead of 'Darwin-XXXX'
|
28
|
+
if name.lower().startswith("darwin") or name.lower().startswith("macos"):
|
29
|
+
return "osx"
|
30
|
+
if name.lower().startswith("windows"):
|
31
|
+
return "win"
|
32
|
+
if name.lower().startswith("linux"):
|
33
|
+
return "linux"
|
34
|
+
if "bsd" in name.lower():
|
35
|
+
return "unix"
|
36
|
+
assert False, f"Unknown platform name {name}"
|
37
|
+
|
38
|
+
|
39
|
+
def import_ti_python_core():
|
40
|
+
if get_os_name() != "win":
|
41
|
+
# pylint: disable=E1101
|
42
|
+
old_flags = sys.getdlopenflags()
|
43
|
+
sys.setdlopenflags(2 | 8) # RTLD_NOW | RTLD_DEEPBIND
|
44
|
+
else:
|
45
|
+
pyddir = os.path.dirname(os.path.realpath(__file__))
|
46
|
+
os.environ["PATH"] += os.pathsep + pyddir
|
47
|
+
try:
|
48
|
+
from gstaichi._lib.core import gstaichi_python as core # pylint: disable=C0415
|
49
|
+
except Exception as e:
|
50
|
+
if isinstance(e, ImportError):
|
51
|
+
print(
|
52
|
+
Fore.YELLOW + "Share object gstaichi_python import failed, "
|
53
|
+
"check this page for possible solutions:\n"
|
54
|
+
"https://docs.taichi-lang.org/docs/install" + Fore.RESET
|
55
|
+
)
|
56
|
+
if get_os_name() == "win":
|
57
|
+
# pylint: disable=E1101
|
58
|
+
e.msg += "\nConsider installing Microsoft Visual C++ Redistributable: https://aka.ms/vs/16/release/vc_redist.x64.exe"
|
59
|
+
raise e from None
|
60
|
+
|
61
|
+
if get_os_name() != "win":
|
62
|
+
sys.setdlopenflags(old_flags) # pylint: disable=E1101
|
63
|
+
lib_dir = os.path.join(package_root, "_lib", "runtime")
|
64
|
+
core.set_lib_dir(locale_encode(lib_dir))
|
65
|
+
return core
|
66
|
+
|
67
|
+
|
68
|
+
def locale_encode(path):
|
69
|
+
try:
|
70
|
+
import locale # pylint: disable=C0415
|
71
|
+
|
72
|
+
return path.encode(locale.getdefaultlocale()[1])
|
73
|
+
except (UnicodeEncodeError, TypeError):
|
74
|
+
try:
|
75
|
+
return path.encode(sys.getfilesystemencoding())
|
76
|
+
except UnicodeEncodeError:
|
77
|
+
try:
|
78
|
+
return path.encode()
|
79
|
+
except UnicodeEncodeError:
|
80
|
+
return path
|
81
|
+
|
82
|
+
|
83
|
+
def is_ci():
|
84
|
+
return os.environ.get("TI_CI", "") == "1"
|
85
|
+
|
86
|
+
|
87
|
+
package_root = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
|
88
|
+
|
89
|
+
|
90
|
+
def get_core_shared_object():
|
91
|
+
directory = os.path.join(package_root, "_lib")
|
92
|
+
return os.path.join(directory, "libgstaichi_python.so")
|
93
|
+
|
94
|
+
|
95
|
+
def print_red_bold(*args, **kwargs):
|
96
|
+
print(Fore.RED + Style.BRIGHT, end="")
|
97
|
+
print(*args, **kwargs)
|
98
|
+
print(Style.RESET_ALL, end="")
|
99
|
+
|
100
|
+
|
101
|
+
def print_yellow_bold(*args, **kwargs):
|
102
|
+
print(Fore.YELLOW + Style.BRIGHT, end="")
|
103
|
+
print(*args, **kwargs)
|
104
|
+
print(Style.RESET_ALL, end="")
|
105
|
+
|
106
|
+
|
107
|
+
def check_exists(src):
|
108
|
+
if not os.path.exists(src):
|
109
|
+
raise FileNotFoundError(f'File "{src}" not exist. Installation corrupted or build incomplete?')
|
110
|
+
|
111
|
+
|
112
|
+
ti_python_core = import_ti_python_core()
|
113
|
+
|
114
|
+
ti_python_core.set_python_package_dir(package_root)
|
115
|
+
|
116
|
+
log_level = os.environ.get("TI_LOG_LEVEL", "")
|
117
|
+
if log_level:
|
118
|
+
ti_python_core.set_logging_level(log_level)
|
119
|
+
|
120
|
+
|
121
|
+
def get_dll_name(name):
|
122
|
+
if get_os_name() == "linux":
|
123
|
+
return f"libgstaichi_{name}.so"
|
124
|
+
if get_os_name() == "osx":
|
125
|
+
return f"libgstaichi_{name}.dylib"
|
126
|
+
if get_os_name() == "win":
|
127
|
+
return f"gstaichi_{name}.dll"
|
128
|
+
raise Exception(f"Unknown OS: {get_os_name()}")
|
129
|
+
|
130
|
+
|
131
|
+
def at_startup():
|
132
|
+
ti_python_core.set_core_state_python_imported(True)
|
133
|
+
|
134
|
+
|
135
|
+
at_startup()
|
136
|
+
|
137
|
+
|
138
|
+
def compare_version(latest, current):
|
139
|
+
latest_num = map(int, latest.split("."))
|
140
|
+
current_num = map(int, current.split("."))
|
141
|
+
return tuple(latest_num) > tuple(current_num)
|
142
|
+
|
143
|
+
|
144
|
+
def _print_gstaichi_header():
|
145
|
+
header = "[GsTaichi] "
|
146
|
+
header += f"version {ti_python_core.get_version_string()}, "
|
147
|
+
|
148
|
+
try:
|
149
|
+
timestamp_path = os.path.join(ti_python_core.get_repo_dir(), "timestamp")
|
150
|
+
if os.path.exists(timestamp_path):
|
151
|
+
latest_version = ""
|
152
|
+
with open(timestamp_path, "r") as f:
|
153
|
+
latest_version = f.readlines()[1].rstrip()
|
154
|
+
if compare_version(latest_version, ti_python_core.get_version_string()):
|
155
|
+
header += f"latest version {latest_version}, "
|
156
|
+
except:
|
157
|
+
pass
|
158
|
+
|
159
|
+
llvm_target_support = ti_python_core.get_llvm_target_support()
|
160
|
+
header += f"llvm {llvm_target_support}, "
|
161
|
+
|
162
|
+
commit_hash = ti_python_core.get_commit_hash()
|
163
|
+
commit_hash = commit_hash[:8]
|
164
|
+
header += f"commit {commit_hash}, "
|
165
|
+
|
166
|
+
header += f"{get_os_name()}, "
|
167
|
+
|
168
|
+
py_ver = ".".join(str(x) for x in sys.version_info[:3])
|
169
|
+
header += f"python {py_ver}"
|
170
|
+
|
171
|
+
print(header)
|
172
|
+
|
173
|
+
|
174
|
+
if os.getenv("ENABLE_GSTAICHI_HEADER_PRINT", "True").lower() not in ("false", "0", "f"):
|
175
|
+
_print_gstaichi_header()
|
176
|
+
|
177
|
+
|
178
|
+
def try_get_wheel_tag(module):
|
179
|
+
try:
|
180
|
+
from email.parser import Parser # pylint: disable=import-outside-toplevel
|
181
|
+
|
182
|
+
wheel_path = f'{module.__path__[0]}-{".".join(map(str, module.__version__))}.dist-info/WHEEL'
|
183
|
+
with open(wheel_path, "r") as f:
|
184
|
+
meta = Parser().parse(f)
|
185
|
+
return meta.get("Tag")
|
186
|
+
except Exception:
|
187
|
+
return None
|
188
|
+
|
189
|
+
|
190
|
+
def try_get_loaded_libc_version():
|
191
|
+
assert platform.system() == "Linux"
|
192
|
+
with open("/proc/self/maps") as f:
|
193
|
+
content = f.read()
|
194
|
+
|
195
|
+
try:
|
196
|
+
libc_path = next(v for v in content.split() if "libc-" in v)
|
197
|
+
ver = re.findall(r"\d+\.\d+", libc_path)
|
198
|
+
if not ver:
|
199
|
+
return None
|
200
|
+
return tuple([int(v) for v in ver[0].split(".")])
|
201
|
+
except StopIteration:
|
202
|
+
return None
|
203
|
+
|
204
|
+
|
205
|
+
def try_get_pip_version():
|
206
|
+
try:
|
207
|
+
with warnings.catch_warnings():
|
208
|
+
warnings.simplefilter("ignore")
|
209
|
+
import pip # pylint: disable=import-outside-toplevel
|
210
|
+
return tuple([int(v) for v in pip.__version__.split(".")])
|
211
|
+
except ImportError:
|
212
|
+
return None
|
213
|
+
|
214
|
+
|
215
|
+
def warn_restricted_version():
|
216
|
+
if os.environ.get("TI_MANYLINUX2014_OK", ""):
|
217
|
+
return
|
218
|
+
|
219
|
+
if get_os_name() == "linux":
|
220
|
+
try:
|
221
|
+
import gstaichi as ti # pylint: disable=import-outside-toplevel
|
222
|
+
|
223
|
+
wheel_tag = try_get_wheel_tag(ti)
|
224
|
+
if wheel_tag and "manylinux2014" in wheel_tag:
|
225
|
+
print_yellow_bold(
|
226
|
+
"You have installed a restricted version of gstaichi, certain features (e.g. Vulkan & GGUI) will not work."
|
227
|
+
)
|
228
|
+
libc_ver = try_get_loaded_libc_version()
|
229
|
+
if libc_ver and libc_ver < (2, 27):
|
230
|
+
print_yellow_bold(
|
231
|
+
"!! GsTaichi requires glibc >= 2.27 to run, please try upgrading your OS to a recent one (e.g. Ubuntu 18.04 or later) if possible."
|
232
|
+
)
|
233
|
+
|
234
|
+
pip_ver = try_get_pip_version()
|
235
|
+
if pip_ver and pip_ver < (20, 3, 0):
|
236
|
+
print_yellow_bold(
|
237
|
+
f"!! Your pip (version {'.'.join(map(str, pip_ver))}) is outdated (20.3.0 or later required), "
|
238
|
+
"try upgrading pip and install gstaichi again."
|
239
|
+
)
|
240
|
+
print()
|
241
|
+
print_yellow_bold(" $ python3 -m pip install --upgrade pip")
|
242
|
+
print_yellow_bold(" $ python3 -m pip install --force-reinstall gstaichi")
|
243
|
+
print()
|
244
|
+
|
245
|
+
print_yellow_bold(
|
246
|
+
"You can suppress this warning by setting the environment variable TI_MANYLINUX2014_OK=1."
|
247
|
+
)
|
248
|
+
except Exception:
|
249
|
+
pass
|
gstaichi/_logging.py
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# type: ignore
|
2
|
+
|
3
|
+
import inspect
|
4
|
+
import os
|
5
|
+
|
6
|
+
from gstaichi._lib import core as ti_python_core
|
7
|
+
|
8
|
+
|
9
|
+
def _get_logging(name):
|
10
|
+
"""Generates a decorator to decorate a specific logger function.
|
11
|
+
|
12
|
+
Args:
|
13
|
+
name (str): The string represents logging level.
|
14
|
+
Effective levels include: 'trace', 'debug', 'info', 'warn', 'error', 'critical'.
|
15
|
+
|
16
|
+
Returns:
|
17
|
+
Callabe: The decorated function.
|
18
|
+
"""
|
19
|
+
|
20
|
+
def logger(msg, *args, **kwargs):
|
21
|
+
# Python inspection takes time (~0.1ms) so avoid it as much as possible
|
22
|
+
if ti_python_core.logging_effective(name):
|
23
|
+
msg_formatted = msg.format(*args, **kwargs)
|
24
|
+
func = getattr(ti_python_core, name)
|
25
|
+
frame = inspect.currentframe().f_back
|
26
|
+
file_name, lineno, func_name, _, _ = inspect.getframeinfo(frame)
|
27
|
+
file_name = os.path.basename(file_name)
|
28
|
+
msg = f"[{file_name}:{func_name}@{lineno}] {msg_formatted}"
|
29
|
+
func(msg)
|
30
|
+
|
31
|
+
return logger
|
32
|
+
|
33
|
+
|
34
|
+
def set_logging_level(level):
|
35
|
+
"""Setting the logging level to a specified value.
|
36
|
+
Available levels are: 'trace', 'debug', 'info', 'warn', 'error', 'critical'.
|
37
|
+
|
38
|
+
Note that after calling this function, logging levels below the specified one will
|
39
|
+
also be effective. For example if `level` is set to 'warn', then the levels below
|
40
|
+
it, which are 'error' and 'critical' in this case, will also be effective.
|
41
|
+
|
42
|
+
See also https://docs.taichi-lang.org/docs/developer_utilities#logging.
|
43
|
+
|
44
|
+
Args:
|
45
|
+
level (str): Logging level.
|
46
|
+
|
47
|
+
Example::
|
48
|
+
|
49
|
+
>>> set_logging_level('debug')
|
50
|
+
"""
|
51
|
+
ti_python_core.set_logging_level(level)
|
52
|
+
|
53
|
+
|
54
|
+
def is_logging_effective(level):
|
55
|
+
"""Check if the specified logging level is effective.
|
56
|
+
All levels below current level will be effective.
|
57
|
+
The default level is 'info'.
|
58
|
+
|
59
|
+
See also https://docs.taichi-lang.org/docs/developer_utilities#logging.
|
60
|
+
|
61
|
+
Args:
|
62
|
+
level (str): The string represents logging level. \
|
63
|
+
Effective levels include: 'trace', 'debug', 'info', 'warn', 'error', 'critical'.
|
64
|
+
|
65
|
+
Returns:
|
66
|
+
Bool: Indicate whether the logging level is effective.
|
67
|
+
|
68
|
+
Example::
|
69
|
+
|
70
|
+
>>> # assume current level is 'info'
|
71
|
+
>>> print(ti.is_logging_effective("trace")) # False
|
72
|
+
>>> print(ti.is_logging_effective("debug")) # False
|
73
|
+
>>> print(ti.is_logging_effective("info")) # True
|
74
|
+
>>> print(ti.is_logging_effective("warn")) # True
|
75
|
+
>>> print(ti.is_logging_effective("error")) # True
|
76
|
+
>>> print(ti.is_logging_effective("critical")) # True
|
77
|
+
"""
|
78
|
+
return ti_python_core.logging_effective(level)
|
79
|
+
|
80
|
+
|
81
|
+
# ------------------------
|
82
|
+
|
83
|
+
DEBUG = "debug"
|
84
|
+
"""The `str` 'debug', used for the `debug` logging level.
|
85
|
+
"""
|
86
|
+
# ------------------------
|
87
|
+
|
88
|
+
TRACE = "trace"
|
89
|
+
"""The `str` 'trace', used for the `debug` logging level.
|
90
|
+
"""
|
91
|
+
# ------------------------
|
92
|
+
|
93
|
+
INFO = "info"
|
94
|
+
"""The `str` 'info', used for the `info` logging level.
|
95
|
+
"""
|
96
|
+
# ------------------------
|
97
|
+
|
98
|
+
WARN = "warn"
|
99
|
+
"""The `str` 'warn', used for the `warn` logging level.
|
100
|
+
"""
|
101
|
+
# ------------------------
|
102
|
+
|
103
|
+
ERROR = "error"
|
104
|
+
"""The `str` 'error', used for the `error` logging level.
|
105
|
+
"""
|
106
|
+
# ------------------------
|
107
|
+
|
108
|
+
CRITICAL = "critical"
|
109
|
+
"""The `str` 'critical', used for the `critical` logging level.
|
110
|
+
"""
|
111
|
+
# ------------------------
|
112
|
+
|
113
|
+
supported_log_levels = [DEBUG, TRACE, INFO, WARN, ERROR, CRITICAL]
|
114
|
+
|
115
|
+
debug = _get_logging(DEBUG)
|
116
|
+
trace = _get_logging(TRACE)
|
117
|
+
info = _get_logging(INFO)
|
118
|
+
warn = _get_logging(WARN)
|
119
|
+
error = _get_logging(ERROR)
|
120
|
+
critical = _get_logging(CRITICAL)
|
121
|
+
|
122
|
+
__all__ = [
|
123
|
+
"DEBUG",
|
124
|
+
"TRACE",
|
125
|
+
"INFO",
|
126
|
+
"WARN",
|
127
|
+
"ERROR",
|
128
|
+
"CRITICAL",
|
129
|
+
"set_logging_level",
|
130
|
+
"is_logging_effective",
|
131
|
+
]
|