Skip to content

Commit

Permalink
add test for exec graph generation in mpi
Browse files Browse the repository at this point in the history
  • Loading branch information
csegarragonz committed Oct 15, 2021
1 parent 64ed2ff commit c631709
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/scheduler/MpiWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ void MpiWorld::create(const faabric::Message& call, int newId, int newSize)
msg.set_mpiworldsize(size);
// Log chained functions to generate execution graphs
sch.logChainedFunction(call.id(), msg.id());
SPDLOG_INFO("Logging chained call (MsgId-WorldId: {}-{}, Rank: {}/{}) -> (MsgId-WorldId: {}-{}, Rank: {}/{})",
call.id(), call.mpiworldid(), call.mpirank(), call.mpiworldsize(),
msg.id(), msg.mpiworldid(), msg.mpirank(), msg.mpiworldsize());
}

std::vector<std::string> executedAt;
Expand Down
50 changes: 50 additions & 0 deletions tests/test/scheduler/test_exec_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#include "faabric_utils.h"

#include <faabric/redis/Redis.h>
#include <faabric/scheduler/MpiWorld.h>
#include <faabric/scheduler/Scheduler.h>
#include <faabric/util/environment.h>
#include <faabric/util/logging.h>

using namespace scheduler;

Expand Down Expand Up @@ -67,4 +69,52 @@ TEST_CASE("Test execution graph", "[scheduler]")

checkExecGraphEquality(expected, actual);
}

TEST_CASE_METHOD(MpiBaseTestFixture,
"Test MPI execution graph",
"[mpi][scheduler]")
{
faabric::scheduler::MpiWorld world;

// Build the message vector to reconstruct the graph
std::vector<faabric::Message> messages(worldSize);
for (int rank = 0; rank < worldSize; rank++) {
messages.at(rank) = faabric::util::messageFactory("mpi", "hellompi");
messages.at(rank).set_mpirank(rank);
}

world.create(msg, worldId, worldSize);

world.destroy();

// Build expected graph
ExecGraphNode nodeB1 = { .msg = messages.at(1) };
ExecGraphNode nodeB2 = { .msg = messages.at(2) };
ExecGraphNode nodeB3 = { .msg = messages.at(3) };
ExecGraphNode nodeB4 = { .msg = messages.at(4) };

ExecGraphNode nodeA = { .msg = messages.at(0),
.children = { nodeB1, nodeB2, nodeB3, nodeB4 } };

ExecGraph expected{ .rootNode = nodeA };

// Check the execution graph
ExecGraph actual = sch.getFunctionExecGraph(msg.id());
REQUIRE(countExecGraphNodes(actual) == worldSize);
REQUIRE(countExecGraphNodes(expected) == worldSize);

// Print contents of actual
SPDLOG_INFO("Actual root node. World id: {}, Rank: {}/{}",
actual.rootNode.msg.mpiworldid(),
actual.rootNode.msg.mpirank(),
actual.rootNode.msg.mpiworldsize());
for (const auto& node : actual.rootNode.children) {
SPDLOG_INFO("Actual children node. World id: {}, Rank: {}/{}",
node.msg.mpiworldid(),
node.msg.mpirank(),
node.msg.mpiworldsize());
}

checkExecGraphEquality(expected, actual, true);
}
}
17 changes: 12 additions & 5 deletions tests/utils/exec_graph_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

namespace tests {
void checkExecGraphNodeEquality(const scheduler::ExecGraphNode& nodeA,
const scheduler::ExecGraphNode& nodeB)
const scheduler::ExecGraphNode& nodeB,
bool isMpi)
{
// Check the message itself
checkMessageEquality(nodeA.msg, nodeB.msg);
if (isMpi) {
REQUIRE(nodeA.msg.mpirank() == nodeB.msg.mpirank());
} else {
checkMessageEquality(nodeA.msg, nodeB.msg);
}

if (nodeA.children.size() != nodeB.children.size()) {
FAIL(fmt::format("Children not same size: {} vs {}",
Expand All @@ -19,13 +24,15 @@ void checkExecGraphNodeEquality(const scheduler::ExecGraphNode& nodeA,

// Assume children are in same order
for (int i = 0; i < nodeA.children.size(); i++) {
checkExecGraphNodeEquality(nodeA.children.at(i), nodeB.children.at(i));
checkExecGraphNodeEquality(
nodeA.children.at(i), nodeB.children.at(i), isMpi);
}
}

void checkExecGraphEquality(const scheduler::ExecGraph& graphA,
const scheduler::ExecGraph& graphB)
const scheduler::ExecGraph& graphB,
bool isMpi)
{
checkExecGraphNodeEquality(graphA.rootNode, graphB.rootNode);
checkExecGraphNodeEquality(graphA.rootNode, graphB.rootNode, isMpi);
}
}
6 changes: 4 additions & 2 deletions tests/utils/faabric_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ void checkMessageEquality(const faabric::Message& msgA,
const faabric::Message& msgB);

void checkExecGraphNodeEquality(const scheduler::ExecGraphNode& nodeA,
const scheduler::ExecGraphNode& nodeB);
const scheduler::ExecGraphNode& nodeB,
bool isMpi = false);

void checkExecGraphEquality(const scheduler::ExecGraph& graphA,
const scheduler::ExecGraph& graphB);
const scheduler::ExecGraph& graphB,
bool isMpi = false);

std::pair<int, std::string> submitGetRequestToUrl(const std::string& host,
int port,
Expand Down

0 comments on commit c631709

Please sign in to comment.