Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions csrc/mma_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ enum class MatmulDomain { M = 0, N, K, Batch };
//! INPUT_B - a producer of MMA input B
//! INPUT_C - a producer of a tensor used in fusion epilogue,
//! for example tensor used in beta scaling fusion
//! OUTPUT_D - the main consumer of MMA op results
//! OUTPUT_AUX - fusion outputs that are consumers of OUTPUT_D
//! OUTPUT_D - fusion outputs that have the matmul as a dependency
//!
//! Naming convention is based on the following formula:
//! D = alpha * A x B + beta * C
//! AUX = relu(D)
//! Note: bias vector tensors will be assigned to INPUT_C role.
enum class MatmulRole { INPUT_A = 0, INPUT_B, OUTPUT_D, INPUT_C, OUTPUT_AUX };
enum class MatmulRole { INPUT_A = 0, INPUT_B, INPUT_C, OUTPUT_D };

//! The expected number of occurances of core TensorView roles in fusion
static constexpr size_t MATMUL_CORE_ROLES_EXPECTED_COUNT = 1;
Expand Down
6 changes: 0 additions & 6 deletions csrc/scheduler/matmul_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,6 @@ std::string isMatmulFusionDefinitionSupported(
tvs_with_roles.insert(entry->second.begin(), entry->second.end());
}

// Non-core output roles are optional, no requirements for definitions
entry = roles_map.find(MatmulRole::OUTPUT_AUX);
if (entry != roles_map.end()) {
tvs_with_roles.insert(entry->second.begin(), entry->second.end());
}

const auto in_out_tvs_count =
fusion_inputs_tvs.size() + fusion_outputs_tvs.size();
if (in_out_tvs_count != tvs_with_roles.size()) {
Expand Down
19 changes: 2 additions & 17 deletions csrc/scheduler/mma_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,27 +1231,12 @@ RolesMapOpt getTensorRoles(
}
}

// NOTE: sort output roles in descending order by uses() size, and
// if equal then by name() to ensure the stable ordering of tensor
// views in collections assigned to the supported roles
std::sort(storage.begin(), storage.end(), [](TensorView* a, TensorView* b) {
return (a->uses().size() == b->uses().size())
? (a->name() < b->name())
: (a->uses().size() > b->uses().size());
});

Comment on lines -1234 to -1242

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized this is redundant since we now do this for all roles, not just outputs.

if (!storage.empty()) {
// NOTE: currently, we pick as a reference tensor one with `m` and `n`
// IterDomains and the most uses
auto pos = storage.begin();
tensor_roles[MatmulRole::OUTPUT_D].push_back(*pos);
for (++pos; pos != storage.end(); ++pos) {
tensor_roles[MatmulRole::OUTPUT_AUX].push_back(*pos);
}
tensor_roles[MatmulRole::OUTPUT_D] = storage;
}

for (auto& [role, tvs] : tensor_roles) {
// NOTE: sort input roles in descending order by uses() size, and
// NOTE: sort role tvs in descending order by uses() size, and
// if equal then by name() to ensure the stable ordering of tensor
// views in collections assigned to the supported roles
std::sort(tvs.begin(), tvs.end(), [](TensorView* a, TensorView* b) {
Expand Down