gstaichi 0.1.18.dev1__cp310-cp310-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.
Files changed (219) hide show
  1. gstaichi-0.1.18.dev1.data/data/include/GLFW/glfw3.h +6389 -0
  2. gstaichi-0.1.18.dev1.data/data/include/GLFW/glfw3native.h +594 -0
  3. gstaichi-0.1.18.dev1.data/data/include/spirv-tools/instrument.hpp +268 -0
  4. gstaichi-0.1.18.dev1.data/data/include/spirv-tools/libspirv.h +907 -0
  5. gstaichi-0.1.18.dev1.data/data/include/spirv-tools/libspirv.hpp +375 -0
  6. gstaichi-0.1.18.dev1.data/data/include/spirv-tools/linker.hpp +97 -0
  7. gstaichi-0.1.18.dev1.data/data/include/spirv-tools/optimizer.hpp +970 -0
  8. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/GLSL.std.450.h +114 -0
  9. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv.h +2568 -0
  10. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv.hpp +2579 -0
  11. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_cfg.hpp +168 -0
  12. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_common.hpp +1920 -0
  13. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_cpp.hpp +93 -0
  14. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_cross.hpp +1171 -0
  15. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_cross_c.h +1074 -0
  16. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_cross_containers.hpp +754 -0
  17. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_cross_error_handling.hpp +94 -0
  18. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_cross_parsed_ir.hpp +256 -0
  19. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_cross_util.hpp +37 -0
  20. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_glsl.hpp +1001 -0
  21. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_hlsl.hpp +406 -0
  22. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_msl.hpp +1273 -0
  23. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_parser.hpp +103 -0
  24. gstaichi-0.1.18.dev1.data/data/include/spirv_cross/spirv_reflect.hpp +91 -0
  25. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools/SPIRV-ToolsConfig.cmake +5 -0
  26. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools/SPIRV-ToolsTarget-release.cmake +29 -0
  27. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools/SPIRV-ToolsTarget.cmake +114 -0
  28. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-diff/SPIRV-Tools-diffConfig.cmake +5 -0
  29. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-diff/SPIRV-Tools-diffTargets-release.cmake +19 -0
  30. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-diff/SPIRV-Tools-diffTargets.cmake +123 -0
  31. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-link/SPIRV-Tools-linkConfig.cmake +5 -0
  32. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-link/SPIRV-Tools-linkTargets-release.cmake +19 -0
  33. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-link/SPIRV-Tools-linkTargets.cmake +123 -0
  34. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-lint/SPIRV-Tools-lintConfig.cmake +5 -0
  35. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-lint/SPIRV-Tools-lintTargets-release.cmake +19 -0
  36. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-lint/SPIRV-Tools-lintTargets.cmake +123 -0
  37. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-opt/SPIRV-Tools-optConfig.cmake +5 -0
  38. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-opt/SPIRV-Tools-optTargets-release.cmake +19 -0
  39. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-opt/SPIRV-Tools-optTargets.cmake +123 -0
  40. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-reduce/SPIRV-Tools-reduceConfig.cmake +5 -0
  41. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-reduce/SPIRV-Tools-reduceTarget-release.cmake +19 -0
  42. gstaichi-0.1.18.dev1.data/data/lib/cmake/SPIRV-Tools-reduce/SPIRV-Tools-reduceTarget.cmake +123 -0
  43. gstaichi-0.1.18.dev1.data/data/lib/cmake/glfw3/glfw3Config.cmake +3 -0
  44. gstaichi-0.1.18.dev1.data/data/lib/cmake/glfw3/glfw3ConfigVersion.cmake +65 -0
  45. gstaichi-0.1.18.dev1.data/data/lib/cmake/glfw3/glfw3Targets-release.cmake +19 -0
  46. gstaichi-0.1.18.dev1.data/data/lib/cmake/glfw3/glfw3Targets.cmake +107 -0
  47. gstaichi-0.1.18.dev1.data/data/lib/libSPIRV-Tools-shared.dylib +0 -0
  48. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_c/cmake/spirv_cross_cConfig-release.cmake +19 -0
  49. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_c/cmake/spirv_cross_cConfig.cmake +123 -0
  50. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_core/cmake/spirv_cross_coreConfig-release.cmake +19 -0
  51. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_core/cmake/spirv_cross_coreConfig.cmake +106 -0
  52. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_cpp/cmake/spirv_cross_cppConfig-release.cmake +19 -0
  53. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_cpp/cmake/spirv_cross_cppConfig.cmake +123 -0
  54. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_glsl/cmake/spirv_cross_glslConfig-release.cmake +19 -0
  55. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_glsl/cmake/spirv_cross_glslConfig.cmake +123 -0
  56. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_hlsl/cmake/spirv_cross_hlslConfig-release.cmake +19 -0
  57. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_hlsl/cmake/spirv_cross_hlslConfig.cmake +123 -0
  58. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_msl/cmake/spirv_cross_mslConfig-release.cmake +19 -0
  59. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_msl/cmake/spirv_cross_mslConfig.cmake +123 -0
  60. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_reflect/cmake/spirv_cross_reflectConfig-release.cmake +19 -0
  61. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_reflect/cmake/spirv_cross_reflectConfig.cmake +106 -0
  62. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_util/cmake/spirv_cross_utilConfig-release.cmake +19 -0
  63. gstaichi-0.1.18.dev1.data/data/share/spirv_cross_util/cmake/spirv_cross_utilConfig.cmake +123 -0
  64. gstaichi-0.1.18.dev1.dist-info/METADATA +108 -0
  65. gstaichi-0.1.18.dev1.dist-info/RECORD +219 -0
  66. gstaichi-0.1.18.dev1.dist-info/WHEEL +5 -0
  67. gstaichi-0.1.18.dev1.dist-info/entry_points.txt +2 -0
  68. gstaichi-0.1.18.dev1.dist-info/licenses/LICENSE +201 -0
  69. gstaichi-0.1.18.dev1.dist-info/top_level.txt +1 -0
  70. taichi/__init__.py +44 -0
  71. taichi/__main__.py +5 -0
  72. taichi/_funcs.py +706 -0
  73. taichi/_kernels.py +420 -0
  74. taichi/_lib/__init__.py +3 -0
  75. taichi/_lib/c_api/include/taichi/cpp/taichi.hpp +1401 -0
  76. taichi/_lib/c_api/include/taichi/taichi.h +29 -0
  77. taichi/_lib/c_api/include/taichi/taichi_core.h +1111 -0
  78. taichi/_lib/c_api/include/taichi/taichi_cpu.h +29 -0
  79. taichi/_lib/c_api/include/taichi/taichi_metal.h +72 -0
  80. taichi/_lib/c_api/include/taichi/taichi_platform.h +55 -0
  81. taichi/_lib/c_api/include/taichi/taichi_unity.h +64 -0
  82. taichi/_lib/c_api/include/taichi/taichi_vulkan.h +151 -0
  83. taichi/_lib/c_api/lib/libtaichi_c_api.dylib +0 -0
  84. taichi/_lib/c_api/runtime/libMoltenVK.dylib +0 -0
  85. taichi/_lib/c_api/runtime/runtime_arm64.bc +0 -0
  86. taichi/_lib/c_api/taichi/lib/cmake/taichi/TaichiConfig.cmake +29 -0
  87. taichi/_lib/c_api/taichi/lib/cmake/taichi/TaichiConfigVersion.cmake +65 -0
  88. taichi/_lib/c_api/taichi/lib/cmake/taichi/TaichiTargets.cmake +121 -0
  89. taichi/_lib/core/__init__.py +0 -0
  90. taichi/_lib/core/py.typed +0 -0
  91. taichi/_lib/core/taichi_python.cpython-310-darwin.so +0 -0
  92. taichi/_lib/core/taichi_python.pyi +3077 -0
  93. taichi/_lib/runtime/libMoltenVK.dylib +0 -0
  94. taichi/_lib/runtime/runtime_arm64.bc +0 -0
  95. taichi/_lib/utils.py +249 -0
  96. taichi/_logging.py +131 -0
  97. taichi/_main.py +552 -0
  98. taichi/_snode/__init__.py +5 -0
  99. taichi/_snode/fields_builder.py +189 -0
  100. taichi/_snode/snode_tree.py +34 -0
  101. taichi/_ti_module/__init__.py +3 -0
  102. taichi/_ti_module/cppgen.py +309 -0
  103. taichi/_ti_module/module.py +145 -0
  104. taichi/_version.py +1 -0
  105. taichi/_version_check.py +100 -0
  106. taichi/ad/__init__.py +3 -0
  107. taichi/ad/_ad.py +530 -0
  108. taichi/algorithms/__init__.py +3 -0
  109. taichi/algorithms/_algorithms.py +117 -0
  110. taichi/aot/__init__.py +12 -0
  111. taichi/aot/_export.py +28 -0
  112. taichi/aot/conventions/__init__.py +3 -0
  113. taichi/aot/conventions/gfxruntime140/__init__.py +38 -0
  114. taichi/aot/conventions/gfxruntime140/dr.py +244 -0
  115. taichi/aot/conventions/gfxruntime140/sr.py +613 -0
  116. taichi/aot/module.py +253 -0
  117. taichi/aot/utils.py +151 -0
  118. taichi/assets/.git +1 -0
  119. taichi/assets/Go-Regular.ttf +0 -0
  120. taichi/assets/static/imgs/ti_gallery.png +0 -0
  121. taichi/examples/minimal.py +28 -0
  122. taichi/experimental.py +16 -0
  123. taichi/graph/__init__.py +3 -0
  124. taichi/graph/_graph.py +292 -0
  125. taichi/lang/__init__.py +50 -0
  126. taichi/lang/_ndarray.py +348 -0
  127. taichi/lang/_ndrange.py +152 -0
  128. taichi/lang/_texture.py +172 -0
  129. taichi/lang/_wrap_inspect.py +189 -0
  130. taichi/lang/any_array.py +99 -0
  131. taichi/lang/argpack.py +411 -0
  132. taichi/lang/ast/__init__.py +5 -0
  133. taichi/lang/ast/ast_transformer.py +1806 -0
  134. taichi/lang/ast/ast_transformer_utils.py +328 -0
  135. taichi/lang/ast/checkers.py +106 -0
  136. taichi/lang/ast/symbol_resolver.py +57 -0
  137. taichi/lang/ast/transform.py +9 -0
  138. taichi/lang/common_ops.py +310 -0
  139. taichi/lang/exception.py +80 -0
  140. taichi/lang/expr.py +180 -0
  141. taichi/lang/field.py +464 -0
  142. taichi/lang/impl.py +1246 -0
  143. taichi/lang/kernel_arguments.py +157 -0
  144. taichi/lang/kernel_impl.py +1415 -0
  145. taichi/lang/matrix.py +1877 -0
  146. taichi/lang/matrix_ops.py +341 -0
  147. taichi/lang/matrix_ops_utils.py +190 -0
  148. taichi/lang/mesh.py +687 -0
  149. taichi/lang/misc.py +807 -0
  150. taichi/lang/ops.py +1489 -0
  151. taichi/lang/runtime_ops.py +13 -0
  152. taichi/lang/shell.py +35 -0
  153. taichi/lang/simt/__init__.py +5 -0
  154. taichi/lang/simt/block.py +94 -0
  155. taichi/lang/simt/grid.py +7 -0
  156. taichi/lang/simt/subgroup.py +191 -0
  157. taichi/lang/simt/warp.py +96 -0
  158. taichi/lang/snode.py +487 -0
  159. taichi/lang/source_builder.py +150 -0
  160. taichi/lang/struct.py +855 -0
  161. taichi/lang/util.py +381 -0
  162. taichi/linalg/__init__.py +8 -0
  163. taichi/linalg/matrixfree_cg.py +310 -0
  164. taichi/linalg/sparse_cg.py +59 -0
  165. taichi/linalg/sparse_matrix.py +303 -0
  166. taichi/linalg/sparse_solver.py +123 -0
  167. taichi/math/__init__.py +11 -0
  168. taichi/math/_complex.py +204 -0
  169. taichi/math/mathimpl.py +886 -0
  170. taichi/profiler/__init__.py +6 -0
  171. taichi/profiler/kernel_metrics.py +260 -0
  172. taichi/profiler/kernel_profiler.py +592 -0
  173. taichi/profiler/memory_profiler.py +15 -0
  174. taichi/profiler/scoped_profiler.py +36 -0
  175. taichi/shaders/Circles_vk.frag +29 -0
  176. taichi/shaders/Circles_vk.vert +45 -0
  177. taichi/shaders/Circles_vk_frag.spv +0 -0
  178. taichi/shaders/Circles_vk_vert.spv +0 -0
  179. taichi/shaders/Lines_vk.frag +9 -0
  180. taichi/shaders/Lines_vk.vert +11 -0
  181. taichi/shaders/Lines_vk_frag.spv +0 -0
  182. taichi/shaders/Lines_vk_vert.spv +0 -0
  183. taichi/shaders/Mesh_vk.frag +71 -0
  184. taichi/shaders/Mesh_vk.vert +68 -0
  185. taichi/shaders/Mesh_vk_frag.spv +0 -0
  186. taichi/shaders/Mesh_vk_vert.spv +0 -0
  187. taichi/shaders/Particles_vk.frag +95 -0
  188. taichi/shaders/Particles_vk.vert +73 -0
  189. taichi/shaders/Particles_vk_frag.spv +0 -0
  190. taichi/shaders/Particles_vk_vert.spv +0 -0
  191. taichi/shaders/SceneLines2quad_vk_comp.spv +0 -0
  192. taichi/shaders/SceneLines_vk.frag +9 -0
  193. taichi/shaders/SceneLines_vk.vert +12 -0
  194. taichi/shaders/SceneLines_vk_frag.spv +0 -0
  195. taichi/shaders/SceneLines_vk_vert.spv +0 -0
  196. taichi/shaders/SetImage_vk.frag +21 -0
  197. taichi/shaders/SetImage_vk.vert +15 -0
  198. taichi/shaders/SetImage_vk_frag.spv +0 -0
  199. taichi/shaders/SetImage_vk_vert.spv +0 -0
  200. taichi/shaders/Triangles_vk.frag +16 -0
  201. taichi/shaders/Triangles_vk.vert +29 -0
  202. taichi/shaders/Triangles_vk_frag.spv +0 -0
  203. taichi/shaders/Triangles_vk_vert.spv +0 -0
  204. taichi/shaders/lines2quad_vk_comp.spv +0 -0
  205. taichi/sparse/__init__.py +3 -0
  206. taichi/sparse/_sparse_grid.py +77 -0
  207. taichi/tools/__init__.py +12 -0
  208. taichi/tools/diagnose.py +124 -0
  209. taichi/tools/np2ply.py +364 -0
  210. taichi/tools/vtk.py +38 -0
  211. taichi/types/__init__.py +19 -0
  212. taichi/types/annotations.py +47 -0
  213. taichi/types/compound_types.py +90 -0
  214. taichi/types/enums.py +49 -0
  215. taichi/types/ndarray_type.py +147 -0
  216. taichi/types/primitive_types.py +203 -0
  217. taichi/types/quant.py +88 -0
  218. taichi/types/texture_type.py +85 -0
  219. taichi/types/utils.py +13 -0
taichi/lang/snode.py ADDED
@@ -0,0 +1,487 @@
1
+ # type: ignore
2
+
3
+ import numbers
4
+
5
+ from taichi._lib import core as _ti_core
6
+ from taichi._lib.core.taichi_python import Axis
7
+ from taichi._lib.core.taichi_python import SNode as SNodeCxx
8
+ from taichi.lang import expr, impl, matrix
9
+ from taichi.lang.exception import TaichiRuntimeError
10
+ from taichi.lang.field import BitpackedFields, Field
11
+ from taichi.lang.util import get_traceback
12
+
13
+
14
+ class SNode:
15
+ """A Python-side SNode wrapper.
16
+
17
+ For more information on Taichi's SNode system, please check out
18
+ these references:
19
+
20
+ * https://docs.taichi-lang.org/docs/sparse
21
+ * https://yuanming.taichi.graphics/publication/2019-taichi/taichi-lang.pdf
22
+
23
+ Arg:
24
+ ptr (pointer): The C++ side SNode pointer.
25
+ """
26
+
27
+ def __init__(self, ptr: SNodeCxx) -> None:
28
+ self.ptr = ptr
29
+
30
+ def dense(self, axes: list[Axis], dimensions: list[int] | int) -> "SNode":
31
+ """Adds a dense SNode as a child component of `self`.
32
+
33
+ Args:
34
+ axes (List[Axis]): Axes to activate.
35
+ dimensions (Union[List[int], int]): Shape of each axis.
36
+
37
+ Returns:
38
+ The added :class:`~taichi.lang.SNode` instance.
39
+ """
40
+ if isinstance(dimensions, numbers.Number):
41
+ dimensions = [dimensions] * len(axes)
42
+ return SNode(self.ptr.dense(axes, dimensions, _ti_core.DebugInfo(get_traceback())))
43
+
44
+ def pointer(self, axes: list[Axis], dimensions: list[int] | int) -> "SNode":
45
+ """Adds a pointer SNode as a child component of `self`.
46
+
47
+ Args:
48
+ axes (List[Axis]): Axes to activate.
49
+ dimensions (Union[List[int], int]): Shape of each axis.
50
+
51
+ Returns:
52
+ The added :class:`~taichi.lang.SNode` instance.
53
+ """
54
+ if not _ti_core.is_extension_supported(impl.current_cfg().arch, _ti_core.Extension.sparse):
55
+ raise TaichiRuntimeError("Pointer SNode is not supported on this backend.")
56
+ if isinstance(dimensions, numbers.Number):
57
+ dimensions = [dimensions] * len(axes)
58
+ return SNode(self.ptr.pointer(axes, dimensions, _ti_core.DebugInfo(get_traceback())))
59
+
60
+ @staticmethod
61
+ def _hash(axes, dimensions):
62
+ # original code is #def hash(self,axes, dimensions) without #@staticmethod before fix pylint R0201
63
+ """Not supported."""
64
+ raise RuntimeError("hash not yet supported")
65
+ # if isinstance(dimensions, int):
66
+ # dimensions = [dimensions] * len(axes)
67
+ # return SNode(self.ptr.hash(axes, dimensions))
68
+
69
+ def dynamic(self, axis: list[Axis], dimension: int, chunk_size: int | None = None) -> "SNode":
70
+ """Adds a dynamic SNode as a child component of `self`.
71
+
72
+ Args:
73
+ axis (List[Axis]): Axis to activate, must be 1.
74
+ dimension (int): Shape of the axis.
75
+ chunk_size (int): Chunk size.
76
+
77
+ Returns:
78
+ The added :class:`~taichi.lang.SNode` instance.
79
+ """
80
+ if not _ti_core.is_extension_supported(impl.current_cfg().arch, _ti_core.Extension.sparse):
81
+ raise TaichiRuntimeError("Dynamic SNode is not supported on this backend.")
82
+ assert len(axis) == 1
83
+ if chunk_size is None:
84
+ chunk_size = dimension
85
+ return SNode(self.ptr.dynamic(axis[0], dimension, chunk_size, _ti_core.DebugInfo(get_traceback())))
86
+
87
+ def bitmasked(self, axes: list[Axis], dimensions: list[int] | int) -> "SNode":
88
+ """Adds a bitmasked SNode as a child component of `self`.
89
+
90
+ Args:
91
+ axes (List[Axis]): Axes to activate.
92
+ dimensions (Union[List[int], int]): Shape of each axis.
93
+
94
+ Returns:
95
+ The added :class:`~taichi.lang.SNode` instance.
96
+ """
97
+ if not _ti_core.is_extension_supported(impl.current_cfg().arch, _ti_core.Extension.sparse):
98
+ raise TaichiRuntimeError("Bitmasked SNode is not supported on this backend.")
99
+ if isinstance(dimensions, numbers.Number):
100
+ dimensions = [dimensions] * len(axes)
101
+ return SNode(self.ptr.bitmasked(axes, dimensions, _ti_core.DebugInfo(get_traceback())))
102
+
103
+ def quant_array(self, axes: list[Axis], dimensions: list[int] | int, max_num_bits: int) -> "SNode":
104
+ """Adds a quant_array SNode as a child component of `self`.
105
+
106
+ Args:
107
+ axes (List[Axis]): Axes to activate.
108
+ dimensions (Union[List[int], int]): Shape of each axis.
109
+ max_num_bits (int): Maximum number of bits it can hold.
110
+
111
+ Returns:
112
+ The added :class:`~taichi.lang.SNode` instance.
113
+ """
114
+ if isinstance(dimensions, numbers.Number):
115
+ dimensions = [dimensions] * len(axes)
116
+ return SNode(self.ptr.quant_array(axes, dimensions, max_num_bits, _ti_core.DebugInfo(get_traceback())))
117
+
118
+ def place(self, *args, offset: numbers.Number | tuple[numbers.Number] | None = None) -> "SNode":
119
+ """Places a list of Taichi fields under the `self` container.
120
+
121
+ Args:
122
+ *args (List[ti.field]): A list of Taichi fields to place.
123
+ offset (Union[Number, tuple[Number]]): Offset of the field domain.
124
+
125
+ Returns:
126
+ The `self` container.
127
+ """
128
+ if offset is None:
129
+ offset = ()
130
+ if isinstance(offset, numbers.Number):
131
+ offset = (offset,)
132
+
133
+ for arg in args:
134
+ if isinstance(arg, BitpackedFields):
135
+ bit_struct_type = arg.bit_struct_type_builder.build()
136
+ bit_struct_snode = self.ptr.bit_struct(bit_struct_type, _ti_core.DebugInfo(get_traceback()))
137
+ for field, id_in_bit_struct in arg.fields:
138
+ bit_struct_snode.place(field, offset, id_in_bit_struct)
139
+ elif isinstance(arg, Field):
140
+ for var in arg._get_field_members():
141
+ self.ptr.place(var.ptr, offset, -1)
142
+ elif isinstance(arg, list):
143
+ for x in arg:
144
+ self.place(x, offset=offset)
145
+ else:
146
+ raise ValueError(f"{arg} cannot be placed")
147
+ return self
148
+
149
+ def lazy_grad(self):
150
+ """Automatically place the adjoint fields following the layout of their primal fields.
151
+
152
+ Users don't need to specify ``needs_grad`` when they define scalar/vector/matrix fields (primal fields) using autodiff.
153
+ When all the primal fields are defined, using ``taichi.root.lazy_grad()`` could automatically generate
154
+ their corresponding adjoint fields (gradient field).
155
+
156
+ To know more details about primal, adjoint fields and ``lazy_grad()``,
157
+ please see Page 4 and Page 13-14 of DiffTaichi Paper: https://arxiv.org/pdf/1910.00935.pdf
158
+ """
159
+ self.ptr.lazy_grad()
160
+
161
+ def lazy_dual(self):
162
+ """Automatically place the dual fields following the layout of their primal fields."""
163
+ self.ptr.lazy_dual()
164
+
165
+ def _allocate_adjoint_checkbit(self):
166
+ """Automatically place the adjoint flag fields following the layout of their primal fields for global data access rule checker"""
167
+ self.ptr.allocate_adjoint_checkbit()
168
+
169
+ def parent(self, n=1):
170
+ """Gets an ancestor of `self` in the SNode tree.
171
+
172
+ Args:
173
+ n (int): the number of levels going up from `self`.
174
+
175
+ Returns:
176
+ Union[None, _Root, SNode]: The n-th parent of `self`.
177
+ """
178
+ p = self.ptr
179
+ while p and n > 0:
180
+ p = p.parent
181
+ n -= 1
182
+ if p is None:
183
+ return None
184
+
185
+ if p.type == _ti_core.SNodeType.root:
186
+ return impl.root
187
+
188
+ return SNode(p)
189
+
190
+ def _path_from_root(self):
191
+ """Gets the path from root to `self` in the SNode tree.
192
+
193
+ Returns:
194
+ List[Union[_Root, SNode]]: The list of SNodes on the path from root to `self`.
195
+ """
196
+ p = self
197
+ res = [p]
198
+ while p != impl.root:
199
+ p = p.parent()
200
+ res.append(p)
201
+ res.reverse()
202
+ return res
203
+
204
+ @property
205
+ def _dtype(self):
206
+ """Gets the data type of `self`.
207
+
208
+ Returns:
209
+ DataType: The data type of `self`.
210
+ """
211
+ return self.ptr.data_type()
212
+
213
+ @property
214
+ def _id(self):
215
+ """Gets the id of `self`.
216
+
217
+ Returns:
218
+ int: The id of `self`.
219
+ """
220
+ return self.ptr.id
221
+
222
+ @property
223
+ def _snode_tree_id(self):
224
+ return self.ptr.get_snode_tree_id()
225
+
226
+ @property
227
+ def shape(self):
228
+ """Gets the number of elements from root in each axis of `self`.
229
+
230
+ Returns:
231
+ Tuple[int]: The number of elements from root in each axis of `self`.
232
+ """
233
+ dim = self.ptr.num_active_indices()
234
+ ret = tuple(self.ptr.get_shape_along_axis(i) for i in range(dim))
235
+
236
+ return ret
237
+
238
+ def _loop_range(self):
239
+ """Gets the taichi_python.SNode to serve as loop range.
240
+
241
+ Returns:
242
+ taichi_python.SNode: See above.
243
+ """
244
+ return self.ptr
245
+
246
+ @property
247
+ def _name(self):
248
+ """Gets the name of `self`.
249
+
250
+ Returns:
251
+ str: The name of `self`.
252
+ """
253
+ return self.ptr.name()
254
+
255
+ @property
256
+ def _snode(self):
257
+ """Gets `self`.
258
+ Returns:
259
+ SNode: `self`.
260
+ """
261
+ return self
262
+
263
+ def _get_children(self):
264
+ """Gets all children components of `self`.
265
+
266
+ Returns:
267
+ List[SNode]: All children components of `self`.
268
+ """
269
+ children = []
270
+ for i in range(self.ptr.get_num_ch()):
271
+ children.append(SNode(self.ptr.get_ch(i)))
272
+ return children
273
+
274
+ @property
275
+ def _num_dynamically_allocated(self):
276
+ runtime = impl.get_runtime()
277
+ runtime.materialize_root_fb(False)
278
+ return runtime.prog.get_snode_num_dynamically_allocated(self.ptr)
279
+
280
+ @property
281
+ def _cell_size_bytes(self):
282
+ impl.get_runtime().materialize_root_fb(False)
283
+ return self.ptr.cell_size_bytes
284
+
285
+ @property
286
+ def _offset_bytes_in_parent_cell(self):
287
+ impl.get_runtime().materialize_root_fb(False)
288
+ return self.ptr.offset_bytes_in_parent_cell
289
+
290
+ def deactivate_all(self):
291
+ """Recursively deactivate all children components of `self`."""
292
+ ch = self._get_children()
293
+ for c in ch:
294
+ c.deactivate_all()
295
+ SNodeType = _ti_core.SNodeType
296
+ if self.ptr.type == SNodeType.pointer or self.ptr.type == SNodeType.bitmasked:
297
+ from taichi._kernels import snode_deactivate # pylint: disable=C0415
298
+
299
+ snode_deactivate(self)
300
+ if self.ptr.type == SNodeType.dynamic:
301
+ # Note that dynamic nodes are different from other sparse nodes:
302
+ # instead of deactivating each element, we only need to deactivate
303
+ # its parent, whose linked list of chunks of elements will be deleted.
304
+ from taichi._kernels import ( # pylint: disable=C0415
305
+ snode_deactivate_dynamic,
306
+ )
307
+
308
+ snode_deactivate_dynamic(self)
309
+
310
+ def __repr__(self):
311
+ type_ = str(self.ptr.type)[len("SNodeType.") :]
312
+ return f"<ti.SNode of type {type_}>"
313
+
314
+ def __str__(self):
315
+ # ti.root.dense(ti.i, 3).dense(ti.jk, (4, 5)).place(x)
316
+ # ti.root => dense [3] => dense [3, 4, 5] => place [3, 4, 5]
317
+ type_ = str(self.ptr.type)[len("SNodeType.") :]
318
+ shape = str(list(self.shape))
319
+ parent = str(self.parent())
320
+ return f"{parent} => {type_} {shape}"
321
+
322
+ def __eq__(self, other):
323
+ return self.ptr == other.ptr
324
+
325
+ def _physical_index_position(self):
326
+ """Gets mappings from virtual axes to physical axes.
327
+
328
+ Returns:
329
+ Dict[int, int]: Mappings from virtual axes to physical axes.
330
+ """
331
+ ret = {}
332
+ for virtual, physical in enumerate(self.ptr.get_physical_index_position()):
333
+ if physical != -1:
334
+ ret[virtual] = physical
335
+ return ret
336
+
337
+
338
+ def rescale_index(a, b, I):
339
+ """Rescales the index 'I' of field (or SNode) 'a' to match the shape of SNode 'b'.
340
+
341
+ Args:
342
+
343
+ a, b (Union[:class:`~taichi.Field`, :class:`~taichi.MatrixField`): Input taichi fields or snodes.
344
+ I (Union[list, :class:`~taichi.Vector`]): grouped loop index.
345
+
346
+ Returns:
347
+ Ib (:class:`~taichi.Vector`): rescaled grouped loop index
348
+ """
349
+
350
+ assert isinstance(a, (Field, SNode)), "The first argument must be a field or an SNode"
351
+ assert isinstance(b, (Field, SNode)), "The second argument must be a field or an SNode"
352
+ if isinstance(I, list):
353
+ n = len(I)
354
+ else:
355
+ assert isinstance(
356
+ I, (expr.Expr, matrix.Matrix)
357
+ ), "The third argument must be an index (list, ti.Vector, or Expr with TensorType)"
358
+ n = I.n
359
+
360
+ from taichi.lang.kernel_impl import pyfunc # pylint: disable=C0415
361
+
362
+ @pyfunc
363
+ def _rescale_index():
364
+ result = matrix.Vector([I[i] for i in range(n)])
365
+ for i in impl.static(range(min(n, min(len(a.shape), len(b.shape))))):
366
+ if a.shape[i] > b.shape[i]:
367
+ result[i] = I[i] // (a.shape[i] // b.shape[i])
368
+ if a.shape[i] < b.shape[i]:
369
+ result[i] = I[i] * (b.shape[i] // a.shape[i])
370
+ return result
371
+
372
+ return _rescale_index()
373
+
374
+
375
+ def append(node, indices, val):
376
+ """Append a value `val` to a SNode `node` at index `indices`.
377
+
378
+ Args:
379
+ node (:class:`~taichi.SNode`): Input SNode.
380
+ indices (Union[int, :class:`~taichi.Vector`]): the indices to visit.
381
+ val (Union[:mod:`~taichi.types.primitive_types`, :mod:`~taichi.types.compound_types`]): the data to be appended.
382
+ """
383
+ ptrs = expr._get_flattened_ptrs(val)
384
+ append_expr = expr.Expr(
385
+ impl.get_runtime()
386
+ .compiling_callable.ast_builder()
387
+ .expr_snode_append(node._snode.ptr, expr.make_expr_group(indices), ptrs),
388
+ dbg_info=_ti_core.DebugInfo(impl.get_runtime().get_current_src_info()),
389
+ )
390
+ a = impl.expr_init(append_expr)
391
+ return a
392
+
393
+
394
+ def is_active(node, indices):
395
+ """Explicitly query whether a cell in a SNode `node` at location
396
+ `indices` is active or not.
397
+
398
+ Args:
399
+ node (:class:`~taichi.SNode`): Must be a pointer, hash or bitmasked node.
400
+ indices (Union[int, list, :class:`~taichi.Vector`]): the indices to visit.
401
+
402
+ Returns:
403
+ bool: the cell `node[indices]` is active or not.
404
+ """
405
+ return expr.Expr(
406
+ impl.get_runtime()
407
+ .compiling_callable.ast_builder()
408
+ .expr_snode_is_active(node._snode.ptr, expr.make_expr_group(indices)),
409
+ dbg_info=_ti_core.DebugInfo(impl.get_runtime().get_current_src_info()),
410
+ )
411
+
412
+
413
+ def activate(node, indices):
414
+ """Explicitly activate a cell of `node` at location `indices`.
415
+
416
+ Args:
417
+ node (:class:`~taichi.SNode`): Must be a pointer, hash or bitmasked node.
418
+ indices (Union[int, :class:`~taichi.Vector`]): the indices to activate.
419
+ """
420
+ impl.get_runtime().compiling_callable.ast_builder().insert_activate(
421
+ node._snode.ptr, expr.make_expr_group(indices), _ti_core.DebugInfo(impl.get_runtime().get_current_src_info())
422
+ )
423
+
424
+
425
+ def deactivate(node, indices):
426
+ """Explicitly deactivate a cell of `node` at location `indices`.
427
+
428
+ After deactivation, the Taichi runtime automatically recycles and zero-fills
429
+ the memory of the deactivated cell.
430
+
431
+ Args:
432
+ node (:class:`~taichi.SNode`): Must be a pointer, hash or bitmasked node.
433
+ indices (Union[int, :class:`~taichi.Vector`]): the indices to deactivate.
434
+ """
435
+ impl.get_runtime().compiling_callable.ast_builder().insert_deactivate(
436
+ node._snode.ptr, expr.make_expr_group(indices), _ti_core.DebugInfo(impl.get_runtime().get_current_src_info())
437
+ )
438
+
439
+
440
+ def length(node, indices):
441
+ """Return the length of the dynamic SNode `node` at index `indices`.
442
+
443
+ Args:
444
+ node (:class:`~taichi.SNode`): a dynamic SNode.
445
+ indices (Union[int, :class:`~taichi.Vector`]): the indices to query.
446
+
447
+ Returns:
448
+ int: the length of cell `node[indices]`.
449
+ """
450
+ return expr.Expr(
451
+ impl.get_runtime()
452
+ .compiling_callable.ast_builder()
453
+ .expr_snode_length(node._snode.ptr, expr.make_expr_group(indices)),
454
+ dbg_info=_ti_core.DebugInfo(impl.get_runtime().get_current_src_info()),
455
+ )
456
+
457
+
458
+ def get_addr(f, indices):
459
+ """Query the memory address (on CUDA/x64) of field `f` at index `indices`.
460
+
461
+ Currently, this function can only be called inside a taichi kernel.
462
+
463
+ Args:
464
+ f (Union[:class:`~taichi.Field`, :class:`~taichi.MatrixField`]): Input taichi field for memory address query.
465
+ indices (Union[int, :class:`~taichi.Vector`]): The specified field indices of the query.
466
+
467
+ Returns:
468
+ ti.u64: The memory address of `f[indices]`.
469
+ """
470
+ return expr.Expr(
471
+ impl.get_runtime()
472
+ .compiling_callable.ast_builder()
473
+ .expr_snode_get_addr(f._snode.ptr, expr.make_expr_group(indices)),
474
+ dbg_info=_ti_core.DebugInfo(impl.get_runtime().get_current_src_info()),
475
+ )
476
+
477
+
478
+ __all__ = [
479
+ "activate",
480
+ "append",
481
+ "deactivate",
482
+ "get_addr",
483
+ "is_active",
484
+ "length",
485
+ "rescale_index",
486
+ "SNode",
487
+ ]
@@ -0,0 +1,150 @@
1
+ # type: ignore
2
+
3
+ import atexit
4
+ import ctypes
5
+ import os
6
+ import shutil
7
+ import subprocess
8
+ import tempfile
9
+
10
+ from taichi._lib import core as _ti_core
11
+ from taichi.lang import impl
12
+ from taichi.lang.exception import TaichiSyntaxError
13
+ from taichi.lang.expr import make_expr_group
14
+ from taichi.lang.util import get_clangpp
15
+
16
+
17
+ class SourceBuilder:
18
+ def __init__(self):
19
+ self.bc = None
20
+ self.so = None
21
+ self.mode = None
22
+ self.td = None
23
+
24
+ def cleanup():
25
+ if self.td is not None:
26
+ shutil.rmtree(self.td)
27
+
28
+ atexit.register(cleanup)
29
+
30
+ @classmethod
31
+ def from_file(cls, filename, compile_fn=None, _temp_dir=None):
32
+ self = cls()
33
+ self.td = _temp_dir
34
+ if self.td is None:
35
+ self.td = tempfile.mkdtemp()
36
+
37
+ if filename.endswith((".cpp", ".c", ".cc")):
38
+ if impl.current_cfg().arch not in [_ti_core.Arch.x64, _ti_core.Arch.cuda]:
39
+ raise TaichiSyntaxError("Unsupported arch for external function call")
40
+ if compile_fn is None:
41
+
42
+ def compile_fn_impl(filename):
43
+ if impl.current_cfg().arch == _ti_core.Arch.x64:
44
+ subprocess.call(
45
+ get_clangpp() + " -flto -c " + filename + " -o " + os.path.join(self.td, "source.bc"),
46
+ shell=True,
47
+ )
48
+ else:
49
+ subprocess.call(
50
+ get_clangpp()
51
+ + " -flto -c "
52
+ + filename
53
+ + " -o "
54
+ + os.path.join(self.td, "source.bc")
55
+ + " -target nvptx64-nvidia-cuda",
56
+ shell=True,
57
+ )
58
+ return os.path.join(self.td, "source.bc")
59
+
60
+ compile_fn = compile_fn_impl
61
+ self.bc = compile_fn(filename)
62
+ self.mode = "bc"
63
+ elif filename.endswith(".cu"):
64
+ if impl.current_cfg().arch not in [_ti_core.Arch.cuda]:
65
+ raise TaichiSyntaxError("Unsupported arch for external function call")
66
+ if compile_fn is None:
67
+ shutil.copy(filename, os.path.join(self.td, "source.cu"))
68
+
69
+ def compile_fn_impl(filename):
70
+ # Cannot use -o to specify multiple output files
71
+ subprocess.call(
72
+ get_clangpp()
73
+ + " "
74
+ + os.path.join(self.td, "source.cu")
75
+ + " -c -emit-llvm -std=c++17 --cuda-gpu-arch=sm_50 -nocudalib",
76
+ cwd=self.td,
77
+ shell=True,
78
+ )
79
+ return os.path.join(self.td, "source-cuda-nvptx64-nvidia-cuda-sm_50.bc")
80
+
81
+ compile_fn = compile_fn_impl
82
+ self.bc = compile_fn(filename)
83
+ self.mode = "bc"
84
+ elif filename.endswith((".so", ".dylib", ".dll")):
85
+ if impl.current_cfg().arch not in [_ti_core.Arch.x64]:
86
+ raise TaichiSyntaxError("Unsupported arch for external function call")
87
+ self.so = ctypes.CDLL(filename)
88
+ self.mode = "so"
89
+ elif filename.endswith(".ll"):
90
+ if impl.current_cfg().arch not in [_ti_core.Arch.x64, _ti_core.Arch.cuda]:
91
+ raise TaichiSyntaxError("Unsupported arch for external function call")
92
+ subprocess.call(
93
+ "llvm-as " + filename + " -o " + os.path.join(self.td, "source.bc"),
94
+ shell=True,
95
+ )
96
+ self.bc = os.path.join(self.td, "source.bc")
97
+ self.mode = "bc"
98
+ elif filename.endswith(".bc"):
99
+ if impl.current_cfg().arch not in [_ti_core.Arch.x64, _ti_core.Arch.cuda]:
100
+ raise TaichiSyntaxError("Unsupported arch for external function call")
101
+ self.bc = filename
102
+ self.mode = "bc"
103
+ else:
104
+ raise TaichiSyntaxError("Unsupported file type for external function call.")
105
+ return self
106
+
107
+ @classmethod
108
+ def from_source(cls, source_code, compile_fn=None):
109
+ if impl.current_cfg().arch not in [_ti_core.Arch.x64, _ti_core.Arch.cuda]:
110
+ raise TaichiSyntaxError("Unsupported arch for external function call")
111
+ _temp_dir = tempfile.mkdtemp()
112
+ _temp_source = os.path.join(_temp_dir, "_temp_source.cpp")
113
+ with open(_temp_source, "w") as f:
114
+ f.write(source_code)
115
+ return SourceBuilder.from_file(_temp_source, compile_fn, _temp_dir)
116
+
117
+ def __getattr__(self, item):
118
+ def bitcode_func_call_wrapper(*args):
119
+ impl.get_runtime().compiling_callable.ast_builder().insert_external_func_call(
120
+ 0,
121
+ "",
122
+ self.bc,
123
+ item,
124
+ make_expr_group(args),
125
+ make_expr_group([]),
126
+ _ti_core.DebugInfo(impl.get_runtime().get_current_src_info()),
127
+ )
128
+
129
+ if self.mode == "bc":
130
+ return bitcode_func_call_wrapper
131
+
132
+ def external_func_call_wrapper(args=[], outputs=[]):
133
+ func_addr = ctypes.cast(self.so.__getattr__(item), ctypes.c_void_p).value
134
+ impl.get_runtime().compiling_callable.ast_builder().insert_external_func_call(
135
+ func_addr,
136
+ "",
137
+ "",
138
+ "",
139
+ make_expr_group(args),
140
+ make_expr_group(outputs),
141
+ _ti_core.DebugInfo(impl.get_runtime().get_current_src_info()),
142
+ )
143
+
144
+ if self.mode == "so":
145
+ return external_func_call_wrapper
146
+
147
+ raise TaichiSyntaxError("Error occurs when calling external function.")
148
+
149
+
150
+ __all__ = []