gstaichi 2.1.1rc3__cp310-cp310-macosx_11_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 (179) hide show
  1. gstaichi/CHANGELOG.md +4 -0
  2. gstaichi/__init__.py +40 -0
  3. gstaichi/_funcs.py +706 -0
  4. gstaichi/_kernels.py +420 -0
  5. gstaichi/_lib/__init__.py +3 -0
  6. gstaichi/_lib/core/__init__.py +0 -0
  7. gstaichi/_lib/core/gstaichi_python.cpython-310-darwin.so +0 -0
  8. gstaichi/_lib/core/gstaichi_python.pyi +2909 -0
  9. gstaichi/_lib/core/py.typed +0 -0
  10. gstaichi/_lib/runtime/libMoltenVK.dylib +0 -0
  11. gstaichi/_lib/runtime/runtime_arm64.bc +0 -0
  12. gstaichi/_lib/utils.py +243 -0
  13. gstaichi/_logging.py +131 -0
  14. gstaichi/_snode/__init__.py +5 -0
  15. gstaichi/_snode/fields_builder.py +187 -0
  16. gstaichi/_snode/snode_tree.py +34 -0
  17. gstaichi/_test_tools/__init__.py +18 -0
  18. gstaichi/_test_tools/dataclass_test_tools.py +36 -0
  19. gstaichi/_test_tools/load_kernel_string.py +30 -0
  20. gstaichi/_test_tools/textwrap2.py +6 -0
  21. gstaichi/_version.py +1 -0
  22. gstaichi/_version_check.py +100 -0
  23. gstaichi/ad/__init__.py +3 -0
  24. gstaichi/ad/_ad.py +530 -0
  25. gstaichi/algorithms/__init__.py +3 -0
  26. gstaichi/algorithms/_algorithms.py +117 -0
  27. gstaichi/assets/.git +1 -0
  28. gstaichi/assets/Go-Regular.ttf +0 -0
  29. gstaichi/assets/static/imgs/ti_gallery.png +0 -0
  30. gstaichi/examples/lcg_python.py +26 -0
  31. gstaichi/examples/lcg_taichi.py +34 -0
  32. gstaichi/examples/minimal.py +28 -0
  33. gstaichi/experimental.py +16 -0
  34. gstaichi/lang/__init__.py +50 -0
  35. gstaichi/lang/_dataclass_util.py +31 -0
  36. gstaichi/lang/_fast_caching/__init__.py +3 -0
  37. gstaichi/lang/_fast_caching/args_hasher.py +110 -0
  38. gstaichi/lang/_fast_caching/config_hasher.py +30 -0
  39. gstaichi/lang/_fast_caching/fast_caching_types.py +21 -0
  40. gstaichi/lang/_fast_caching/function_hasher.py +57 -0
  41. gstaichi/lang/_fast_caching/hash_utils.py +11 -0
  42. gstaichi/lang/_fast_caching/python_side_cache.py +52 -0
  43. gstaichi/lang/_fast_caching/src_hasher.py +75 -0
  44. gstaichi/lang/_kernel_impl_dataclass.py +212 -0
  45. gstaichi/lang/_ndarray.py +352 -0
  46. gstaichi/lang/_ndrange.py +152 -0
  47. gstaichi/lang/_template_mapper.py +195 -0
  48. gstaichi/lang/_texture.py +172 -0
  49. gstaichi/lang/_wrap_inspect.py +215 -0
  50. gstaichi/lang/any_array.py +99 -0
  51. gstaichi/lang/ast/__init__.py +5 -0
  52. gstaichi/lang/ast/ast_transformer.py +1323 -0
  53. gstaichi/lang/ast/ast_transformer_utils.py +346 -0
  54. gstaichi/lang/ast/ast_transformers/__init__.py +0 -0
  55. gstaichi/lang/ast/ast_transformers/call_transformer.py +324 -0
  56. gstaichi/lang/ast/ast_transformers/function_def_transformer.py +304 -0
  57. gstaichi/lang/ast/checkers.py +106 -0
  58. gstaichi/lang/ast/symbol_resolver.py +57 -0
  59. gstaichi/lang/ast/transform.py +9 -0
  60. gstaichi/lang/common_ops.py +310 -0
  61. gstaichi/lang/exception.py +80 -0
  62. gstaichi/lang/expr.py +180 -0
  63. gstaichi/lang/field.py +428 -0
  64. gstaichi/lang/impl.py +1243 -0
  65. gstaichi/lang/kernel_arguments.py +155 -0
  66. gstaichi/lang/kernel_impl.py +1341 -0
  67. gstaichi/lang/matrix.py +1835 -0
  68. gstaichi/lang/matrix_ops.py +341 -0
  69. gstaichi/lang/matrix_ops_utils.py +190 -0
  70. gstaichi/lang/mesh.py +687 -0
  71. gstaichi/lang/misc.py +782 -0
  72. gstaichi/lang/ops.py +1494 -0
  73. gstaichi/lang/runtime_ops.py +13 -0
  74. gstaichi/lang/shell.py +35 -0
  75. gstaichi/lang/simt/__init__.py +5 -0
  76. gstaichi/lang/simt/block.py +94 -0
  77. gstaichi/lang/simt/grid.py +7 -0
  78. gstaichi/lang/simt/subgroup.py +191 -0
  79. gstaichi/lang/simt/warp.py +96 -0
  80. gstaichi/lang/snode.py +489 -0
  81. gstaichi/lang/source_builder.py +150 -0
  82. gstaichi/lang/struct.py +810 -0
  83. gstaichi/lang/util.py +312 -0
  84. gstaichi/linalg/__init__.py +8 -0
  85. gstaichi/linalg/matrixfree_cg.py +310 -0
  86. gstaichi/linalg/sparse_cg.py +59 -0
  87. gstaichi/linalg/sparse_matrix.py +303 -0
  88. gstaichi/linalg/sparse_solver.py +123 -0
  89. gstaichi/math/__init__.py +11 -0
  90. gstaichi/math/_complex.py +205 -0
  91. gstaichi/math/mathimpl.py +886 -0
  92. gstaichi/profiler/__init__.py +6 -0
  93. gstaichi/profiler/kernel_metrics.py +260 -0
  94. gstaichi/profiler/kernel_profiler.py +586 -0
  95. gstaichi/profiler/memory_profiler.py +15 -0
  96. gstaichi/profiler/scoped_profiler.py +36 -0
  97. gstaichi/sparse/__init__.py +3 -0
  98. gstaichi/sparse/_sparse_grid.py +77 -0
  99. gstaichi/tools/__init__.py +12 -0
  100. gstaichi/tools/diagnose.py +117 -0
  101. gstaichi/tools/np2ply.py +364 -0
  102. gstaichi/tools/vtk.py +38 -0
  103. gstaichi/types/__init__.py +19 -0
  104. gstaichi/types/annotations.py +52 -0
  105. gstaichi/types/compound_types.py +71 -0
  106. gstaichi/types/enums.py +49 -0
  107. gstaichi/types/ndarray_type.py +169 -0
  108. gstaichi/types/primitive_types.py +206 -0
  109. gstaichi/types/quant.py +88 -0
  110. gstaichi/types/texture_type.py +85 -0
  111. gstaichi/types/utils.py +11 -0
  112. gstaichi-2.1.1rc3.data/data/include/GLFW/glfw3.h +6389 -0
  113. gstaichi-2.1.1rc3.data/data/include/GLFW/glfw3native.h +594 -0
  114. gstaichi-2.1.1rc3.data/data/include/spirv-tools/instrument.hpp +268 -0
  115. gstaichi-2.1.1rc3.data/data/include/spirv-tools/libspirv.h +907 -0
  116. gstaichi-2.1.1rc3.data/data/include/spirv-tools/libspirv.hpp +375 -0
  117. gstaichi-2.1.1rc3.data/data/include/spirv-tools/linker.hpp +97 -0
  118. gstaichi-2.1.1rc3.data/data/include/spirv-tools/optimizer.hpp +970 -0
  119. gstaichi-2.1.1rc3.data/data/include/spirv_cross/GLSL.std.450.h +114 -0
  120. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv.h +2568 -0
  121. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv.hpp +2579 -0
  122. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cfg.hpp +168 -0
  123. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_common.hpp +1920 -0
  124. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cpp.hpp +93 -0
  125. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cross.hpp +1171 -0
  126. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cross_c.h +1074 -0
  127. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cross_containers.hpp +754 -0
  128. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cross_error_handling.hpp +94 -0
  129. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cross_parsed_ir.hpp +256 -0
  130. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_cross_util.hpp +37 -0
  131. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_glsl.hpp +1001 -0
  132. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_hlsl.hpp +406 -0
  133. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_msl.hpp +1273 -0
  134. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_parser.hpp +103 -0
  135. gstaichi-2.1.1rc3.data/data/include/spirv_cross/spirv_reflect.hpp +91 -0
  136. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools/SPIRV-ToolsConfig.cmake +5 -0
  137. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools/SPIRV-ToolsTarget-release.cmake +29 -0
  138. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools/SPIRV-ToolsTarget.cmake +114 -0
  139. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-diff/SPIRV-Tools-diffConfig.cmake +5 -0
  140. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-diff/SPIRV-Tools-diffTargets-release.cmake +19 -0
  141. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-diff/SPIRV-Tools-diffTargets.cmake +123 -0
  142. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-link/SPIRV-Tools-linkConfig.cmake +5 -0
  143. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-link/SPIRV-Tools-linkTargets-release.cmake +19 -0
  144. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-link/SPIRV-Tools-linkTargets.cmake +123 -0
  145. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-lint/SPIRV-Tools-lintConfig.cmake +5 -0
  146. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-lint/SPIRV-Tools-lintTargets-release.cmake +19 -0
  147. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-lint/SPIRV-Tools-lintTargets.cmake +123 -0
  148. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-opt/SPIRV-Tools-optConfig.cmake +5 -0
  149. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-opt/SPIRV-Tools-optTargets-release.cmake +19 -0
  150. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-opt/SPIRV-Tools-optTargets.cmake +123 -0
  151. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-reduce/SPIRV-Tools-reduceConfig.cmake +5 -0
  152. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-reduce/SPIRV-Tools-reduceTarget-release.cmake +19 -0
  153. gstaichi-2.1.1rc3.data/data/lib/cmake/SPIRV-Tools-reduce/SPIRV-Tools-reduceTarget.cmake +123 -0
  154. gstaichi-2.1.1rc3.data/data/lib/cmake/glfw3/glfw3Config.cmake +3 -0
  155. gstaichi-2.1.1rc3.data/data/lib/cmake/glfw3/glfw3ConfigVersion.cmake +65 -0
  156. gstaichi-2.1.1rc3.data/data/lib/cmake/glfw3/glfw3Targets-release.cmake +19 -0
  157. gstaichi-2.1.1rc3.data/data/lib/cmake/glfw3/glfw3Targets.cmake +107 -0
  158. gstaichi-2.1.1rc3.data/data/lib/libSPIRV-Tools-shared.dylib +0 -0
  159. gstaichi-2.1.1rc3.data/data/share/spirv_cross_c/cmake/spirv_cross_cConfig-release.cmake +19 -0
  160. gstaichi-2.1.1rc3.data/data/share/spirv_cross_c/cmake/spirv_cross_cConfig.cmake +123 -0
  161. gstaichi-2.1.1rc3.data/data/share/spirv_cross_core/cmake/spirv_cross_coreConfig-release.cmake +19 -0
  162. gstaichi-2.1.1rc3.data/data/share/spirv_cross_core/cmake/spirv_cross_coreConfig.cmake +106 -0
  163. gstaichi-2.1.1rc3.data/data/share/spirv_cross_cpp/cmake/spirv_cross_cppConfig-release.cmake +19 -0
  164. gstaichi-2.1.1rc3.data/data/share/spirv_cross_cpp/cmake/spirv_cross_cppConfig.cmake +123 -0
  165. gstaichi-2.1.1rc3.data/data/share/spirv_cross_glsl/cmake/spirv_cross_glslConfig-release.cmake +19 -0
  166. gstaichi-2.1.1rc3.data/data/share/spirv_cross_glsl/cmake/spirv_cross_glslConfig.cmake +123 -0
  167. gstaichi-2.1.1rc3.data/data/share/spirv_cross_hlsl/cmake/spirv_cross_hlslConfig-release.cmake +19 -0
  168. gstaichi-2.1.1rc3.data/data/share/spirv_cross_hlsl/cmake/spirv_cross_hlslConfig.cmake +123 -0
  169. gstaichi-2.1.1rc3.data/data/share/spirv_cross_msl/cmake/spirv_cross_mslConfig-release.cmake +19 -0
  170. gstaichi-2.1.1rc3.data/data/share/spirv_cross_msl/cmake/spirv_cross_mslConfig.cmake +123 -0
  171. gstaichi-2.1.1rc3.data/data/share/spirv_cross_reflect/cmake/spirv_cross_reflectConfig-release.cmake +19 -0
  172. gstaichi-2.1.1rc3.data/data/share/spirv_cross_reflect/cmake/spirv_cross_reflectConfig.cmake +106 -0
  173. gstaichi-2.1.1rc3.data/data/share/spirv_cross_util/cmake/spirv_cross_utilConfig-release.cmake +19 -0
  174. gstaichi-2.1.1rc3.data/data/share/spirv_cross_util/cmake/spirv_cross_utilConfig.cmake +123 -0
  175. gstaichi-2.1.1rc3.dist-info/METADATA +106 -0
  176. gstaichi-2.1.1rc3.dist-info/RECORD +179 -0
  177. gstaichi-2.1.1rc3.dist-info/WHEEL +5 -0
  178. gstaichi-2.1.1rc3.dist-info/licenses/LICENSE +201 -0
  179. gstaichi-2.1.1rc3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,375 @@
1
+ // Copyright (c) 2016 Google Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #ifndef INCLUDE_SPIRV_TOOLS_LIBSPIRV_HPP_
16
+ #define INCLUDE_SPIRV_TOOLS_LIBSPIRV_HPP_
17
+
18
+ #include <functional>
19
+ #include <memory>
20
+ #include <string>
21
+ #include <vector>
22
+
23
+ #include "spirv-tools/libspirv.h"
24
+
25
+ namespace spvtools {
26
+
27
+ // Message consumer. The C strings for source and message are only alive for the
28
+ // specific invocation.
29
+ using MessageConsumer = std::function<void(
30
+ spv_message_level_t /* level */, const char* /* source */,
31
+ const spv_position_t& /* position */, const char* /* message */
32
+ )>;
33
+
34
+ // C++ RAII wrapper around the C context object spv_context.
35
+ class Context {
36
+ public:
37
+ // Constructs a context targeting the given environment |env|.
38
+ //
39
+ // See specific API calls for how the target environment is interpreted
40
+ // (particularly assembly and validation).
41
+ //
42
+ // The constructed instance will have an empty message consumer, which just
43
+ // ignores all messages from the library. Use SetMessageConsumer() to supply
44
+ // one if messages are of concern.
45
+ explicit Context(spv_target_env env);
46
+
47
+ // Enables move constructor/assignment operations.
48
+ Context(Context&& other);
49
+ Context& operator=(Context&& other);
50
+
51
+ // Disables copy constructor/assignment operations.
52
+ Context(const Context&) = delete;
53
+ Context& operator=(const Context&) = delete;
54
+
55
+ // Destructs this instance.
56
+ ~Context();
57
+
58
+ // Sets the message consumer to the given |consumer|. The |consumer| will be
59
+ // invoked once for each message communicated from the library.
60
+ void SetMessageConsumer(MessageConsumer consumer);
61
+
62
+ // Returns the underlying spv_context.
63
+ spv_context& CContext();
64
+ const spv_context& CContext() const;
65
+
66
+ private:
67
+ spv_context context_;
68
+ };
69
+
70
+ // A RAII wrapper around a validator options object.
71
+ class ValidatorOptions {
72
+ public:
73
+ ValidatorOptions() : options_(spvValidatorOptionsCreate()) {}
74
+ ~ValidatorOptions() { spvValidatorOptionsDestroy(options_); }
75
+ // Allow implicit conversion to the underlying object.
76
+ operator spv_validator_options() const { return options_; }
77
+
78
+ // Sets a limit.
79
+ void SetUniversalLimit(spv_validator_limit limit_type, uint32_t limit) {
80
+ spvValidatorOptionsSetUniversalLimit(options_, limit_type, limit);
81
+ }
82
+
83
+ void SetRelaxStructStore(bool val) {
84
+ spvValidatorOptionsSetRelaxStoreStruct(options_, val);
85
+ }
86
+
87
+ // Enables VK_KHR_relaxed_block_layout when validating standard
88
+ // uniform/storage buffer/push-constant layout. If true, disables
89
+ // scalar block layout rules.
90
+ void SetRelaxBlockLayout(bool val) {
91
+ spvValidatorOptionsSetRelaxBlockLayout(options_, val);
92
+ }
93
+
94
+ // Enables VK_KHR_uniform_buffer_standard_layout when validating standard
95
+ // uniform layout. If true, disables scalar block layout rules.
96
+ void SetUniformBufferStandardLayout(bool val) {
97
+ spvValidatorOptionsSetUniformBufferStandardLayout(options_, val);
98
+ }
99
+
100
+ // Enables VK_EXT_scalar_block_layout when validating standard
101
+ // uniform/storage buffer/push-constant layout. If true, disables
102
+ // relaxed block layout rules.
103
+ void SetScalarBlockLayout(bool val) {
104
+ spvValidatorOptionsSetScalarBlockLayout(options_, val);
105
+ }
106
+
107
+ // Enables scalar layout when validating Workgroup blocks. See
108
+ // VK_KHR_workgroup_memory_explicit_layout.
109
+ void SetWorkgroupScalarBlockLayout(bool val) {
110
+ spvValidatorOptionsSetWorkgroupScalarBlockLayout(options_, val);
111
+ }
112
+
113
+ // Skips validating standard uniform/storage buffer/push-constant layout.
114
+ void SetSkipBlockLayout(bool val) {
115
+ spvValidatorOptionsSetSkipBlockLayout(options_, val);
116
+ }
117
+
118
+ // Enables LocalSizeId decorations where the environment would not otherwise
119
+ // allow them.
120
+ void SetAllowLocalSizeId(bool val) {
121
+ spvValidatorOptionsSetAllowLocalSizeId(options_, val);
122
+ }
123
+
124
+ // Records whether or not the validator should relax the rules on pointer
125
+ // usage in logical addressing mode.
126
+ //
127
+ // When relaxed, it will allow the following usage cases of pointers:
128
+ // 1) OpVariable allocating an object whose type is a pointer type
129
+ // 2) OpReturnValue returning a pointer value
130
+ void SetRelaxLogicalPointer(bool val) {
131
+ spvValidatorOptionsSetRelaxLogicalPointer(options_, val);
132
+ }
133
+
134
+ // Records whether or not the validator should relax the rules because it is
135
+ // expected that the optimizations will make the code legal.
136
+ //
137
+ // When relaxed, it will allow the following:
138
+ // 1) It will allow relaxed logical pointers. Setting this option will also
139
+ // set that option.
140
+ // 2) Pointers that are pass as parameters to function calls do not have to
141
+ // match the storage class of the formal parameter.
142
+ // 3) Pointers that are actual parameters on function calls do not have to
143
+ // point to the same type pointed as the formal parameter. The types just
144
+ // need to logically match.
145
+ // 4) GLSLstd450 Interpolate* instructions can have a load of an interpolant
146
+ // for a first argument.
147
+ void SetBeforeHlslLegalization(bool val) {
148
+ spvValidatorOptionsSetBeforeHlslLegalization(options_, val);
149
+ }
150
+
151
+ // Whether friendly names should be used in validation error messages.
152
+ void SetFriendlyNames(bool val) {
153
+ spvValidatorOptionsSetFriendlyNames(options_, val);
154
+ }
155
+
156
+ private:
157
+ spv_validator_options options_;
158
+ };
159
+
160
+ // A C++ wrapper around an optimization options object.
161
+ class OptimizerOptions {
162
+ public:
163
+ OptimizerOptions() : options_(spvOptimizerOptionsCreate()) {}
164
+ ~OptimizerOptions() { spvOptimizerOptionsDestroy(options_); }
165
+
166
+ // Allow implicit conversion to the underlying object.
167
+ operator spv_optimizer_options() const { return options_; }
168
+
169
+ // Records whether or not the optimizer should run the validator before
170
+ // optimizing. If |run| is true, the validator will be run.
171
+ void set_run_validator(bool run) {
172
+ spvOptimizerOptionsSetRunValidator(options_, run);
173
+ }
174
+
175
+ // Records the validator options that should be passed to the validator if it
176
+ // is run.
177
+ void set_validator_options(const ValidatorOptions& val_options) {
178
+ spvOptimizerOptionsSetValidatorOptions(options_, val_options);
179
+ }
180
+
181
+ // Records the maximum possible value for the id bound.
182
+ void set_max_id_bound(uint32_t new_bound) {
183
+ spvOptimizerOptionsSetMaxIdBound(options_, new_bound);
184
+ }
185
+
186
+ // Records whether all bindings within the module should be preserved.
187
+ void set_preserve_bindings(bool preserve_bindings) {
188
+ spvOptimizerOptionsSetPreserveBindings(options_, preserve_bindings);
189
+ }
190
+
191
+ // Records whether all specialization constants within the module
192
+ // should be preserved.
193
+ void set_preserve_spec_constants(bool preserve_spec_constants) {
194
+ spvOptimizerOptionsSetPreserveSpecConstants(options_,
195
+ preserve_spec_constants);
196
+ }
197
+
198
+ private:
199
+ spv_optimizer_options options_;
200
+ };
201
+
202
+ // A C++ wrapper around a reducer options object.
203
+ class ReducerOptions {
204
+ public:
205
+ ReducerOptions() : options_(spvReducerOptionsCreate()) {}
206
+ ~ReducerOptions() { spvReducerOptionsDestroy(options_); }
207
+
208
+ // Allow implicit conversion to the underlying object.
209
+ operator spv_reducer_options() const { // NOLINT(google-explicit-constructor)
210
+ return options_;
211
+ }
212
+
213
+ // See spvReducerOptionsSetStepLimit.
214
+ void set_step_limit(uint32_t step_limit) {
215
+ spvReducerOptionsSetStepLimit(options_, step_limit);
216
+ }
217
+
218
+ // See spvReducerOptionsSetFailOnValidationError.
219
+ void set_fail_on_validation_error(bool fail_on_validation_error) {
220
+ spvReducerOptionsSetFailOnValidationError(options_,
221
+ fail_on_validation_error);
222
+ }
223
+
224
+ // See spvReducerOptionsSetTargetFunction.
225
+ void set_target_function(uint32_t target_function) {
226
+ spvReducerOptionsSetTargetFunction(options_, target_function);
227
+ }
228
+
229
+ private:
230
+ spv_reducer_options options_;
231
+ };
232
+
233
+ // A C++ wrapper around a fuzzer options object.
234
+ class FuzzerOptions {
235
+ public:
236
+ FuzzerOptions() : options_(spvFuzzerOptionsCreate()) {}
237
+ ~FuzzerOptions() { spvFuzzerOptionsDestroy(options_); }
238
+
239
+ // Allow implicit conversion to the underlying object.
240
+ operator spv_fuzzer_options() const { // NOLINT(google-explicit-constructor)
241
+ return options_;
242
+ }
243
+
244
+ // See spvFuzzerOptionsEnableReplayValidation.
245
+ void enable_replay_validation() {
246
+ spvFuzzerOptionsEnableReplayValidation(options_);
247
+ }
248
+
249
+ // See spvFuzzerOptionsSetRandomSeed.
250
+ void set_random_seed(uint32_t seed) {
251
+ spvFuzzerOptionsSetRandomSeed(options_, seed);
252
+ }
253
+
254
+ // See spvFuzzerOptionsSetReplayRange.
255
+ void set_replay_range(int32_t replay_range) {
256
+ spvFuzzerOptionsSetReplayRange(options_, replay_range);
257
+ }
258
+
259
+ // See spvFuzzerOptionsSetShrinkerStepLimit.
260
+ void set_shrinker_step_limit(uint32_t shrinker_step_limit) {
261
+ spvFuzzerOptionsSetShrinkerStepLimit(options_, shrinker_step_limit);
262
+ }
263
+
264
+ // See spvFuzzerOptionsEnableFuzzerPassValidation.
265
+ void enable_fuzzer_pass_validation() {
266
+ spvFuzzerOptionsEnableFuzzerPassValidation(options_);
267
+ }
268
+
269
+ // See spvFuzzerOptionsEnableAllPasses.
270
+ void enable_all_passes() { spvFuzzerOptionsEnableAllPasses(options_); }
271
+
272
+ private:
273
+ spv_fuzzer_options options_;
274
+ };
275
+
276
+ // C++ interface for SPIRV-Tools functionalities. It wraps the context
277
+ // (including target environment and the corresponding SPIR-V grammar) and
278
+ // provides methods for assembling, disassembling, and validating.
279
+ //
280
+ // Instances of this class provide basic thread-safety guarantee.
281
+ class SpirvTools {
282
+ public:
283
+ enum {
284
+ // Default assembling option used by assemble():
285
+ kDefaultAssembleOption = SPV_TEXT_TO_BINARY_OPTION_NONE,
286
+
287
+ // Default disassembling option used by Disassemble():
288
+ // * Avoid prefix comments from decoding the SPIR-V module header, and
289
+ // * Use friendly names for variables.
290
+ kDefaultDisassembleOption = SPV_BINARY_TO_TEXT_OPTION_NO_HEADER |
291
+ SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES
292
+ };
293
+
294
+ // Constructs an instance targeting the given environment |env|.
295
+ //
296
+ // The constructed instance will have an empty message consumer, which just
297
+ // ignores all messages from the library. Use SetMessageConsumer() to supply
298
+ // one if messages are of concern.
299
+ explicit SpirvTools(spv_target_env env);
300
+
301
+ // Disables copy/move constructor/assignment operations.
302
+ SpirvTools(const SpirvTools&) = delete;
303
+ SpirvTools(SpirvTools&&) = delete;
304
+ SpirvTools& operator=(const SpirvTools&) = delete;
305
+ SpirvTools& operator=(SpirvTools&&) = delete;
306
+
307
+ // Destructs this instance.
308
+ ~SpirvTools();
309
+
310
+ // Sets the message consumer to the given |consumer|. The |consumer| will be
311
+ // invoked once for each message communicated from the library.
312
+ void SetMessageConsumer(MessageConsumer consumer);
313
+
314
+ // Assembles the given assembly |text| and writes the result to |binary|.
315
+ // Returns true on successful assembling. |binary| will be kept untouched if
316
+ // assembling is unsuccessful.
317
+ // The SPIR-V binary version is set to the highest version of SPIR-V supported
318
+ // by the target environment with which this SpirvTools object was created.
319
+ bool Assemble(const std::string& text, std::vector<uint32_t>* binary,
320
+ uint32_t options = kDefaultAssembleOption) const;
321
+ // |text_size| specifies the number of bytes in |text|. A terminating null
322
+ // character is not required to present in |text| as long as |text| is valid.
323
+ // The SPIR-V binary version is set to the highest version of SPIR-V supported
324
+ // by the target environment with which this SpirvTools object was created.
325
+ bool Assemble(const char* text, size_t text_size,
326
+ std::vector<uint32_t>* binary,
327
+ uint32_t options = kDefaultAssembleOption) const;
328
+
329
+ // Disassembles the given SPIR-V |binary| with the given |options| and writes
330
+ // the assembly to |text|. Returns true on successful disassembling. |text|
331
+ // will be kept untouched if diassembling is unsuccessful.
332
+ bool Disassemble(const std::vector<uint32_t>& binary, std::string* text,
333
+ uint32_t options = kDefaultDisassembleOption) const;
334
+ // |binary_size| specifies the number of words in |binary|.
335
+ bool Disassemble(const uint32_t* binary, size_t binary_size,
336
+ std::string* text,
337
+ uint32_t options = kDefaultDisassembleOption) const;
338
+
339
+ // Validates the given SPIR-V |binary|. Returns true if no issues are found.
340
+ // Otherwise, returns false and communicates issues via the message consumer
341
+ // registered.
342
+ // Validates for SPIR-V spec rules for the SPIR-V version named in the
343
+ // binary's header (at word offset 1). Additionally, if the target
344
+ // environment is a client API (such as Vulkan 1.1), then validate for that
345
+ // client API version, to the extent that it is verifiable from data in the
346
+ // binary itself.
347
+ bool Validate(const std::vector<uint32_t>& binary) const;
348
+ // Like the previous overload, but provides the binary as a pointer and size:
349
+ // |binary_size| specifies the number of words in |binary|.
350
+ // Validates for SPIR-V spec rules for the SPIR-V version named in the
351
+ // binary's header (at word offset 1). Additionally, if the target
352
+ // environment is a client API (such as Vulkan 1.1), then validate for that
353
+ // client API version, to the extent that it is verifiable from data in the
354
+ // binary itself.
355
+ bool Validate(const uint32_t* binary, size_t binary_size) const;
356
+ // Like the previous overload, but takes an options object.
357
+ // Validates for SPIR-V spec rules for the SPIR-V version named in the
358
+ // binary's header (at word offset 1). Additionally, if the target
359
+ // environment is a client API (such as Vulkan 1.1), then validate for that
360
+ // client API version, to the extent that it is verifiable from data in the
361
+ // binary itself, or in the validator options.
362
+ bool Validate(const uint32_t* binary, size_t binary_size,
363
+ spv_validator_options options) const;
364
+
365
+ // Was this object successfully constructed.
366
+ bool IsValid() const;
367
+
368
+ private:
369
+ struct Impl; // Opaque struct for holding the data fields used by this class.
370
+ std::unique_ptr<Impl> impl_; // Unique pointer to implementation data.
371
+ };
372
+
373
+ } // namespace spvtools
374
+
375
+ #endif // INCLUDE_SPIRV_TOOLS_LIBSPIRV_HPP_
@@ -0,0 +1,97 @@
1
+ // Copyright (c) 2017 Pierre Moreau
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ #ifndef INCLUDE_SPIRV_TOOLS_LINKER_HPP_
16
+ #define INCLUDE_SPIRV_TOOLS_LINKER_HPP_
17
+
18
+ #include <cstdint>
19
+
20
+ #include <memory>
21
+ #include <vector>
22
+
23
+ #include "libspirv.hpp"
24
+
25
+ namespace spvtools {
26
+
27
+ class LinkerOptions {
28
+ public:
29
+ LinkerOptions()
30
+ : create_library_(false),
31
+ verify_ids_(false),
32
+ allow_partial_linkage_(false) {}
33
+
34
+ // Returns whether a library or an executable should be produced by the
35
+ // linking phase.
36
+ //
37
+ // All exported symbols are kept when creating a library, whereas they will
38
+ // be removed when creating an executable.
39
+ // The returned value will be true if creating a library, and false if
40
+ // creating an executable.
41
+ bool GetCreateLibrary() const { return create_library_; }
42
+
43
+ // Sets whether a library or an executable should be produced.
44
+ void SetCreateLibrary(bool create_library) {
45
+ create_library_ = create_library;
46
+ }
47
+
48
+ // Returns whether to verify the uniqueness of the unique ids in the merged
49
+ // context.
50
+ bool GetVerifyIds() const { return verify_ids_; }
51
+
52
+ // Sets whether to verify the uniqueness of the unique ids in the merged
53
+ // context.
54
+ void SetVerifyIds(bool verify_ids) { verify_ids_ = verify_ids; }
55
+
56
+ // Returns whether to allow for imported symbols to have no corresponding
57
+ // exported symbols
58
+ bool GetAllowPartialLinkage() const { return allow_partial_linkage_; }
59
+
60
+ // Sets whether to allow for imported symbols to have no corresponding
61
+ // exported symbols
62
+ void SetAllowPartialLinkage(bool allow_partial_linkage) {
63
+ allow_partial_linkage_ = allow_partial_linkage;
64
+ }
65
+
66
+ private:
67
+ bool create_library_;
68
+ bool verify_ids_;
69
+ bool allow_partial_linkage_;
70
+ };
71
+
72
+ // Links one or more SPIR-V modules into a new SPIR-V module. That is, combine
73
+ // several SPIR-V modules into one, resolving link dependencies between them.
74
+ //
75
+ // At least one binary has to be provided in |binaries|. Those binaries do not
76
+ // have to be valid, but they should be at least parseable.
77
+ // The functions can fail due to the following:
78
+ // * The given context was not initialised using `spvContextCreate()`;
79
+ // * No input modules were given;
80
+ // * One or more of those modules were not parseable;
81
+ // * The input modules used different addressing or memory models;
82
+ // * The ID or global variable number limit were exceeded;
83
+ // * Some entry points were defined multiple times;
84
+ // * Some imported symbols did not have an exported counterpart;
85
+ // * Possibly other reasons.
86
+ spv_result_t Link(const Context& context,
87
+ const std::vector<std::vector<uint32_t>>& binaries,
88
+ std::vector<uint32_t>* linked_binary,
89
+ const LinkerOptions& options = LinkerOptions());
90
+ spv_result_t Link(const Context& context, const uint32_t* const* binaries,
91
+ const size_t* binary_sizes, size_t num_binaries,
92
+ std::vector<uint32_t>* linked_binary,
93
+ const LinkerOptions& options = LinkerOptions());
94
+
95
+ } // namespace spvtools
96
+
97
+ #endif // INCLUDE_SPIRV_TOOLS_LINKER_HPP_