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.
- nvfuser/_C.cpython-312-x86_64-linux-gnu.so +0 -0
- nvfuser/__init__.py +618 -0
- nvfuser/__init__.pyi +4 -0
- nvfuser/contrib/__init__.py +9 -0
- nvfuser/contrib/nn/__init__.py +13 -0
- nvfuser/contrib/nn/normalization.py +725 -0
- nvfuser/include/nvfuser/alias_analysis.h +116 -0
- nvfuser/include/nvfuser/bfs.h +929 -0
- nvfuser/include/nvfuser/codegen.h +26 -0
- nvfuser/include/nvfuser/compute_at.h +28 -0
- nvfuser/include/nvfuser/compute_at_map.h +394 -0
- nvfuser/include/nvfuser/contiguity.h +351 -0
- nvfuser/include/nvfuser/cuda_utils.h +50 -0
- nvfuser/include/nvfuser/debug.h +50 -0
- nvfuser/include/nvfuser/device_lower/analysis/bank_conflict.h +53 -0
- nvfuser/include/nvfuser/device_lower/analysis/circular_buffer.h +109 -0
- nvfuser/include/nvfuser/device_lower/analysis/device_version.h +65 -0
- nvfuser/include/nvfuser/device_lower/analysis/divisible_split.h +28 -0
- nvfuser/include/nvfuser/device_lower/analysis/fused_reduction.h +36 -0
- nvfuser/include/nvfuser/device_lower/analysis/index_compute.h +322 -0
- nvfuser/include/nvfuser/device_lower/analysis/predicate_elimination.h +71 -0
- nvfuser/include/nvfuser/device_lower/analysis/sync_information.h +47 -0
- nvfuser/include/nvfuser/device_lower/analysis/tensor_memory.h +65 -0
- nvfuser/include/nvfuser/device_lower/analysis/thread_predicate.h +158 -0
- nvfuser/include/nvfuser/device_lower/analysis/tma.h +93 -0
- nvfuser/include/nvfuser/device_lower/analysis/trivial_broadcast.h +75 -0
- nvfuser/include/nvfuser/device_lower/id_model_options.h +135 -0
- nvfuser/include/nvfuser/device_lower/lower2device.h +391 -0
- nvfuser/include/nvfuser/device_lower/pass/alias_memory.h +37 -0
- nvfuser/include/nvfuser/device_lower/pass/allocation.h +32 -0
- nvfuser/include/nvfuser/device_lower/pass/circular_buffer.h +191 -0
- nvfuser/include/nvfuser/device_lower/pass/expr_sort.h +17 -0
- nvfuser/include/nvfuser/device_lower/pass/fusion_simplifier.h +21 -0
- nvfuser/include/nvfuser/device_lower/pass/grid_serialization.h +26 -0
- nvfuser/include/nvfuser/device_lower/pass/index.h +200 -0
- nvfuser/include/nvfuser/device_lower/pass/inline_ptx.h +16 -0
- nvfuser/include/nvfuser/device_lower/pass/insert_syncs.h +39 -0
- nvfuser/include/nvfuser/device_lower/pass/instrument.h +24 -0
- nvfuser/include/nvfuser/device_lower/pass/loop_rotation.h +150 -0
- nvfuser/include/nvfuser/device_lower/pass/loops.h +68 -0
- nvfuser/include/nvfuser/device_lower/pass/magic_zero.h +86 -0
- nvfuser/include/nvfuser/device_lower/pass/misaligned_vectorization.h +118 -0
- nvfuser/include/nvfuser/device_lower/pass/predicate.h +23 -0
- nvfuser/include/nvfuser/device_lower/pass/replace_size.h +24 -0
- nvfuser/include/nvfuser/device_lower/pass/scalar_hoist.h +115 -0
- nvfuser/include/nvfuser/device_lower/pass/unroll.h +98 -0
- nvfuser/include/nvfuser/device_lower/pass/vectorize_welford.h +45 -0
- nvfuser/include/nvfuser/device_lower/pass/warp_reduce.h +23 -0
- nvfuser/include/nvfuser/device_lower/utils.h +382 -0
- nvfuser/include/nvfuser/device_lower/validation.h +74 -0
- nvfuser/include/nvfuser/disjoint_set.h +556 -0
- nvfuser/include/nvfuser/dispatch.h +334 -0
- nvfuser/include/nvfuser/driver_api.h +49 -0
- nvfuser/include/nvfuser/dynamic_transform.h +316 -0
- nvfuser/include/nvfuser/dynamic_type/C++20/type_traits +37 -0
- nvfuser/include/nvfuser/dynamic_type/dynamic_type.h +969 -0
- nvfuser/include/nvfuser/dynamic_type/error.h +24 -0
- nvfuser/include/nvfuser/dynamic_type/type_traits.h +703 -0
- nvfuser/include/nvfuser/evaluator_common.h +295 -0
- nvfuser/include/nvfuser/exceptions.h +283 -0
- nvfuser/include/nvfuser/expr_evaluator.h +125 -0
- nvfuser/include/nvfuser/expr_simplifier.h +218 -0
- nvfuser/include/nvfuser/flatbuffers/allocator.h +68 -0
- nvfuser/include/nvfuser/flatbuffers/array.h +253 -0
- nvfuser/include/nvfuser/flatbuffers/base.h +486 -0
- nvfuser/include/nvfuser/flatbuffers/buffer.h +154 -0
- nvfuser/include/nvfuser/flatbuffers/buffer_ref.h +53 -0
- nvfuser/include/nvfuser/flatbuffers/code_generator.h +80 -0
- nvfuser/include/nvfuser/flatbuffers/code_generators.h +234 -0
- nvfuser/include/nvfuser/flatbuffers/default_allocator.h +64 -0
- nvfuser/include/nvfuser/flatbuffers/detached_buffer.h +114 -0
- nvfuser/include/nvfuser/flatbuffers/flatbuffer_builder.h +1225 -0
- nvfuser/include/nvfuser/flatbuffers/flatbuffers.h +272 -0
- nvfuser/include/nvfuser/flatbuffers/flatc.h +130 -0
- nvfuser/include/nvfuser/flatbuffers/flex_flat_util.h +36 -0
- nvfuser/include/nvfuser/flatbuffers/flexbuffers.h +1889 -0
- nvfuser/include/nvfuser/flatbuffers/grpc.h +300 -0
- nvfuser/include/nvfuser/flatbuffers/hash.h +127 -0
- nvfuser/include/nvfuser/flatbuffers/idl.h +1359 -0
- nvfuser/include/nvfuser/flatbuffers/minireflect.h +420 -0
- nvfuser/include/nvfuser/flatbuffers/reflection.h +522 -0
- nvfuser/include/nvfuser/flatbuffers/reflection_generated.h +1471 -0
- nvfuser/include/nvfuser/flatbuffers/registry.h +128 -0
- nvfuser/include/nvfuser/flatbuffers/stl_emulation.h +513 -0
- nvfuser/include/nvfuser/flatbuffers/string.h +64 -0
- nvfuser/include/nvfuser/flatbuffers/struct.h +53 -0
- nvfuser/include/nvfuser/flatbuffers/table.h +168 -0
- nvfuser/include/nvfuser/flatbuffers/util.h +731 -0
- nvfuser/include/nvfuser/flatbuffers/vector.h +393 -0
- nvfuser/include/nvfuser/flatbuffers/vector_downward.h +273 -0
- nvfuser/include/nvfuser/flatbuffers/verifier.h +317 -0
- nvfuser/include/nvfuser/fusion.h +511 -0
- nvfuser/include/nvfuser/fusion_guard.h +37 -0
- nvfuser/include/nvfuser/fusion_profiler.h +311 -0
- nvfuser/include/nvfuser/fusion_segmenter.h +751 -0
- nvfuser/include/nvfuser/global_allocator.h +27 -0
- nvfuser/include/nvfuser/grouped_reduction.h +47 -0
- nvfuser/include/nvfuser/host_ir/container.h +60 -0
- nvfuser/include/nvfuser/host_ir/executor.h +152 -0
- nvfuser/include/nvfuser/host_ir/host_ir.h +320 -0
- nvfuser/include/nvfuser/host_ir/lower.h +35 -0
- nvfuser/include/nvfuser/id_model/circular_buffer_indexing.h +56 -0
- nvfuser/include/nvfuser/id_model/contiguity.h +166 -0
- nvfuser/include/nvfuser/id_model/id_model.h +359 -0
- nvfuser/include/nvfuser/id_model/id_model_index_compute.h +81 -0
- nvfuser/include/nvfuser/id_model/indexing.h +208 -0
- nvfuser/include/nvfuser/id_model/indexing_traversal.h +72 -0
- nvfuser/include/nvfuser/id_model/indexing_utils.h +62 -0
- nvfuser/include/nvfuser/id_model/loop_promotion.h +180 -0
- nvfuser/include/nvfuser/id_model/predicate_indexing.h +104 -0
- nvfuser/include/nvfuser/id_model/schedule.h +54 -0
- nvfuser/include/nvfuser/id_model/to_string.h +87 -0
- nvfuser/include/nvfuser/id_model/transform_replay.h +58 -0
- nvfuser/include/nvfuser/id_model/utils.h +176 -0
- nvfuser/include/nvfuser/id_model/validation_utils.h +55 -0
- nvfuser/include/nvfuser/index_compute.h +651 -0
- nvfuser/include/nvfuser/instrumentation.h +107 -0
- nvfuser/include/nvfuser/ir/all_nodes.h +14 -0
- nvfuser/include/nvfuser/ir/base_nodes.h +687 -0
- nvfuser/include/nvfuser/ir/builder.h +215 -0
- nvfuser/include/nvfuser/ir/builder_passkey.h +29 -0
- nvfuser/include/nvfuser/ir/cloner.h +185 -0
- nvfuser/include/nvfuser/ir/container.h +226 -0
- nvfuser/include/nvfuser/ir/graphviz.h +119 -0
- nvfuser/include/nvfuser/ir/interface_nodes.h +957 -0
- nvfuser/include/nvfuser/ir/internal_base_nodes.h +744 -0
- nvfuser/include/nvfuser/ir/internal_nodes.h +2792 -0
- nvfuser/include/nvfuser/ir/iostream.h +98 -0
- nvfuser/include/nvfuser/ir/printer.h +57 -0
- nvfuser/include/nvfuser/ir/utils.h +801 -0
- nvfuser/include/nvfuser/iter_visitor.h +661 -0
- nvfuser/include/nvfuser/kernel.h +299 -0
- nvfuser/include/nvfuser/kernel_db/kernel_db.h +109 -0
- nvfuser/include/nvfuser/kernel_db/utils.h +37 -0
- nvfuser/include/nvfuser/kernel_ir.h +1457 -0
- nvfuser/include/nvfuser/kernel_ir_dispatch.h +147 -0
- nvfuser/include/nvfuser/linked_hash_map.h +97 -0
- nvfuser/include/nvfuser/logical_domain_map.h +577 -0
- nvfuser/include/nvfuser/macros.h +23 -0
- nvfuser/include/nvfuser/mma_type.h +257 -0
- nvfuser/include/nvfuser/multidevice/c10d_mock.h +175 -0
- nvfuser/include/nvfuser/multidevice/communication.h +232 -0
- nvfuser/include/nvfuser/multidevice/communicator.h +179 -0
- nvfuser/include/nvfuser/multidevice/device_mesh.h +95 -0
- nvfuser/include/nvfuser/multidevice/executor.h +107 -0
- nvfuser/include/nvfuser/multidevice/multidevice.h +18 -0
- nvfuser/include/nvfuser/multidevice/utils.h +187 -0
- nvfuser/include/nvfuser/non_divisible_split.h +86 -0
- nvfuser/include/nvfuser/opaque_type.h +129 -0
- nvfuser/include/nvfuser/ops/alias.h +192 -0
- nvfuser/include/nvfuser/ops/all_ops.h +13 -0
- nvfuser/include/nvfuser/ops/arith.h +712 -0
- nvfuser/include/nvfuser/ops/composite.h +130 -0
- nvfuser/include/nvfuser/ops/indexing.h +55 -0
- nvfuser/include/nvfuser/ops/normalization.h +263 -0
- nvfuser/include/nvfuser/ops/utils.h +127 -0
- nvfuser/include/nvfuser/options.h +313 -0
- nvfuser/include/nvfuser/parallel_dimension_map.h +95 -0
- nvfuser/include/nvfuser/parallel_type_bitmap.h +365 -0
- nvfuser/include/nvfuser/polymorphic_value.h +432 -0
- nvfuser/include/nvfuser/predicate_compute.h +213 -0
- nvfuser/include/nvfuser/python_frontend/distributed_tensor.h +50 -0
- nvfuser/include/nvfuser/python_frontend/fusion_cache.h +298 -0
- nvfuser/include/nvfuser/python_frontend/fusion_definition.h +372 -0
- nvfuser/include/nvfuser/python_frontend/fusion_record.h +3124 -0
- nvfuser/include/nvfuser/python_frontend/fusion_state.h +143 -0
- nvfuser/include/nvfuser/python_frontend/python_bindings.h +27 -0
- nvfuser/include/nvfuser/python_frontend/segmentation.h +246 -0
- nvfuser/include/nvfuser/python_frontend/translation.h +20 -0
- nvfuser/include/nvfuser/python_frontend/translation_utils.h +308 -0
- nvfuser/include/nvfuser/scheduler/all_schedulers.h +17 -0
- nvfuser/include/nvfuser/scheduler/ampere_multi_matmul.h +206 -0
- nvfuser/include/nvfuser/scheduler/cache_policy_refiner.h +19 -0
- nvfuser/include/nvfuser/scheduler/compile_time_info.h +322 -0
- nvfuser/include/nvfuser/scheduler/debug_utils.h +68 -0
- nvfuser/include/nvfuser/scheduler/expr_eval_sched.h +45 -0
- nvfuser/include/nvfuser/scheduler/heuristic.h +113 -0
- nvfuser/include/nvfuser/scheduler/hopper_multi_matmul.h +204 -0
- nvfuser/include/nvfuser/scheduler/mark_aliases.h +19 -0
- nvfuser/include/nvfuser/scheduler/matmul.h +40 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic.h +293 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic_plugin.h +65 -0
- nvfuser/include/nvfuser/scheduler/matmul_heuristic_plugin_api.h +99 -0
- nvfuser/include/nvfuser/scheduler/matmul_utils.h +54 -0
- nvfuser/include/nvfuser/scheduler/mma_utils.h +500 -0
- nvfuser/include/nvfuser/scheduler/multi_matmul.h +74 -0
- nvfuser/include/nvfuser/scheduler/no_op.h +48 -0
- nvfuser/include/nvfuser/scheduler/normalization_inner.h +49 -0
- nvfuser/include/nvfuser/scheduler/normalization_inner_outer.h +51 -0
- nvfuser/include/nvfuser/scheduler/normalization_outer.h +48 -0
- nvfuser/include/nvfuser/scheduler/normalization_utils.h +379 -0
- nvfuser/include/nvfuser/scheduler/pointwise.h +183 -0
- nvfuser/include/nvfuser/scheduler/pointwise_heuristic.h +118 -0
- nvfuser/include/nvfuser/scheduler/pointwise_utils.h +24 -0
- nvfuser/include/nvfuser/scheduler/reduction.h +43 -0
- nvfuser/include/nvfuser/scheduler/reduction_heuristic.h +339 -0
- nvfuser/include/nvfuser/scheduler/reduction_utils.h +159 -0
- nvfuser/include/nvfuser/scheduler/registry.h +97 -0
- nvfuser/include/nvfuser/scheduler/registry_utils.h +111 -0
- nvfuser/include/nvfuser/scheduler/resize.h +41 -0
- nvfuser/include/nvfuser/scheduler/resize_heuristic.h +67 -0
- nvfuser/include/nvfuser/scheduler/runtime_info.h +166 -0
- nvfuser/include/nvfuser/scheduler/scheduler_types.h +80 -0
- nvfuser/include/nvfuser/scheduler/transpose.h +114 -0
- nvfuser/include/nvfuser/scheduler/transpose_heuristic.h +164 -0
- nvfuser/include/nvfuser/scheduler/utils.h +771 -0
- nvfuser/include/nvfuser/scheduler/vectorize_helper.h +349 -0
- nvfuser/include/nvfuser/serde/factory.h +55 -0
- nvfuser/include/nvfuser/serde/fusion_cache_generated.h +4319 -0
- nvfuser/include/nvfuser/serde/fusion_record.h +124 -0
- nvfuser/include/nvfuser/serde/polymorphic_value.h +52 -0
- nvfuser/include/nvfuser/serde/utils.h +34 -0
- nvfuser/include/nvfuser/struct.inl +127 -0
- nvfuser/include/nvfuser/swizzle.h +54 -0
- nvfuser/include/nvfuser/sys_utils.h +40 -0
- nvfuser/include/nvfuser/tensor_metadata.h +118 -0
- nvfuser/include/nvfuser/tma.h +124 -0
- nvfuser/include/nvfuser/transform_iter.h +522 -0
- nvfuser/include/nvfuser/transform_replay.h +297 -0
- nvfuser/include/nvfuser/transform_rfactor.h +33 -0
- nvfuser/include/nvfuser/transform_view.h +136 -0
- nvfuser/include/nvfuser/type.h +1125 -0
- nvfuser/include/nvfuser/type_promotion.h +61 -0
- nvfuser/include/nvfuser/utils.h +619 -0
- nvfuser/include/nvfuser/val_graph.h +446 -0
- nvfuser/include/nvfuser/val_graph_visitor.h +259 -0
- nvfuser/include/nvfuser/validator_utils.h +92 -0
- nvfuser/include/nvfuser/vectorization_info.h +31 -0
- nvfuser/include/nvfuser/visibility.h +21 -0
- nvfuser/lib/libnvfuser_codegen.so +0 -0
- nvfuser/nvfuser_version.py +69 -0
- nvfuser/pytorch_utils.py +184 -0
- nvfuser/share/cmake/nvfuser/NvfuserConfig-release.cmake +20 -0
- nvfuser/share/cmake/nvfuser/NvfuserConfig.cmake +106 -0
- nvfuser/utils.py +18 -0
- nvfuser/version.py +1 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/LICENSE +976 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/METADATA +16 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/RECORD +242 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/WHEEL +5 -0
- nvfuser_cu121_torch25-0.2.25.dev20250201.dist-info/top_level.txt +1 -0
- nvfuser_cu121_torch25.libs/libnvToolsExt-847d78f2.so.1.0.0 +0 -0
@@ -0,0 +1,556 @@
|
|
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 <algorithm>
|
13
|
+
#include <initializer_list>
|
14
|
+
#include <unordered_map>
|
15
|
+
#include <unordered_set>
|
16
|
+
#include <vector>
|
17
|
+
|
18
|
+
// For printing of the set when using a Statement as the type for the set
|
19
|
+
#include <ir/base_nodes.h>
|
20
|
+
|
21
|
+
namespace nvfuser {
|
22
|
+
|
23
|
+
namespace {
|
24
|
+
|
25
|
+
template <typename T>
|
26
|
+
std::string abstractToString(T* ptr) {
|
27
|
+
return ptr->toString();
|
28
|
+
}
|
29
|
+
|
30
|
+
template <typename T>
|
31
|
+
std::string abstractToString(T ref) {
|
32
|
+
return ref.toString();
|
33
|
+
}
|
34
|
+
|
35
|
+
} // namespace
|
36
|
+
|
37
|
+
// Vector like class that will prevent adding duplicate entries by also
|
38
|
+
// maintaing a set
|
39
|
+
//
|
40
|
+
// TODO: Can we support std::back_inserter with this class?
|
41
|
+
template <typename T, typename Hash = std::hash<T>>
|
42
|
+
class VectorOfUniqueEntries {
|
43
|
+
public:
|
44
|
+
// Naming not following our conventions but using the same name as
|
45
|
+
// std::vector makes it more convenient when we want to use this
|
46
|
+
// class as if it's like std::vector
|
47
|
+
using value_type = T;
|
48
|
+
|
49
|
+
VectorOfUniqueEntries() = default;
|
50
|
+
|
51
|
+
VectorOfUniqueEntries(const std::initializer_list<T>& initializer)
|
52
|
+
: VectorOfUniqueEntries(initializer.begin(), initializer.end()) {}
|
53
|
+
|
54
|
+
VectorOfUniqueEntries(const VectorOfUniqueEntries& other) = default;
|
55
|
+
|
56
|
+
VectorOfUniqueEntries& operator=(const VectorOfUniqueEntries& other) =
|
57
|
+
default;
|
58
|
+
|
59
|
+
template <class InputIt>
|
60
|
+
VectorOfUniqueEntries(InputIt first, InputIt last) {
|
61
|
+
pushBack(first, last);
|
62
|
+
}
|
63
|
+
|
64
|
+
template <class Container>
|
65
|
+
VectorOfUniqueEntries(const Container& container)
|
66
|
+
: VectorOfUniqueEntries(container.begin(), container.end()) {}
|
67
|
+
|
68
|
+
template <class InputIt>
|
69
|
+
void pushBack(InputIt first, InputIt last) {
|
70
|
+
while (first != last) {
|
71
|
+
pushBack(*first++);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
// Returns if a node was actually added
|
76
|
+
bool pushBack(T entry) {
|
77
|
+
if (set_.emplace(entry).second) {
|
78
|
+
vector_.push_back(entry);
|
79
|
+
return true;
|
80
|
+
}
|
81
|
+
return false;
|
82
|
+
}
|
83
|
+
|
84
|
+
// Returns true if any node was added
|
85
|
+
bool pushBack(const VectorOfUniqueEntries<T, Hash>& other) {
|
86
|
+
return pushBack(other.vector());
|
87
|
+
}
|
88
|
+
|
89
|
+
// Returns true if any node was added
|
90
|
+
template <typename OtherType>
|
91
|
+
bool pushBack(const std::vector<OtherType>& other) {
|
92
|
+
bool any_added = false;
|
93
|
+
for (const auto& entry : other) {
|
94
|
+
auto added = pushBack(entry);
|
95
|
+
any_added = any_added || added;
|
96
|
+
}
|
97
|
+
return any_added;
|
98
|
+
}
|
99
|
+
|
100
|
+
// Returns a new VectorOfUniqueEntries with entries that are in both this and
|
101
|
+
// other, order is preserved as this.
|
102
|
+
VectorOfUniqueEntries<T, Hash> computeIntersect(
|
103
|
+
const VectorOfUniqueEntries<T, Hash>& other) const {
|
104
|
+
VectorOfUniqueEntries<T, Hash> intersection;
|
105
|
+
for (const auto& entry : vector()) {
|
106
|
+
if (other.has(entry)) {
|
107
|
+
intersection.pushBack(entry);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
return intersection;
|
111
|
+
}
|
112
|
+
|
113
|
+
// Returns a new VectorOfUniqueEntries with entries that are in this but not
|
114
|
+
// in other.
|
115
|
+
VectorOfUniqueEntries<T, Hash> computeSubtract(
|
116
|
+
const VectorOfUniqueEntries<T, Hash>& other) const {
|
117
|
+
VectorOfUniqueEntries<T, Hash> subtraction;
|
118
|
+
for (const auto& entry : vector()) {
|
119
|
+
if (!other.has(entry)) {
|
120
|
+
subtraction.pushBack(entry);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
return subtraction;
|
124
|
+
}
|
125
|
+
|
126
|
+
// Returns a new VectorOfUniqueEntries with entries that are either in this or
|
127
|
+
// other.
|
128
|
+
VectorOfUniqueEntries<T, Hash> computeUnion(
|
129
|
+
const VectorOfUniqueEntries<T, Hash>& other) const {
|
130
|
+
VectorOfUniqueEntries<T, Hash> union_(*this);
|
131
|
+
for (const auto& entry : other.vector()) {
|
132
|
+
union_.pushBack(entry);
|
133
|
+
}
|
134
|
+
return union_;
|
135
|
+
}
|
136
|
+
|
137
|
+
// Returns a const vector useful for iterating on
|
138
|
+
const std::vector<T>& vector() const {
|
139
|
+
return vector_;
|
140
|
+
}
|
141
|
+
|
142
|
+
const std::unordered_set<T>& set() const {
|
143
|
+
return set_;
|
144
|
+
}
|
145
|
+
|
146
|
+
bool operator==(const VectorOfUniqueEntries& other) const {
|
147
|
+
return vector() == other.vector();
|
148
|
+
}
|
149
|
+
|
150
|
+
bool operator!=(const VectorOfUniqueEntries& other) const {
|
151
|
+
return !operator==(other);
|
152
|
+
}
|
153
|
+
|
154
|
+
// Returns first element in vector
|
155
|
+
T front() const {
|
156
|
+
#if defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_CHECK)
|
157
|
+
NVF_ERROR(!empty());
|
158
|
+
#endif // defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_CHECK)
|
159
|
+
return vector_.front();
|
160
|
+
}
|
161
|
+
|
162
|
+
// Returns last element in vector
|
163
|
+
T back() const {
|
164
|
+
#if defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_CHECK)
|
165
|
+
NVF_ERROR(!empty());
|
166
|
+
#endif // defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_CHECK)
|
167
|
+
return vector_.back();
|
168
|
+
}
|
169
|
+
|
170
|
+
// Remove and returns the last element in vector
|
171
|
+
T popBack() {
|
172
|
+
#if defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_CHECK)
|
173
|
+
NVF_ERROR(!empty());
|
174
|
+
#endif // defined(NDEBUG) && !defined(NVFUSER_EXPLICIT_CHECK)
|
175
|
+
T v = vector_.back();
|
176
|
+
set_.erase(v);
|
177
|
+
vector_.pop_back();
|
178
|
+
return v;
|
179
|
+
}
|
180
|
+
|
181
|
+
// Returns if this container is empty
|
182
|
+
bool empty() const {
|
183
|
+
return vector_.empty();
|
184
|
+
}
|
185
|
+
|
186
|
+
void clear() {
|
187
|
+
vector_.clear();
|
188
|
+
set_.clear();
|
189
|
+
}
|
190
|
+
|
191
|
+
// Returns the number of elements in this container
|
192
|
+
int64_t size() const {
|
193
|
+
return vector_.size();
|
194
|
+
}
|
195
|
+
|
196
|
+
// Returns if entry is in this vector
|
197
|
+
bool has(T entry) const {
|
198
|
+
return set_.find(entry) != set_.end();
|
199
|
+
}
|
200
|
+
|
201
|
+
// Erase given entry from the containers if
|
202
|
+
// there is a match.
|
203
|
+
int64_t erase(T entry) {
|
204
|
+
vector_.erase(
|
205
|
+
std::remove_if(
|
206
|
+
vector_.begin(),
|
207
|
+
vector_.end(),
|
208
|
+
[entry](T val) { return val == entry; }),
|
209
|
+
vector_.end());
|
210
|
+
|
211
|
+
return static_cast<int64_t>(set_.erase(entry));
|
212
|
+
}
|
213
|
+
|
214
|
+
// Insert elements at the end of the container.
|
215
|
+
template <typename InputIt>
|
216
|
+
void insert(InputIt begin, InputIt end) {
|
217
|
+
for (auto it = begin; it != end; it++) {
|
218
|
+
pushBack(*it);
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
// Returns iterator pointing to the beginning of vector container
|
223
|
+
typename std::vector<T>::const_iterator begin() const {
|
224
|
+
return vector().begin();
|
225
|
+
}
|
226
|
+
|
227
|
+
// Returns iterator pointing to the end of vector container
|
228
|
+
typename std::vector<T>::const_iterator end() const {
|
229
|
+
return vector().end();
|
230
|
+
}
|
231
|
+
|
232
|
+
// Returns iterator pointing to the beginning of vector container
|
233
|
+
typename std::vector<T>::iterator begin() {
|
234
|
+
return vector_.begin();
|
235
|
+
}
|
236
|
+
|
237
|
+
// Returns iterator pointing to the end of vector container
|
238
|
+
typename std::vector<T>::iterator end() {
|
239
|
+
return vector_.end();
|
240
|
+
}
|
241
|
+
|
242
|
+
auto rbegin() const {
|
243
|
+
return vector().rbegin();
|
244
|
+
}
|
245
|
+
|
246
|
+
auto rend() const {
|
247
|
+
return vector().rend();
|
248
|
+
}
|
249
|
+
|
250
|
+
auto rbegin() {
|
251
|
+
return vector_.rbegin();
|
252
|
+
}
|
253
|
+
|
254
|
+
auto rend() {
|
255
|
+
return vector_.rend();
|
256
|
+
}
|
257
|
+
|
258
|
+
T& at(int64_t pos) {
|
259
|
+
return vector_.at(pos);
|
260
|
+
}
|
261
|
+
|
262
|
+
const T& at(int64_t pos) const {
|
263
|
+
return vector_.at(pos);
|
264
|
+
}
|
265
|
+
|
266
|
+
std::string toString() const {
|
267
|
+
std::stringstream ss;
|
268
|
+
ss << "{ ";
|
269
|
+
for (const auto& entry : vector()) {
|
270
|
+
ss << abstractToString(entry);
|
271
|
+
if (entry != vector().back()) {
|
272
|
+
ss << "; ";
|
273
|
+
}
|
274
|
+
}
|
275
|
+
ss << " }";
|
276
|
+
return ss.str();
|
277
|
+
}
|
278
|
+
|
279
|
+
private:
|
280
|
+
std::vector<T> vector_;
|
281
|
+
std::unordered_set<T, Hash> set_;
|
282
|
+
};
|
283
|
+
|
284
|
+
//! Container class DisjointSet models equivalence relationships
|
285
|
+
//!
|
286
|
+
//! Each instance of this class keeps equivalence sets
|
287
|
+
//! DisjointSet::mapEntries(a,b) makes the full set of a and b equivalent
|
288
|
+
//! DisjointSet::*AreMapped(a,b) checks if a and b belong to the same disjoint
|
289
|
+
//! set
|
290
|
+
template <typename T, typename Hash = std::hash<T>>
|
291
|
+
class DisjointSets {
|
292
|
+
public:
|
293
|
+
using DisjointSet = std::shared_ptr<VectorOfUniqueEntries<T, Hash>>;
|
294
|
+
using DisjointSetMap = std::unordered_map<T, DisjointSet, Hash>;
|
295
|
+
|
296
|
+
DisjointSets() = default;
|
297
|
+
|
298
|
+
DisjointSets(const DisjointSets<T, Hash>& other);
|
299
|
+
|
300
|
+
DisjointSets(DisjointSets<T, Hash>&& other) = default;
|
301
|
+
|
302
|
+
DisjointSets<T, Hash>& operator=(const DisjointSets<T, Hash>& other);
|
303
|
+
|
304
|
+
DisjointSets<T, Hash>& operator=(DisjointSets<T, Hash>&& other) = default;
|
305
|
+
|
306
|
+
friend void swap(DisjointSets<T, Hash>& sets1, DisjointSets<T, Hash>& sets2) {
|
307
|
+
using std::swap;
|
308
|
+
swap(sets1.disjoint_sets_, sets2.disjoint_sets_);
|
309
|
+
swap(sets1.disjoint_set_maps_, sets2.disjoint_set_maps_);
|
310
|
+
}
|
311
|
+
|
312
|
+
// Warning: returned values should never be modified. This accessor isn't
|
313
|
+
// strictly safe as VectorOfUniqueEntries is not returned as a const.
|
314
|
+
const DisjointSetMap& disjointSetMap() const {
|
315
|
+
return disjoint_set_maps_;
|
316
|
+
}
|
317
|
+
|
318
|
+
// Warning: returned values should never be modified. This accessor isn't
|
319
|
+
// strictly safe as VectorOfUniqueEntries is not returned as a const.
|
320
|
+
const std::vector<DisjointSet>& disjointSets() const {
|
321
|
+
return disjoint_sets_;
|
322
|
+
}
|
323
|
+
|
324
|
+
typename DisjointSetMap::iterator find(T entry) {
|
325
|
+
return disjoint_set_maps_.find(entry);
|
326
|
+
}
|
327
|
+
|
328
|
+
typename DisjointSetMap::iterator end() {
|
329
|
+
return disjoint_set_maps_.end();
|
330
|
+
}
|
331
|
+
|
332
|
+
typename DisjointSetMap::const_iterator find(T entry) const {
|
333
|
+
return disjoint_set_maps_.find(entry);
|
334
|
+
}
|
335
|
+
|
336
|
+
typename DisjointSetMap::const_iterator end() const {
|
337
|
+
return disjoint_set_maps_.end();
|
338
|
+
}
|
339
|
+
|
340
|
+
// Return the entire disjoint set of provided entry
|
341
|
+
const VectorOfUniqueEntries<T, Hash>& getDisjointSetOf(T entry) const {
|
342
|
+
auto set_it = disjoint_set_maps_.find(entry);
|
343
|
+
NVF_ERROR(
|
344
|
+
set_it != disjoint_set_maps_.end(),
|
345
|
+
"Could not find entry for ",
|
346
|
+
entry->toString());
|
347
|
+
return *(set_it->second);
|
348
|
+
}
|
349
|
+
|
350
|
+
// Initializes a new set for provided entry
|
351
|
+
std::pair<typename DisjointSetMap::iterator, bool> initializeSet(T entry) {
|
352
|
+
auto disjoint_set_maps_it = disjoint_set_maps_.find(entry);
|
353
|
+
if (disjoint_set_maps_it != disjoint_set_maps_.end()) {
|
354
|
+
return std::make_pair(disjoint_set_maps_it, false);
|
355
|
+
}
|
356
|
+
|
357
|
+
disjoint_sets_.push_back(
|
358
|
+
std::make_shared<VectorOfUniqueEntries<T, Hash>>());
|
359
|
+
disjoint_sets_.back()->pushBack(entry);
|
360
|
+
return disjoint_set_maps_.emplace(
|
361
|
+
std::make_pair(entry, disjoint_sets_.back()));
|
362
|
+
}
|
363
|
+
|
364
|
+
// Adds all of the disjoint set belonging to entry1 to the disjoint set
|
365
|
+
// belonging to entry0, maps all entries of disjoint set belonging to entry1
|
366
|
+
// to entry0, removes original disjoint set belonging to entry1.
|
367
|
+
void mapEntries(T entry0, T entry1) {
|
368
|
+
auto set_it_0 = disjoint_set_maps_.find(entry0);
|
369
|
+
auto set_it_1 = disjoint_set_maps_.find(entry1);
|
370
|
+
|
371
|
+
auto set_0_found = set_it_0 != disjoint_set_maps_.end();
|
372
|
+
auto set_1_found = set_it_1 != disjoint_set_maps_.end();
|
373
|
+
|
374
|
+
// Sets already joined
|
375
|
+
if (set_0_found && set_1_found && set_it_0->second == set_it_1->second) {
|
376
|
+
return;
|
377
|
+
}
|
378
|
+
|
379
|
+
// Make and map new set
|
380
|
+
disjoint_sets_.push_back(
|
381
|
+
std::make_shared<VectorOfUniqueEntries<T, Hash>>());
|
382
|
+
auto new_set = disjoint_sets_.back();
|
383
|
+
|
384
|
+
// Add an entry to new_set along with the other entries previously
|
385
|
+
// grouped together with the entry. The existing set is erased.
|
386
|
+
auto mergeSets = [this](const T& entry, auto& new_set) {
|
387
|
+
if (auto it = disjoint_set_maps_.find(entry);
|
388
|
+
it != disjoint_set_maps_.end()) {
|
389
|
+
auto existing_set = it->second;
|
390
|
+
for (const auto& existing_entry : *existing_set) {
|
391
|
+
new_set->pushBack(existing_entry);
|
392
|
+
disjoint_set_maps_[existing_entry] = new_set;
|
393
|
+
}
|
394
|
+
disjoint_sets_.erase(std::find(
|
395
|
+
disjoint_sets_.begin(), disjoint_sets_.end(), existing_set));
|
396
|
+
} else {
|
397
|
+
new_set->pushBack(entry);
|
398
|
+
disjoint_set_maps_[entry] = new_set;
|
399
|
+
}
|
400
|
+
};
|
401
|
+
|
402
|
+
mergeSets(entry0, new_set);
|
403
|
+
|
404
|
+
// This should be after we enter a new set in case it doesn't exist.
|
405
|
+
if (entry0 == entry1) {
|
406
|
+
return;
|
407
|
+
}
|
408
|
+
|
409
|
+
mergeSets(entry1, new_set);
|
410
|
+
}
|
411
|
+
|
412
|
+
// Will assert if provided entry0 is not in any disjoint set, otherwise
|
413
|
+
// returns if entry0 and entry1 are in the same disjoint set.
|
414
|
+
bool strictAreMapped(T entry0, T entry1) const {
|
415
|
+
auto entry_it = disjointSetMap().find(entry0);
|
416
|
+
NVF_ERROR(
|
417
|
+
entry_it != disjointSetMap().end(),
|
418
|
+
"Strict mapping failed on element: ",
|
419
|
+
abstractToString(entry0),
|
420
|
+
" either an error occurred, or non strict mapping should have been used.");
|
421
|
+
return entry_it->second->has(entry1);
|
422
|
+
}
|
423
|
+
|
424
|
+
// If entry0 doesn't have a disjoint set returns false, otherwise returns if
|
425
|
+
// entry0 and entry1 are in the same disjoint set.
|
426
|
+
bool permissiveAreMapped(T entry0, T entry1) const {
|
427
|
+
auto entry_it = disjointSetMap().find(entry0);
|
428
|
+
if (entry_it == disjointSetMap().end()) {
|
429
|
+
return false;
|
430
|
+
}
|
431
|
+
return entry_it->second->has(entry1);
|
432
|
+
}
|
433
|
+
|
434
|
+
// Returns if a set exists with provided entry
|
435
|
+
bool mappingExists(T entry) const {
|
436
|
+
return disjoint_set_maps_.find(entry) != disjoint_set_maps_.end();
|
437
|
+
}
|
438
|
+
|
439
|
+
// Append a new item into an existing disjoint set, and add mapping for this
|
440
|
+
// item
|
441
|
+
void appendToSet(T item, DisjointSet set) {
|
442
|
+
NVF_CHECK(!mappingExists(item), "Item already exist.");
|
443
|
+
NVF_CHECK(
|
444
|
+
!set->empty() && &getDisjointSetOf(set->front()) == set.get(),
|
445
|
+
"Invalid disjoint set given.");
|
446
|
+
set->pushBack(item);
|
447
|
+
disjoint_set_maps_[item] = set;
|
448
|
+
}
|
449
|
+
|
450
|
+
// Erases element if it exists in the disjoint set. Returns true if element
|
451
|
+
// found.
|
452
|
+
bool erase(T entry) {
|
453
|
+
auto entry_it = disjoint_set_maps_.find(entry);
|
454
|
+
if (entry_it == disjoint_set_maps_.end()) {
|
455
|
+
return false;
|
456
|
+
}
|
457
|
+
|
458
|
+
auto set = entry_it->second;
|
459
|
+
if (set->size() == 1) {
|
460
|
+
NVF_ERROR(
|
461
|
+
set->front() == entry,
|
462
|
+
"Disjoint set container found to be in inconsistent state.");
|
463
|
+
disjoint_set_maps_.erase(entry);
|
464
|
+
disjoint_sets_.erase(
|
465
|
+
std::find(disjoint_sets_.begin(), disjoint_sets_.end(), set));
|
466
|
+
} else {
|
467
|
+
disjoint_set_maps_.erase(entry);
|
468
|
+
set->erase(entry);
|
469
|
+
}
|
470
|
+
|
471
|
+
return true;
|
472
|
+
}
|
473
|
+
|
474
|
+
// Returns a deterministic list of all entries that have been added to any
|
475
|
+
// disjoint set.
|
476
|
+
//
|
477
|
+
// Warning: constructed on every call, consider caching result.
|
478
|
+
VectorOfUniqueEntries<T, Hash> getAllElements() const {
|
479
|
+
VectorOfUniqueEntries<T, Hash> all_elements;
|
480
|
+
for (auto set : disjoint_sets_) {
|
481
|
+
for (auto entry : set->vector()) {
|
482
|
+
all_elements.pushBack(entry);
|
483
|
+
}
|
484
|
+
}
|
485
|
+
return all_elements;
|
486
|
+
}
|
487
|
+
|
488
|
+
// Completely clears all disjoint sets
|
489
|
+
void clear() {
|
490
|
+
disjoint_set_maps_.clear();
|
491
|
+
disjoint_sets_.clear();
|
492
|
+
}
|
493
|
+
|
494
|
+
std::string toString() const {
|
495
|
+
std::stringstream ss;
|
496
|
+
ss << "disjoint sets{\n";
|
497
|
+
const std::string sep(" ");
|
498
|
+
for (auto s_ptr : disjoint_sets_) {
|
499
|
+
auto& set = *s_ptr;
|
500
|
+
ss << sep << abstractToString(set) << "\n";
|
501
|
+
}
|
502
|
+
ss << "}";
|
503
|
+
return ss.str();
|
504
|
+
}
|
505
|
+
|
506
|
+
int64_t size() const {
|
507
|
+
return disjoint_sets_.size();
|
508
|
+
}
|
509
|
+
|
510
|
+
private:
|
511
|
+
// Disjoint sets
|
512
|
+
DisjointSetMap disjoint_set_maps_;
|
513
|
+
|
514
|
+
// Keep a list of disjoint_sets that's deterministic to iterate over
|
515
|
+
//
|
516
|
+
// TODO: Should this just be a
|
517
|
+
// VectorOfUniqueEntries<std::shared_ptr<VectorOfUniqueEntries ?
|
518
|
+
std::vector<DisjointSet> disjoint_sets_;
|
519
|
+
};
|
520
|
+
|
521
|
+
template <typename T, typename Hash>
|
522
|
+
DisjointSets<T, Hash>::DisjointSets(const DisjointSets<T, Hash>& other) {
|
523
|
+
std::unordered_map<DisjointSet, int> ptr_map;
|
524
|
+
|
525
|
+
// Deep copy the vector of the disjoint sets, keeping the same
|
526
|
+
// ordering of the sets.
|
527
|
+
for (const auto& other_set : other.disjoint_sets_) {
|
528
|
+
auto new_set = std::make_shared<VectorOfUniqueEntries<T, Hash>>(*other_set);
|
529
|
+
int new_set_index = disjoint_sets_.size();
|
530
|
+
disjoint_sets_.emplace_back(new_set);
|
531
|
+
NVF_ERROR(
|
532
|
+
ptr_map.emplace(other_set, new_set_index).second,
|
533
|
+
"Duplicated set found: ",
|
534
|
+
other_set->toString());
|
535
|
+
}
|
536
|
+
|
537
|
+
// Copy the mappings using the new sets
|
538
|
+
for (const auto& kv : other.disjoint_set_maps_) {
|
539
|
+
const auto key = kv.first;
|
540
|
+
const auto new_set_index = ptr_map.at(kv.second);
|
541
|
+
disjoint_set_maps_.emplace(key, disjoint_sets_.at(new_set_index));
|
542
|
+
}
|
543
|
+
}
|
544
|
+
|
545
|
+
template <typename T, typename Hash>
|
546
|
+
DisjointSets<T, Hash>& DisjointSets<T, Hash>::operator=(
|
547
|
+
const DisjointSets<T, Hash>& other) {
|
548
|
+
disjoint_set_maps_.clear();
|
549
|
+
disjoint_sets_.clear();
|
550
|
+
|
551
|
+
DisjointSets<T, Hash> copy(other);
|
552
|
+
swap(*this, copy);
|
553
|
+
return *this;
|
554
|
+
}
|
555
|
+
|
556
|
+
} // namespace nvfuser
|