gstaichi 0.1.25.dev0__cp311-cp311-win_amd64.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/CHANGELOG.md +9 -0
- 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.cp311-win_amd64.pyd +0 -0
- gstaichi/_lib/core/gstaichi_python.pyi +2937 -0
- gstaichi/_lib/core/py.typed +0 -0
- gstaichi/_lib/runtime/runtime_cuda.bc +0 -0
- gstaichi/_lib/runtime/runtime_x64.bc +0 -0
- gstaichi/_lib/runtime/slim_libdevice.10.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/SPIRV-Tools/cmake/SPIRV-ToolsConfig.cmake +5 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools/cmake/SPIRV-ToolsTarget-release.cmake +29 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools/cmake/SPIRV-ToolsTarget.cmake +113 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-diff/cmake/SPIRV-Tools-diffConfig.cmake +5 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-diff/cmake/SPIRV-Tools-diffTargets-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-diff/cmake/SPIRV-Tools-diffTargets.cmake +122 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-link/cmake/SPIRV-Tools-linkConfig.cmake +5 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-link/cmake/SPIRV-Tools-linkTargets-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-link/cmake/SPIRV-Tools-linkTargets.cmake +122 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-lint/cmake/SPIRV-Tools-lintConfig.cmake +5 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-lint/cmake/SPIRV-Tools-lintTargets-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-lint/cmake/SPIRV-Tools-lintTargets.cmake +122 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-opt/cmake/SPIRV-Tools-optConfig.cmake +5 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-opt/cmake/SPIRV-Tools-optTargets-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-opt/cmake/SPIRV-Tools-optTargets.cmake +122 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-reduce/cmake/SPIRV-Tools-reduceConfig.cmake +5 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-reduce/cmake/SPIRV-Tools-reduceTarget-release.cmake +19 -0
- gstaichi-0.1.25.dev0.data/data/SPIRV-Tools-reduce/cmake/SPIRV-Tools-reduceTarget.cmake +122 -0
- gstaichi-0.1.25.dev0.data/data/bin/SPIRV-Tools-shared.dll +0 -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/lib/SPIRV-Tools-diff.lib +0 -0
- gstaichi-0.1.25.dev0.data/data/lib/SPIRV-Tools-link.lib +0 -0
- gstaichi-0.1.25.dev0.data/data/lib/SPIRV-Tools-lint.lib +0 -0
- gstaichi-0.1.25.dev0.data/data/lib/SPIRV-Tools-opt.lib +0 -0
- gstaichi-0.1.25.dev0.data/data/lib/SPIRV-Tools-reduce.lib +0 -0
- gstaichi-0.1.25.dev0.data/data/lib/SPIRV-Tools-shared.lib +0 -0
- gstaichi-0.1.25.dev0.data/data/lib/SPIRV-Tools.lib +0 -0
- gstaichi-0.1.25.dev0.dist-info/METADATA +105 -0
- gstaichi-0.1.25.dev0.dist-info/RECORD +138 -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
@@ -0,0 +1,187 @@
|
|
1
|
+
# type: ignore
|
2
|
+
|
3
|
+
from typing import Any, Optional, Sequence, Union
|
4
|
+
|
5
|
+
from gstaichi._lib import core as _ti_core
|
6
|
+
from gstaichi._lib.core.gstaichi_python import SNodeCxx
|
7
|
+
from gstaichi._snode.snode_tree import SNodeTree
|
8
|
+
from gstaichi.lang import impl, snode
|
9
|
+
from gstaichi.lang.exception import GsTaichiRuntimeError
|
10
|
+
from gstaichi.lang.util import warning
|
11
|
+
|
12
|
+
_snode_registry = _ti_core.SNodeRegistry()
|
13
|
+
|
14
|
+
_Axis = _ti_core.Axis
|
15
|
+
|
16
|
+
|
17
|
+
class FieldsBuilder:
|
18
|
+
"""A builder that constructs a SNodeTree instance.
|
19
|
+
|
20
|
+
Example::
|
21
|
+
|
22
|
+
x = ti.field(ti.i32)
|
23
|
+
y = ti.field(ti.f32)
|
24
|
+
fb = ti.FieldsBuilder()
|
25
|
+
fb.dense(ti.ij, 8).place(x)
|
26
|
+
fb.pointer(ti.ij, 8).dense(ti.ij, 4).place(y)
|
27
|
+
|
28
|
+
# After this line, `x` and `y` are placed. No more fields can be placed
|
29
|
+
# into `fb`.
|
30
|
+
#
|
31
|
+
# The tree looks like the following:
|
32
|
+
# (implicit root)
|
33
|
+
# |
|
34
|
+
# +-- dense +-- place(x)
|
35
|
+
# |
|
36
|
+
# +-- pointer +-- dense +-- place(y)
|
37
|
+
fb.finalize()
|
38
|
+
"""
|
39
|
+
|
40
|
+
def __init__(self):
|
41
|
+
self.ptr: SNodeCxx = _snode_registry.create_root(impl.get_runtime().prog)
|
42
|
+
self.root = snode.SNode(self.ptr)
|
43
|
+
self.finalized = False
|
44
|
+
self.empty = True
|
45
|
+
impl.get_runtime().initialize_fields_builder(self)
|
46
|
+
|
47
|
+
# TODO: move this into SNodeTree
|
48
|
+
@classmethod
|
49
|
+
def _finalized_roots(cls):
|
50
|
+
"""Gets all the roots of the finalized SNodeTree.
|
51
|
+
|
52
|
+
Returns:
|
53
|
+
A list of the roots of the finalized SNodeTree.
|
54
|
+
"""
|
55
|
+
roots_ptr = []
|
56
|
+
size = impl.get_runtime().prog.get_snode_tree_size()
|
57
|
+
for i in range(size):
|
58
|
+
res = impl.get_runtime().prog.get_snode_root(i)
|
59
|
+
roots_ptr.append(snode.SNode(res))
|
60
|
+
return roots_ptr
|
61
|
+
|
62
|
+
# TODO: move this to SNodeTree class.
|
63
|
+
def deactivate_all(self):
|
64
|
+
"""Same as :func:`gstaichi.lang.snode.SNode.deactivate_all`"""
|
65
|
+
if self.finalized:
|
66
|
+
self.root.deactivate_all()
|
67
|
+
else:
|
68
|
+
warning("""'deactivate_all()' would do nothing if FieldsBuilder is not finalized""")
|
69
|
+
|
70
|
+
def dense(
|
71
|
+
self,
|
72
|
+
indices: Union[Sequence[_Axis], _Axis],
|
73
|
+
dimensions: Union[Sequence[int], int],
|
74
|
+
):
|
75
|
+
"""Same as :func:`gstaichi.lang.snode.SNode.dense`"""
|
76
|
+
self._check_not_finalized()
|
77
|
+
self.empty = False
|
78
|
+
return self.root.dense(indices, dimensions)
|
79
|
+
|
80
|
+
def pointer(
|
81
|
+
self,
|
82
|
+
indices: Union[Sequence[_Axis], _Axis],
|
83
|
+
dimensions: Union[Sequence[int], int],
|
84
|
+
):
|
85
|
+
"""Same as :func:`gstaichi.lang.snode.SNode.pointer`"""
|
86
|
+
if not _ti_core.is_extension_supported(impl.current_cfg().arch, _ti_core.Extension.sparse):
|
87
|
+
raise GsTaichiRuntimeError("Pointer SNode is not supported on this backend.")
|
88
|
+
self._check_not_finalized()
|
89
|
+
self.empty = False
|
90
|
+
return self.root.pointer(indices, dimensions)
|
91
|
+
|
92
|
+
def _hash(self, indices, dimensions):
|
93
|
+
"""Same as :func:`gstaichi.lang.snode.SNode.hash`"""
|
94
|
+
raise NotImplementedError()
|
95
|
+
|
96
|
+
def dynamic(
|
97
|
+
self,
|
98
|
+
index: Union[Sequence[_Axis], _Axis],
|
99
|
+
dimension: Union[Sequence[int], int],
|
100
|
+
chunk_size: Optional[int] = None,
|
101
|
+
):
|
102
|
+
"""Same as :func:`gstaichi.lang.snode.SNode.dynamic`"""
|
103
|
+
if not _ti_core.is_extension_supported(impl.current_cfg().arch, _ti_core.Extension.sparse):
|
104
|
+
raise GsTaichiRuntimeError("Dynamic SNode is not supported on this backend.")
|
105
|
+
|
106
|
+
if dimension >= 2**31:
|
107
|
+
raise GsTaichiRuntimeError(
|
108
|
+
f"The maximum dimension of a dynamic SNode cannot exceed the maximum value of a 32-bit signed integer: Got {dimension} > 2**31-1"
|
109
|
+
)
|
110
|
+
if chunk_size is not None and chunk_size >= 2**31:
|
111
|
+
raise GsTaichiRuntimeError(
|
112
|
+
f"Chunk size cannot exceed the maximum value of a 32-bit signed integer: Got {chunk_size} > 2**31-1"
|
113
|
+
)
|
114
|
+
|
115
|
+
self._check_not_finalized()
|
116
|
+
self.empty = False
|
117
|
+
return self.root.dynamic(index, dimension, chunk_size)
|
118
|
+
|
119
|
+
def bitmasked(
|
120
|
+
self,
|
121
|
+
indices: Union[Sequence[_Axis], _Axis],
|
122
|
+
dimensions: Union[Sequence[int], int],
|
123
|
+
):
|
124
|
+
"""Same as :func:`gstaichi.lang.snode.SNode.bitmasked`"""
|
125
|
+
if not _ti_core.is_extension_supported(impl.current_cfg().arch, _ti_core.Extension.sparse):
|
126
|
+
raise GsTaichiRuntimeError("Bitmasked SNode is not supported on this backend.")
|
127
|
+
self._check_not_finalized()
|
128
|
+
self.empty = False
|
129
|
+
return self.root.bitmasked(indices, dimensions)
|
130
|
+
|
131
|
+
def quant_array(
|
132
|
+
self,
|
133
|
+
indices: Union[Sequence[_Axis], _Axis],
|
134
|
+
dimensions: Union[Sequence[int], int],
|
135
|
+
max_num_bits: int,
|
136
|
+
):
|
137
|
+
"""Same as :func:`gstaichi.lang.snode.SNode.quant_array`"""
|
138
|
+
self._check_not_finalized()
|
139
|
+
self.empty = False
|
140
|
+
return self.root.quant_array(indices, dimensions, max_num_bits)
|
141
|
+
|
142
|
+
def place(self, *args: Any, offset: Optional[Union[Sequence[int], int]] = None):
|
143
|
+
"""Same as :func:`gstaichi.lang.snode.SNode.place`"""
|
144
|
+
self._check_not_finalized()
|
145
|
+
self.empty = False
|
146
|
+
self.root.place(*args, offset=offset)
|
147
|
+
|
148
|
+
def lazy_grad(self):
|
149
|
+
"""Same as :func:`gstaichi.lang.snode.SNode.lazy_grad`"""
|
150
|
+
# TODO: This complicates the implementation. Figure out why we need this
|
151
|
+
self._check_not_finalized()
|
152
|
+
self.empty = False
|
153
|
+
self.root.lazy_grad()
|
154
|
+
|
155
|
+
def _allocate_adjoint_checkbit(self):
|
156
|
+
"""Same as :func:`gstaichi.lang.snode.SNode._allocate_adjoint_checkbit`"""
|
157
|
+
self._check_not_finalized()
|
158
|
+
self.empty = False
|
159
|
+
self.root._allocate_adjoint_checkbit()
|
160
|
+
|
161
|
+
def lazy_dual(self):
|
162
|
+
"""Same as :func:`gstaichi.lang.snode.SNode.lazy_dual`"""
|
163
|
+
# TODO: This complicates the implementation. Figure out why we need this
|
164
|
+
self._check_not_finalized()
|
165
|
+
self.empty = False
|
166
|
+
self.root.lazy_dual()
|
167
|
+
|
168
|
+
def finalize(self, raise_warning=True):
|
169
|
+
"""Constructs the SNodeTree and finalizes this builder.
|
170
|
+
|
171
|
+
Args:
|
172
|
+
raise_warning (bool): Raise warning or not."""
|
173
|
+
return self._finalize(raise_warning, compile_only=False)
|
174
|
+
|
175
|
+
def _finalize(self, raise_warning, compile_only) -> SNodeTree:
|
176
|
+
self._check_not_finalized()
|
177
|
+
if self.empty and raise_warning:
|
178
|
+
warning("Finalizing an empty FieldsBuilder!")
|
179
|
+
self.finalized = True
|
180
|
+
impl.get_runtime().finalize_fields_builder(self)
|
181
|
+
return SNodeTree(
|
182
|
+
_ti_core.finalize_snode_tree(_snode_registry, self.ptr, impl.get_runtime()._prog, compile_only)
|
183
|
+
)
|
184
|
+
|
185
|
+
def _check_not_finalized(self):
|
186
|
+
if self.finalized:
|
187
|
+
raise GsTaichiRuntimeError("FieldsBuilder finalized")
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# type: ignore
|
2
|
+
|
3
|
+
# The reason we import just the gstaichi.core.util module, instead of the ti_python_core
|
4
|
+
# object within it, is that ti_python_core is stateful. While in practice ti_python_core is
|
5
|
+
# loaded during the import procedure, it's probably still good to delay the
|
6
|
+
# access to it.
|
7
|
+
|
8
|
+
from gstaichi.lang import impl
|
9
|
+
from gstaichi.lang.exception import GsTaichiRuntimeError
|
10
|
+
|
11
|
+
|
12
|
+
class SNodeTree:
|
13
|
+
def __init__(self, ptr):
|
14
|
+
self.prog = impl.get_runtime().prog
|
15
|
+
self.ptr = ptr
|
16
|
+
self.destroyed = False
|
17
|
+
|
18
|
+
def destroy(self):
|
19
|
+
if self.destroyed:
|
20
|
+
raise GsTaichiRuntimeError("SNode tree has been destroyed")
|
21
|
+
if self.prog != impl.get_runtime().prog:
|
22
|
+
return
|
23
|
+
self.ptr.destroy_snode_tree(impl.get_runtime().prog)
|
24
|
+
|
25
|
+
# FieldExpression holds a SNode* to the place-SNode associated with a SNodeTree
|
26
|
+
# Therefore, we have to recompile all the kernels after destroying a SNodeTree
|
27
|
+
impl.get_runtime().clear_compiled_functions()
|
28
|
+
self.destroyed = True
|
29
|
+
|
30
|
+
@property
|
31
|
+
def id(self):
|
32
|
+
if self.destroyed:
|
33
|
+
raise GsTaichiRuntimeError("SNode tree has been destroyed")
|
34
|
+
return self.ptr.id()
|
File without changes
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import importlib.util
|
2
|
+
import sys
|
3
|
+
import tempfile
|
4
|
+
from contextlib import contextmanager
|
5
|
+
from pathlib import Path
|
6
|
+
|
7
|
+
|
8
|
+
def import_kernel_from_file(kernel_filepath: Path, kernel_name: str):
|
9
|
+
spec = importlib.util.spec_from_file_location(kernel_name, kernel_filepath)
|
10
|
+
assert spec is not None
|
11
|
+
module = importlib.util.module_from_spec(spec)
|
12
|
+
sys.modules[kernel_name] = module
|
13
|
+
loader = spec.loader
|
14
|
+
assert loader is not None
|
15
|
+
loader.exec_module(module)
|
16
|
+
return getattr(module, kernel_name)
|
17
|
+
|
18
|
+
|
19
|
+
@contextmanager
|
20
|
+
def load_kernel_from_string(kernel_str: str, kernel_name: str):
|
21
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
22
|
+
filepath = Path(temp_dir) / f"{kernel_name}.py"
|
23
|
+
with open(filepath, "w") as f:
|
24
|
+
f.write(kernel_str)
|
25
|
+
try:
|
26
|
+
kernel = import_kernel_from_file(kernel_filepath=filepath, kernel_name=kernel_name)
|
27
|
+
yield kernel
|
28
|
+
finally:
|
29
|
+
if kernel_name in sys.modules:
|
30
|
+
del sys.modules[kernel_name]
|
gstaichi/_version.py
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = '0.1.25.dev0'
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# type: ignore
|
2
|
+
|
3
|
+
import datetime
|
4
|
+
import json
|
5
|
+
import os
|
6
|
+
import platform
|
7
|
+
import threading
|
8
|
+
import uuid
|
9
|
+
from urllib import request
|
10
|
+
|
11
|
+
from gstaichi._lib import core as _ti_core
|
12
|
+
|
13
|
+
|
14
|
+
def check_version(cur_uuid):
|
15
|
+
# Check GsTaichi version for the user.
|
16
|
+
major = _ti_core.get_version_major()
|
17
|
+
minor = _ti_core.get_version_minor()
|
18
|
+
patch = _ti_core.get_version_patch()
|
19
|
+
version = f"{major}.{minor}.{patch}"
|
20
|
+
payload = {"version": version, "platform": "", "python": ""}
|
21
|
+
|
22
|
+
system = platform.system()
|
23
|
+
u = platform.uname()
|
24
|
+
if (u.system, u.machine) == ("Linux", "x86_64"):
|
25
|
+
payload["platform"] = "manylinux_2_27_x86_64"
|
26
|
+
elif (u.system, u.machine) in (("Linux", "arm64"), ("Linux", "aarch64")):
|
27
|
+
payload["platform"] = "manylinux_2_27_aarch64"
|
28
|
+
elif system == "Windows":
|
29
|
+
payload["platform"] = "win_amd64"
|
30
|
+
elif system == "Darwin":
|
31
|
+
if platform.release() < "19.0.0":
|
32
|
+
payload["platform"] = "macosx_10_14_x86_64"
|
33
|
+
elif platform.machine() == "x86_64":
|
34
|
+
payload["platform"] = "macosx_10_15_x86_64"
|
35
|
+
else:
|
36
|
+
payload["platform"] = "macosx_11_0_arm64"
|
37
|
+
|
38
|
+
python_version = platform.python_version().split(".")
|
39
|
+
payload["python"] = "cp" + python_version[0] + python_version[1]
|
40
|
+
|
41
|
+
payload["uuid"] = cur_uuid
|
42
|
+
if os.getenv("TI_CI") == "1":
|
43
|
+
payload["type"] = "CI"
|
44
|
+
# We do not want request exceptions break users' usage of GsTaichi.
|
45
|
+
try:
|
46
|
+
payload = json.dumps(payload)
|
47
|
+
payload = payload.encode()
|
48
|
+
req = request.Request("https://metadata.gstaichi.graphics/check_version", method="POST")
|
49
|
+
req.add_header("Content-Type", "application/json")
|
50
|
+
with request.urlopen(req, data=payload, timeout=5) as response:
|
51
|
+
response = json.loads(response.read().decode("utf-8"))
|
52
|
+
return response
|
53
|
+
except:
|
54
|
+
return None
|
55
|
+
|
56
|
+
|
57
|
+
def write_version_info(response, cur_uuid, version_info_path, cur_date):
|
58
|
+
if response is None:
|
59
|
+
return
|
60
|
+
with open(version_info_path, "w") as f:
|
61
|
+
f.write((cur_date).strftime("%Y-%m-%d"))
|
62
|
+
f.write("\n")
|
63
|
+
if response["status"] == 1:
|
64
|
+
f.write(response["latest_version"])
|
65
|
+
else:
|
66
|
+
f.write("0.0.0")
|
67
|
+
f.write("\n")
|
68
|
+
f.write(cur_uuid)
|
69
|
+
f.write("\n")
|
70
|
+
|
71
|
+
|
72
|
+
def try_check_version():
|
73
|
+
try:
|
74
|
+
os.makedirs(_ti_core.get_repo_dir(), exist_ok=True)
|
75
|
+
version_info_path = os.path.join(_ti_core.get_repo_dir(), "version_info")
|
76
|
+
cur_date = datetime.date.today()
|
77
|
+
if os.path.exists(version_info_path):
|
78
|
+
with open(version_info_path, "r") as f:
|
79
|
+
version_info_file = f.readlines()
|
80
|
+
last_time = version_info_file[0].rstrip()
|
81
|
+
cur_uuid = version_info_file[2].rstrip()
|
82
|
+
if cur_date.strftime("%Y-%m-%d") > last_time:
|
83
|
+
response = check_version(cur_uuid)
|
84
|
+
write_version_info(response, cur_uuid, version_info_path, cur_date)
|
85
|
+
else:
|
86
|
+
cur_uuid = str(uuid.uuid4())
|
87
|
+
write_version_info({"status": 0}, cur_uuid, version_info_path, cur_date)
|
88
|
+
response = check_version(cur_uuid)
|
89
|
+
write_version_info(response, cur_uuid, version_info_path, cur_date)
|
90
|
+
# Wildcard exception to catch potential file writing errors.
|
91
|
+
except:
|
92
|
+
pass
|
93
|
+
|
94
|
+
|
95
|
+
def start_version_check_thread():
|
96
|
+
skip = os.environ.get("TI_SKIP_VERSION_CHECK")
|
97
|
+
if skip != "ON":
|
98
|
+
# We don't join this thread because we do not wish to block users.
|
99
|
+
check_version_thread = threading.Thread(target=try_check_version, daemon=True)
|
100
|
+
check_version_thread.start()
|
101
|
+
|
102
|
+
|
103
|
+
__all__ = []
|
gstaichi/ad/__init__.py
ADDED