nvfuser-cu121-torch25 0.2.25.dev20250201__cp312-cp312-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-312-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 +16 -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,80 @@
1
+ /*
2
+ * Copyright 2023 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_CODE_GENERATOR_H_
18
+ #define FLATBUFFERS_CODE_GENERATOR_H_
19
+
20
+ #include <string>
21
+
22
+ #include "flatbuffers/idl.h"
23
+
24
+ namespace flatbuffers {
25
+
26
+ // A code generator interface for producing converting flatbuffer schema into
27
+ // code.
28
+ class CodeGenerator {
29
+ public:
30
+ virtual ~CodeGenerator() = default;
31
+
32
+ enum Status {
33
+ OK = 0,
34
+ ERROR = 1,
35
+ FAILED_VERIFICATION = 2,
36
+ NOT_IMPLEMENTED = 3
37
+ };
38
+
39
+ // Generate code from the provided `parser`.
40
+ //
41
+ // DEPRECATED: prefer using the other overload of GenerateCode for bfbs.
42
+ virtual Status GenerateCode(const Parser &parser, const std::string &path,
43
+ const std::string &filename) = 0;
44
+
45
+ // Generate code from the provided `buffer` of given `length`. The buffer is a
46
+ // serialized reflection.fbs.
47
+ virtual Status GenerateCode(const uint8_t *buffer, int64_t length) = 0;
48
+
49
+ virtual Status GenerateMakeRule(const Parser &parser, const std::string &path,
50
+ const std::string &filename,
51
+ std::string &output) = 0;
52
+
53
+ virtual Status GenerateGrpcCode(const Parser &parser, const std::string &path,
54
+ const std::string &filename) = 0;
55
+
56
+ virtual Status GenerateRootFile(const Parser &parser,
57
+ const std::string &path) = 0;
58
+
59
+ virtual bool IsSchemaOnly() const = 0;
60
+
61
+ virtual bool SupportsBfbsGeneration() const = 0;
62
+
63
+ virtual bool SupportsRootFileGeneration() const = 0;
64
+
65
+ virtual IDLOptions::Language Language() const = 0;
66
+
67
+ virtual std::string LanguageName() const = 0;
68
+
69
+ protected:
70
+ CodeGenerator() = default;
71
+
72
+ private:
73
+ // Copying is not supported.
74
+ CodeGenerator(const CodeGenerator &) = delete;
75
+ CodeGenerator &operator=(const CodeGenerator &) = delete;
76
+ };
77
+
78
+ } // namespace flatbuffers
79
+
80
+ #endif // FLATBUFFERS_CODE_GENERATOR_H_
@@ -0,0 +1,234 @@
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_CODE_GENERATORS_H_
18
+ #define FLATBUFFERS_CODE_GENERATORS_H_
19
+
20
+ #include <map>
21
+ #include <sstream>
22
+
23
+ #include "flatbuffers/idl.h"
24
+
25
+ namespace flatbuffers {
26
+
27
+ // Utility class to assist in generating code through use of text templates.
28
+ //
29
+ // Example code:
30
+ // CodeWriter code("\t");
31
+ // code.SetValue("NAME", "Foo");
32
+ // code += "void {{NAME}}() { printf("%s", "{{NAME}}"); }";
33
+ // code.SetValue("NAME", "Bar");
34
+ // code += "void {{NAME}}() { printf("%s", "{{NAME}}"); }";
35
+ // std::cout << code.ToString() << std::endl;
36
+ //
37
+ // Output:
38
+ // void Foo() { printf("%s", "Foo"); }
39
+ // void Bar() { printf("%s", "Bar"); }
40
+ class CodeWriter {
41
+ public:
42
+ CodeWriter(std::string pad = std::string())
43
+ : pad_(pad), cur_ident_lvl_(0), ignore_ident_(false) {}
44
+
45
+ // Clears the current "written" code.
46
+ void Clear() {
47
+ stream_.str("");
48
+ stream_.clear();
49
+ }
50
+
51
+ // Associates a key with a value. All subsequent calls to operator+=, where
52
+ // the specified key is contained in {{ and }} delimiters will be replaced by
53
+ // the given value.
54
+ void SetValue(const std::string &key, const std::string &value) {
55
+ value_map_[key] = value;
56
+ }
57
+
58
+ std::string GetValue(const std::string &key) const {
59
+ const auto it = value_map_.find(key);
60
+ return it == value_map_.end() ? "" : it->second;
61
+ }
62
+
63
+ // Appends the given text to the generated code as well as a newline
64
+ // character. Any text within {{ and }} delimiters is replaced by values
65
+ // previously stored in the CodeWriter by calling SetValue above. The newline
66
+ // will be suppressed if the text ends with the \\ character.
67
+ void operator+=(std::string text);
68
+
69
+ // Returns the current contents of the CodeWriter as a std::string.
70
+ std::string ToString() const { return stream_.str(); }
71
+
72
+ // Increase ident level for writing code
73
+ void IncrementIdentLevel() { cur_ident_lvl_++; }
74
+ // Decrease ident level for writing code
75
+ void DecrementIdentLevel() {
76
+ if (cur_ident_lvl_) cur_ident_lvl_--;
77
+ }
78
+
79
+ void SetPadding(const std::string &padding) { pad_ = padding; }
80
+
81
+ private:
82
+ std::map<std::string, std::string> value_map_;
83
+ std::stringstream stream_;
84
+ std::string pad_;
85
+ int cur_ident_lvl_;
86
+ bool ignore_ident_;
87
+
88
+ // Add ident padding (tab or space) based on ident level
89
+ void AppendIdent(std::stringstream &stream);
90
+ };
91
+
92
+ class BaseGenerator {
93
+ public:
94
+ virtual bool generate() = 0;
95
+
96
+ static std::string NamespaceDir(const Parser &parser, const std::string &path,
97
+ const Namespace &ns,
98
+ const bool dasherize = false);
99
+
100
+ std::string GeneratedFileName(const std::string &path,
101
+ const std::string &file_name,
102
+ const IDLOptions &options) const;
103
+
104
+ protected:
105
+ BaseGenerator(const Parser &parser, const std::string &path,
106
+ const std::string &file_name, std::string qualifying_start,
107
+ std::string qualifying_separator, std::string default_extension)
108
+ : parser_(parser),
109
+ path_(path),
110
+ file_name_(file_name),
111
+ qualifying_start_(qualifying_start),
112
+ qualifying_separator_(qualifying_separator),
113
+ default_extension_(default_extension) {}
114
+ virtual ~BaseGenerator() {}
115
+
116
+ // No copy/assign.
117
+ BaseGenerator &operator=(const BaseGenerator &);
118
+ BaseGenerator(const BaseGenerator &);
119
+
120
+ std::string NamespaceDir(const Namespace &ns,
121
+ const bool dasherize = false) const;
122
+
123
+ static const char *FlatBuffersGeneratedWarning();
124
+
125
+ static std::string FullNamespace(const char *separator, const Namespace &ns);
126
+
127
+ static std::string LastNamespacePart(const Namespace &ns);
128
+
129
+ // tracks the current namespace for early exit in WrapInNameSpace
130
+ // c++, java and csharp returns a different namespace from
131
+ // the following default (no early exit, always fully qualify),
132
+ // which works for js and php
133
+ virtual const Namespace *CurrentNameSpace() const { return nullptr; }
134
+
135
+ // Ensure that a type is prefixed with its namespace even within
136
+ // its own namespace to avoid conflict between generated method
137
+ // names and similarly named classes or structs
138
+ std::string WrapInNameSpace(const Namespace *ns,
139
+ const std::string &name) const;
140
+
141
+ std::string WrapInNameSpace(const Definition &def,
142
+ const std::string &suffix = "") const;
143
+
144
+ std::string GetNameSpace(const Definition &def) const;
145
+
146
+ const Parser &parser_;
147
+ const std::string &path_;
148
+ const std::string &file_name_;
149
+ const std::string qualifying_start_;
150
+ const std::string qualifying_separator_;
151
+ const std::string default_extension_;
152
+ };
153
+
154
+ struct CommentConfig {
155
+ const char *first_line;
156
+ const char *content_line_prefix;
157
+ const char *last_line;
158
+ };
159
+
160
+ extern void GenComment(const std::vector<std::string> &dc,
161
+ std::string *code_ptr, const CommentConfig *config,
162
+ const char *prefix = "");
163
+
164
+ class FloatConstantGenerator {
165
+ public:
166
+ virtual ~FloatConstantGenerator() {}
167
+ std::string GenFloatConstant(const FieldDef &field) const;
168
+
169
+ private:
170
+ virtual std::string Value(double v, const std::string &src) const = 0;
171
+ virtual std::string Inf(double v) const = 0;
172
+ virtual std::string NaN(double v) const = 0;
173
+
174
+ virtual std::string Value(float v, const std::string &src) const = 0;
175
+ virtual std::string Inf(float v) const = 0;
176
+ virtual std::string NaN(float v) const = 0;
177
+
178
+ template<typename T>
179
+ std::string GenFloatConstantImpl(const FieldDef &field) const;
180
+ };
181
+
182
+ class SimpleFloatConstantGenerator : public FloatConstantGenerator {
183
+ public:
184
+ SimpleFloatConstantGenerator(const char *nan_number,
185
+ const char *pos_inf_number,
186
+ const char *neg_inf_number);
187
+
188
+ private:
189
+ std::string Value(double v,
190
+ const std::string &src) const FLATBUFFERS_OVERRIDE;
191
+ std::string Inf(double v) const FLATBUFFERS_OVERRIDE;
192
+ std::string NaN(double v) const FLATBUFFERS_OVERRIDE;
193
+
194
+ std::string Value(float v, const std::string &src) const FLATBUFFERS_OVERRIDE;
195
+ std::string Inf(float v) const FLATBUFFERS_OVERRIDE;
196
+ std::string NaN(float v) const FLATBUFFERS_OVERRIDE;
197
+
198
+ const std::string nan_number_;
199
+ const std::string pos_inf_number_;
200
+ const std::string neg_inf_number_;
201
+ };
202
+
203
+ // C++, C#, Java like generator.
204
+ class TypedFloatConstantGenerator : public FloatConstantGenerator {
205
+ public:
206
+ TypedFloatConstantGenerator(const char *double_prefix,
207
+ const char *single_prefix, const char *nan_number,
208
+ const char *pos_inf_number,
209
+ const char *neg_inf_number = "");
210
+
211
+ private:
212
+ std::string Value(double v,
213
+ const std::string &src) const FLATBUFFERS_OVERRIDE;
214
+ std::string Inf(double v) const FLATBUFFERS_OVERRIDE;
215
+
216
+ std::string NaN(double v) const FLATBUFFERS_OVERRIDE;
217
+
218
+ std::string Value(float v, const std::string &src) const FLATBUFFERS_OVERRIDE;
219
+ std::string Inf(float v) const FLATBUFFERS_OVERRIDE;
220
+ std::string NaN(float v) const FLATBUFFERS_OVERRIDE;
221
+
222
+ std::string MakeNaN(const std::string &prefix) const;
223
+ std::string MakeInf(bool neg, const std::string &prefix) const;
224
+
225
+ const std::string double_prefix_;
226
+ const std::string single_prefix_;
227
+ const std::string nan_number_;
228
+ const std::string pos_inf_number_;
229
+ const std::string neg_inf_number_;
230
+ };
231
+
232
+ } // namespace flatbuffers
233
+
234
+ #endif // FLATBUFFERS_CODE_GENERATORS_H_
@@ -0,0 +1,64 @@
1
+ /*
2
+ * Copyright 2021 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_DEFAULT_ALLOCATOR_H_
18
+ #define FLATBUFFERS_DEFAULT_ALLOCATOR_H_
19
+
20
+ #include "flatbuffers/allocator.h"
21
+ #include "flatbuffers/base.h"
22
+
23
+ namespace flatbuffers {
24
+
25
+ // DefaultAllocator uses new/delete to allocate memory regions
26
+ class DefaultAllocator : public Allocator {
27
+ public:
28
+ uint8_t *allocate(size_t size) FLATBUFFERS_OVERRIDE {
29
+ return new uint8_t[size];
30
+ }
31
+
32
+ void deallocate(uint8_t *p, size_t) FLATBUFFERS_OVERRIDE { delete[] p; }
33
+
34
+ static void dealloc(void *p, size_t) { delete[] static_cast<uint8_t *>(p); }
35
+ };
36
+
37
+ // These functions allow for a null allocator to mean use the default allocator,
38
+ // as used by DetachedBuffer and vector_downward below.
39
+ // This is to avoid having a statically or dynamically allocated default
40
+ // allocator, or having to move it between the classes that may own it.
41
+ inline uint8_t *Allocate(Allocator *allocator, size_t size) {
42
+ return allocator ? allocator->allocate(size)
43
+ : DefaultAllocator().allocate(size);
44
+ }
45
+
46
+ inline void Deallocate(Allocator *allocator, uint8_t *p, size_t size) {
47
+ if (allocator)
48
+ allocator->deallocate(p, size);
49
+ else
50
+ DefaultAllocator().deallocate(p, size);
51
+ }
52
+
53
+ inline uint8_t *ReallocateDownward(Allocator *allocator, uint8_t *old_p,
54
+ size_t old_size, size_t new_size,
55
+ size_t in_use_back, size_t in_use_front) {
56
+ return allocator ? allocator->reallocate_downward(old_p, old_size, new_size,
57
+ in_use_back, in_use_front)
58
+ : DefaultAllocator().reallocate_downward(
59
+ old_p, old_size, new_size, in_use_back, in_use_front);
60
+ }
61
+
62
+ } // namespace flatbuffers
63
+
64
+ #endif // FLATBUFFERS_DEFAULT_ALLOCATOR_H_
@@ -0,0 +1,114 @@
1
+ /*
2
+ * Copyright 2021 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_DETACHED_BUFFER_H_
18
+ #define FLATBUFFERS_DETACHED_BUFFER_H_
19
+
20
+ #include "flatbuffers/allocator.h"
21
+ #include "flatbuffers/base.h"
22
+ #include "flatbuffers/default_allocator.h"
23
+
24
+ namespace flatbuffers {
25
+
26
+ // DetachedBuffer is a finished flatbuffer memory region, detached from its
27
+ // builder. The original memory region and allocator are also stored so that
28
+ // the DetachedBuffer can manage the memory lifetime.
29
+ class DetachedBuffer {
30
+ public:
31
+ DetachedBuffer()
32
+ : allocator_(nullptr),
33
+ own_allocator_(false),
34
+ buf_(nullptr),
35
+ reserved_(0),
36
+ cur_(nullptr),
37
+ size_(0) {}
38
+
39
+ DetachedBuffer(Allocator *allocator, bool own_allocator, uint8_t *buf,
40
+ size_t reserved, uint8_t *cur, size_t sz)
41
+ : allocator_(allocator),
42
+ own_allocator_(own_allocator),
43
+ buf_(buf),
44
+ reserved_(reserved),
45
+ cur_(cur),
46
+ size_(sz) {}
47
+
48
+ DetachedBuffer(DetachedBuffer &&other) noexcept
49
+ : allocator_(other.allocator_),
50
+ own_allocator_(other.own_allocator_),
51
+ buf_(other.buf_),
52
+ reserved_(other.reserved_),
53
+ cur_(other.cur_),
54
+ size_(other.size_) {
55
+ other.reset();
56
+ }
57
+
58
+ DetachedBuffer &operator=(DetachedBuffer &&other) noexcept {
59
+ if (this == &other) return *this;
60
+
61
+ destroy();
62
+
63
+ allocator_ = other.allocator_;
64
+ own_allocator_ = other.own_allocator_;
65
+ buf_ = other.buf_;
66
+ reserved_ = other.reserved_;
67
+ cur_ = other.cur_;
68
+ size_ = other.size_;
69
+
70
+ other.reset();
71
+
72
+ return *this;
73
+ }
74
+
75
+ ~DetachedBuffer() { destroy(); }
76
+
77
+ const uint8_t *data() const { return cur_; }
78
+
79
+ uint8_t *data() { return cur_; }
80
+
81
+ size_t size() const { return size_; }
82
+
83
+ // These may change access mode, leave these at end of public section
84
+ FLATBUFFERS_DELETE_FUNC(DetachedBuffer(const DetachedBuffer &other));
85
+ FLATBUFFERS_DELETE_FUNC(
86
+ DetachedBuffer &operator=(const DetachedBuffer &other));
87
+
88
+ protected:
89
+ Allocator *allocator_;
90
+ bool own_allocator_;
91
+ uint8_t *buf_;
92
+ size_t reserved_;
93
+ uint8_t *cur_;
94
+ size_t size_;
95
+
96
+ inline void destroy() {
97
+ if (buf_) Deallocate(allocator_, buf_, reserved_);
98
+ if (own_allocator_ && allocator_) { delete allocator_; }
99
+ reset();
100
+ }
101
+
102
+ inline void reset() {
103
+ allocator_ = nullptr;
104
+ own_allocator_ = false;
105
+ buf_ = nullptr;
106
+ reserved_ = 0;
107
+ cur_ = nullptr;
108
+ size_ = 0;
109
+ }
110
+ };
111
+
112
+ } // namespace flatbuffers
113
+
114
+ #endif // FLATBUFFERS_DETACHED_BUFFER_H_