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,299 @@
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
+
12
+ #include <device_lower/analysis/circular_buffer.h>
13
+ #include <device_lower/analysis/sync_information.h>
14
+ #include <device_lower/pass/warp_reduce.h>
15
+ #include <fusion.h>
16
+ #include <ir/base_nodes.h>
17
+ #include <ir/builder.h>
18
+ #include <parallel_dimension_map.h>
19
+ #include <utils.h>
20
+ #include <vectorization_info.h>
21
+ #include <visibility.h>
22
+
23
+ #include <memory>
24
+ #include <unordered_map>
25
+ #include <utility>
26
+ #include <vector>
27
+
28
+ namespace nvfuser {
29
+ namespace kir {
30
+
31
+ //! Summary of interesting facts about the kernel
32
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
33
+ struct KernelSummary {
34
+ //! Count of WAR (write-after-read) hazard barriers
35
+ int64_t war_hazard_syncs_count = 0;
36
+
37
+ //! List of global buffers
38
+ std::vector<const kir::Allocate*> global_allocations;
39
+
40
+ //! List of dynamic shared memory buffers
41
+ std::vector<const kir::Allocate*> dynamic_smem_allocations;
42
+
43
+ //! List of static shared memory buffers
44
+ std::vector<const kir::Allocate*> static_smem_allocations;
45
+
46
+ //! Indicate the need to generate random numbers
47
+ bool has_philox_op = false;
48
+
49
+ //! Do we have any block reductions?
50
+ bool has_block_reductions = false;
51
+
52
+ //! Number of static grid reductions
53
+ bool has_grid_reductions = false;
54
+
55
+ //! Do we have any grid reduction in a loop, or grid reductions dependent on
56
+ //! grid reductions
57
+ bool has_cooperative_grid_reduction = false;
58
+
59
+ //! Do we have any block broadcasts?
60
+ bool has_block_broadcasts = false;
61
+
62
+ //! Do we have any grid broadcasts?
63
+ bool has_grid_broadcasts = false;
64
+
65
+ //! Do we have any welford op?
66
+ bool has_welford = false;
67
+
68
+ //! Do we have any welford op?
69
+ bool has_block_welford = false;
70
+
71
+ //! Do we have any welford op?
72
+ bool has_grid_welford = false;
73
+
74
+ //! Do we have any iter grouped outer block reduction op?
75
+ bool has_iter_grouped_reductions = false;
76
+
77
+ //! number of grouped iters for grouped outer block reduction
78
+ int64_t num_grouped_iterations = 1;
79
+
80
+ //! Do we have any outer grouped grid welford op?
81
+ bool has_outer_grouped_grid_welford = false;
82
+
83
+ //! Largest shared memory buffer size of outer grouped grid welford
84
+ int64_t outer_grouped_grid_welford_largest_smem_size = 0;
85
+
86
+ //! Largest shared memory buffer base type
87
+ DataType largest_smem_data_type = DataType::Null;
88
+
89
+ //! Do we have allocations of dynamic local memory?
90
+ bool has_dynamic_local_memory_allocations = false;
91
+
92
+ //! List of dynamic local memory buffers.
93
+ //! Only used for debugging.
94
+ std::vector<const kir::Allocate*> dynamic_lmem_allocations;
95
+
96
+ //! Validations needed and information about them. For example, a pair of
97
+ //! "extent mod split_factor == 0" and an error message for divisibility check
98
+ //! for vectorization.
99
+ std::vector<std::pair<const Val*, std::string>> validations;
100
+
101
+ //! Effective ParallelTypes of broadcast ops
102
+ std::unordered_map<const BroadcastOp*, ParallelTypeBitmap>
103
+ broadcast_parallel_types;
104
+
105
+ //! Track which tensor views are inputs or outputs of a vectorized operation
106
+ //! and their maximum vectorized access size
107
+ std::unordered_map<TensorView*, int64_t> vectorized_accesses;
108
+
109
+ // Sync map is needed to figure out if global memory buffers need to be marked
110
+ // as volatile because they're used for communication.
111
+ std::shared_ptr<const SyncMap> sync_map;
112
+
113
+ // Parallel dimension map needed to set the correct properties of grid buffers
114
+ // (is a dim inactive)
115
+ ParallelDimensionMap parallel_dimension_map;
116
+
117
+ //! Track information on vectorized set operations for runtime validation
118
+ std::vector<VectorizedSetInfo> vectorized_set_info;
119
+
120
+ //! Minimum compute capability of device that can execute this kernel
121
+ std::pair<int64_t, int64_t> min_device_version;
122
+
123
+ //! Plain text description of why min_device_version_ is required
124
+ std::string min_device_version_reason;
125
+
126
+ //! Track Circular Buffer TensorViews
127
+ CircularBufferInfo circular_buffer_info;
128
+
129
+ //! Track if there are ElectSync predicates in this Kernel.
130
+ //! Reason: At runtime, we check that at least a single warp along TIDx axis
131
+ //! exists.
132
+ bool has_elect_sync_predicate = false;
133
+ };
134
+
135
+ class KernelPerformanceProfile {
136
+ public:
137
+ //! Register an expression to profile
138
+ void registerExpr(const Expr* expr);
139
+
140
+ //! Query if an expression is profiled
141
+ bool isProfiled(const Expr* expr) const;
142
+
143
+ //! Get the number of profiled expressions
144
+ int64_t getNumberOfProfileEntries() const {
145
+ return num_profile_entries_;
146
+ }
147
+
148
+ //! Set the backing buffer of profile.
149
+ void setBuffer(TensorView* buffer) {
150
+ buffer_ = buffer;
151
+ }
152
+
153
+ //! Get the backing buffer
154
+ TensorView* getBuffer() const {
155
+ return buffer_;
156
+ }
157
+
158
+ //! Get the indices of the profile of an expression in the backing buffer
159
+ std::array<int64_t, 2> getIndicesInProfileBuffer(const Expr* expr) const;
160
+
161
+ std::string toString(const at::Tensor& buffer) const;
162
+
163
+ private:
164
+ //! Get the new profile index
165
+ int64_t getNewIndex();
166
+
167
+ //! Get the profile index
168
+ std::optional<int64_t> getIndex(const Expr* expr) const;
169
+
170
+ private:
171
+ int64_t num_profile_entries_ = 0;
172
+
173
+ //! Backing buffer of Nx2 integer tensor, where N is the number of profiled
174
+ //! regions. Each region has two integer values, one representing
175
+ //! the cycles spent, and another the count.
176
+ TensorView* buffer_ = nullptr;
177
+
178
+ //! Map profiled expressions to profile entry offsets
179
+ std::unordered_map<const Expr*, int64_t> expr_entry_map_;
180
+
181
+ // TODO: Allow profiling of ForLoops
182
+ //! Map profiled ForLoop to profile entry offsets
183
+ // std::unordered_map<const ForLoop*, int64_t> loop_entry_map_;
184
+ };
185
+
186
+ class KernelInternalProxy;
187
+
188
+ //! Container for a lowered Kernel IR
189
+ //!
190
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
191
+ class NVF_API Kernel final : public Fusion {
192
+ friend KernelInternalProxy;
193
+
194
+ public:
195
+ // Kernel starts by grabbing all the nodes from the provided fusion.
196
+ // Kernel is not SSA, if a definition is not set, we should update it, but
197
+ // not remove previous definition if it is set. This is primarily because when
198
+ // we do something like generate an initialization statement for a reduction
199
+ // TV, we may want to continue to do fusion like analysis on the original
200
+ // expression.
201
+ Kernel(Fusion* fusion, PrimDataType index_type = PrimDataType::Int);
202
+ Kernel() = delete;
203
+
204
+ // No move or copy semantics
205
+ Kernel(const Kernel&) = delete;
206
+ Kernel& operator=(const Kernel&) = delete;
207
+
208
+ //! Finalize a kernel definition
209
+ //!
210
+ //! At this point we have a complete kernel definition and we can
211
+ //! run analysis passes to build a KernelSummary.
212
+ void finalize(std::vector<Expr*> top_level_exprs);
213
+
214
+ const std::vector<Expr*>& topLevelExprs() const {
215
+ return top_level_exprs_;
216
+ }
217
+
218
+ const KernelSummary& summary() const {
219
+ return summary_;
220
+ }
221
+
222
+ PrimDataType indexType() const {
223
+ return index_type_;
224
+ }
225
+
226
+ //! Checks if parallel type is padded
227
+ bool isParallelTypePadded(ParallelType ptype) const {
228
+ return ptype == ParallelType::TIDx &&
229
+ warp_padded_parallel_info_.is_tidx_padded;
230
+ }
231
+
232
+ const WarpPaddedParallelInfo& getWarpPaddedParallelInfo() const {
233
+ return warp_padded_parallel_info_;
234
+ }
235
+
236
+ const KernelPerformanceProfile& profile() const {
237
+ return profile_;
238
+ }
239
+
240
+ //! Debug dump of the Kernel IR
241
+ void print() const;
242
+
243
+ const std::vector<Val*>& parameters() const {
244
+ return parameters_;
245
+ }
246
+
247
+ protected:
248
+ using IrContainer::registerExpr;
249
+ using IrContainer::registerVal;
250
+
251
+ //! Register the Val with this fusion
252
+ void registerVal(Val* val) override;
253
+
254
+ //! Register expr with this fusion.
255
+ //! When we register an expression, we want to update the dependency tracking
256
+ //! of Vals. We add expr to our general expr_set_,
257
+ void registerExpr(Expr* expr) override;
258
+
259
+ private:
260
+ // Analyze the kernel IR and caches the summary of interesting data
261
+ void analyze();
262
+
263
+ // Top level statements
264
+ std::vector<Expr*> top_level_exprs_;
265
+
266
+ // Summary of interesting kernel data
267
+ KernelSummary summary_;
268
+
269
+ // Is this kernel being compiled with int32 or int64 indexing. This
270
+ // information is required to resolve DataType::Index
271
+ PrimDataType index_type_ = PrimDataType::Int;
272
+
273
+ WarpPaddedParallelInfo warp_padded_parallel_info_;
274
+
275
+ KernelPerformanceProfile profile_;
276
+
277
+ // Parameters of the kernel. The parameters contain the inputs and outputs of
278
+ // the kernel, intermediate buffers, and special items such as RNG state and
279
+ // tensor map for TMA support, etc. The parameters are not required to have no
280
+ // definition. If a parameter has a definition, its definition will be
281
+ // evaluated before the kernel is executed.
282
+ std::vector<Val*> parameters_;
283
+ };
284
+
285
+ //! A special debugging proxy for Kernel.
286
+ //!
287
+ //! Should not be used for other than testing and debugging.
288
+ class NVF_API KernelInternalProxy {
289
+ public:
290
+ KernelInternalProxy(Kernel* kernel) : kernel_(kernel) {}
291
+
292
+ std::vector<Expr*>& topLevelExprs();
293
+
294
+ private:
295
+ Kernel* kernel_ = nullptr;
296
+ };
297
+
298
+ } // namespace kir
299
+ } // namespace nvfuser
@@ -0,0 +1,109 @@
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
+ #if defined(__cplusplus) && (__cplusplus >= 201703L)
11
+ #include <filesystem>
12
+ namespace fs = std::filesystem;
13
+ #elif defined(__cplusplus) && (__cplusplus >= 201402L)
14
+ #include <experimental/filesystem>
15
+ namespace fs = std::experimental::filesystem;
16
+ #else
17
+ #error "C++14 or Higher is required for filesystem library!"
18
+ #endif
19
+
20
+ #include <unordered_map>
21
+ #include <vector>
22
+
23
+ #include <visibility.h>
24
+
25
+ namespace nvfuser {
26
+
27
+ //! KernelDbEntry captures information to be printed per fusion in a csv file
28
+ //! that is used to restore a hash map
29
+ struct KernelDbEntry {
30
+ //! Cuda kernel function signature that is required to load the Cubin
31
+ std::string kernel_signature;
32
+ //! Compilation args supplied to NVRTC -- register usage and compute
33
+ //! capability can be specific to a kernel instance
34
+ std::string compile_args;
35
+ //! Full file path to Cuda Kernel
36
+ std::string kernel_code_file;
37
+ //! Full file path to cubin
38
+ std::string cubin_file;
39
+ };
40
+
41
+ //! KernelDb class is a singleton structure that is used to open, query, and
42
+ //! write to the the database that is held in a hash map. The kernel code is
43
+ //! used as string key to the hash map.
44
+ class KernelDb {
45
+ KernelDb(bool _disabled);
46
+
47
+ //! Open is private because this method should only be called once by the
48
+ //! singleton upon creation to create a new db or restore an existing one.
49
+ bool open(
50
+ const std::string& kernel_db_dir,
51
+ const std::string& kernel_db_file,
52
+ bool use_temp_dir);
53
+
54
+ public:
55
+ // clang-tidy - deleted member function should be public
56
+ KernelDb(const KernelDb&) = delete;
57
+ KernelDb& operator=(const KernelDb&) = delete;
58
+
59
+ //! Thread-Safe method to get the Meyer's singleton -- Interface
60
+ static KernelDb& get();
61
+ //! Thread-Safe method to get the Meyer's singleton -- For testing
62
+ NVF_API static KernelDb& get(
63
+ const std::string& kernel_db_dir,
64
+ const std::string& kernel_db_file,
65
+ bool use_temp_dir = true,
66
+ bool disabled = false,
67
+ bool reset = false);
68
+
69
+ //! Enable is derived from two booleans
70
+ bool enabled() const {
71
+ return !disabled_ && initialized_;
72
+ }
73
+ //! Returns the number entries in the db
74
+ size_t size() const {
75
+ return kernel_map_.size();
76
+ }
77
+
78
+ //! Query uses the string of the kernel code to lookup whether a cubin already
79
+ //! exists for the given kernel. Additionally, the compile args are also
80
+ //! matched.
81
+ NVF_API bool query(
82
+ const std::string& kernel_code,
83
+ const std::string& compile_args,
84
+ std::string& kernel_signature,
85
+ std::vector<char>& cubin) const;
86
+ //! Write is used to write a new entry to the db upon compilation of a
87
+ //! new fusion
88
+ NVF_API bool write(
89
+ const std::string& kernel_code,
90
+ const std::string& compile_args,
91
+ const std::string& kernel_signature,
92
+ const std::vector<char>& cubin);
93
+
94
+ private:
95
+ //! Disablement is specified by the user and can also be set by a
96
+ //! failure to open the db
97
+ bool disabled_ = true;
98
+ //! Db is only initialized after it is successfully open
99
+ bool initialized_ = false;
100
+ //! Hash Map of kernel_string -> db_entry
101
+ std::unordered_map<std::string, KernelDbEntry> kernel_map_;
102
+
103
+ //! Full path to the db directory
104
+ fs::path kernel_db_path_;
105
+ //! Full path to csv file used to record and restore the db
106
+ fs::path kernel_db_txt_file_;
107
+ };
108
+
109
+ } // namespace nvfuser
@@ -0,0 +1,37 @@
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 <string>
10
+ #include <vector>
11
+
12
+ #include <visibility.h>
13
+
14
+ namespace nvfuser {
15
+
16
+ //! Helper methods to faciliate moving data between data buffers and files based
17
+ //! on what type of data is being copied.
18
+
19
+ NVF_API bool append_to_text_file(
20
+ const std::string& file_path,
21
+ const std::string& src);
22
+
23
+ NVF_API bool copy_from_binary_file(
24
+ const std::string& file_path,
25
+ std::vector<char>& dst);
26
+ NVF_API bool copy_from_text_file(
27
+ const std::string& file_path,
28
+ std::string& dst);
29
+
30
+ bool copy_to_binary_file(
31
+ const std::string& file_path,
32
+ const std::vector<char>& dst);
33
+ NVF_API bool copy_to_text_file(
34
+ const std::string& file_path,
35
+ const std::string& src);
36
+
37
+ } // namespace nvfuser