// Copyright Advanced Micro Devices, Inc., or its affiliates. // SPDX-License-Identifier: MIT #include #include #include "CustomMatchers.hpp" #include "CustomSections.hpp" #include "ExpressionMatchers.hpp" #include "TestContext.hpp" #include #include #include #include #include #include #include namespace HypergraphSerializationTest { using namespace rocRoller; TEST_CASE("Hypergraph is ordered when deserialized", "[hypergraph][kernel-graph][serialization]") { // NOTE: ControlGraph Operations and Edges are used here for their serialization properties using pseudoControlGraph = Graph::Hypergraph; pseudoControlGraph g; auto u0 = g.addElement(KernelGraph::ControlGraph::SetCoordinate{}); auto op0 = g.addElement(KernelGraph::ControlGraph::DoWhileOp{}); auto op1 = g.addElement(KernelGraph::ControlGraph::ConditionalOp{}); auto op2 = g.addElement(KernelGraph::ControlGraph::AssertOp{}); auto op3 = g.addElement(KernelGraph::ControlGraph::Barrier{}); auto body0 = g.addElement(KernelGraph::ControlGraph::Body{}, {u0}, {op0, op2, op1}); auto body1 = g.addElement(KernelGraph::ControlGraph::Body{}, {op0, op2, op1}, {op3}); SECTION("Elements are sorted in the order they were added") { CHECK(g.getNeighbours(body0) == std::vector{op0, op2, op1}); CHECK(g.getNeighbours(body1) == std::vector{op0, op2, op1}); } SECTION("Serialization preserves ordering") { auto yaml = Serialization::toYAML(g); auto gDeserialized = Serialization::fromYAML(yaml); CHECK(gDeserialized.getNeighbours(body0) == std::vector{op0, op2, op1}); CHECK(gDeserialized.getNeighbours(body1) == std::vector{op0, op2, op1}); } } }