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,143 @@
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
+ #include <exceptions.h>
10
+ #include <ir/interface_nodes.h>
11
+ #include <serde/fusion_cache_generated.h>
12
+ #include <visibility.h>
13
+
14
+ namespace nvfuser::python_frontend {
15
+
16
+ struct RecordFunctor;
17
+
18
+ struct State {
19
+ State()
20
+ : index(0),
21
+ stype(serde::StateType::None),
22
+ inline_def_record_(std::nullopt) {}
23
+ State(
24
+ size_t _index,
25
+ serde::StateType _stype,
26
+ std::optional<const RecordFunctor*> inline_def_record = std::nullopt)
27
+ : index(_index), stype(_stype), inline_def_record_(inline_def_record) {}
28
+
29
+ bool inlineDef() const;
30
+ void setInlineDefRecord(const RecordFunctor* record);
31
+ const RecordFunctor* inlineDefRecord() const;
32
+
33
+ bool operator==(const State& other) const;
34
+ bool operator!=(const State& other) const;
35
+
36
+ //! A unique index to identifiy each recorded state item.
37
+ size_t index;
38
+ //! StateType is either: Tensor, Scalar, or Vector
39
+ serde::StateType stype;
40
+
41
+ private:
42
+ // This data member is only set if this state is inline defined!
43
+ std::optional<const RecordFunctor*> inline_def_record_;
44
+ };
45
+
46
+ NVF_API std::ostream& operator<<(std::ostream& os, const State& state);
47
+
48
+ //! Get extents for TensorView inputs in Fusion
49
+ std::vector<Val*> getExtents(Fusion* fusion);
50
+
51
+ //! FusionState contains the information used to build a new cpp Fusion object.
52
+ //! Unlike FusionDefinition, it does not modify the FusionCache Trie structure.
53
+ class FusionState {
54
+ public:
55
+ FusionState();
56
+
57
+ // The copy/move/assign constructors/operators are removed
58
+ FusionState(const FusionState& other) = delete;
59
+ FusionState(FusionState&& other) noexcept = delete;
60
+ FusionState& operator=(const FusionState& other) = delete;
61
+ FusionState& operator=(FusionState&& other) noexcept = delete;
62
+ virtual ~FusionState() = default;
63
+
64
+ //! Get fusion object
65
+ Fusion* fusion();
66
+ //! Prints the Fusion IR representation
67
+ void printIr() const;
68
+
69
+ //! Adds a Fusion IR Tensor/Scalar object
70
+ NVF_API void addFusionState(Val* val);
71
+ //! Adds a Fusion IR Vector of Scalars
72
+ void addFusionStateVector(std::vector<Val*> val);
73
+ //! Gets a Fusion IR Tensor/Scalar object
74
+ NVF_API Val* getFusionState(size_t index) const;
75
+ //! Gets a Fusion IR Vector of Scalars
76
+ NVF_API const std::vector<Val*>& getFusionStateVector(size_t index) const;
77
+ //! Number of fusion states
78
+ NVF_API size_t numFusionStates() const;
79
+ //! Sets a Fusion IR Tensor/Scalar object
80
+ NVF_API void setFusionState(size_t index, Val* val);
81
+ //! Sets a Fusion IR Vector of Scalars
82
+ NVF_API void setFusionStateVector(size_t index, std::vector<Val*> val);
83
+
84
+ //! Adds a Tensor/Scalar input to the Fusion object
85
+ NVF_API void addInput(Val* input, size_t index);
86
+ //! Adds a Tensor/Scalar output to the Fusion object
87
+ NVF_API void addOutput(Val* output, size_t index);
88
+ //! Alias an Output to Input in the Fusion object
89
+ NVF_API void aliasOutputToInput(Val* output, Val* input);
90
+
91
+ //! Get map between CPP Fusion and Python FusionDefinition
92
+ NVF_API const std::unordered_map<const Val*, int64_t>& getValueMap() const;
93
+ //! Get indicies for the inputs of FusionState
94
+ NVF_API const std::vector<int64_t>& inputs() const;
95
+ //! Get indicies for the outputs of FusionState
96
+ NVF_API const std::vector<int64_t>& outputs() const;
97
+ //! Get indicies for the extents of TensorView inputs of FusionState
98
+ NVF_API const std::vector<int64_t>& extents() const;
99
+
100
+ //! Add a Record
101
+ void addRecord(RecordFunctor* record);
102
+ //! Builds an nvFuser Fusion IR object
103
+ void buildFusionIr(Fusion* fusion);
104
+
105
+ //! Create clone of FusionState
106
+ std::unique_ptr<FusionState> clone();
107
+
108
+ private:
109
+ //! Add extents of TensorView inputs to FusionState
110
+ void addExtents();
111
+ //! Change the fusion ptr and reset its state
112
+ void resetFusionState(Fusion* fusion, size_t size);
113
+
114
+ protected:
115
+ //! Holds an End Record
116
+ std::unique_ptr<RecordFunctor> end_record_;
117
+ //! A vector of record operations in the FusionDefintion
118
+ std::vector<std::unique_ptr<RecordFunctor>> recording_;
119
+ //! A vector of state that represents Tensors/Vectors/Scalars
120
+ std::vector<State> recording_state_;
121
+ //! Input arguments for FusionState
122
+ std::vector<int64_t> inputs_fid_;
123
+ //! Output arguments for FusionState
124
+ std::vector<int64_t> outputs_fid_;
125
+ //! Extents for TensorView input arguments for FusionState
126
+ std::vector<int64_t> extents_fid_;
127
+ //! Map Fusion Val to its corresponding FusionDefinition index
128
+ std::unordered_map<const Val*, int64_t> map_value_to_fid_;
129
+
130
+ private:
131
+ //! A ptr to the container used when building the Fusion IR from a definition
132
+ Fusion* fusion_ = nullptr;
133
+ //! A vector of nvFuser Fusion IR TensorViews/Vectors/Scalars for building the
134
+ //! Fusion IR graph.
135
+ //! NOTE: Vectors are represented by a vector<Val*>. This could
136
+ //! be another child class of Val in the IR, similar to TensorView.
137
+ std::vector<std::vector<Val*>> fusion_state_;
138
+ //! The number of states in Fusion Container
139
+ //! A sum of all outputs for each RecordFunctor
140
+ size_t num_recording_states_;
141
+ };
142
+
143
+ } // namespace nvfuser::python_frontend
@@ -0,0 +1,27 @@
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 <torch/csrc/jit/python/pybind.h>
11
+ #include <torch/csrc/utils/pybind.h>
12
+
13
+ #include <python_frontend/fusion_definition.h>
14
+ #include <visibility.h>
15
+
16
+ namespace nvfuser::python_frontend {
17
+
18
+ NVF_API void initNvFuserPythonBindings(PyObject* module);
19
+
20
+ // Add bindings for multi-GPU capabilities, e.g., DeviceMesh and Communicator.
21
+ void bindMultidevice(py::module& nvfuser);
22
+
23
+ void bindSchedule(py::class_<FusionDefinition>& fusion_def);
24
+
25
+ NVF_API void cleanup();
26
+
27
+ } // namespace nvfuser::python_frontend
@@ -0,0 +1,246 @@
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 <python_frontend/fusion_definition.h>
11
+ #include <python_frontend/fusion_state.h>
12
+ #include <runtime/fusion_executor_cache.h>
13
+
14
+ namespace nvfuser::python_frontend {
15
+
16
+ class FusionDefinition;
17
+
18
+ //! Overview:
19
+ //! Segmentation decomposes a fusion into a directed acyclic graph (DAG) of
20
+ //! sub-fusions. After applying the segmentation algorithm, we can translate
21
+ //! the sub-fusions into their corresponding python definitions. Then, given the
22
+ //! fusion's input arguments, the segments are run in the correct order to
23
+ //! produce the output results.
24
+ //!
25
+ //! Each FusionDefinition contains a set of states representing tensors, vectors
26
+ //! and scalars. Every state has a unique index, which matches the insertion
27
+ //! order of the state in the FusionDefinition. These indices form a linear
28
+ //! index space for each FusionDefinition.
29
+ //!
30
+ //! The original FusionDefinition stores the sequence of sub-fusions and acts as
31
+ //! an argument manager. It gathers the input arguments before running the
32
+ //! sub-fusion and stores its results. To perform this function, it requires a
33
+ //! map from the segment index space to the original index space. This mapping
34
+ //! is generated while creating the python definition for each sub-fusion.
35
+ //!
36
+ //! Algorithm:
37
+ //! Step 1: setupSegmentation runs the segmentation algorithm on the CPP Fusion
38
+ //! to create the SegmentedFusion. Then, sub-fusions are ordered according to
39
+ //! their dependencies by the prepareGroupOrder function. It returns the number
40
+ //! of segments in SegmentedFusion.
41
+ //!
42
+ //! Step 2: buildSegment creates the CPP Fusion for a given segment id,
43
+ //! translates it to a python FusionDefinition, then returns a mapping from the
44
+ //! segment fusion state indices to the original fusion state indices.
45
+ //!
46
+ //! ===========================================================================
47
+ //!
48
+ //! Example 1: A simple fusion with two iota operations.
49
+ //!
50
+ //! Original Fusion:
51
+ //! def nvfuser_fusion_id1(fd : FusionDefinition) -> None :
52
+ //! S0 = fd.define_scalar(2, dtype=DataType.Int)
53
+ //! S1 = fd.define_scalar(0, dtype=DataType.Int)
54
+ //! S2 = fd.define_scalar(2, dtype=DataType.Int)
55
+ //! T3 = fd.ops.iota(S0, S1, S2, dtype=DataType.Int)
56
+ //! S4 = fd.define_scalar(3, dtype=DataType.Int)
57
+ //! S5 = fd.define_scalar(100, dtype=DataType.Int32)
58
+ //! S6 = fd.define_scalar(1, dtype=DataType.Int32)
59
+ //! T7 = fd.ops.iota(S4, S5, S6, dtype=DataType.Int32)
60
+ //! fd.add_output(T3)
61
+ //! fd.add_output(T7)
62
+ //!
63
+ //! After Segmentation:
64
+ //! The original fusion is divided into two segments. There is no dependencies
65
+ //! between either segment so they can run in any order.
66
+ //!
67
+ //! First Segment:
68
+ //! def nvfuser_fusion_id2(fd : FusionDefinition) -> None :
69
+ //! S0 = fd.define_scalar(2, dtype=DataType.Int)
70
+ //! S1 = fd.define_scalar(0, dtype=DataType.Int)
71
+ //! S2 = fd.define_scalar(2, dtype=DataType.Int)
72
+ //! T3 = fd.ops.iota(S0, S1, S2, dtype=DataType.Int)
73
+ //! fd.add_output(T3)
74
+ //!
75
+ //! Second Segment:
76
+ //! def nvfuser_fusion_id3(fd : FusionDefinition) -> None :
77
+ //! S0 = fd.define_scalar(3, dtype=DataType.Int)
78
+ //! S1 = fd.define_scalar(100, dtype=DataType.Int32)
79
+ //! S2 = fd.define_scalar(1, dtype=DataType.Int32)
80
+ //! T3 = fd.ops.iota(S0, S1, S2, dtype=DataType.Int32)
81
+ //! fd.add_output(T3)
82
+ //!
83
+ //! The first segment corresponds with [S0, S1, S2, T3] in the original fusion.
84
+ //! The second segment corresponds with [S4, S5, S6, S7] in the original fusion.
85
+ //!
86
+ //! Neither segment requires any input arguments from the original fusion.
87
+ //!
88
+ //! For the first segment, the segment's T3 is mapped to the original's T3.
89
+ //! Segment Index : Original Index Mapping
90
+ //! --------------------------------------
91
+ //! T3 : T3
92
+ //!
93
+ //! For the second segment the segment's T3 is mapped to the original's T7.
94
+ //! Segment Index : Original Index Mapping
95
+ //! --------------------------------------
96
+ //! T3 : T7
97
+ //!
98
+ //! ===========================================================================
99
+ //!
100
+ //! Example 2: A reduction + broadcast + pointwise fusion.
101
+ //!
102
+ //! Original Fusion:
103
+ //! def nvfuser_fusion_id1(fd : FusionDefinition) -> None :
104
+ //! T0 = fd.define_tensor(shape=[-1, -1],
105
+ //! contiguity=[True, True],
106
+ //! dtype=DataType.Float,
107
+ //! is_cpu=False)
108
+ //! T1 = fd.define_tensor(shape=[-1, -1],
109
+ //! contiguity=[True, True],
110
+ //! dtype=DataType.Float,
111
+ //! is_cpu=False)
112
+ //! T2 = fd.ops.sum(T0, dims=[1], keepdim=False, dtype=DataType.Float)
113
+ //! T3 = fd.ops.broadcast(T2, is_broadcast_dim=[False, True])
114
+ //! T4 = fd.ops.add(T1, T3)
115
+ //! fd.add_output(T4)
116
+ //!
117
+ //! After Segmentation:
118
+ //! The reduction scheduler does not support fusing any operations with an
119
+ //! inner reduction, so the original fusion is divided into two segments.
120
+ //! Segment 2 depends on Segment 1, so there is a strict segment ordering.
121
+ //!
122
+ //! First Segment:
123
+ //! def nvfuser_fusion_id2(fd : FusionDefinition) -> None :
124
+ //! T0 = fd.define_tensor(shape=[-1, -1],
125
+ //! contiguity=[True, True],
126
+ //! dtype=DataType.Float,
127
+ //! is_cpu=False)
128
+ //! T1 = fd.ops.sum(T0, dims=[1], keepdim=False, dtype=DataType.Float)
129
+ //! T2 = fd.ops.broadcast(T1, is_broadcast_dim=[False, True])
130
+ //! fd.add_output(T2)
131
+ //!
132
+ //! Second Segment:
133
+ //! def nvfuser_fusion_id3(fd : FusionDefinition) -> None :
134
+ //! T0 = fd.define_tensor(shape=[-1, -1],
135
+ //! contiguity=[True, True],
136
+ //! dtype=DataType.Float,
137
+ //! is_cpu=False)
138
+ //! T1 = fd.define_tensor(shape=[-1, 1],
139
+ //! contiguity=[True, None],
140
+ //! dtype=DataType.Float,
141
+ //! is_cpu=False)
142
+ //! T2 = fd.ops.add(T0, T1)
143
+ //! fd.add_output(T2)
144
+ //!
145
+ //! The first segment contains the reduction and broadcast operations, which
146
+ //! corresponds with [T0, T2, T3] in the original fusion. Therefore, the segment
147
+ //! index to original index map has two entries.
148
+ //!
149
+ //! Segment Index : Original Index Mapping
150
+ //! --------------------------------------
151
+ //! T0 : T0 --- The first tensor argument for the original fusion.
152
+ //! T2 : T3 --- The broadcasted, reduction tensor is this segment's output.
153
+ //!
154
+ //! The second segment is the pointwise addition with the broadcasted reduction.
155
+ //! It corresponds with [T1, T3, T4] in the original fusion.
156
+ //!
157
+ //! Segment Index : Original Index Mapping
158
+ //! --------------------------------------
159
+ //! T0 : T1 --- The second tensor argument for the original fusion.
160
+ //! T1 : T3 --- The broadcasted, reduction tensor, which is the output from the
161
+ //! first segment.
162
+ //! T2 : T4 --- The pointwise addition, which is the output for the original
163
+ //! fusion.
164
+ //! ===========================================================================
165
+ class SegmentationState {
166
+ public:
167
+ // setupSegmentation runs the segmentation algorithm on CPP Fusion to create
168
+ // SegmentedFusion. It returns the number of segments in SegmentedFusion.
169
+ //
170
+ // Details:
171
+ // 1) Clone preschedFusion CPP Fusion.
172
+ // 2) Concretize fusion using input arguments.
173
+ // 3) Given the map_presched_value_to_original_python_index, the IRCloner
174
+ // returned by Fusion::copy, AND symbolic_to_concrete map returned by
175
+ // concretization pass, create a mapping from cloned Vals to original fusion
176
+ // state indices.
177
+ // 4) Get extents for cloned fusion.
178
+ // 5) Create SchedulerRuntimeInfo.
179
+ // 6) Run segmentation algorithm using cloned fusion, input arguments, and
180
+ // scheduler runtime information.
181
+ // 7) Get sequential order of fusion segments using prepareGroupOrder.
182
+ // 8) Return the number of segments created by segmentation algorithm.
183
+ int64_t setupSegmentation(
184
+ Fusion* fusion,
185
+ const std::unordered_map<const Val*, int64_t>&
186
+ map_presched_value_to_original_python_index,
187
+ const at::ArrayRef<c10::IValue>& inputs);
188
+
189
+ // Given an empty FusionDefinition and a segment id, buildSegment creates the
190
+ // CPP Fusion, translates it to the python FusionDefinition, then returns a
191
+ // mapping from segment fusion state indices to the original fusion state
192
+ // indices.
193
+ //
194
+ // The mapping is constructed from the segment's python definition ->
195
+ // segment's CPP Fusion -> original's CPP Fusion -> original's python
196
+ // definition.
197
+ //
198
+ // NOTE: Sometimes the python definition requires the extents from the
199
+ // original fusion's input tensors as extra arguments. Therefore, the input
200
+ // arguments for the python definition and the CPP Fusion may not exactly
201
+ // match.
202
+ NVF_API std::unordered_map<int64_t, int64_t> buildSegment(
203
+ FusionDefinition& segment_fd,
204
+ int64_t segment_id);
205
+
206
+ private:
207
+ // prepareGroupOrder is similar to prepareRuntimeOrder. It generates the
208
+ // topological order of SegmentedGroups in SegmentedFusion.
209
+ //
210
+ // Details:
211
+ // 1) Gather initial inputs for SegmentedFusion.
212
+ // 2) Gather IterDomain extents from the tensor input arguments.
213
+ // 3) Track the run status of all SegmentedGroups in SegmentedFusion
214
+ // 4) While not all the SegmentedGroups are run:
215
+ // 5) For each SegmentedGroup:
216
+ // 6) Skip SegmentedGroup if it is already run
217
+ // 7) Skip SegmentedGroup if inputs are not ready
218
+ // 8) Add SegmentedGroup to group_run_order_. Mark all outputs of
219
+ // SegmentedGroup as ready.
220
+ // 9) End For
221
+ // 10) Fail if none of the SegmentedGroups are available to run.
222
+ // 11) End While
223
+ void prepareGroupOrder();
224
+
225
+ private:
226
+ // Clone of original fusion for segmentation
227
+ std::unique_ptr<Fusion> cloned_original_fusion_ = nullptr;
228
+
229
+ // This FusionDefinition may require multiple kernels if it cannot be handled
230
+ // by a single heuristic scheduler. SegmentedFusion takes a fusion and runs
231
+ // the segmentation algorithm.
232
+ std::unique_ptr<SegmentedFusion> segmented_fusion_ = nullptr;
233
+
234
+ // Pre-determined order to run the segmented groups
235
+ std::vector<SegmentedGroup*> group_run_order_;
236
+
237
+ // Map values from cloned, concretized fusion to the indices of the original
238
+ // python definition.
239
+ std::unordered_map<const Val*, int64_t>
240
+ map_cloned_concretized_value_to_original_python_index_;
241
+
242
+ // Extents for TensorView input arguments for cloned Fusion
243
+ std::vector<Val*> cloned_original_extents_;
244
+ };
245
+
246
+ } // namespace nvfuser::python_frontend
@@ -0,0 +1,20 @@
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
+ #include <fusion.h>
10
+ #include <python_frontend/fusion_definition.h>
11
+ #include <python_frontend/fusion_record.h>
12
+
13
+ namespace nvfuser::python_frontend {
14
+
15
+ // Translate a CPP Fusion into a Python FusionDefinition.
16
+ std::unordered_map<const nvfuser::Val*, size_t> translate(
17
+ Fusion* fusion,
18
+ FusionDefinition* fd);
19
+
20
+ } // namespace nvfuser::python_frontend