Skip to content

Commit

Permalink
Add test utility to create a DataDepGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
Quincunx271 committed Oct 27, 2021
1 parent 4556a00 commit bf32b46
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 0 deletions.
1 change: 1 addition & 0 deletions unittests/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ add_optsched_unittest(OptSchedBasicTests
LoggerTest.cpp
UtilitiesTest.cpp
simple_machine_model_test.cpp
ddg_test.cpp
)
45 changes: 45 additions & 0 deletions unittests/Basic/ddg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef OPTSCHED_TESTS_DDG_H
#define OPTSCHED_TESTS_DDG_H

#include "opt-sched/Scheduler/data_dep.h"
#include "simple_machine_model.h"
#include "gtest/gtest.h"
#include <memory>
#include <string>

std::shared_ptr<llvm::opt_sched::DataDepGraph>
makeDDG(const std::string &DDG,
llvm::opt_sched::MachineModel *Model = nullptr) {
using namespace llvm::opt_sched;

class SimpleDDG : public DataDepGraph {
public:
using DataDepGraph::DataDepGraph;

void convertSUnits(bool, bool) override {
FAIL() << "Unsupported operation convertSUnits()";
}
void convertRegFiles() override {
FAIL() << "Unsupported operation convertRegFile()";
}
};

struct DDGData {
std::unique_ptr<MachineModel> Model = nullptr;
SimpleDDG DDG;

DDGData(MachineModel *Model) : DDG(Model) {}
DDGData()
: Model(llvm::make_unique<MachineModel>(simpleMachineModel())),
DDG(Model.get()) {}
};

auto Result =
Model ? std::make_shared<DDGData>(Model) : std::make_shared<DDGData>();
auto Ret = Result->DDG.ReadFromString(DDG);
EXPECT_TRUE(Ret != RES_ERROR && Ret != RES_FAIL && Ret != RES_TIMEOUT)
<< "Failed to parse DDG";
return std::shared_ptr<DataDepGraph>(Result, &Result->DDG);
}

#endif
114 changes: 114 additions & 0 deletions unittests/Basic/ddg_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include "ddg.h"

#include "gtest/gtest.h"

using namespace llvm::opt_sched;

namespace {
TEST(SimpleDDG, CanBeMade) {
std::shared_ptr<DataDepGraph> DDG = makeDDG(R"(
dag 7 "Simple"
{
dag_id fake:3
dag_weight 1.000000
compiler LLVM
dag_lb -1
dag_ub -1
nodes
node 0 "Inst"
sched_order 0
issue_cycle 0
node 1 "Inst"
sched_order 1
issue_cycle 1
node 2 "Inst"
sched_order 2
issue_cycle 2
node 3 "Inst"
sched_order 3
issue_cycle 3
node 4 "Inst"
sched_order 4
issue_cycle 4
node 5 "artificial" "__optsched_entry"
node 6 "artificial"
dependencies
dep 0 1 "other" 0
dep 1 2 "other" 0
dep 2 6 "other" 0
dep 3 4 "data" 1
dep 4 6 "other" 0
dep 5 3 "other" 0
dep 5 0 "other" 0
}
)");

EXPECT_EQ(7, DDG->GetNodeCnt());
}

TEST(SimpleDDG, CanBeMadeWithRealData) {
MachineModel Model = simpleMachineModel();
{
InstTypeInfo Info;
Info.issuType = Model.getDefaultIssueType();
Info.name = "ATOMIC_FENCE";
Info.isCntxtDep = false;
Info.ltncy = 0;
Info.pipelined = true;
Info.sprtd = true;
Info.blksCycle = true;
Model.AddInstType(Info);

Info.name = "S_BARRIER";
Model.AddInstType(Info);

Info.name = "S_ADD_I32";
Info.ltncy = 1;
Model.AddInstType(Info);

Info.name = "S_CMP_LT_U32";
Info.ltncy = 1;
Model.AddInstType(Info);
}

std::shared_ptr<DataDepGraph> DDG = makeDDG(R"(
dag 7 "Simple"
{
dag_id kernel_c18_sdk_94:3
dag_weight 1.000000
compiler LLVM
dag_lb -1
dag_ub -1
nodes
node 0 "ATOMIC_FENCE"
sched_order 0
issue_cycle 0
node 1 "S_BARRIER" "S_BARRIER"
sched_order 1
issue_cycle 1
node 2 "ATOMIC_FENCE" "ATOMIC_FENCE"
sched_order 2
issue_cycle 2
node 3 "S_ADD_I32" "S_ADD_I32"
sched_order 3
issue_cycle 3
node 4 "S_CMP_LT_U32" "S_CMP_LT_U32"
sched_order 4
issue_cycle 4
node 5 "artificial" "__optsched_entry"
node 6 "artificial"
dependencies
dep 0 1 "other" 0
dep 1 2 "other" 0
dep 2 6 "other" 0
dep 3 4 "data" 1
dep 4 6 "other" 0
dep 5 3 "other" 0
dep 5 0 "other" 0
}
)",
&Model);

EXPECT_EQ(7, DDG->GetNodeCnt());
}
} // namespace

0 comments on commit bf32b46

Please sign in to comment.