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,215 @@
1
+ // clang-format off
2
+ /*
3
+ * SPDX-FileCopyrightText: Copyright (c) 2023-present NVIDIA CORPORATION & AFFILIATES.
4
+ * All rights reserved.
5
+ * SPDX-License-Identifier: BSD-3-Clause
6
+ */
7
+ // clang-format on
8
+ #pragma once
9
+
10
+ #include <exceptions.h>
11
+ #include <fusion_guard.h>
12
+ #include <ir/builder_passkey.h>
13
+ #include <ir/container.h>
14
+ #include <utils.h>
15
+ #include <visibility.h>
16
+
17
+ namespace nvfuser {
18
+
19
+ namespace kir {
20
+ class Kernel;
21
+ }
22
+
23
+ class ArrayConstruct;
24
+ class IrCloner;
25
+ class NamedScalar;
26
+ class StructConstruct;
27
+ class TensorView;
28
+ class Val;
29
+
30
+ //! IR builder interface
31
+ class IrBuilder {
32
+ public:
33
+ //! Allocate a new IR node, forwarding the arguments to the appropriate
34
+ //! constructor and registering with the container
35
+ template <class T, class... Args>
36
+ static T* create(Args&&... args) {
37
+ Fusion* fusion = FusionGuard::getCurFusion();
38
+ return createInContainer<T>(fusion, std::forward<Args>(args)...);
39
+ }
40
+
41
+ //! Allocate a new IR node, forwarding the arguments to the appropriate
42
+ //! constructor and registering with the container
43
+ template <class T, class... Args>
44
+ static T* createInContainer(IrContainer* container, Args&&... args) {
45
+ NVF_ERROR(container != nullptr, "Need an active container to build IR.");
46
+ T* node = new T(IrBuilderPasskey(container), std::forward<Args>(args)...);
47
+
48
+ container->registerStmt(IrBuilderPasskey(container), node);
49
+
50
+ return node;
51
+ }
52
+
53
+ //! Clone an IR node, forwarding the arguments to the IrCloner constructor.
54
+ //! Register clones with IrCloner's target container.
55
+ template <class T>
56
+ static T* clone(const T* src, IrCloner* ir_cloner);
57
+
58
+ // Unary operations
59
+ NVF_API static Val* derefExpr(Val* val);
60
+ NVF_API static Val* negExpr(Val* val);
61
+ NVF_API static Val* logicalNotExpr(Val* val);
62
+ static Val* bitwiseNotExpr(Val* val);
63
+ NVF_API static Val* absExpr(Val* val);
64
+ static Val* setExpr(Val* val);
65
+ static Val* maybeCastExpr(DataType dtype, Val* val);
66
+ static Val* maybeRefCastExpr(DataType dtype, Val* val);
67
+ static Val* addressExpr(Val* val);
68
+ static NamedScalar* setExprNamedScalar(const std::string& name, Val* val);
69
+ static NamedScalar* addressExprNamedScalar(const std::string& name, Val* val);
70
+
71
+ // Binary operations
72
+ NVF_API static Val* logicalAndExpr(Val* lhs, Val* rhs);
73
+ NVF_API static Val* logicalOrExpr(Val* lhs, Val* rhs);
74
+ NVF_API static Val* bitwiseAndExpr(Val* lhs, Val* rhs);
75
+ NVF_API static Val* bitwiseOrExpr(Val* lhs, Val* rhs);
76
+ NVF_API static Val* bitwiseXorExpr(Val* lhs, Val* rhs);
77
+ NVF_API static Val* lShiftExpr(Val* lhs, Val* rhs);
78
+ NVF_API static Val* rShiftExpr(Val* lhs, Val* rhs);
79
+ NVF_API static Val* eqExpr(Val* lhs, Val* rhs);
80
+ NVF_API static Val* neExpr(Val* lhs, Val* rhs);
81
+ NVF_API static Val* gtExpr(Val* lhs, Val* rhs);
82
+ NVF_API static Val* ltExpr(Val* lhs, Val* rhs);
83
+ NVF_API static Val* leExpr(Val* lhs, Val* rhs);
84
+ NVF_API static Val* geExpr(Val* lhs, Val* rhs);
85
+ NVF_API static Val* addExpr(Val* lhs, Val* rhs);
86
+ NVF_API static Val* subExpr(Val* lhs, Val* rhs);
87
+ NVF_API static Val* mulExpr(Val* lhs, Val* rhs);
88
+ NVF_API static Val* divExpr(Val* lhs, Val* rhs);
89
+ NVF_API static Val* ceilDivExpr(Val* lhs, Val* rhs);
90
+ NVF_API static Val* modExpr(Val* lhs, Val* rhs);
91
+ NVF_API static Val* maxExpr(Val* lhs, Val* rhs);
92
+ NVF_API static Val* minExpr(Val* lhs, Val* rhs);
93
+ NVF_API static Val* gcdExpr(Val* lhs, Val* rhs);
94
+ NVF_API static Val* isDivisibleExpr(Val* dividend, Val* divisor);
95
+
96
+ // Ternary operations
97
+ NVF_API static Val* whereExpr(Val* pred, Val* lhs, Val* rhs);
98
+
99
+ // Array and struct access
100
+ NVF_API static Val* getItemExpr(Val* array, Val* index);
101
+ NVF_API static Val* getItemExpr(Val* array, PolymorphicValue index);
102
+ NVF_API static Val* getAttrExpr(Val* struct_, std::string attr);
103
+ NVF_API static Val* reverseArrayExpr(Val* array);
104
+
105
+ // Get tensor metadata
106
+ NVF_API static Val* metadataExpr(TensorView* tv);
107
+
108
+ // Get tensor base address, for gmem tensor, it is something like
109
+ // `T1.data`. For smem tensor, it is something like `toSmem(T1)`.
110
+ static Val* baseAddressExpr(TensorView* tv);
111
+
112
+ // Construct an array of values, or nested arrays of values.
113
+ template <typename T>
114
+ static Val* arrayExpr(std::vector<T> members) {
115
+ if constexpr (std::is_same_v<T, Val*>) {
116
+ NVF_ERROR(!members.empty(), "Cannot create an array with no members.");
117
+ auto in_dtype = members.at(0)->dtype();
118
+ auto out_dtype =
119
+ ArrayType{std::make_shared<DataType>(in_dtype), members.size()};
120
+ auto out = create<Val>(out_dtype);
121
+ create<ArrayConstruct>(out, members);
122
+ return out;
123
+ } else {
124
+ static_assert(
125
+ is_std_vector_v<T>,
126
+ "Argument for function array must be vector of value or nested vector");
127
+ std::vector<Val*> array_members;
128
+ std::transform(
129
+ members.begin(),
130
+ members.end(),
131
+ std::back_inserter(array_members),
132
+ [](const T& member) { return arrayExpr(member); });
133
+ return arrayExpr(array_members);
134
+ }
135
+ }
136
+
137
+ template <typename T = NotImplementedStruct>
138
+ static Val* structExpr(
139
+ const std::vector<std::pair<std::string, Val*>>& fields,
140
+ std::string name = "") {
141
+ std::vector<StructType::FieldInfo> field_infos;
142
+ field_infos.reserve(fields.size());
143
+ for (auto& field : fields) {
144
+ field_infos.emplace_back(StructType::FieldInfo{
145
+ field.first,
146
+ std::make_shared<DataType>(field.second->dtype()),
147
+ true});
148
+ }
149
+ DataType dtype =
150
+ StructType::make<T>(std::move(field_infos), std::move(name));
151
+ auto out = create<Val>(dtype);
152
+ create<StructConstruct>(out, fields);
153
+ return out;
154
+ }
155
+
156
+ private:
157
+ static Val* newArithmeticExpr(BinaryOpType op_type, Val* lhs, Val* rhs);
158
+ static Val* newLogicExpr(BinaryOpType op_type, Val* lhs, Val* rhs);
159
+ };
160
+
161
+ //! A wrapper builder with static expression simplification
162
+ //!
163
+ //! Example:
164
+ //! - addExpr(new Scalar(DataType::Int, 1), new Scalar(DataType::Int, 2)) ->
165
+ //! Scalar(DataType::Int, 3)
166
+ //! - addExpr(new Scalar(DataType::Int, 0), new NamedScalar("foo")) ->
167
+ //! NamedScalar("foo")
168
+ //!
169
+ //! Designed to be used to simplify predicate and index expressions in
170
+ //! generated code. Also, the shift validation may fail without
171
+ //! this simplification.
172
+ class SimplifyingIrBuilder : public IrBuilder {
173
+ public:
174
+ static Val* negExpr(Val* val);
175
+ static Val* logicalNotExpr(Val* val);
176
+ static Val* bitwiseNotExpr(Val* val);
177
+ static Val* maybeCastExpr(DataType dtype, Val* val);
178
+
179
+ static Val* addExpr(
180
+ Val* lhs,
181
+ PolymorphicValue rhs,
182
+ DataType rhs_dtype = DataType::Null);
183
+ static Val* addExpr(Val* lhs, Val* rhs);
184
+
185
+ static Val* subExpr(Val* lhs, Val* rhs);
186
+
187
+ NVF_API static Val* mulExpr(
188
+ Val* lhs,
189
+ PolymorphicValue rhs,
190
+ DataType rhs_dtype = DataType::Null);
191
+ static Val* mulExpr(Val* lhs, Val* rhs);
192
+ static Val* divExpr(Val* lhs, Val* rhs);
193
+
194
+ static Val* ceilDivExpr(Val* lhs, Val* rhs);
195
+
196
+ static Val* modExpr(Val* lhs, Val* rhs);
197
+ static Val* logicalAndExpr(Val* lhs, Val* rhs);
198
+ static Val* logicalOrExpr(Val* lhs, Val* rhs);
199
+ static Val* bitwiseAndExpr(Val* lhs, Val* rhs);
200
+ static Val* bitwiseOrExpr(Val* lhs, Val* rhs);
201
+ static Val* maxExpr(Val* lhs, Val* rhs);
202
+ static Val* minExpr(Val* lhs, Val* rhs);
203
+ static Val* gcdExpr(Val* lhs, Val* rhs);
204
+
205
+ static Val* ltExpr(Val* lhs, Val* rhs);
206
+ static Val* leExpr(Val* lhs, Val* rhs);
207
+ static Val* eqExpr(Val* lhs, Val* rhs);
208
+ static Val* neExpr(Val* lhs, Val* rhs);
209
+ static Val* geExpr(Val* lhs, Val* rhs);
210
+ static Val* gtExpr(Val* lhs, Val* rhs);
211
+
212
+ static Val* whereExpr(Val* pred, Val* lhs, Val* rhs);
213
+ };
214
+
215
+ } // namespace nvfuser
@@ -0,0 +1,29 @@
1
+ // clang-format off
2
+ /*
3
+ * SPDX-FileCopyrightText: Copyright (c) 2023-present NVIDIA CORPORATION & AFFILIATES.
4
+ * All rights reserved.
5
+ * SPDX-License-Identifier: BSD-3-Clause
6
+ */
7
+ // clang-format on
8
+ #pragma once
9
+
10
+ namespace nvfuser {
11
+
12
+ class IrContainer;
13
+
14
+ // Passkey for builder to register properties with statements, and to call
15
+ // functions in IrContainer
16
+ class IrBuilderPasskey {
17
+ friend class IrBuilder;
18
+
19
+ public:
20
+ // TODO: Collapse ir_container and Kernel once Kernel inherits from
21
+ // IrContainer
22
+ IrContainer* const ir_container_ = nullptr;
23
+
24
+ private:
25
+ explicit IrBuilderPasskey(IrContainer* ir_container)
26
+ : ir_container_(ir_container) {}
27
+ };
28
+
29
+ } // namespace nvfuser
@@ -0,0 +1,185 @@
1
+ // clang-format off
2
+ /*
3
+ * SPDX-FileCopyrightText: Copyright (c) 2023-present NVIDIA CORPORATION & AFFILIATES.
4
+ * All rights reserved.
5
+ * SPDX-License-Identifier: BSD-3-Clause
6
+ */
7
+ // clang-format on
8
+ #pragma once
9
+
10
+ #include <disjoint_set.h>
11
+ #include <dispatch.h>
12
+ #include <exceptions.h>
13
+ #include <ir/builder.h>
14
+ #include <visibility.h>
15
+
16
+ #include <tuple>
17
+ #include <unordered_map>
18
+ #include <unordered_set>
19
+ #include <vector>
20
+
21
+ namespace nvfuser {
22
+
23
+ class IrContainer;
24
+
25
+ //! Clones nodes from an exiting Fusion
26
+ //!
27
+ //! \warning IrCloner machinery is a specialized helper for implementing
28
+ //! Fusion copy operations and the and limited scope of RecomputeTv below.
29
+ //! It is not intended for any other uses.
30
+ //!
31
+ class IrCloner {
32
+ friend class Statement;
33
+ friend class IrBuilder;
34
+
35
+ public:
36
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
37
+ explicit IrCloner(IrContainer* container);
38
+ virtual ~IrCloner() = default;
39
+
40
+ NVF_API Statement* clone(const Statement* statement);
41
+
42
+ int64_t clone(int64_t x) {
43
+ return x;
44
+ }
45
+
46
+ template <class T>
47
+ T* clone(const T* node) {
48
+ return node ? clone(node->template as<Statement>())->template as<T>()
49
+ : nullptr;
50
+ }
51
+
52
+ template <class T>
53
+ std::vector<T> clone(const std::vector<T>& container) {
54
+ // NOLINTNEXTLINE(cppcoreguidelines-init-variables)
55
+ std::vector<T> copy;
56
+ copy.reserve(container.size());
57
+ for (auto p : container) {
58
+ copy.push_back(clone(p));
59
+ }
60
+ return copy;
61
+ }
62
+
63
+ template <class T>
64
+ std::unordered_set<T> clone(const std::unordered_set<T>& container) {
65
+ std::unordered_set<T> copy;
66
+ copy.reserve(container.size());
67
+ for (auto p : container) {
68
+ copy.insert(clone(p));
69
+ }
70
+ return copy;
71
+ }
72
+
73
+ template <typename... Ts>
74
+ std::tuple<Ts...> clone(const std::tuple<Ts...>& tup) {
75
+ return std::apply(
76
+ [this](auto&... x) {
77
+ return std::make_tuple<Ts...>(this->clone(x)...);
78
+ },
79
+ tup);
80
+ }
81
+
82
+ template <typename T, typename U>
83
+ std::pair<T, U> clone(const std::pair<T, U>& p) {
84
+ return std::make_pair<T, U>(this->clone(p.first), this->clone(p.second));
85
+ }
86
+
87
+ template <class T, class U>
88
+ std::unordered_map<T, U> clone(const std::unordered_map<T, U>& container) {
89
+ std::unordered_map<T, U> copy;
90
+ copy.reserve(container.size());
91
+ for (const auto& [k, v] : container) {
92
+ copy.emplace(clone(k), clone(v));
93
+ }
94
+ return copy;
95
+ }
96
+
97
+ template <typename T, typename Hash = std::hash<T>>
98
+ DisjointSets<T, Hash> clone(const DisjointSets<T, Hash>& disjoint_sets) {
99
+ DisjointSets<T, Hash> cloned_disjoint_sets;
100
+ for (const auto& original_set : disjoint_sets.disjointSets()) {
101
+ NVF_ERROR(!original_set->empty());
102
+ bool first = true;
103
+ typename DisjointSets<T, Hash>::DisjointSet new_set;
104
+ for (const auto& val : *original_set) {
105
+ auto clone_of_val = clone(val);
106
+ if (first) {
107
+ auto it = cloned_disjoint_sets.initializeSet(clone_of_val).first;
108
+ new_set = it->second;
109
+ first = false;
110
+ } else {
111
+ cloned_disjoint_sets.appendToSet(clone_of_val, new_set);
112
+ }
113
+ }
114
+ }
115
+
116
+ return cloned_disjoint_sets;
117
+ }
118
+
119
+ IrContainer* container() const {
120
+ return ir_container_;
121
+ }
122
+
123
+ protected:
124
+ NVF_API void registerClone(const Statement* src, Statement* clone);
125
+ virtual Statement* handle(const Statement* s);
126
+
127
+ protected:
128
+ // We keep track of the original -> clone map so we don't
129
+ // duplicate clones of the same object if referenced multiple times
130
+ std::unordered_map<const Statement*, Statement*> clones_map_;
131
+
132
+ private:
133
+ // The destination Fusion container
134
+ IrContainer* ir_container_ = nullptr;
135
+
136
+ // Builder to make all the new nodes
137
+ IrBuilder builder_;
138
+ };
139
+
140
+ // Replicates all expressions used to generate the provided TensorView. Does not
141
+ // replicate inputs. Does not replicate scalar values. In other words the value
142
+ // provided will be recomputed from the inputs of the fusion.
143
+ class RecomputeTv : private IrCloner {
144
+ public:
145
+ // Replicates expressions and values in provided expressions.
146
+ NVF_API static TensorView* recompute(
147
+ TensorView* tv,
148
+ const std::vector<Val*>& from = {});
149
+
150
+ private:
151
+ RecomputeTv(Fusion* fusion);
152
+ Statement* handle(const Statement* s) override;
153
+ Statement* handle(const TensorDomain*);
154
+ };
155
+
156
+ //! Clone an IR node, forwarding the arguments to the IrCloner constructor.
157
+ template <class T>
158
+ T* IrBuilder::clone(const T* src, IrCloner* ir_cloner) {
159
+ NVF_ERROR(
160
+ ir_cloner != nullptr,
161
+ "Cannot use create when a cloner object is set. Use clone.");
162
+
163
+ NVF_ERROR(
164
+ ir_cloner->container() != nullptr,
165
+ "Cloner doesn't have a valid container to store cloned object.");
166
+
167
+ T* dest = new T(src, ir_cloner);
168
+ const Statement* src_stmt = dynamic_cast<const Statement*>(src);
169
+ Statement* dest_stmt = dynamic_cast<Statement*>(dest);
170
+
171
+ auto dest_container = ir_cloner->container();
172
+ auto src_container = src_stmt->container();
173
+
174
+ dest_container->registerStmt(IrBuilderPasskey(dest_container), dest_stmt);
175
+
176
+ if (src_container != dest_container) {
177
+ dest_stmt->setName(IrBuilderPasskey(dest_container), src_stmt->name());
178
+ }
179
+
180
+ ir_cloner->registerClone(src_stmt, dest_stmt);
181
+
182
+ return dest;
183
+ }
184
+
185
+ } // namespace nvfuser
@@ -0,0 +1,226 @@
1
+ // clang-format off
2
+ /*
3
+ * SPDX-FileCopyrightText: Copyright (c) 2023-present NVIDIA CORPORATION & AFFILIATES.
4
+ * All rights reserved.
5
+ * SPDX-License-Identifier: BSD-3-Clause
6
+ */
7
+ // clang-format on
8
+ #pragma once
9
+
10
+ #include <exceptions.h>
11
+ #include <visibility.h>
12
+
13
+ #include <ir/base_nodes.h>
14
+ #include <utils.h>
15
+
16
+ #include <deque>
17
+ #include <unordered_map>
18
+ #include <unordered_set>
19
+
20
+ namespace nvfuser {
21
+
22
+ class IrBuilderPasskey;
23
+ class ExprPasskey;
24
+ class OptOutMutator;
25
+
26
+ class NamedScalar;
27
+
28
+ // Passkey for container to register names with statements
29
+ class IrContainerPasskey {
30
+ friend class IrContainer;
31
+
32
+ private:
33
+ explicit IrContainerPasskey() = default;
34
+ };
35
+
36
+ class IrContainer : public PolymorphicBase {
37
+ public:
38
+ NVF_API IrContainer();
39
+
40
+ IrContainer(const IrContainer& other);
41
+ IrContainer(IrContainer&& other) noexcept;
42
+
43
+ IrContainer& operator=(const IrContainer& other);
44
+ IrContainer& operator=(IrContainer&& other) noexcept;
45
+
46
+ ~IrContainer() override;
47
+
48
+ bool inContainer(const Statement* stmt) const;
49
+
50
+ void assertInContainer(const Statement* stmt, const std::string& msg) const {
51
+ NVF_CHECK(
52
+ inContainer(stmt), msg, " it was not found in the active container.");
53
+ }
54
+
55
+ //! Return values in insertion order
56
+ const std::deque<Val*> deterministic_vals() const noexcept {
57
+ std::deque<Val*> vals_deque;
58
+ std::transform(
59
+ vals_up_.begin(),
60
+ vals_up_.end(),
61
+ std::back_inserter(vals_deque),
62
+ [](const std::unique_ptr<Val>& val_up) { return val_up.get(); });
63
+ return vals_deque;
64
+ }
65
+
66
+ //! Return expression in insertion order
67
+ const std::deque<Expr*> deterministic_exprs() const noexcept {
68
+ std::deque<Expr*> exprs_deque;
69
+ std::transform(
70
+ exprs_up_.begin(),
71
+ exprs_up_.end(),
72
+ std::back_inserter(exprs_deque),
73
+ [](const std::unique_ptr<Expr>& expr_up) { return expr_up.get(); });
74
+ return exprs_deque;
75
+ }
76
+
77
+ //! Return mapping from value to integer id
78
+ const std::unordered_map<Val*, int64_t> deterministic_vals_map()
79
+ const noexcept {
80
+ std::unordered_map<Val*, int64_t> vals_map;
81
+ int64_t count = 0;
82
+ std::transform(
83
+ vals_up_.begin(),
84
+ vals_up_.end(),
85
+ std::inserter(vals_map, vals_map.end()),
86
+ [&count](const std::unique_ptr<Val>& val_up) {
87
+ return std::make_pair(val_up.get(), count++);
88
+ });
89
+ return vals_map;
90
+ }
91
+
92
+ //! Return mapping from expression to integer id
93
+ const std::unordered_map<Expr*, int64_t> deterministic_exprs_map()
94
+ const noexcept {
95
+ std::unordered_map<Expr*, int64_t> exprs_map;
96
+ int64_t count = 0;
97
+ std::transform(
98
+ exprs_up_.begin(),
99
+ exprs_up_.end(),
100
+ std::inserter(exprs_map, exprs_map.end()),
101
+ [&count](const std::unique_ptr<Expr>& expr_up) {
102
+ return std::make_pair(expr_up.get(), count++);
103
+ });
104
+ return exprs_map;
105
+ }
106
+
107
+ //! Register the Statement with this container
108
+ NVF_API virtual void registerStmt(IrBuilderPasskey, Statement* stmt);
109
+
110
+ //! Register the Val with this container
111
+ NVF_API virtual void registerVal(IrBuilderPasskey, Val* val);
112
+
113
+ //! Register expr with this container.
114
+ NVF_API virtual void registerExpr(IrBuilderPasskey, Expr* expr);
115
+
116
+ //! Return the set of Exprs registered with this fusion. Warning: This will
117
+ //! return exprs outside inputs/outputs, so can be unsafe for use with
118
+ //! segmented fusions.
119
+ const std::unordered_set<Expr*>& unordered_exprs() const noexcept {
120
+ return exprs_;
121
+ }
122
+
123
+ //! Return the set of Vals registered with this fusion
124
+ const std::unordered_set<Val*>& vals() const noexcept {
125
+ return vals_;
126
+ }
127
+
128
+ // Shortcuts for frequently used vals
129
+ NVF_API Val* zeroVal();
130
+ NVF_API Val* oneVal();
131
+ Val* falseVal();
132
+ Val* trueVal();
133
+ NamedScalar* magicZeroVal();
134
+ NVF_API Val* zeroVal(DataType dtype);
135
+ NVF_API Val* oneVal(DataType dtype);
136
+ Val* metadataOf(Val*);
137
+
138
+ // Axioms about CUDA programming, for example: threadIdx.x < blockDim.x
139
+ const std::vector<Val*>& axioms() {
140
+ lazyInitAxioms();
141
+ return *axioms_;
142
+ }
143
+
144
+ void assumePositive(Val* val);
145
+ void assumeNonNegative(Val* val);
146
+
147
+ protected:
148
+ static IrCloner copy(const IrContainer* from, IrContainer* to);
149
+
150
+ friend void swap(IrContainer& a, IrContainer& b) noexcept;
151
+
152
+ // Let mutator remove Exprs.
153
+ friend OptOutMutator;
154
+
155
+ virtual void removeExpr(Expr* expr);
156
+
157
+ //! Completely remove val from the fusion, break all dependencies associated
158
+ //! with it
159
+ virtual void removeVal(Val* val);
160
+
161
+ //! Register the Val with this container
162
+ virtual void registerVal(Val* val);
163
+
164
+ //! Register expr with this container.
165
+ virtual void registerExpr(Expr* expr);
166
+
167
+ StmtNameType getValName(ValType vtype) {
168
+ if (val_type_name_map_.find(vtype) == val_type_name_map_.end()) {
169
+ val_type_name_map_[vtype] = 0;
170
+ }
171
+ return val_type_name_map_[vtype]++;
172
+ }
173
+
174
+ StmtNameType getExprName() {
175
+ return expr_name_counter_++;
176
+ }
177
+
178
+ void clear() noexcept;
179
+
180
+ void lazyInitAxioms();
181
+
182
+ // Deque of unique pointer is the memory owning data structure
183
+ std::deque<std::unique_ptr<Val>> vals_up_;
184
+
185
+ // A convenient set to return when we just need an unordered set to do
186
+ // something like check if a Val is in this container
187
+ std::unordered_set<Val*> vals_;
188
+
189
+ // Deque of unique pointer is the memory owning data structure
190
+ std::deque<std::unique_ptr<Expr>> exprs_up_;
191
+
192
+ // A convenient set to return when we just need an unordered set to do
193
+ // something like check if an Expr is in this container
194
+ std::unordered_set<Expr*> exprs_;
195
+
196
+ // Used to implement a generic "inContainer" that can be passed an invalid
197
+ // pointer. Specifically a pointer to a Statement owned by another container
198
+ // that has been freed. We can't check normally with the unordered_sets we
199
+ // already have because it would require a const_cast from a constant
200
+ // expr/val, or a dynamic cast from a Statement.
201
+ std::unordered_set<void*> raw_ptrs_;
202
+
203
+ // Values names counters
204
+ std::unordered_map<ValType, StmtNameType> val_type_name_map_;
205
+
206
+ // Expression names counter
207
+ StmtNameType expr_name_counter_ = 0;
208
+
209
+ // Manually store some persistent, frequently used nodes. It's very
210
+ // challenging to do this anything but manually as detecting when a container
211
+ // may or may not have one of these vals is tricky. Specifically because if
212
+ // the container doesn't own it, it's hard to understand from the outside if
213
+ // the node may have been removed then re-registered. It could also be tricky
214
+ // to know when we're using a different container as in FusionCopy_test
215
+ // demonstrates deleting then creating containers can result in the same
216
+ // pointer for the container.
217
+ std::unique_ptr<Val> true_val_;
218
+ std::unique_ptr<Val> false_val_;
219
+ std::unique_ptr<Val> one_val_;
220
+ std::unique_ptr<Val> zero_val_;
221
+ std::unique_ptr<NamedScalar> magic_zero_val_;
222
+ std::unique_ptr<std::vector<Val*>> axioms_;
223
+ std::unordered_map<Val*, std::pair<Val*, Expr*>> metadata_;
224
+ };
225
+
226
+ } // namespace nvfuser