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,295 @@
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 <device_lower/lower2device.h>
10
+ #include <exceptions.h>
11
+ #include <fusion.h>
12
+ #include <ir/all_nodes.h>
13
+ #include <polymorphic_value.h>
14
+ #include <runtime/executor_params.h>
15
+ #include <utils.h>
16
+ #include <visibility.h>
17
+
18
+ #include <c10/core/DeviceType.h>
19
+
20
+ namespace nvfuser {
21
+
22
+ class PrecomputedValues;
23
+ class KernelArgumentHolder;
24
+ struct TensorArgAbstract;
25
+
26
+ //! NaiveValueMachine:
27
+ //! This is an un-optimized runtime for evaluating a
28
+ //! set of values in one run. The runtime contains
29
+ //! a vector of instructions inferred from IR at compile-time
30
+ //! and it currently must be associated with an instance of
31
+ //! PrecomputedValues that will provide the workspace
32
+ //! containing the concrete values for the values.
33
+ class NaiveValueMachine {
34
+ //! The generic types of instructions supported for this machine.
35
+ enum class InstructionType { UNARY_OP, BINARY_OP, TERNARY_OP, SET_OP };
36
+
37
+ public:
38
+ //! Constructor lowers all the expr IR nodes stored in precomputed_values
39
+ //! and stores them in the private state.
40
+ NaiveValueMachine(PrecomputedValues& precomputed_values);
41
+
42
+ //! Copy all values other than `precomputed_values_` from other
43
+ //! This would be better implemented as a copy constructor, except that would
44
+ //! also presumably bind precomputed_values_ which we could not then rebind,
45
+ //! as we need to during cloning.
46
+ void copyFrom(const NaiveValueMachine& other);
47
+
48
+ //! Runs all the instructions and write results to the associated
49
+ //! precomputed_values.
50
+ void run();
51
+
52
+ private:
53
+ //! Convert an unary IR expr to an instruction
54
+ void makeUnaryOp(UnaryOp* uop);
55
+
56
+ //! Convert an binary IR expr to an instruction
57
+ void makeBinaryOp(BinaryOp* bop);
58
+
59
+ //! Convert an ternary IR expr to an instruction
60
+ void makeTernaryOp(TernaryOp* bop);
61
+
62
+ //! Create an empty instruction with all default values
63
+ //! and place it at the end of the instruction buffer.
64
+ int makeInstructionEntry();
65
+
66
+ //! Run a single instruction at the given index of
67
+ //! the instruction buffer. Decodes and dispatches
68
+ //! to the corresponding instruction handle functions.
69
+ void runInstruction(int index);
70
+
71
+ //! Runs a unary operation at given index of instruction buffer
72
+ void runUnaryOp(int index);
73
+
74
+ //! Runs a binary operation at given index of instruction buffer
75
+ void runBinaryOp(int index);
76
+
77
+ //! Runs a ternary operation at given index of instruction buffer
78
+ void runTernaryOp(int index);
79
+
80
+ private:
81
+ friend PrecomputedValues;
82
+
83
+ //! Reference to the PrecomputedValues workspace associated with
84
+ //! this runtime. All the instructions will read and write the
85
+ //! values in this workspace.
86
+ PrecomputedValues& precomputed_values_;
87
+
88
+ //! Instruction buffer. All states are in separate vectors and
89
+ //! the entry of each vector at the same index correspond to
90
+ //! the same instruction.
91
+
92
+ //! Total number of instructions
93
+ int num_of_instructions_ = 0;
94
+
95
+ //! Machine instruction type for each instruction i.e.
96
+ //! unary or binary
97
+ std::vector<InstructionType> inst_type_;
98
+
99
+ //! Unary operator type if applicable, contains a default
100
+ //! value at each index corresponding to a binary op.
101
+ std::vector<UnaryOpType> uop_type_;
102
+
103
+ //! Data type for unary op of type UnaryOpType::Cast, contains a default
104
+ //! value at each index corresponding other ops.
105
+ std::vector<DataType> data_type_;
106
+
107
+ //! Binary operator type if applicable, contains a default
108
+ //! value at each index corresponding to a binary op.
109
+ std::vector<BinaryOpType> bop_type_;
110
+
111
+ //! Ternary operator type if applicable, contains a default
112
+ //! value at each index corresponding to a ternary op.
113
+ std::vector<TernaryOpType> top_type_;
114
+
115
+ //! Indexes of operands and destination of each instruction.
116
+ //! The indexes corresponds to positions in the workspace
117
+ //! where concrete values are hosted.
118
+
119
+ //! Operand 0 of each instruction.
120
+ std::vector<int> src0_;
121
+
122
+ //! Operand 1 of each instruction, a default value at
123
+ //! each index corresponding to a unary op.
124
+ std::vector<int> src1_;
125
+
126
+ //! Operand 2 of each instruction, a default value at
127
+ //! each index corresponding to a unary or binary op.
128
+ std::vector<int> src2_;
129
+
130
+ //! Destination of each instruction.
131
+ std::vector<int> dest_;
132
+ };
133
+
134
+ //! PrecomputedValues:
135
+ //! A class to support optimized evaluation of values
136
+ //! at runtime.
137
+ //! At compile time all necessary values are collected
138
+ //! from given IR nodes and a runtime and a workspace containing
139
+ //! the concrete values is created and pre-allocated.
140
+ //! At runtime the value vm is used to evaluate all the
141
+ //! values and store them in the workspace ahead of time.
142
+ class PrecomputedValues {
143
+ public:
144
+ PrecomputedValues() = delete;
145
+ NVF_API PrecomputedValues(PrecomputedValues&&) = default;
146
+
147
+ NVF_API explicit PrecomputedValues(Fusion* fusion);
148
+
149
+ NVF_API ~PrecomputedValues();
150
+
151
+ //! Bind a list of concrete values to the fusion's runtime inputs.
152
+ void bindInputs(const KernelArgumentHolder& args);
153
+
154
+ //! Bind a list of concrete values to a list of fusion values. The two lists
155
+ //! must have the same size.
156
+ void bindValues(
157
+ const std::vector<Val*>& values,
158
+ const KernelArgumentHolder& args);
159
+
160
+ using ParallelExtentMap =
161
+ std::unordered_map<ParallelType, std::vector<const Val*>>;
162
+
163
+ //! Bind concrete values from launch constraints
164
+ void bindParallelExtents(
165
+ const ParallelExtentMap& parallel_extents,
166
+ const LaunchParams& launch_constraint);
167
+
168
+ //! Bind the NamedScalars corresponding to the
169
+ //! concrete parallel dimension sizes after the
170
+ //! actual value has been resolved.
171
+ void bindConcreteParallelTypeValue(ParallelType pt, PolymorphicValue value);
172
+
173
+ //! Returns if the workspace contains evaluated results.
174
+ bool hasValidValues() {
175
+ return has_valid_values_;
176
+ }
177
+
178
+ //! Runs the internal value machine that will compute
179
+ //! the values allocated in the workspace.
180
+ void evaluate();
181
+
182
+ //! Returns value for the given IR node if it's stored
183
+ //! in the workspace and has been evaluated.
184
+ const PolymorphicValue& getMaybeValueFor(const Val* val) const;
185
+
186
+ //! Debugging helper, prints all the currently known values
187
+ void print() const;
188
+
189
+ PrecomputedValues clone(IrCloner& ir_cloner) const;
190
+
191
+ protected:
192
+ // Fusion IR associated with the precomputed values. Can be kir::Kernel or
193
+ // Fusion.
194
+ Fusion* fusion_ = nullptr;
195
+
196
+ //! Contains all the named scalars correspond
197
+ //! to thread size of each parallel type.
198
+ std::unordered_map<ParallelType, std::unique_ptr<std::vector<int>>>
199
+ thread_dim_value_indices_;
200
+
201
+ //! Initialize the workspace before first use.
202
+ //! Assume the given value list IR nodes have
203
+ //! been topologically sorted.
204
+ void initializeValueList(const std::vector<Val*>& sorted_value_list);
205
+
206
+ //! Bind concrete value to the given index
207
+ //! if the index is valid.
208
+ void bindValue_(int index, const PolymorphicValue& value) {
209
+ if (index < 0 || is_constant_[index]) {
210
+ return;
211
+ }
212
+ defined_[index] = true;
213
+ values_[index] = value;
214
+ binding_log_.emplace_back(index, value);
215
+ }
216
+ template <typename T>
217
+ void bindValue(int index, const T& value) {
218
+ bindValue_(index, PolymorphicValue(value));
219
+ }
220
+
221
+ //! Invalidate all computed values in the workspace.
222
+ void invalidate();
223
+
224
+ //! Interface for subclasses to access symbols_
225
+ void loadSymbols(std::vector<Val*> symbols) {
226
+ symbols_ = std::move(symbols);
227
+ }
228
+
229
+ //! Interface for subclasses to access symbols_
230
+ std::vector<Val*>& symbols() {
231
+ return symbols_;
232
+ }
233
+
234
+ //! Initialize the value runtime that will
235
+ //! infer instructions from the workspace.
236
+ void initializeIntegerMachine() {
237
+ value_machine_ = std::make_unique<NaiveValueMachine>(*this);
238
+ }
239
+
240
+ //! Iterate through all the named scalars corresponding
241
+ //! to thread sizes and pre-group them by their parallel
242
+ //! types.
243
+ void initializeNamedScalars();
244
+
245
+ private:
246
+ //! Post evaluation check, throws if any computed value
247
+ //! is inconsistent with its bound value
248
+ void validate();
249
+
250
+ //! Returns true if workspace has a computed or constant
251
+ //! value for given index.
252
+ bool hasValue(int index) {
253
+ NVF_ERROR(index > 0);
254
+ return defined_[index] || is_constant_[index];
255
+ }
256
+
257
+ void bindTensorMetaData(TensorView* tv, const at::Tensor& tensor);
258
+
259
+ private:
260
+ friend NaiveValueMachine;
261
+
262
+ //! Marks if an evaluation has finished
263
+ bool has_valid_values_ = false;
264
+
265
+ //! The size of workspace
266
+ int num_of_values_ = -1;
267
+
268
+ //! Marks if a value has been bound or
269
+ //! computed at each index.
270
+ std::vector<bool> defined_;
271
+
272
+ //! Marks if a value is compile-time constant
273
+ //! at each index.
274
+ std::vector<bool> is_constant_;
275
+
276
+ //! Stores the concrete values at each index.
277
+ std::vector<PolymorphicValue> values_;
278
+
279
+ //! Use a single monostate to represent null, instead of creating a new
280
+ //! PolymorphicValue for each null.
281
+ PolymorphicValue null_ = std::monostate{};
282
+
283
+ //! Stores the IR nodes corresponding to each index.
284
+ std::vector<Val*> symbols_;
285
+
286
+ //! An internal log to keep track of all the bindings
287
+ //! used in each evaluation cycle. To be used for
288
+ //! consistency check.
289
+ std::vector<std::pair<int, PolymorphicValue>> binding_log_;
290
+
291
+ //! Integer runtime for realizing the values computations.
292
+ std::unique_ptr<NaiveValueMachine> value_machine_;
293
+ };
294
+
295
+ } // namespace nvfuser
@@ -0,0 +1,283 @@
1
+ // clang-format off
2
+ /*
3
+ * SPDX-FileCopyrightText: Copyright (c) 2024-present NVIDIA CORPORATION & AFFILIATES.
4
+ * All rights reserved.
5
+ * SPDX-License-Identifier: BSD-3-Clause
6
+ */
7
+ // clang-format on
8
+ // This is a refactor of the NVF_ERROR and NVF_CHECK macros
9
+ // from PyTorch for implementing NVFuser specific macros.
10
+
11
+ #pragma once
12
+
13
+ #include <array>
14
+ #include <cstdint>
15
+ #include <deque>
16
+ #include <exception>
17
+ #include <iosfwd>
18
+ #include <optional>
19
+ #include <sstream>
20
+ #include <string>
21
+ #include <vector>
22
+
23
+ #include <visibility.h>
24
+
25
+ namespace nvfuser {
26
+
27
+ // This function will demangle the mangled function name into a more human
28
+ // readable format, e.g. _Z1gv -> g().
29
+ // More information:
30
+ // https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/libsupc%2B%2B/cxxabi.h
31
+ // NOTE: `__cxa_demangle` returns a malloc'd string that we have to free
32
+ // ourselves.
33
+ std::string demangle(const char* name);
34
+
35
+ std::string _get_backtrace(
36
+ size_t frames_to_skip = 0,
37
+ size_t maximum_number_of_frames = 64,
38
+ bool skip_python_frames = true);
39
+
40
+ struct SourceLocation {
41
+ const char* function;
42
+ const char* file;
43
+ uint32_t line;
44
+ };
45
+
46
+ std::ostream& operator<<(std::ostream& out, const SourceLocation& loc);
47
+
48
+ struct CompileTimeEmptyString {
49
+ operator const std::string&() const {
50
+ static const std::string empty_string_literal;
51
+ return empty_string_literal;
52
+ }
53
+ operator const char*() const {
54
+ return "";
55
+ }
56
+ };
57
+
58
+ template <typename T>
59
+ struct CanonicalizeStrTypes {
60
+ using type = const T&;
61
+ };
62
+
63
+ template <size_t N>
64
+ struct CanonicalizeStrTypes<std::array<char, N>> {
65
+ using type = const char*;
66
+ };
67
+
68
+ inline std::ostream& _to_str(std::ostream& ss) {
69
+ return ss;
70
+ }
71
+
72
+ template <typename T>
73
+ inline std::ostream& _to_str(std::ostream& ss, const T& t) {
74
+ // NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage)
75
+ ss << t;
76
+ return ss;
77
+ }
78
+
79
+ template <>
80
+ inline std::ostream& _to_str<CompileTimeEmptyString>(
81
+ std::ostream& ss,
82
+ const CompileTimeEmptyString&) {
83
+ return ss;
84
+ }
85
+
86
+ template <typename T, typename... Args>
87
+ inline std::ostream& _to_str(
88
+ std::ostream& ss,
89
+ const T& t,
90
+ const Args&... args) {
91
+ return _to_str(_to_str(ss, t), args...);
92
+ }
93
+
94
+ template <typename... Args>
95
+ struct _str_wrapper final {
96
+ static std::string call(const Args&... args) {
97
+ std::ostringstream ss;
98
+ _to_str(ss, args...);
99
+ return ss.str();
100
+ }
101
+ };
102
+
103
+ // Specializations for already-a-string types.
104
+ template <>
105
+ struct _str_wrapper<std::string> final {
106
+ // return by reference to avoid the binary size of a string copy
107
+ static const std::string& call(const std::string& str) {
108
+ return str;
109
+ }
110
+ };
111
+
112
+ template <>
113
+ struct _str_wrapper<const char*> final {
114
+ static const char* call(const char* str) {
115
+ return str;
116
+ }
117
+ };
118
+
119
+ // For nvfuser::to_str() with an empty argument list (which is common in our
120
+ // assert macros), we don't want to pay the binary size for constructing and
121
+ // destructing a stringstream or even constructing a string.
122
+ template <>
123
+ struct _str_wrapper<> final {
124
+ static CompileTimeEmptyString call() {
125
+ return CompileTimeEmptyString();
126
+ }
127
+ };
128
+
129
+ // Convert a list of string-like arguments into a single string.
130
+ template <typename... Args>
131
+ inline decltype(auto) to_str(const Args&... args) {
132
+ return _str_wrapper<typename CanonicalizeStrTypes<Args>::type...>::call(
133
+ args...);
134
+ }
135
+
136
+ class NVF_API nvfError : public std::exception {
137
+ // The actual error message.
138
+ std::string msg_;
139
+ // Context for the message (in order of decreasing specificity). Context will
140
+ // be automatically formatted appropriately, so it is not necessary to add
141
+ // extra leading/trailing newlines to strings inside this vector
142
+ std::vector<std::string> context_;
143
+ // The C++ backtrace at the point when this exception was raised. This
144
+ // may be empty if there is no valid backtrace. (We don't use optional
145
+ // here to reduce the dependencies this file has.)
146
+ std::string backtrace_;
147
+ // These two are derived fields from msg_stack_ and backtrace_, but we need
148
+ // fields for the strings so that we can return a const char* (as the
149
+ // signature of std::exception requires). Currently, the invariant
150
+ // is that these fields are ALWAYS populated consistently with respect
151
+ // to msg_stack_ and backtrace_.
152
+ std::string what_;
153
+ std::string what_without_backtrace_;
154
+ // This is a little debugging trick: you can stash a relevant pointer
155
+ // in caller, and then when you catch the exception, you can compare
156
+ // against pointers you have on hand to get more information about
157
+ // where the exception came from. In Caffe2, this is used to figure
158
+ // out which operator raised an exception.
159
+ const void* caller_;
160
+
161
+ public:
162
+ // PyTorch-style Error constructor.
163
+ nvfError(SourceLocation source_location, std::string msg);
164
+ // Base constructor
165
+ nvfError(
166
+ std::string msg,
167
+ std::string backtrace,
168
+ const void* caller = nullptr);
169
+ // Add some new context to the message stack. The last added context
170
+ // will be formatted at the end of the context list upon printing.
171
+ // WARNING: This method is O(n) in the size of the stack, so don't go
172
+ // wild adding a ridiculous amount of context to error messages.
173
+ void add_context(std::string msg);
174
+ const std::string& msg() const {
175
+ return msg_;
176
+ }
177
+ const std::vector<std::string>& context() const {
178
+ return context_;
179
+ }
180
+ const std::string& backtrace() const {
181
+ return backtrace_;
182
+ }
183
+ /// Returns the complete error message, including the source location.
184
+ /// The returned pointer is invalidated if you call add_context() on
185
+ /// this object.
186
+ const char* what() const noexcept override {
187
+ return what_.c_str();
188
+ }
189
+ const void* caller() const noexcept {
190
+ return caller_;
191
+ }
192
+ /// Returns only the error message string, without source location.
193
+ /// The returned pointer is invalidated if you call add_context() on
194
+ /// this object.
195
+ const char* what_without_backtrace() const noexcept {
196
+ return what_without_backtrace_.c_str();
197
+ }
198
+
199
+ private:
200
+ void refresh_what();
201
+ std::string compute_what(bool include_backtrace) const;
202
+ };
203
+
204
+ [[noreturn]] NVF_API void nvfCheckFail(
205
+ const char* func,
206
+ const char* file,
207
+ uint32_t line,
208
+ const std::string& msg);
209
+
210
+ [[noreturn]] NVF_API void nvfCheckFail(
211
+ const char* func,
212
+ const char* file,
213
+ uint32_t line,
214
+ const char* msg);
215
+
216
+ [[noreturn]] void nvfErrorFail(
217
+ const char* func,
218
+ const char* file,
219
+ uint32_t line,
220
+ const char* condMsg,
221
+ const char* userMsg);
222
+
223
+ [[noreturn]] inline void nvfErrorFail(
224
+ const char* func,
225
+ const char* file,
226
+ uint32_t line,
227
+ const char* condMsg,
228
+ CompileTimeEmptyString /*userMsg*/) {
229
+ nvfCheckFail(func, file, line, condMsg);
230
+ }
231
+
232
+ [[noreturn]] NVF_API void nvfErrorFail(
233
+ const char* func,
234
+ const char* file,
235
+ uint32_t line,
236
+ const char* condMsg,
237
+ const std::string& userMsg);
238
+
239
+ template <typename... Args>
240
+ decltype(auto) nvfCheckMsgImpl(const char* /*msg*/, const Args&... args) {
241
+ return to_str(args...);
242
+ }
243
+ inline const char* nvfCheckMsgImpl(const char* msg) {
244
+ return msg;
245
+ }
246
+ // If there is just 1 user-provided C-string argument, use it.
247
+ inline const char* nvfCheckMsgImpl(const char* /*msg*/, const char* args) {
248
+ return args;
249
+ }
250
+
251
+ } // namespace nvfuser
252
+
253
+ #define STRINGIZE_IMPL(x) #x
254
+ #define STRINGIZE(x) STRINGIZE_IMPL(x)
255
+
256
+ #define NVF_THROW(...) \
257
+ nvfuser::nvfErrorFail( \
258
+ __FUNCTION__, \
259
+ __FILE__, \
260
+ static_cast<uint32_t>(__LINE__), \
261
+ " INTERNAL ASSERT FAILED at " \
262
+ STRINGIZE(__FILE__) ":" STRINGIZE(__LINE__) \
263
+ ", please report a bug with repro script to NVFuser at " \
264
+ "https://github.com/NVIDIA/Fuser/issues. ", \
265
+ nvfuser::to_str(__VA_ARGS__));
266
+
267
+ #define NVF_ERROR(cond, ...) \
268
+ if ((!(cond))) { \
269
+ NVF_THROW(__VA_ARGS__) \
270
+ }
271
+
272
+ #define NVF_CHECK_MSG(cond, type, ...) \
273
+ (nvfuser::nvfCheckMsgImpl( \
274
+ "Expected " #cond " to be true, but got false. ", ##__VA_ARGS__))
275
+
276
+ #define NVF_CHECK(cond, ...) \
277
+ if ((!(cond))) { \
278
+ nvfuser::nvfCheckFail( \
279
+ __func__, \
280
+ __FILE__, \
281
+ static_cast<uint32_t>(__LINE__), \
282
+ NVF_CHECK_MSG(cond, "", ##__VA_ARGS__)); \
283
+ }
@@ -0,0 +1,125 @@
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 <evaluator_common.h>
11
+ #include <exceptions.h>
12
+ #include <ir/cloner.h>
13
+ #include <ir/interface_nodes.h>
14
+ #include <iter_visitor.h>
15
+ #include <logical_domain_map.h>
16
+ #include <polymorphic_value.h>
17
+ #include <visibility.h>
18
+
19
+ #include <string>
20
+ #include <unordered_map>
21
+
22
+ namespace nvfuser {
23
+
24
+ class PrecomputedValues;
25
+
26
+ //! Calculate Fusion IR expressions
27
+ class ExpressionEvaluator {
28
+ public:
29
+ //! Bind a concrete value to an IR variable
30
+ //! If evaluate_validate is true, and value is evaluatable with the
31
+ //! information already known, then evaluate and validate the value with the
32
+ //! concrete value.
33
+ void bind(
34
+ const Val* value,
35
+ PolymorphicValue concrete_value,
36
+ bool evaluate_validate = false) {
37
+ bind_(value, std::move(concrete_value), evaluate_validate);
38
+ }
39
+
40
+ //! Bind a concrete value to a named scalar
41
+ void bind(const std::string& name, PolymorphicValue concrete_value) {
42
+ bind_(name, std::move(concrete_value));
43
+ }
44
+
45
+ //! Set a concrete value for a parallel dimension
46
+ void bind(ParallelType pt, PolymorphicValue concrete_value);
47
+
48
+ //! Try to evaluate a Fusion IR value
49
+ NVF_API const PolymorphicValue& evaluate(const Val* value);
50
+
51
+ //! Try to evaluate a parallel dimension
52
+ const PolymorphicValue& evaluate(ParallelType pt);
53
+
54
+ //! Evaluates a value through a const evaluator reference.
55
+ //! Initializes a known_values map to store intermediate values in lieu of
56
+ //! known_values_.
57
+ NVF_API PolymorphicValue evaluate(const Val* value) const;
58
+
59
+ //! Base evaluate method called by other overloads and Expr::evaluate.
60
+ const PolymorphicValue& evaluate(
61
+ const Val* value,
62
+ std::unordered_map<const Val*, PolymorphicValue>& known_values) const;
63
+
64
+ bool isKnown(const Val* value) const {
65
+ return known_values_.count(value) > 0;
66
+ }
67
+
68
+ void invalidate(const Val* value) {
69
+ known_values_.erase(value);
70
+ }
71
+
72
+ //! Debugging helper, prints all the currently known values
73
+ void print() const;
74
+
75
+ void bindPrecomputedValues(PrecomputedValues* precomputed_values) {
76
+ precomputed_values_ = precomputed_values;
77
+ }
78
+
79
+ auto& precomputedValues() {
80
+ return precomputed_values_;
81
+ }
82
+
83
+ //! Augment the evaluator with the exact root-domain map such that
84
+ //! if the extent of a root ID is known, the extents of all other
85
+ //! root IDs that are exactly mapped also get bound to the same
86
+ //! value. This is currently just done with ExactLogicalDomainMap, but
87
+ //! can be similarly done with the Exact CA map as well.
88
+ void propagateBoundValuesThroughExactMaps(
89
+ Fusion* fusion,
90
+ ExactLogicalDomainMap* exact_map = nullptr);
91
+
92
+ ExpressionEvaluator clone(IrCloner& ir_cloner) const;
93
+
94
+ private:
95
+ void bind_(
96
+ const Val* value,
97
+ PolymorphicValue concrete_value,
98
+ bool evaluate_validate);
99
+
100
+ void bind_(const std::string& name, PolymorphicValue concrete_value);
101
+
102
+ void bindTensorDomain(
103
+ const TensorView* tv,
104
+ const at::Tensor& t,
105
+ bool evaluate_validate);
106
+
107
+ const PolymorphicValue& getValue(
108
+ const Val* value,
109
+ const std::unordered_map<const Val*, PolymorphicValue>&
110
+ additional_known_values) const;
111
+
112
+ private:
113
+ // TODO: Consider make this const. It can't be const as bind() of
114
+ // this class calls
115
+ // PrecomputedValuess::bindConcreteParallelTypeValue, but it's
116
+ // unclear why the precompute values cannot be kept constant and
117
+ // binding a value to ExpressionEvaluator just updates
118
+ // known_named_scalars_.
119
+ PrecomputedValues* precomputed_values_ = nullptr;
120
+ std::unordered_map<const Val*, PolymorphicValue> known_values_;
121
+ std::unordered_map<std::string, PolymorphicValue> known_named_scalars_;
122
+ PolymorphicValue null_ = std::monostate{};
123
+ };
124
+
125
+ } // namespace nvfuser