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,349 @@
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 <compute_at_map.h>
11
+ #include <device_lower/analysis/divisible_split.h>
12
+ #include <exceptions.h>
13
+ #include <fusion.h>
14
+ #include <ir/all_nodes.h>
15
+ #include <scheduler/tools/maxinfo_propagator.h>
16
+ #include <visibility.h>
17
+ // TODO: Move to cpp file.
18
+ #include <ir/builder.h>
19
+
20
+ #include <sstream>
21
+ #include <unordered_map>
22
+ #include <utility>
23
+ #include <vector>
24
+
25
+ namespace nvfuser {
26
+
27
+ class SchedulerRuntimeInfo;
28
+ class HeuristicDataCache;
29
+
30
+ namespace vectorize_helper {
31
+
32
+ // Projects IterDomains through the fusion starting at provided reference. IDs
33
+ // in the reference are expected to be "contiguous", simply means dimensions
34
+ // that the iter domains are consecutive and next to each other in the
35
+ // reference. This property is not enforced, but mapping can have some
36
+ // unpredictbale results if they are not. The reason we want contiguity here
37
+ // is this class is primarily used for vectorization analysis. Domains may be
38
+ // inserted or removed while propogating through the fusion and this class has
39
+ // to be senstitive to that.
40
+ //
41
+ // For example:
42
+ // Input: T0[i0, i2]
43
+ // Reference: T5[i0, i1, i2]
44
+ // If we want to base the vectorization size on the reference being contiguous
45
+ // in a 1D scheduler, we'd start the proces on the reference with {i0, i1,
46
+ // i2}. When we propogate to the input what we would still like is: {i0, i1,
47
+ // i2} to signify to us that the root domains in the input that map to the
48
+ // reference are not contiguous. So when we think of vector word, if we want
49
+ // the input to be included in the vectorized dimensions, we can only check
50
+ // multiples based on i2, not i0*i1*i2 like the reference would indicate.
51
+ //
52
+ // Another example:
53
+ // Input:[i1, i0, i2]
54
+ // Refrence [i0, i1, i2]
55
+ // Similarly as above when we propogate from the reference to the Input we'd
56
+ // like {i0, i1, i2}, which is the order of the reference, not the input. This
57
+ // is because we can compare that with the input domains to understand it's
58
+ // not ordered consistently, so once again we can only take into consideration
59
+ // vectorization based on i2.
60
+ //
61
+ // Another example:
62
+ // Input:[i0, i1, i2]
63
+ // Intermediate: [i1, i0, i2]
64
+ // Refrence [i0, i1, i2]
65
+ // Keeping the ordering relative to the reference also allows us to look
66
+ // though transpose operations without missing out in a case like this that
67
+ // the reference and input are consistently ordered so we can look at i0*i1*i2
68
+ // for our vector multiple even though there are transposes in between them.
69
+ //
70
+ // The tricky part of this class is what happens through combinations of view
71
+ // and transpose. IterDomains are projected for example:
72
+ // tv0[2*3, 5*7, 11]
73
+ // tv1[2*3, 5, 7*11] = view(tv0)
74
+ // With tv1 and 7*11 as the reference and ids. When we project from tv1 to
75
+ // tv0, we'd map the inner most 11, but we also want to map the 5*7 with an
76
+ // extent of 7. This can get tricky though as:
77
+ // tv0[2, 3*5*7, 11]
78
+ // tv1[2*3, 5, 7*11] = view(tv0)
79
+ // with tv1 and [2*3, 7*11] as the reference and ids. tv0's 2 and 11 dim are
80
+ // easily identified as being mapped. The 3*5*7 dimension however, is
81
+ // partially mapped on the left and right side. Since this class is intended to
82
+ // line up "inner dimensions" of tensors through out the graph for the purpose
83
+ // of unrolling and vectorization, it only tracks partial dimensions as they are
84
+ // on the right hand side of iteration domains. For example in the last case we
85
+ // would only identify tv0's 3*5*7 dimension as being a mapping with extent 7.
86
+ // If we further had:
87
+ // tv0[5*7*11]
88
+ // tv1[5*7, 11] = view(tv0)
89
+ // tv2[5, 7*11] = view(tv1)
90
+ // with tv2 and [7*11] as the reference and ids (this could be a valid example
91
+ // from the pointwise scheduler).
92
+ // (1) tv1 would:
93
+ // map on 5*7 with extent 7
94
+ // map on 11 with extent 11.
95
+ // (1) tv0 would:
96
+ // map on 5*7*11 with size 7*11
97
+ //
98
+ // Finally if we have:
99
+ // tv0[3, 5, 7]
100
+ // tv1[7, 5, 3] = view(tv0)
101
+ // tv2[3, 5, 7] = view(tv1)
102
+ // with tv2 mapping on 5, 7
103
+ // We use fractional, symbolic, and conditional mappings so tv1:
104
+ // maps on 3 with extent 3
105
+ // maps on 5 with extent 5
106
+ // maps on 7 with extent (5*7)/(5*3)
107
+ // Then tv0:
108
+ // maps on 7 with extent 7
109
+ // maps on 5 with extent 5
110
+ //
111
+ // This class is responsible for both computing the spanning tree and running
112
+ // the spanning tree.
113
+ //
114
+ // In other words this class implements:
115
+ // MaxInfoSpanningTree::computeInfoC2P
116
+ // and
117
+ // MaxInfoSpanningTree::Propagator::propagateC2P
118
+ //
119
+ // The challenge here is the information we need for
120
+ // MaxInfoSpanningTree::computeInfoC2P is the same information we need to
121
+ // compute for MaxInfoSpanningTree::Propagator::propagateC2P
122
+ //
123
+ // We could compute both of these passes at the same time, only saving the
124
+ // result produced from processing the edge that's chosen from
125
+ // MaxInfoSpanningTree::computeInfoC2P while processing based on
126
+ // MaxInfoSpanningTree::Propagator::propagateC2P. However, this would require
127
+ // refactoring of MaxInfoSpanningTree so for right now this class just uses
128
+ // two passes.
129
+ //
130
+ // MaxInfoSpanningTree::computeInfoC2P runs first with recording_=false and
131
+ // will effectively compute the values of projected_root_ids_ and
132
+ // projected_logical_ids_. However it will compute these by running all edges
133
+ // between expressions. Therefore,
134
+ // MaxInfoSpanningTree::Propagator::propagateC2P later simply calls
135
+ // MaxInfoSpanningTree::computeInfoC2P with recording_=true where it will
136
+ // actually record the computed information since it will be then projected
137
+ // through the DAG maximizing saving information.
138
+ class NVF_API ContiguousInnerDimensionsMapper
139
+ : public MaxInfoSpanningTree,
140
+ MaxInfoSpanningTree::Propagator {
141
+ public:
142
+ ContiguousInnerDimensionsMapper() = delete;
143
+
144
+ static ContiguousInnerDimensionsMapper map(
145
+ TensorView* reference,
146
+ const std::vector<IterDomain*>& ids,
147
+ std::shared_ptr<const ComputeAtMap> ca_map,
148
+ const std::unordered_set<Split*>& divisible_splits);
149
+
150
+ static ContiguousInnerDimensionsMapper map(
151
+ TensorView* reference,
152
+ const std::vector<IterDomain*>& ids) {
153
+ auto ca_map = std::make_shared<ComputeAtMap>(reference->fusion());
154
+ auto divisible_splits =
155
+ getAllDivisibleSplits(reference->fusion(), ca_map.get());
156
+ return ContiguousInnerDimensionsMapper::map(
157
+ reference, ids, ca_map, divisible_splits);
158
+ }
159
+
160
+ bool hasMappedDims(TensorView* tv) const {
161
+ return tv_infos_.find(tv) != tv_infos_.end();
162
+ }
163
+
164
+ const std::vector<IterDomain*>& mappedRootIds(TensorView* tv) const {
165
+ NVF_ERROR(
166
+ tv_infos_.find(tv) != tv_infos_.end(),
167
+ "TensorView not found: ",
168
+ tv->toString());
169
+ return std::dynamic_pointer_cast<const MappedDomain>(tv_infos_.at(tv))
170
+ ->mapped_root_ids_;
171
+ }
172
+
173
+ const std::vector<IterDomain*>& mappedLogicalIds(TensorView* tv) const {
174
+ NVF_ERROR(
175
+ tv_infos_.find(tv) != tv_infos_.end(),
176
+ "TensorView not found: ",
177
+ tv->toString());
178
+ return std::dynamic_pointer_cast<const MappedDomain>(tv_infos_.at(tv))
179
+ ->mapped_logical_ids_;
180
+ }
181
+
182
+ Val* getProjectedExtent(IterDomain* id) const {
183
+ if (projected_extent_.find(id) == projected_extent_.end()) {
184
+ NVF_THROW("Not projected: ", id->toString());
185
+ }
186
+ return projected_extent_.at(id);
187
+ }
188
+
189
+ std::unordered_map<TensorView*, Val*> getTvToContigMergeOfInnerSizeMap();
190
+
191
+ private:
192
+ ContiguousInnerDimensionsMapper(
193
+ TensorView* reference,
194
+ const std::vector<IterDomain*>& ids,
195
+ std::shared_ptr<const ComputeAtMap> ca_map,
196
+ const std::unordered_set<Split*>& divisible_splits);
197
+
198
+ class MappedDomain : public Information {
199
+ public:
200
+ MappedDomain() = default;
201
+
202
+ static std::shared_ptr<MappedDomain> build(
203
+ std::vector<IterDomain*> root_ids,
204
+ std::vector<IterDomain*> logical_ids,
205
+ bool is_c2p) {
206
+ auto ptr = std::make_shared<MappedDomain>();
207
+ ptr->mapped_root_ids_ = root_ids;
208
+ ptr->mapped_logical_ids_ = logical_ids;
209
+ ptr->is_c2p_ = is_c2p;
210
+ return ptr;
211
+ }
212
+
213
+ operator bool() const final {
214
+ return !mapped_root_ids_.empty() || !mapped_logical_ids_.empty();
215
+ }
216
+
217
+ bool operator<(const Information& other_info) const final {
218
+ auto other_mapped_domain = dynamic_cast<const MappedDomain&>(other_info);
219
+
220
+ if (is_c2p_) {
221
+ return mapped_logical_ids_.size() <
222
+ other_mapped_domain.mapped_logical_ids_.size();
223
+ }
224
+ return mapped_root_ids_.size() <
225
+ other_mapped_domain.mapped_root_ids_.size();
226
+ }
227
+
228
+ std::vector<IterDomain*> mapped_root_ids_;
229
+ std::vector<IterDomain*> mapped_logical_ids_;
230
+ // Information is not symmetric between c2p and p2c, track which direction
231
+ // the computation is in for the < operator
232
+ bool is_c2p_ = true;
233
+ };
234
+
235
+ // TODO: make pe a lanmda function so it is not evaluated if not needed
236
+ void addProjectedExtent(IterDomain* id, Val* pe) {
237
+ if (!recording_) {
238
+ return;
239
+ }
240
+
241
+ NVF_ERROR(
242
+ projected_extent_.count(id) == 0,
243
+ "Already registered: ",
244
+ id->toString(),
245
+ ", existing: ",
246
+ projected_extent_.at(id)->toInlineString(),
247
+ ", new: ",
248
+ pe->toInlineString());
249
+
250
+ projected_extent_[id] = pe;
251
+ }
252
+
253
+ // Return a boolean predicate indicating if the given ID is fully projected.
254
+ Val* isFullyProjected(IterDomain* id);
255
+
256
+ // From the projected extent (PE) of I1 and I2, update the PE of I1*I2.
257
+ template <typename MergeOrSplit>
258
+ void combinePE(const MergeOrSplit* merge_or_split, bool outer_maps);
259
+ // From the projected extent (PE) of I1*I2, update the PE of I1 and I2.
260
+ template <typename MergeOrSplit>
261
+ void distributePE(const MergeOrSplit* merge_or_split);
262
+
263
+ // Returns the projected inner size. Contiguous inner dimensions are merged.
264
+ Val* getContigMergeOfInnerSize(TensorView* of_tv);
265
+
266
+ // MaxInfoSpanningTree functions
267
+ std::shared_ptr<Information> computeInfoC2P(
268
+ TensorView* from,
269
+ TensorView* to,
270
+ std::shared_ptr<Information> from_info) final;
271
+
272
+ std::shared_ptr<Information> computeInfoP2C(
273
+ TensorView* from,
274
+ TensorView* to,
275
+ std::shared_ptr<Information> from_info) final;
276
+
277
+ std::shared_ptr<Information> computeInfoSibling(
278
+ TensorView* from,
279
+ TensorView* to,
280
+ std::shared_ptr<Information> from_info) final;
281
+
282
+ // Projection from root<->logical domains
283
+ std::vector<IterDomain*> projectId(
284
+ const std::vector<IterDomain*>& from,
285
+ const std::vector<IterDomain*>& to);
286
+
287
+ // Propagator functions
288
+ void propagateC2P(TensorView* from, TensorView* to) final;
289
+ void propagateP2C(TensorView* from, TensorView* to) final;
290
+ void propagateSibling(TensorView* from, TensorView* to) final;
291
+
292
+ // Initialized to false, series of compute... calls will be performed to find
293
+ // the spanning tree. Then propagate... calls will call the compute... calls.
294
+ // recording_ starts as false, and stays that way during the first series of
295
+ // compute... calls. As soon as the first propagate... calls are called,
296
+ // recording_ will perpetually stay on.
297
+ bool recording_ = false;
298
+
299
+ std::shared_ptr<const ComputeAtMap> ca_map_;
300
+ const std::unordered_set<Split*>& divisible_splits_;
301
+
302
+ // Mapped root dimensions for each TensorView as we propogate. These
303
+ // mappings are in the order of the reference.
304
+
305
+ std::unordered_map<
306
+ TensorView*,
307
+ std::shared_ptr<MaxInfoSpanningTree::Information>>
308
+ tv_infos_;
309
+
310
+ std::unordered_map<IterDomain*, Val*> projected_extent_;
311
+ };
312
+
313
+ // logical_reorder_map is provided to assume reference_tv will be reordered per
314
+ // the map, hence changing the order of IterDomain in the reference
315
+ int64_t getVectorizationFactor(
316
+ SchedulerRuntimeInfo& runtime_info,
317
+ TensorView* reference_tv,
318
+ HeuristicDataCache* data_cache,
319
+ int64_t break_point,
320
+ const std::unordered_map<int64_t, int64_t>& logical_reorder = {});
321
+
322
+ int64_t getVectorizationFactorTransposeGroup(
323
+ SchedulerRuntimeInfo& runtime_info,
324
+ TensorView* reference,
325
+ int64_t inner_most_dim,
326
+ const std::vector<int64_t>& dims_to_merge,
327
+ const std::vector<TensorView*>& vec_tv,
328
+ int64_t max_vectorization);
329
+
330
+ //! Find the break point for vectorization. Here, we vectorize either
331
+ //! the innermost reduction or iteration domains. We use the producer
332
+ //! of the reduction as a reference of the vectorization
333
+ //! analsis.
334
+ //
335
+ //! Since this is for the reduction and normalization schedulers, the
336
+ //! producer of the reduction should not have reduction domains,
337
+ //! except when it's a fusion input, in which case the reduction
338
+ //! domains of the producer should just be ignored.
339
+ //
340
+ //! \param reduction_consumer
341
+ //! \param reduction_producer
342
+ //! \param consumer_innermost_ndims Innermost consumer domains to vectorize
343
+ int64_t getVectorizationBreakPointOfReductionProducer(
344
+ TensorView* reduction_consumer,
345
+ TensorView* reduction_producer,
346
+ int64_t consumer_innermost_ndims);
347
+
348
+ } // namespace vectorize_helper
349
+ } // namespace nvfuser
@@ -0,0 +1,55 @@
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 <type.h>
12
+ #include <functional>
13
+
14
+ namespace nvfuser::serde {
15
+
16
+ // Flatbuffer enum are represented as an unscoped enumeration, so we can map
17
+ // them to an Integer type. This Factory class contains a vector that maps from
18
+ // an enum integer to its corresponding parser function.
19
+ //
20
+ // All parser functions have the same signature. We use lambdas to support
21
+ // functions that require extra arguments.
22
+
23
+ template <typename SerdeBuffer, typename BaseTypePtr>
24
+ class Factory {
25
+ public:
26
+ // A function pointer that creates a BaseType object given a Buffer
27
+ typedef std::function<BaseTypePtr(const SerdeBuffer*)> SerdeParser;
28
+
29
+ Factory(size_t num_parsers) : parsers_(num_parsers, nullptr) {};
30
+
31
+ template <typename SerdeEnum>
32
+ void registerParser(SerdeEnum serde_type, SerdeParser parser) {
33
+ auto serde_integer = nvfuser::toUnderlying(serde_type);
34
+ NVF_ERROR(
35
+ serde_integer >= 0 && serde_integer < (int)parsers_.size(),
36
+ "RegisterParser: Invalid serde type: ",
37
+ serde_integer);
38
+ parsers_.at(serde_integer) = parser;
39
+ }
40
+
41
+ template <typename SerdeEnum>
42
+ BaseTypePtr parse(SerdeEnum serde_type, const SerdeBuffer* buffer) {
43
+ auto serde_integer = nvfuser::toUnderlying(serde_type);
44
+ NVF_ERROR(
45
+ serde_integer >= 0 && serde_integer < (int)parsers_.size(),
46
+ "Deserialize: Invalid serde type: ",
47
+ serde_integer);
48
+ return parsers_.at(serde_integer)(buffer);
49
+ }
50
+
51
+ private:
52
+ std::vector<SerdeParser> parsers_;
53
+ };
54
+
55
+ } // namespace nvfuser::serde