CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
128 lines
4.4 KiB
C++
128 lines
4.4 KiB
C++
// Copyright Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include "NodeSchedulingUtils.hpp"
|
|
|
|
namespace rocRoller::KernelGraph::NodeScheduling
|
|
{
|
|
std::unordered_map<int, std::vector<int>> getGroupedNodes(KernelGraph const& graph,
|
|
std::predicate<int> auto pred)
|
|
{
|
|
auto theNodes = graph.control.getNodes().filter(pred);
|
|
|
|
std::unordered_map<int, std::vector<int>> rv;
|
|
for(auto node : theNodes)
|
|
{
|
|
auto parentPair = containingAncestors(node, graph).take(1).only();
|
|
AssertFatal(parentPair.has_value(), "Node has no containing ancestor", ShowValue(node));
|
|
|
|
rv[parentPair->first].push_back(node);
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
template <ControlGraph::COperation T>
|
|
std::unordered_map<int, std::vector<int>> getGroupedNodes(KernelGraph const& graph)
|
|
{
|
|
auto pred = [&graph](int idx) { return graph.control.get<T>(idx).has_value(); };
|
|
|
|
return getGroupedNodes(graph, pred);
|
|
}
|
|
|
|
void orderNodes(KernelGraph const& graph, std::vector<int>& nodes, auto const& comp)
|
|
{
|
|
std::vector<int> desiredOrder;
|
|
|
|
if(Log::getLogger()->should_log(LogLevel::Debug))
|
|
{
|
|
std::set tmp(nodes.begin(), nodes.end());
|
|
Log::debug("Pre-existing order:\n{}", graph.control.nodeOrderTableString(tmp));
|
|
|
|
desiredOrder = nodes;
|
|
std::ranges::sort(desiredOrder, comp);
|
|
}
|
|
// Simply including existing order in `BestNodeOrder` and calling `sort` can
|
|
// lead to a situation where existing nodes appear out of program order.
|
|
//
|
|
// Instead:
|
|
// 1. Create a subgraph that just contains `nodes` but preserves the same
|
|
// order relationships between them.
|
|
// 2. Walk that subgraph in topological order, using `BestNodeOrder` to decide
|
|
// which node to pick next when there are multiple topologically valid options.
|
|
|
|
auto subGraph = createSubGraph(graph, nodes);
|
|
|
|
auto candidates = subGraph.roots().to<std::deque>();
|
|
|
|
std::unordered_set<int> remainingNodes(nodes.begin(), nodes.end());
|
|
remainingNodes.reserve(nodes.size());
|
|
|
|
std::unordered_set<int> completedNodes;
|
|
completedNodes.reserve(nodes.size());
|
|
|
|
auto nodeSatisfied = [&](int node) -> bool {
|
|
if(completedNodes.contains(node))
|
|
return false;
|
|
|
|
for(auto input : subGraph.getInputNodeIndices<ControlGraph::Sequence>(node))
|
|
{
|
|
if(!completedNodes.contains(input))
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
for(auto candidate : candidates)
|
|
{
|
|
remainingNodes.erase(candidate);
|
|
}
|
|
|
|
nodes.clear();
|
|
|
|
if(Log::getLogger()->should_log(LogLevel::Debug))
|
|
{
|
|
std::ranges::sort(candidates, comp);
|
|
Log::debug("Starting with ({})", fmt::join(candidates, ","));
|
|
}
|
|
|
|
while(!remainingNodes.empty() || !candidates.empty())
|
|
{
|
|
std::ranges::sort(candidates, comp);
|
|
auto nextNode = candidates.front();
|
|
candidates.pop_front();
|
|
Log::debug("Picking {}", nextNode);
|
|
|
|
nodes.push_back(nextNode);
|
|
completedNodes.insert(nextNode);
|
|
|
|
if(!remainingNodes.empty())
|
|
{
|
|
auto outputNodes = subGraph.getOutputNodeIndices<ControlGraph::Sequence>(nextNode);
|
|
|
|
std::set<int> newNodes;
|
|
|
|
for(auto outputNode : outputNodes)
|
|
{
|
|
if(nodeSatisfied(outputNode))
|
|
{
|
|
newNodes.insert(outputNode);
|
|
candidates.push_back(outputNode);
|
|
remainingNodes.erase(outputNode);
|
|
}
|
|
}
|
|
|
|
if(!newNodes.empty() && Log::getLogger()->should_log(LogLevel::Debug))
|
|
{
|
|
Log::debug("Adding ({})", fmt::join(newNodes, ", "));
|
|
std::ranges::sort(candidates, comp);
|
|
Log::debug("Now ({})", fmt::join(candidates, ", "));
|
|
}
|
|
}
|
|
}
|
|
|
|
Log::debug("Desired order: \n{}", fmt::join(desiredOrder, "\n"));
|
|
Log::debug("Actual order: \n{}", fmt::join(nodes, "\n"));
|
|
}
|
|
} |