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
90 lines
2.7 KiB
C++
90 lines
2.7 KiB
C++
// Copyright Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include <set>
|
|
#include <unordered_map>
|
|
#include <unordered_set>
|
|
#include <variant>
|
|
|
|
#include <rocRoller/KernelGraph/KernelGraph_fwd.hpp>
|
|
|
|
namespace rocRoller::KernelGraph
|
|
{
|
|
/**
|
|
* Utility base class that facilitates visiting each node in a control
|
|
* graph in topological (program) order.
|
|
* Note that this will only walk in one of potentially many valid
|
|
* topological orderings of the control graph; most kernels have some
|
|
* ambiguity here.
|
|
*
|
|
* If MyClass is derived from TopoControlGraphVisitor<MyClass>, it must
|
|
* implement the call operator for the following signature:
|
|
* void (operator()(int node, Operation op));
|
|
*
|
|
* A FatalError will be thrown if the entire graph cannot be walked in
|
|
* program order. This might be because:
|
|
* - There is a cycle in the graph
|
|
* - There is a Sequence edge that spans two Body scopes: either between
|
|
* two nodes which have different immediate Body parents, or between two
|
|
* separate logical scopes of the same Body parent (such as from the
|
|
* Initialize section of a For loop to the Body section of that same
|
|
* For loop.)
|
|
*/
|
|
template <typename Derived>
|
|
class TopoControlGraphVisitor
|
|
{
|
|
public:
|
|
/**
|
|
* Walks the entire control graph in topological order.
|
|
*/
|
|
void walk();
|
|
|
|
/**
|
|
* Walks `nodes` and their descendents (both by Body and Sequence
|
|
* relationships) in topological order.
|
|
*
|
|
* `nodes` must all have the same logical scope.
|
|
*/
|
|
void walk(std::set<int> nodes);
|
|
|
|
/**
|
|
* Walks `node` and its Body descendents in topological order.
|
|
*/
|
|
void walk(int node);
|
|
|
|
/**
|
|
* Resets the internal set of which nodes have been visited. This
|
|
* must be called in between calls in order to reuse this object.
|
|
*/
|
|
void reset();
|
|
|
|
TopoControlGraphVisitor(KernelGraph const& kgraph);
|
|
|
|
protected:
|
|
KernelGraph const& m_graph;
|
|
|
|
/**
|
|
* Default error handling. Base implementation will throw an error.
|
|
* Derived classes can override this in order to report an error in a
|
|
* different way.
|
|
*/
|
|
virtual void errorCondition(std::string const& message);
|
|
|
|
private:
|
|
std::unordered_map<int, std::unordered_set<int>> m_nodeDependencies;
|
|
std::unordered_set<int> m_visitedNodes;
|
|
|
|
std::unordered_set<int>& nodeDependencies(int node);
|
|
|
|
bool hasWalkedInputs(int node);
|
|
|
|
constexpr Derived* derived();
|
|
|
|
auto call(int node);
|
|
};
|
|
}
|
|
|
|
#include "TopoVisitor_impl.hpp"
|