nvfuser-cu121-torch25 0.2.25.dev20250201__cp310-cp310-manylinux_2_28_x86_64.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (242) hide show
  1. nvfuser/_C.cpython-310-x86_64-linux-gnu.so +0 -0
  2. nvfuser/__init__.py +618 -0
  3. nvfuser/__init__.pyi +4 -0
  4. nvfuser/contrib/__init__.py +9 -0
  5. nvfuser/contrib/nn/__init__.py +13 -0
  6. nvfuser/contrib/nn/normalization.py +725 -0
  7. nvfuser/include/nvfuser/alias_analysis.h +116 -0
  8. nvfuser/include/nvfuser/bfs.h +929 -0
  9. nvfuser/include/nvfuser/codegen.h +26 -0
  10. nvfuser/include/nvfuser/compute_at.h +28 -0
  11. nvfuser/include/nvfuser/compute_at_map.h +394 -0
  12. nvfuser/include/nvfuser/contiguity.h +351 -0
  13. nvfuser/include/nvfuser/cuda_utils.h +50 -0
  14. nvfuser/include/nvfuser/debug.h +50 -0
  15. nvfuser/include/nvfuser/device_lower/analysis/bank_conflict.h +53 -0
  16. nvfuser/include/nvfuser/device_lower/analysis/circular_buffer.h +109 -0
  17. nvfuser/include/nvfuser/device_lower/analysis/device_version.h +65 -0
  18. nvfuser/include/nvfuser/device_lower/analysis/divisible_split.h +28 -0
  19. nvfuser/include/nvfuser/device_lower/analysis/fused_reduction.h +36 -0
  20. nvfuser/include/nvfuser/device_lower/analysis/index_compute.h +322 -0
  21. nvfuser/include/nvfuser/device_lower/analysis/predicate_elimination.h +71 -0
  22. nvfuser/include/nvfuser/device_lower/analysis/sync_information.h +47 -0
  23. nvfuser/include/nvfuser/device_lower/analysis/tensor_memory.h +65 -0
  24. nvfuser/include/nvfuser/device_lower/analysis/thread_predicate.h +158 -0
  25. nvfuser/include/nvfuser/device_lower/analysis/tma.h +93 -0
  26. nvfuser/include/nvfuser/device_lower/analysis/trivial_broadcast.h +75 -0
  27. nvfuser/include/nvfuser/device_lower/id_model_options.h +135 -0
  28. nvfuser/include/nvfuser/device_lower/lower2device.h +391 -0
  29. nvfuser/include/nvfuser/device_lower/pass/alias_memory.h +37 -0
  30. nvfuser/include/nvfuser/device_lower/pass/allocation.h +32 -0
  31. nvfuser/include/nvfuser/device_lower/pass/circular_buffer.h +191 -0
  32. nvfuser/include/nvfuser/device_lower/pass/expr_sort.h +17 -0
  33. nvfuser/include/nvfuser/device_lower/pass/fusion_simplifier.h +21 -0
  34. nvfuser/include/nvfuser/device_lower/pass/grid_serialization.h +26 -0
  35. nvfuser/include/nvfuser/device_lower/pass/index.h +200 -0
  36. nvfuser/include/nvfuser/device_lower/pass/inline_ptx.h +16 -0
  37. nvfuser/include/nvfuser/device_lower/pass/insert_syncs.h +39 -0
  38. nvfuser/include/nvfuser/device_lower/pass/instrument.h +24 -0
  39. nvfuser/include/nvfuser/device_lower/pass/loop_rotation.h +150 -0
  40. nvfuser/include/nvfuser/device_lower/pass/loops.h +68 -0
  41. nvfuser/include/nvfuser/device_lower/pass/magic_zero.h +86 -0
  42. nvfuser/include/nvfuser/device_lower/pass/misaligned_vectorization.h +118 -0
  43. nvfuser/include/nvfuser/device_lower/pass/predicate.h +23 -0
  44. nvfuser/include/nvfuser/device_lower/pass/replace_size.h +24 -0
  45. nvfuser/include/nvfuser/device_lower/pass/scalar_hoist.h +115 -0
  46. nvfuser/include/nvfuser/device_lower/pass/unroll.h +98 -0
  47. nvfuser/include/nvfuser/device_lower/pass/vectorize_welford.h +45 -0
  48. nvfuser/include/nvfuser/device_lower/pass/warp_reduce.h +23 -0
  49. nvfuser/include/nvfuser/device_lower/utils.h +382 -0
  50. nvfuser/include/nvfuser/device_lower/validation.h +74 -0
  51. nvfuser/include/nvfuser/disjoint_set.h +556 -0
  52. nvfuser/include/nvfuser/dispatch.h +334 -0
  53. nvfuser/include/nvfuser/driver_api.h +49 -0
  54. nvfuser/include/nvfuser/dynamic_transform.h +316 -0
  55. nvfuser/include/nvfuser/dynamic_type/C++20/type_traits +37 -0
  56. nvfuser/include/nvfuser/dynamic_type/dynamic_type.h +969 -0
  57. nvfuser/include/nvfuser/dynamic_type/error.h +24 -0
  58. nvfuser/include/nvfuser/dynamic_type/type_traits.h +703 -0
  59. nvfuser/include/nvfuser/evaluator_common.h +295 -0
  60. nvfuser/include/nvfuser/exceptions.h +283 -0
  61. nvfuser/include/nvfuser/expr_evaluator.h +125 -0
  62. nvfuser/include/nvfuser/expr_simplifier.h +218 -0
  63. nvfuser/include/nvfuser/flatbuffers/allocator.h +68 -0
  64. nvfuser/include/nvfuser/flatbuffers/array.h +253 -0
  65. nvfuser/include/nvfuser/flatbuffers/base.h +486 -0
  66. nvfuser/include/nvfuser/flatbuffers/buffer.h +154 -0
  67. nvfuser/include/nvfuser/flatbuffers/buffer_ref.h +53 -0
  68. nvfuser/include/nvfuser/flatbuffers/code_generator.h +80 -0
  69. nvfuser/include/nvfuser/flatbuffers/code_generators.h +234 -0
  70. nvfuser/include/nvfuser/flatbuffers/default_allocator.h +64 -0
  71. nvfuser/include/nvfuser/flatbuffers/detached_buffer.h +114 -0
  72. nvfuser/include/nvfuser/flatbuffers/flatbuffer_builder.h +1225 -0
  73. nvfuser/include/nvfuser/flatbuffers/flatbuffers.h +272 -0
  74. nvfuser/include/nvfuser/flatbuffers/flatc.h +130 -0
  75. nvfuser/include/nvfuser/flatbuffers/flex_flat_util.h +36 -0
  76. nvfuser/include/nvfuser/flatbuffers/flexbuffers.h +1889 -0
  77. nvfuser/include/nvfuser/flatbuffers/grpc.h +300 -0
  78. nvfuser/include/nvfuser/flatbuffers/hash.h +127 -0
  79. nvfuser/include/nvfuser/flatbuffers/idl.h +1359 -0
  80. nvfuser/include/nvfuser/flatbuffers/minireflect.h +420 -0
  81. nvfuser/include/nvfuser/flatbuffers/reflection.h +522 -0
  82. nvfuser/include/nvfuser/flatbuffers/reflection_generated.h +1471 -0
  83. nvfuser/include/nvfuser/flatbuffers/registry.h +128 -0
  84. nvfuser/include/nvfuser/flatbuffers/stl_emulation.h +513 -0
  85. nvfuser/include/nvfuser/flatbuffers/string.h +64 -0
  86. nvfuser/include/nvfuser/flatbuffers/struct.h +53 -0
  87. nvfuser/include/nvfuser/flatbuffers/table.h +168 -0
  88. nvfuser/include/nvfuser/flatbuffers/util.h +731 -0
  89. nvfuser/include/nvfuser/flatbuffers/vector.h +393 -0
  90. nvfuser/include/nvfuser/flatbuffers/vector_downward.h +273 -0
  91. nvfuser/include/nvfuser/flatbuffers/verifier.h +317 -0
  92. nvfuser/include/nvfuser/fusion.h +511 -0
  93. nvfuser/include/nvfuser/fusion_guard.h +37 -0
  94. nvfuser/include/nvfuser/fusion_profiler.h +311 -0
  95. nvfuser/include/nvfuser/fusion_segmenter.h +751 -0
  96. nvfuser/include/nvfuser/global_allocator.h +27 -0
  97. nvfuser/include/nvfuser/grouped_reduction.h +47 -0
  98. nvfuser/include/nvfuser/host_ir/container.h +60 -0
  99. nvfuser/include/nvfuser/host_ir/executor.h +152 -0
  100. nvfuser/include/nvfuser/host_ir/host_ir.h +320 -0
  101. nvfuser/include/nvfuser/host_ir/lower.h +35 -0
  102. nvfuser/include/nvfuser/id_model/circular_buffer_indexing.h +56 -0
  103. nvfuser/include/nvfuser/id_model/contiguity.h +166 -0
  104. nvfuser/include/nvfuser/id_model/id_model.h +359 -0
  105. nvfuser/include/nvfuser/id_model/id_model_index_compute.h +81 -0
  106. nvfuser/include/nvfuser/id_model/indexing.h +208 -0
  107. nvfuser/include/nvfuser/id_model/indexing_traversal.h +72 -0
  108. nvfuser/include/nvfuser/id_model/indexing_utils.h +62 -0
  109. nvfuser/include/nvfuser/id_model/loop_promotion.h +180 -0
  110. nvfuser/include/nvfuser/id_model/predicate_indexing.h +104 -0
  111. nvfuser/include/nvfuser/id_model/schedule.h +54 -0
  112. nvfuser/include/nvfuser/id_model/to_string.h +87 -0
  113. nvfuser/include/nvfuser/id_model/transform_replay.h +58 -0
  114. nvfuser/include/nvfuser/id_model/utils.h +176 -0
  115. nvfuser/include/nvfuser/id_model/validation_utils.h +55 -0
  116. nvfuser/include/nvfuser/index_compute.h +651 -0
  117. nvfuser/include/nvfuser/instrumentation.h +107 -0
  118. nvfuser/include/nvfuser/ir/all_nodes.h +14 -0
  119. nvfuser/include/nvfuser/ir/base_nodes.h +687 -0
  120. nvfuser/include/nvfuser/ir/builder.h +215 -0
  121. nvfuser/include/nvfuser/ir/builder_passkey.h +29 -0
  122. nvfuser/include/nvfuser/ir/cloner.h +185 -0
  123. nvfuser/include/nvfuser/ir/container.h +226 -0
  124. nvfuser/include/nvfuser/ir/graphviz.h +119 -0
  125. nvfuser/include/nvfuser/ir/interface_nodes.h +957 -0
  126. nvfuser/include/nvfuser/ir/internal_base_nodes.h +744 -0
  127. nvfuser/include/nvfuser/ir/internal_nodes.h +2792 -0
  128. nvfuser/include/nvfuser/ir/iostream.h +98 -0
  129. nvfuser/include/nvfuser/ir/printer.h +57 -0
  130. nvfuser/include/nvfuser/ir/utils.h +801 -0
  131. nvfuser/include/nvfuser/iter_visitor.h +661 -0
  132. nvfuser/include/nvfuser/kernel.h +299 -0
  133. nvfuser/include/nvfuser/kernel_db/kernel_db.h +109 -0
  134. nvfuser/include/nvfuser/kernel_db/utils.h +37 -0
  135. nvfuser/include/nvfuser/kernel_ir.h +1457 -0
  136. nvfuser/include/nvfuser/kernel_ir_dispatch.h +147 -0
  137. nvfuser/include/nvfuser/linked_hash_map.h +97 -0
  138. nvfuser/include/nvfuser/logical_domain_map.h +577 -0
  139. nvfuser/include/nvfuser/macros.h +23 -0
  140. nvfuser/include/nvfuser/mma_type.h +257 -0
  141. nvfuser/include/nvfuser/multidevice/c10d_mock.h +175 -0
  142. nvfuser/include/nvfuser/multidevice/communication.h +232 -0
  143. nvfuser/include/nvfuser/multidevice/communicator.h +179 -0
  144. nvfuser/include/nvfuser/multidevice/device_mesh.h +95 -0
  145. nvfuser/include/nvfuser/multidevice/executor.h +107 -0
  146. nvfuser/include/nvfuser/multidevice/multidevice.h +18 -0
  147. nvfuser/include/nvfuser/multidevice/utils.h +187 -0
  148. nvfuser/include/nvfuser/non_divisible_split.h +86 -0
  149. nvfuser/include/nvfuser/opaque_type.h +129 -0
  150. nvfuser/include/nvfuser/ops/alias.h +192 -0
  151. nvfuser/include/nvfuser/ops/all_ops.h +13 -0
  152. nvfuser/include/nvfuser/ops/arith.h +712 -0
  153. nvfuser/include/nvfuser/ops/composite.h +130 -0
  154. nvfuser/include/nvfuser/ops/indexing.h +55 -0
  155. nvfuser/include/nvfuser/ops/normalization.h +263 -0
  156. nvfuser/include/nvfuser/ops/utils.h +127 -0
  157. nvfuser/include/nvfuser/options.h +313 -0
  158. nvfuser/include/nvfuser/parallel_dimension_map.h +95 -0
  159. nvfuser/include/nvfuser/parallel_type_bitmap.h +365 -0
  160. nvfuser/include/nvfuser/polymorphic_value.h +432 -0
  161. nvfuser/include/nvfuser/predicate_compute.h +213 -0
  162. nvfuser/include/nvfuser/python_frontend/distributed_tensor.h +50 -0
  163. nvfuser/include/nvfuser/python_frontend/fusion_cache.h +298 -0
  164. nvfuser/include/nvfuser/python_frontend/fusion_definition.h +372 -0
  165. nvfuser/include/nvfuser/python_frontend/fusion_record.h +3124 -0
  166. nvfuser/include/nvfuser/python_frontend/fusion_state.h +143 -0
  167. nvfuser/include/nvfuser/python_frontend/python_bindings.h +27 -0
  168. nvfuser/include/nvfuser/python_frontend/segmentation.h +246 -0
  169. nvfuser/include/nvfuser/python_frontend/translation.h +20 -0
  170. nvfuser/include/nvfuser/python_frontend/translation_utils.h +308 -0
  171. nvfuser/include/nvfuser/scheduler/all_schedulers.h +17 -0
  172. nvfuser/include/nvfuser/scheduler/ampere_multi_matmul.h +206 -0
  173. nvfuser/include/nvfuser/scheduler/cache_policy_refiner.h +19 -0
  174. nvfuser/include/nvfuser/scheduler/compile_time_info.h +322 -0
  175. nvfuser/include/nvfuser/scheduler/debug_utils.h +68 -0
  176. nvfuser/include/nvfuser/scheduler/expr_eval_sched.h +45 -0
  177. nvfuser/include/nvfuser/scheduler/heuristic.h +113 -0
  178. nvfuser/include/nvfuser/scheduler/hopper_multi_matmul.h +204 -0
  179. nvfuser/include/nvfuser/scheduler/mark_aliases.h +19 -0
  180. nvfuser/include/nvfuser/scheduler/matmul.h +40 -0
  181. nvfuser/include/nvfuser/scheduler/matmul_heuristic.h +293 -0
  182. nvfuser/include/nvfuser/scheduler/matmul_heuristic_plugin.h +65 -0
  183. nvfuser/include/nvfuser/scheduler/matmul_heuristic_plugin_api.h +99 -0
  184. nvfuser/include/nvfuser/scheduler/matmul_utils.h +54 -0
  185. nvfuser/include/nvfuser/scheduler/mma_utils.h +500 -0
  186. nvfuser/include/nvfuser/scheduler/multi_matmul.h +74 -0
  187. nvfuser/include/nvfuser/scheduler/no_op.h +48 -0
  188. nvfuser/include/nvfuser/scheduler/normalization_inner.h +49 -0
  189. nvfuser/include/nvfuser/scheduler/normalization_inner_outer.h +51 -0
  190. nvfuser/include/nvfuser/scheduler/normalization_outer.h +48 -0
  191. nvfuser/include/nvfuser/scheduler/normalization_utils.h +379 -0
  192. nvfuser/include/nvfuser/scheduler/pointwise.h +183 -0
  193. nvfuser/include/nvfuser/scheduler/pointwise_heuristic.h +118 -0
  194. nvfuser/include/nvfuser/scheduler/pointwise_utils.h +24 -0
  195. nvfuser/include/nvfuser/scheduler/reduction.h +43 -0
  196. nvfuser/include/nvfuser/scheduler/reduction_heuristic.h +339 -0
  197. nvfuser/include/nvfuser/scheduler/reduction_utils.h +159 -0
  198. nvfuser/include/nvfuser/scheduler/registry.h +97 -0
  199. nvfuser/include/nvfuser/scheduler/registry_utils.h +111 -0
  200. nvfuser/include/nvfuser/scheduler/resize.h +41 -0
  201. nvfuser/include/nvfuser/scheduler/resize_heuristic.h +67 -0
  202. nvfuser/include/nvfuser/scheduler/runtime_info.h +166 -0
  203. nvfuser/include/nvfuser/scheduler/scheduler_types.h +80 -0
  204. nvfuser/include/nvfuser/scheduler/transpose.h +114 -0
  205. nvfuser/include/nvfuser/scheduler/transpose_heuristic.h +164 -0
  206. nvfuser/include/nvfuser/scheduler/utils.h +771 -0
  207. nvfuser/include/nvfuser/scheduler/vectorize_helper.h +349 -0
  208. nvfuser/include/nvfuser/serde/factory.h +55 -0
  209. nvfuser/include/nvfuser/serde/fusion_cache_generated.h +4319 -0
  210. nvfuser/include/nvfuser/serde/fusion_record.h +124 -0
  211. nvfuser/include/nvfuser/serde/polymorphic_value.h +52 -0
  212. nvfuser/include/nvfuser/serde/utils.h +34 -0
  213. nvfuser/include/nvfuser/struct.inl +127 -0
  214. nvfuser/include/nvfuser/swizzle.h +54 -0
  215. nvfuser/include/nvfuser/sys_utils.h +40 -0
  216. nvfuser/include/nvfuser/tensor_metadata.h +118 -0
  217. nvfuser/include/nvfuser/tma.h +124 -0
  218. nvfuser/include/nvfuser/transform_iter.h +522 -0
  219. nvfuser/include/nvfuser/transform_replay.h +297 -0
  220. nvfuser/include/nvfuser/transform_rfactor.h +33 -0
  221. nvfuser/include/nvfuser/transform_view.h +136 -0
  222. nvfuser/include/nvfuser/type.h +1125 -0
  223. nvfuser/include/nvfuser/type_promotion.h +61 -0
  224. nvfuser/include/nvfuser/utils.h +619 -0
  225. nvfuser/include/nvfuser/val_graph.h +446 -0
  226. nvfuser/include/nvfuser/val_graph_visitor.h +259 -0
  227. nvfuser/include/nvfuser/validator_utils.h +92 -0
  228. nvfuser/include/nvfuser/vectorization_info.h +31 -0
  229. nvfuser/include/nvfuser/visibility.h +21 -0
  230. nvfuser/lib/libnvfuser_codegen.so +0 -0
  231. nvfuser/nvfuser_version.py +69 -0
  232. nvfuser/pytorch_utils.py +184 -0
  233. nvfuser/share/cmake/nvfuser/NvfuserConfig-release.cmake +20 -0
  234. nvfuser/share/cmake/nvfuser/NvfuserConfig.cmake +106 -0
  235. nvfuser/utils.py +18 -0
  236. nvfuser/version.py +1 -0
  237. nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/LICENSE +976 -0
  238. nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/METADATA +20 -0
  239. nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/RECORD +242 -0
  240. nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/WHEEL +5 -0
  241. nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/top_level.txt +1 -0
  242. nvfuser_cu121_torch25.libs/libnvToolsExt-847d78f2.so.1.0.0 +0 -0
@@ -0,0 +1,272 @@
1
+ /*
2
+ * Copyright 2014 Google Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #ifndef FLATBUFFERS_H_
18
+ #define FLATBUFFERS_H_
19
+
20
+ #include <algorithm>
21
+
22
+ // TODO: These includes are for mitigating the pains of users editing their
23
+ // source because they relied on flatbuffers.h to include everything for them.
24
+ #include "flatbuffers/array.h"
25
+ #include "flatbuffers/base.h"
26
+ #include "flatbuffers/buffer.h"
27
+ #include "flatbuffers/buffer_ref.h"
28
+ #include "flatbuffers/detached_buffer.h"
29
+ #include "flatbuffers/flatbuffer_builder.h"
30
+ #include "flatbuffers/stl_emulation.h"
31
+ #include "flatbuffers/string.h"
32
+ #include "flatbuffers/struct.h"
33
+ #include "flatbuffers/table.h"
34
+ #include "flatbuffers/vector.h"
35
+ #include "flatbuffers/vector_downward.h"
36
+ #include "flatbuffers/verifier.h"
37
+
38
+ namespace flatbuffers {
39
+
40
+ /// @brief This can compute the start of a FlatBuffer from a root pointer, i.e.
41
+ /// it is the opposite transformation of GetRoot().
42
+ /// This may be useful if you want to pass on a root and have the recipient
43
+ /// delete the buffer afterwards.
44
+ inline const uint8_t *GetBufferStartFromRootPointer(const void *root) {
45
+ auto table = reinterpret_cast<const Table *>(root);
46
+ auto vtable = table->GetVTable();
47
+ // Either the vtable is before the root or after the root.
48
+ auto start = (std::min)(vtable, reinterpret_cast<const uint8_t *>(root));
49
+ // Align to at least sizeof(uoffset_t).
50
+ start = reinterpret_cast<const uint8_t *>(reinterpret_cast<uintptr_t>(start) &
51
+ ~(sizeof(uoffset_t) - 1));
52
+ // Additionally, there may be a file_identifier in the buffer, and the root
53
+ // offset. The buffer may have been aligned to any size between
54
+ // sizeof(uoffset_t) and FLATBUFFERS_MAX_ALIGNMENT (see "force_align").
55
+ // Sadly, the exact alignment is only known when constructing the buffer,
56
+ // since it depends on the presence of values with said alignment properties.
57
+ // So instead, we simply look at the next uoffset_t values (root,
58
+ // file_identifier, and alignment padding) to see which points to the root.
59
+ // None of the other values can "impersonate" the root since they will either
60
+ // be 0 or four ASCII characters.
61
+ static_assert(flatbuffers::kFileIdentifierLength == sizeof(uoffset_t),
62
+ "file_identifier is assumed to be the same size as uoffset_t");
63
+ for (auto possible_roots = FLATBUFFERS_MAX_ALIGNMENT / sizeof(uoffset_t) + 1;
64
+ possible_roots; possible_roots--) {
65
+ start -= sizeof(uoffset_t);
66
+ if (ReadScalar<uoffset_t>(start) + start ==
67
+ reinterpret_cast<const uint8_t *>(root))
68
+ return start;
69
+ }
70
+ // We didn't find the root, either the "root" passed isn't really a root,
71
+ // or the buffer is corrupt.
72
+ // Assert, because calling this function with bad data may cause reads
73
+ // outside of buffer boundaries.
74
+ FLATBUFFERS_ASSERT(false);
75
+ return nullptr;
76
+ }
77
+
78
+ /// @brief This return the prefixed size of a FlatBuffer.
79
+ inline uoffset_t GetPrefixedSize(const uint8_t *buf) {
80
+ return ReadScalar<uoffset_t>(buf);
81
+ }
82
+
83
+ // Base class for native objects (FlatBuffer data de-serialized into native
84
+ // C++ data structures).
85
+ // Contains no functionality, purely documentative.
86
+ struct NativeTable {};
87
+
88
+ /// @brief Function types to be used with resolving hashes into objects and
89
+ /// back again. The resolver gets a pointer to a field inside an object API
90
+ /// object that is of the type specified in the schema using the attribute
91
+ /// `cpp_type` (it is thus important whatever you write to this address
92
+ /// matches that type). The value of this field is initially null, so you
93
+ /// may choose to implement a delayed binding lookup using this function
94
+ /// if you wish. The resolver does the opposite lookup, for when the object
95
+ /// is being serialized again.
96
+ typedef uint64_t hash_value_t;
97
+ typedef std::function<void(void **pointer_adr, hash_value_t hash)>
98
+ resolver_function_t;
99
+ typedef std::function<hash_value_t(void *pointer)> rehasher_function_t;
100
+
101
+ // Helper function to test if a field is present, using any of the field
102
+ // enums in the generated code.
103
+ // `table` must be a generated table type. Since this is a template parameter,
104
+ // this is not typechecked to be a subclass of Table, so beware!
105
+ // Note: this function will return false for fields equal to the default
106
+ // value, since they're not stored in the buffer (unless force_defaults was
107
+ // used).
108
+ template<typename T>
109
+ bool IsFieldPresent(const T *table, typename T::FlatBuffersVTableOffset field) {
110
+ // Cast, since Table is a private baseclass of any table types.
111
+ return reinterpret_cast<const Table *>(table)->CheckField(
112
+ static_cast<voffset_t>(field));
113
+ }
114
+
115
+ // Utility function for reverse lookups on the EnumNames*() functions
116
+ // (in the generated C++ code)
117
+ // names must be NULL terminated.
118
+ inline int LookupEnum(const char **names, const char *name) {
119
+ for (const char **p = names; *p; p++)
120
+ if (!strcmp(*p, name)) return static_cast<int>(p - names);
121
+ return -1;
122
+ }
123
+
124
+ // These macros allow us to layout a struct with a guarantee that they'll end
125
+ // up looking the same on different compilers and platforms.
126
+ // It does this by disallowing the compiler to do any padding, and then
127
+ // does padding itself by inserting extra padding fields that make every
128
+ // element aligned to its own size.
129
+ // Additionally, it manually sets the alignment of the struct as a whole,
130
+ // which is typically its largest element, or a custom size set in the schema
131
+ // by the force_align attribute.
132
+ // These are used in the generated code only.
133
+
134
+ // clang-format off
135
+ #if defined(_MSC_VER)
136
+ #define FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(alignment) \
137
+ __pragma(pack(1)) \
138
+ struct __declspec(align(alignment))
139
+ #define FLATBUFFERS_STRUCT_END(name, size) \
140
+ __pragma(pack()) \
141
+ static_assert(sizeof(name) == size, "compiler breaks packing rules")
142
+ #elif defined(__GNUC__) || defined(__clang__) || defined(__ICCARM__)
143
+ #define FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(alignment) \
144
+ _Pragma("pack(1)") \
145
+ struct __attribute__((aligned(alignment)))
146
+ #define FLATBUFFERS_STRUCT_END(name, size) \
147
+ _Pragma("pack()") \
148
+ static_assert(sizeof(name) == size, "compiler breaks packing rules")
149
+ #else
150
+ #error Unknown compiler, please define structure alignment macros
151
+ #endif
152
+ // clang-format on
153
+
154
+ // Minimal reflection via code generation.
155
+ // Besides full-fat reflection (see reflection.h) and parsing/printing by
156
+ // loading schemas (see idl.h), we can also have code generation for minimal
157
+ // reflection data which allows pretty-printing and other uses without needing
158
+ // a schema or a parser.
159
+ // Generate code with --reflect-types (types only) or --reflect-names (names
160
+ // also) to enable.
161
+ // See minireflect.h for utilities using this functionality.
162
+
163
+ // These types are organized slightly differently as the ones in idl.h.
164
+ enum SequenceType { ST_TABLE, ST_STRUCT, ST_UNION, ST_ENUM };
165
+
166
+ // Scalars have the same order as in idl.h
167
+ // clang-format off
168
+ #define FLATBUFFERS_GEN_ELEMENTARY_TYPES(ET) \
169
+ ET(ET_UTYPE) \
170
+ ET(ET_BOOL) \
171
+ ET(ET_CHAR) \
172
+ ET(ET_UCHAR) \
173
+ ET(ET_SHORT) \
174
+ ET(ET_USHORT) \
175
+ ET(ET_INT) \
176
+ ET(ET_UINT) \
177
+ ET(ET_LONG) \
178
+ ET(ET_ULONG) \
179
+ ET(ET_FLOAT) \
180
+ ET(ET_DOUBLE) \
181
+ ET(ET_STRING) \
182
+ ET(ET_SEQUENCE) // See SequenceType.
183
+
184
+ enum ElementaryType {
185
+ #define FLATBUFFERS_ET(E) E,
186
+ FLATBUFFERS_GEN_ELEMENTARY_TYPES(FLATBUFFERS_ET)
187
+ #undef FLATBUFFERS_ET
188
+ };
189
+
190
+ inline const char * const *ElementaryTypeNames() {
191
+ static const char * const names[] = {
192
+ #define FLATBUFFERS_ET(E) #E,
193
+ FLATBUFFERS_GEN_ELEMENTARY_TYPES(FLATBUFFERS_ET)
194
+ #undef FLATBUFFERS_ET
195
+ };
196
+ return names;
197
+ }
198
+ // clang-format on
199
+
200
+ // Basic type info cost just 16bits per field!
201
+ // We're explicitly defining the signedness since the signedness of integer
202
+ // bitfields is otherwise implementation-defined and causes warnings on older
203
+ // GCC compilers.
204
+ struct TypeCode {
205
+ // ElementaryType
206
+ unsigned short base_type : 4;
207
+ // Either vector (in table) or array (in struct)
208
+ unsigned short is_repeating : 1;
209
+ // Index into type_refs below, or -1 for none.
210
+ signed short sequence_ref : 11;
211
+ };
212
+
213
+ static_assert(sizeof(TypeCode) == 2, "TypeCode");
214
+
215
+ struct TypeTable;
216
+
217
+ // Signature of the static method present in each type.
218
+ typedef const TypeTable *(*TypeFunction)();
219
+
220
+ struct TypeTable {
221
+ SequenceType st;
222
+ size_t num_elems; // of type_codes, values, names (but not type_refs).
223
+ const TypeCode *type_codes; // num_elems count
224
+ const TypeFunction *type_refs; // less than num_elems entries (see TypeCode).
225
+ const int16_t *array_sizes; // less than num_elems entries (see TypeCode).
226
+ const int64_t *values; // Only set for non-consecutive enum/union or structs.
227
+ const char *const *names; // Only set if compiled with --reflect-names.
228
+ };
229
+
230
+ // String which identifies the current version of FlatBuffers.
231
+ inline const char *flatbuffers_version_string() {
232
+ return "FlatBuffers " FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MAJOR) "."
233
+ FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MINOR) "."
234
+ FLATBUFFERS_STRING(FLATBUFFERS_VERSION_REVISION);
235
+ }
236
+
237
+ // clang-format off
238
+ #define FLATBUFFERS_DEFINE_BITMASK_OPERATORS(E, T)\
239
+ inline E operator | (E lhs, E rhs){\
240
+ return E(T(lhs) | T(rhs));\
241
+ }\
242
+ inline E operator & (E lhs, E rhs){\
243
+ return E(T(lhs) & T(rhs));\
244
+ }\
245
+ inline E operator ^ (E lhs, E rhs){\
246
+ return E(T(lhs) ^ T(rhs));\
247
+ }\
248
+ inline E operator ~ (E lhs){\
249
+ return E(~T(lhs));\
250
+ }\
251
+ inline E operator |= (E &lhs, E rhs){\
252
+ lhs = lhs | rhs;\
253
+ return lhs;\
254
+ }\
255
+ inline E operator &= (E &lhs, E rhs){\
256
+ lhs = lhs & rhs;\
257
+ return lhs;\
258
+ }\
259
+ inline E operator ^= (E &lhs, E rhs){\
260
+ lhs = lhs ^ rhs;\
261
+ return lhs;\
262
+ }\
263
+ inline bool operator !(E rhs) \
264
+ {\
265
+ return !bool(T(rhs)); \
266
+ }
267
+ /// @endcond
268
+ } // namespace flatbuffers
269
+
270
+ // clang-format on
271
+
272
+ #endif // FLATBUFFERS_H_
@@ -0,0 +1,130 @@
1
+ /*
2
+ * Copyright 2017 Google Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #ifndef FLATBUFFERS_FLATC_H_
18
+ #define FLATBUFFERS_FLATC_H_
19
+
20
+ #include <functional>
21
+ #include <limits>
22
+ #include <list>
23
+ #include <memory>
24
+ #include <string>
25
+
26
+ #include "flatbuffers/code_generator.h"
27
+ #include "flatbuffers/flatbuffers.h"
28
+ #include "flatbuffers/idl.h"
29
+ #include "flatbuffers/util.h"
30
+
31
+ namespace flatbuffers {
32
+
33
+ extern void LogCompilerWarn(const std::string &warn);
34
+ extern void LogCompilerError(const std::string &err);
35
+
36
+ struct FlatCOptions {
37
+ IDLOptions opts;
38
+
39
+ std::string program_name;
40
+
41
+ std::string output_path;
42
+
43
+ std::vector<std::string> filenames;
44
+
45
+ std::list<std::string> include_directories_storage;
46
+ std::vector<const char *> include_directories;
47
+ std::vector<const char *> conform_include_directories;
48
+ std::vector<bool> generator_enabled;
49
+ size_t binary_files_from = std::numeric_limits<size_t>::max();
50
+ std::string conform_to_schema;
51
+ std::string annotate_schema;
52
+ bool annotate_include_vector_contents = true;
53
+ bool any_generator = false;
54
+ bool print_make_rules = false;
55
+ bool raw_binary = false;
56
+ bool schema_binary = false;
57
+ bool grpc_enabled = false;
58
+ bool requires_bfbs = false;
59
+
60
+ std::vector<std::shared_ptr<CodeGenerator>> generators;
61
+ };
62
+
63
+ struct FlatCOption {
64
+ std::string short_opt;
65
+ std::string long_opt;
66
+ std::string parameter;
67
+ std::string description;
68
+ };
69
+
70
+ class FlatCompiler {
71
+ public:
72
+ typedef void (*WarnFn)(const FlatCompiler *flatc, const std::string &warn,
73
+ bool show_exe_name);
74
+
75
+ typedef void (*ErrorFn)(const FlatCompiler *flatc, const std::string &err,
76
+ bool usage, bool show_exe_name);
77
+
78
+ // Parameters required to initialize the FlatCompiler.
79
+ struct InitParams {
80
+ InitParams() : warn_fn(nullptr), error_fn(nullptr) {}
81
+
82
+ WarnFn warn_fn;
83
+ ErrorFn error_fn;
84
+ };
85
+
86
+ explicit FlatCompiler(const InitParams &params) : params_(params) {}
87
+
88
+ bool RegisterCodeGenerator(const FlatCOption &option,
89
+ std::shared_ptr<CodeGenerator> code_generator);
90
+
91
+ int Compile(const FlatCOptions &options);
92
+
93
+ std::string GetShortUsageString(const std::string &program_name) const;
94
+ std::string GetUsageString(const std::string &program_name) const;
95
+
96
+ // Parse the FlatC options from command line arguments.
97
+ FlatCOptions ParseFromCommandLineArguments(int argc, const char **argv);
98
+
99
+ private:
100
+ void ParseFile(flatbuffers::Parser &parser, const std::string &filename,
101
+ const std::string &contents,
102
+ const std::vector<const char *> &include_directories) const;
103
+
104
+ void LoadBinarySchema(Parser &parser, const std::string &filename,
105
+ const std::string &contents);
106
+
107
+ void Warn(const std::string &warn, bool show_exe_name = true) const;
108
+
109
+ void Error(const std::string &err, bool usage = true,
110
+ bool show_exe_name = true) const;
111
+
112
+ void AnnotateBinaries(const uint8_t *binary_schema,
113
+ uint64_t binary_schema_size,
114
+ const FlatCOptions &options);
115
+
116
+ void ValidateOptions(const FlatCOptions &options);
117
+
118
+ Parser GetConformParser(const FlatCOptions &options);
119
+
120
+ std::unique_ptr<Parser> GenerateCode(const FlatCOptions &options,
121
+ Parser &conform_parser);
122
+
123
+ std::map<std::string, std::shared_ptr<CodeGenerator>> code_generators_;
124
+
125
+ InitParams params_;
126
+ };
127
+
128
+ } // namespace flatbuffers
129
+
130
+ #endif // FLATBUFFERS_FLATC_H_
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright 2022 Google Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ #ifndef FLATBUFFERS_FLEX_FLAT_UTIL_H_
18
+ #define FLATBUFFERS_FLEX_FLAT_UTIL_H_
19
+
20
+ #include "flatbuffers/flatbuffers.h"
21
+ #include "flatbuffers/flexbuffers.h"
22
+
23
+ namespace flexbuffers {
24
+
25
+ // Verifies the `nested` flexbuffer within a flatbuffer vector is valid.
26
+ inline bool VerifyNestedFlexBuffer(
27
+ const flatbuffers::Vector<uint8_t> *const nested,
28
+ flatbuffers::Verifier &verifier) {
29
+ if (!nested) return true;
30
+ return verifier.Check(flexbuffers::VerifyBuffer(
31
+ nested->data(), nested->size(), verifier.GetFlexReuseTracker()));
32
+ }
33
+
34
+ } // namespace flexbuffers
35
+
36
+ #endif // FLATBUFFERS_FLEX_FLAT_UTIL_H_