better compile times for throughput scheduling
Validate Operations / validate-operations (push) Has been cancelled
Validate Operations / validate-operations (push) Has been cancelled
fix failing no-plan throughput ablation runs update results
This commit is contained in:
@@ -69,6 +69,7 @@ add_pim_unittest(SpatialSchedulingTargetTest
|
||||
|
||||
add_pim_unittest(PeriodicDependenciesTest
|
||||
PeriodicDependenciesTest.cpp
|
||||
PeriodicDependenciesReference.cpp
|
||||
|
||||
LINK_LIBS PRIVATE
|
||||
OMPimCompilerUtils
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
// Test-only reference from commit 3c7679594beb29ba9497aaf3e341cee74fa0be50.
|
||||
#include "src/Accelerators/PIM/Dialect/Spatial/Passes/Transforms/MergeComputeNodes/Scheduling/PeriodicDependencies.hpp"
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace onnx_mlir::spatial {
|
||||
|
||||
mlir::FailureOr<PeriodicDependencyEstimate> analyzeFrozenPeriodicDependencies(
|
||||
size_t nodeCount, llvm::ArrayRef<PeriodicDependency> edges,
|
||||
std::string &error) {
|
||||
std::vector<std::vector<size_t>> outgoing(nodeCount);
|
||||
std::vector<size_t> indegree(nodeCount), recurrent;
|
||||
Cost upper = 0;
|
||||
for (auto [index, edge] : llvm::enumerate(edges)) {
|
||||
if (edge.source >= nodeCount || edge.target >= nodeCount) {
|
||||
error = "periodic dependency references an invalid event";
|
||||
return mlir::failure();
|
||||
}
|
||||
if (edge.delayNs > std::numeric_limits<Cost>::max() - upper) {
|
||||
error = "periodic delay sum exceeds the timing range";
|
||||
return mlir::failure();
|
||||
}
|
||||
upper += edge.delayNs;
|
||||
if (edge.distance) {
|
||||
recurrent.push_back(index);
|
||||
} else {
|
||||
outgoing[edge.source].push_back(index);
|
||||
++indegree[edge.target];
|
||||
}
|
||||
}
|
||||
std::vector<size_t> order;
|
||||
for (size_t node = 0; node < nodeCount; ++node)
|
||||
if (!indegree[node])
|
||||
order.push_back(node);
|
||||
for (size_t cursor = 0; cursor < order.size(); ++cursor)
|
||||
for (size_t index : outgoing[order[cursor]])
|
||||
if (!--indegree[edges[index].target])
|
||||
order.push_back(edges[index].target);
|
||||
if (order.size() != nodeCount) {
|
||||
error = "periodic distance-zero dependencies contain a cycle";
|
||||
return mlir::failure();
|
||||
}
|
||||
|
||||
PeriodicDependencyEstimate result;
|
||||
std::vector<Cost> span(nodeCount);
|
||||
for (size_t node : order) {
|
||||
result.withinGenerationSpanNs =
|
||||
std::max(result.withinGenerationSpanNs, span[node]);
|
||||
for (size_t index : outgoing[node]) {
|
||||
const auto &edge = edges[index];
|
||||
span[edge.target] = std::max(span[edge.target],
|
||||
checkedAdd(span[node], edge.delayNs));
|
||||
}
|
||||
}
|
||||
if (recurrent.empty() || !upper)
|
||||
return result;
|
||||
|
||||
const size_t absent = std::numeric_limits<size_t>::max();
|
||||
std::vector<double> potential(nodeCount);
|
||||
std::vector<size_t> predecessor(nodeCount, absent);
|
||||
auto infeasible = [&](double interval) {
|
||||
std::fill(potential.begin(), potential.end(), 0);
|
||||
std::fill(predecessor.begin(), predecessor.end(), absent);
|
||||
auto relax = [&](size_t index) {
|
||||
const auto &edge = edges[index];
|
||||
double value = potential[edge.source] + edge.delayNs
|
||||
- interval * edge.distance;
|
||||
if (value <= potential[edge.target] + 1e-7)
|
||||
return false;
|
||||
potential[edge.target] = value;
|
||||
predecessor[edge.target] = index;
|
||||
return true;
|
||||
};
|
||||
for (size_t node : order)
|
||||
for (size_t index : outgoing[node])
|
||||
relax(index);
|
||||
// Eliminate distance-zero paths by a DAG sweep. A simple residual path
|
||||
// visits at most R recurrent edges, so R+1 rounds detect a positive cycle.
|
||||
for (size_t round = 0; round <= recurrent.size(); ++round) {
|
||||
++result.relaxationRounds;
|
||||
bool changed = false;
|
||||
for (size_t index : recurrent)
|
||||
changed |= relax(index);
|
||||
for (size_t node : order)
|
||||
for (size_t index : outgoing[node])
|
||||
changed |= relax(index);
|
||||
if (!changed)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
result.recurrenceUpperNs = upper;
|
||||
for (unsigned iteration = 0;
|
||||
iteration < 64 && result.recurrenceUpperNs - result.recurrenceLowerNs > 1;
|
||||
++iteration) {
|
||||
double middle = (result.recurrenceLowerNs + result.recurrenceUpperNs) / 2;
|
||||
if (middle == result.recurrenceLowerNs || middle == result.recurrenceUpperNs)
|
||||
break;
|
||||
if (infeasible(middle))
|
||||
result.recurrenceLowerNs = middle;
|
||||
else
|
||||
result.recurrenceUpperNs = middle;
|
||||
}
|
||||
if (result.recurrenceUpperNs - result.recurrenceLowerNs > 1) {
|
||||
error = "periodic timing exceeds one-nanosecond floating-point precision";
|
||||
return mlir::failure();
|
||||
}
|
||||
if (!infeasible(result.recurrenceLowerNs))
|
||||
return result;
|
||||
|
||||
// Recover witness cycles from the last longest-path predecessor forest.
|
||||
std::vector<size_t> seen(nodeCount, absent);
|
||||
double best = 0;
|
||||
for (size_t start = 0; start < nodeCount; ++start) {
|
||||
size_t node = start;
|
||||
while (seen[node] == absent && predecessor[node] != absent) {
|
||||
seen[node] = start;
|
||||
node = edges[predecessor[node]].source;
|
||||
}
|
||||
if (seen[node] != start || predecessor[node] == absent)
|
||||
continue;
|
||||
size_t first = node;
|
||||
Cost delay = 0, distance = 0;
|
||||
std::vector<size_t> cycle;
|
||||
do {
|
||||
size_t index = predecessor[node];
|
||||
cycle.push_back(index);
|
||||
delay = checkedAdd(delay, edges[index].delayNs);
|
||||
distance = checkedAdd(distance, static_cast<Cost>(edges[index].distance));
|
||||
node = edges[index].source;
|
||||
} while (node != first);
|
||||
double ratio = distance ? static_cast<double>(delay) / distance : 0;
|
||||
if (ratio > best) {
|
||||
best = ratio;
|
||||
std::reverse(cycle.begin(), cycle.end());
|
||||
result.criticalCycle = std::move(cycle);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace onnx_mlir::spatial
|
||||
@@ -5,11 +5,96 @@
|
||||
#error "Periodic dependency tests require assertions"
|
||||
#endif
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
|
||||
using namespace onnx_mlir::spatial;
|
||||
|
||||
namespace onnx_mlir::spatial {
|
||||
mlir::FailureOr<PeriodicDependencyEstimate> analyzeFrozenPeriodicDependencies(
|
||||
size_t, llvm::ArrayRef<PeriodicDependency>, std::string &);
|
||||
}
|
||||
|
||||
static size_t differentialCases = 0, acceleratedRounds = 0, frozenRounds = 0;
|
||||
static double acceleratedSeconds = 0, frozenSeconds = 0;
|
||||
|
||||
static void differential(size_t count, const std::vector<PeriodicDependency> &edges) {
|
||||
std::string actualError, referenceError;
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
auto actual = analyzePeriodicDependencies(count, edges, actualError);
|
||||
acceleratedSeconds += std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count();
|
||||
start = std::chrono::steady_clock::now();
|
||||
auto reference = analyzeFrozenPeriodicDependencies(count, edges, referenceError);
|
||||
frozenSeconds += std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count();
|
||||
++differentialCases;
|
||||
assert(mlir::succeeded(actual) == mlir::succeeded(reference));
|
||||
assert(actualError == referenceError);
|
||||
if (mlir::failed(actual)) return;
|
||||
acceleratedRounds += actual->relaxationRounds;
|
||||
frozenRounds += reference->relaxationRounds;
|
||||
assert(actual->recurrenceLowerNs == reference->recurrenceLowerNs);
|
||||
assert(actual->recurrenceUpperNs == reference->recurrenceUpperNs);
|
||||
assert(actual->withinGenerationSpanNs == reference->withinGenerationSpanNs);
|
||||
assert(actual->criticalCycle == reference->criticalCycle);
|
||||
}
|
||||
|
||||
static void testFrozenDifferential() {
|
||||
std::mt19937 random(171221);
|
||||
for (size_t sample = 0; sample < 800; ++sample) {
|
||||
const size_t count = sample < 600 ? 2 + random() % 31 : 64 + random() % 193;
|
||||
std::vector<PeriodicDependency> edges;
|
||||
for (size_t source = 0; source < count; ++source) {
|
||||
const size_t component = source / 32;
|
||||
for (size_t link = 0; link < 4; ++link) {
|
||||
size_t target = random() % count;
|
||||
if (sample % 3 == 0 && target / 32 != component) continue;
|
||||
unsigned distance = target > source && link % 2 == 0 ? 0 : 1 + random() % 7;
|
||||
edges.push_back({source, target, random() % 100001, distance});
|
||||
}
|
||||
}
|
||||
differential(count, edges);
|
||||
}
|
||||
for (size_t sample = 0; sample < 100; ++sample) {
|
||||
std::vector<PeriodicDependency> edges;
|
||||
for (size_t node = 0; node < 32; ++node) {
|
||||
edges.push_back({node, node, (Cost{1} << 40) + random() % 10001,
|
||||
static_cast<unsigned>(1024 + random() % 7)});
|
||||
edges.push_back({node, (node + 1) % 32, random() % 101, 1});
|
||||
}
|
||||
differential(32, edges);
|
||||
}
|
||||
differential(2, {{0,1,1,0}, {1,0,1000000000000ULL, std::numeric_limits<unsigned>::max()}});
|
||||
for (size_t count : {2u, 64u, 1024u}) {
|
||||
std::vector<PeriodicDependency> edges;
|
||||
for (size_t node = 0; node < count; ++node) {
|
||||
edges.push_back({node, node, 1000000 + node % 2, 3});
|
||||
if (node + 1 < count) edges.push_back({node, node + 1, 1, 0});
|
||||
}
|
||||
differential(count, edges);
|
||||
}
|
||||
std::vector<PeriodicDependency> large;
|
||||
constexpr size_t componentSize = 2048, components = 32;
|
||||
for (size_t component = 0; component < components; ++component) {
|
||||
size_t first = component * componentSize;
|
||||
for (size_t node = first; node + 1 < first + componentSize; ++node)
|
||||
large.push_back({node, node + 1, 1, 0});
|
||||
large.push_back({first + componentSize - 1, first, 17 + component,
|
||||
static_cast<unsigned>(1 + component % 7)});
|
||||
}
|
||||
differential(componentSize * components, large);
|
||||
differential(0, {});
|
||||
differential(2, {{0, 1, 0, 0}, {1, 0, 0, 0}});
|
||||
differential(2, {{0, 1, 10, 0}, {1, 0, 3, 0}});
|
||||
differential(1, {{0, 1, 1, 1}});
|
||||
differential(1, {{0, 0, Cost{1} << 60, 1}});
|
||||
differential(1, {{0, 0, std::numeric_limits<Cost>::max(), 1}, {0, 0, 1, 1}});
|
||||
std::cout << "frozen_differential_cases=" << differentialCases
|
||||
<< " accelerated_rounds=" << acceleratedRounds << " frozen_rounds=" << frozenRounds
|
||||
<< " accelerated_seconds=" << acceleratedSeconds << " frozen_seconds=" << frozenSeconds << '\n';
|
||||
}
|
||||
|
||||
static double enumerateCycles(size_t count,
|
||||
const std::vector<PeriodicDependency> &edges) {
|
||||
double maximum = 0;
|
||||
@@ -59,11 +144,22 @@ static void check(size_t count, const std::vector<PeriodicDependency> &edges,
|
||||
}
|
||||
|
||||
int main() {
|
||||
testFrozenDifferential();
|
||||
check(3, {{0, 1, 12, 0}, {1, 2, 7, 0}}, 0);
|
||||
check(3, {{0, 1, 12, 1}, {1, 2, 7, 1}}, 0);
|
||||
check(1, {{0, 0, 30, 2}}, 15);
|
||||
// Independent core periods remain parallel.
|
||||
check(2, {{0, 0, 10, 1}, {1, 1, 20, 1}}, 20);
|
||||
// Positive-cycle checks must not change the optimum or the final witness.
|
||||
std::vector<PeriodicDependency> independent;
|
||||
for (size_t core = 0; core < 128; ++core)
|
||||
independent.push_back({core, core, 1000 + core, 1});
|
||||
check(128, independent, 1127);
|
||||
std::string performanceError;
|
||||
auto accelerated = analyzePeriodicDependencies(128, independent, performanceError);
|
||||
assert(mlir::succeeded(accelerated));
|
||||
assert(accelerated->criticalCycle == std::vector<size_t>{127});
|
||||
assert(accelerated->relaxationRounds < 512);
|
||||
// Equal serial demand, different cross-core blocking recurrences.
|
||||
check(4, {{0, 1, 10, 0}, {2, 3, 10, 0},
|
||||
{1, 0, 0, 1}, {3, 2, 0, 1}}, 10);
|
||||
|
||||
@@ -243,6 +243,17 @@ static void testSharedEngine(PimInstructionTiming target) {
|
||||
actual = analyzePimExecution(abstract, target);
|
||||
TEST_CHECK(actual.getInteger("global_read_requests") == 2);
|
||||
TEST_CHECK(actual.getInteger("global_memory_service_ns") == 160);
|
||||
// The construction limit applies to interpreted patterns, not just traffic.
|
||||
// These zero-trip request bodies do not allocate a large event graph.
|
||||
abstract[0] = {{E::Work, 4}, {E::Repeat, 1500000, 0, 0, 0,
|
||||
{{E::Repeat, 0, 0, 0, 0, {{E::Load, 1}}}}}};
|
||||
auto largerPattern = evaluatePimExecution(abstract, target);
|
||||
TEST_CHECK(largerPattern.cost.available());
|
||||
TEST_CHECK(largerPattern.report.getInteger("global_read_requests") == 0);
|
||||
abstract[0] = {{E::Repeat, 2000001, 0, 0, 0, {{E::Load, 1}}}};
|
||||
auto aboveBudget = evaluatePimExecution(abstract, target);
|
||||
TEST_CHECK(!aboveBudget.cost.available());
|
||||
TEST_CHECK(aboveBudget.cost.reason == "abstract repetition budget exceeded");
|
||||
abstract[0] = {{E::Repeat, 1000000000000ull, 0, 0, 0, {{E::Load, 1}}}};
|
||||
actual = analyzePimExecution(abstract, target);
|
||||
TEST_CHECK(actual.getString("status") == "unavailable");
|
||||
@@ -433,6 +444,48 @@ static void testDependencyTokens() {
|
||||
TEST_CHECK(drained.empty() && drained.remaining().empty());
|
||||
}
|
||||
|
||||
static void testSpatialExtractionBudget(PimInstructionTiming target) {
|
||||
MLIRContext context;
|
||||
context.loadDialect<arith::ArithDialect, func::FuncDialect, scf::SCFDialect,
|
||||
tensor::TensorDialect, spatial::SpatialDialect>();
|
||||
auto module = ModuleOp::create(UnknownLoc::get(&context));
|
||||
OpBuilder builder(module.getBodyRegion());
|
||||
auto loc = module.getLoc();
|
||||
auto function = func::FuncOp::create(builder, loc, "test", builder.getFunctionType({}, {}));
|
||||
builder.setInsertionPointToStart(function.addEntryBlock());
|
||||
auto batch = spatial::SpatScheduledComputeBatch::create(builder, loc, TypeRange{},
|
||||
builder.getI32IntegerAttr(2), ValueRange{}, ValueRange{});
|
||||
batch->setAttr("coreIds", builder.getDenseI32ArrayAttr({0, 1}));
|
||||
batch.getBody().push_back(new Block);
|
||||
batch.getBody().front().addArgument(builder.getIndexType(), loc);
|
||||
builder.setInsertionPointToStart(&batch.getBody().front());
|
||||
Value zero = arith::ConstantIndexOp::create(builder, loc, 0);
|
||||
Value upper = arith::ConstantIndexOp::create(builder, loc, 100000);
|
||||
Value one = arith::ConstantIndexOp::create(builder, loc, 1);
|
||||
auto type = RankedTensorType::get({16}, builder.getF32Type());
|
||||
Value local = tensor::EmptyOp::create(builder, loc, type.getShape(), type.getElementType());
|
||||
spatial::SpatReluOp::create(builder, loc, type, local);
|
||||
auto loop = scf::ForOp::create(builder, loc, zero, upper, one);
|
||||
builder.setInsertionPointToStart(loop.getBody());
|
||||
for (int64_t i = 0; i < 5; ++i) arith::ConstantIndexOp::create(builder, loc, i);
|
||||
// A zero-count wait is runtime-free, but requires indexed interpretation.
|
||||
spatial::SpatWaitOp::create(builder, loc, zero, zero);
|
||||
builder.setInsertionPointAfter(loop);
|
||||
spatial::SpatYieldOp::create(builder, loc, ValueRange{});
|
||||
builder.setInsertionPointAfter(batch);
|
||||
func::ReturnOp::create(builder, loc);
|
||||
TEST_CHECK(succeeded(verify(module)));
|
||||
auto supported = evaluatePimSpatialSchedule(module, target);
|
||||
TEST_CHECK(supported.report.getInteger("visited_operations") > 1000000);
|
||||
TEST_CHECK(supported.cost.available());
|
||||
builder.setInsertionPointToStart(loop.getBody());
|
||||
for (int64_t i = 0; i < 5; ++i) arith::ConstantIndexOp::create(builder, loc, i);
|
||||
auto unsupported = evaluatePimSpatialSchedule(module, target);
|
||||
TEST_CHECK(!unsupported.cost.available());
|
||||
TEST_CHECK(unsupported.cost.reason == "abstract extraction budget exceeded on physical core 0");
|
||||
module.erase();
|
||||
}
|
||||
|
||||
static void testReadOnlySpatial(PimInstructionTiming target, bool batched) {
|
||||
MLIRContext context;
|
||||
context.loadDialect<arith::ArithDialect, func::FuncDialect, scf::SCFDialect,
|
||||
@@ -918,6 +971,7 @@ int main() {
|
||||
testCapturedVectorWeights(hardware(period));
|
||||
testPublicationAndOutput(hardware(period));
|
||||
testUnrepresentableSpatial(hardware(period));
|
||||
testSpatialExtractionBudget(hardware(period));
|
||||
testReadOnlySpatial(hardware(period), false);
|
||||
testReadOnlySpatial(hardware(period), true);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "src/Accelerators/PIM/Compiler/PimInstructionTiming.hpp"
|
||||
#include "src/Accelerators/PIM/Dialect/Spatial/Passes/Transforms/MergeComputeNodes/Scheduling/PipelineScheduling.hpp"
|
||||
#include "src/Accelerators/PIM/Dialect/Spatial/Passes/Transforms/MergeComputeNodes/Scheduling/ScheduleEvaluation.hpp"
|
||||
#include "src/Accelerators/PIM/Dialect/Spatial/Passes/Transforms/MergeComputeNodes/Scheduling/ResidentWeightPacking.hpp"
|
||||
#include "src/Accelerators/PIM/Dialect/Spatial/SpatialOps.hpp"
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
@@ -14,6 +16,76 @@ using namespace onnx_mlir::spatial;
|
||||
using E = PimExecutionEvent;
|
||||
static bool sawJointMove = false, sawSuccessiveMoves = false;
|
||||
|
||||
static void testPackingFeasibility() {
|
||||
ComputeGraph graph;
|
||||
for (size_t task = 0; task < 4; ++task) {
|
||||
ResidentWeight weight;
|
||||
weight.opaqueLane = task % 2;
|
||||
graph.nodes.push_back({{nullptr, static_cast<uint32_t>(task), 1}, 10, {weight}, task});
|
||||
}
|
||||
IndexedResidentWeights weights(graph);
|
||||
const std::vector<size_t> tasks{0, 1, 2, 3};
|
||||
const std::vector<Cost> work{10, 10, 10, 10};
|
||||
std::vector<size_t> assignment{99};
|
||||
TEST_CHECK(!estimateOrderedPackCost(work, weights.taskWeightIds, weights.weightCount,
|
||||
tasks, 1, 2, &assignment));
|
||||
TEST_CHECK(assignment.empty());
|
||||
TEST_CHECK(!estimateOrderedPackCost(work, weights.taskWeightIds, weights.weightCount,
|
||||
tasks, 1, 0));
|
||||
TEST_CHECK(weights.estimatePackCost(tasks, work, 1, 2) == 20);
|
||||
auto placement = weights.pack(tasks, work, 1, 2);
|
||||
TEST_CHECK(placement && (*placement)[0] == (*placement)[2]
|
||||
&& (*placement)[1] == (*placement)[3] && (*placement)[0] != (*placement)[1]);
|
||||
TEST_CHECK(!weights.estimatePackCost(tasks, work, 1, 1));
|
||||
for (size_t cores = 4; cores <= 8; ++cores)
|
||||
TEST_CHECK(estimateOrderedPackCost(work, weights.taskWeightIds, weights.weightCount,
|
||||
tasks, 1, cores) == 10);
|
||||
weights.taskWeightIds[0] = {0, 1};
|
||||
TEST_CHECK(!estimateOrderedPackCost(work, weights.taskWeightIds, weights.weightCount,
|
||||
tasks, 1, 4));
|
||||
weights.taskWeightIds = {{0, 1}, {2}, {0, 1}, {2}};
|
||||
weights.weightCount = 3;
|
||||
TEST_CHECK(!estimateOrderedPackCost(work, weights.taskWeightIds, weights.weightCount,
|
||||
tasks, 2, 2));
|
||||
TEST_CHECK(weights.estimatePackCost(tasks, work, 2, 2) == 20);
|
||||
}
|
||||
|
||||
static void testQuantizedFeasibility(uint32_t first) {
|
||||
mlir::MLIRContext context;
|
||||
context.loadDialect<spatial::SpatialDialect>();
|
||||
auto module = mlir::ModuleOp::create(mlir::UnknownLoc::get(&context));
|
||||
mlir::OpBuilder builder(module.getBodyRegion());
|
||||
ComputeGraph graph;
|
||||
graph.predecessors.resize(40); graph.successors.resize(40);
|
||||
for (uint32_t group = 0; group < 2; ++group) {
|
||||
const uint32_t lanes = group ? 40 - first : first;
|
||||
auto batch = spatial::SpatGraphComputeBatch::create(builder, module.getLoc(),
|
||||
mlir::TypeRange{}, builder.getI32IntegerAttr(lanes), mlir::ValueRange{}, mlir::ValueRange{});
|
||||
for (uint32_t lane = 0; lane < lanes; ++lane) {
|
||||
size_t task = graph.nodes.size();
|
||||
ResidentWeight weight; weight.opaqueLane = task;
|
||||
graph.nodes.push_back({{batch, lane, 1}, 10, {weight}, task});
|
||||
if (group) {
|
||||
graph.predecessors[task].push_back({0, {0, 0}});
|
||||
graph.successors[0].push_back({task, {0, 0}});
|
||||
}
|
||||
}
|
||||
}
|
||||
SchedulingTarget target;
|
||||
target.processorCount = 40; target.residentWeightCapacity = 1;
|
||||
target.interProcessorLatencyNs.assign(1600, 0);
|
||||
MergeScheduleResult schedule;
|
||||
std::string error;
|
||||
TEST_CHECK(mlir::succeeded(runPipelineScheduler(graph, schedule, 2, target, error)));
|
||||
std::vector<size_t> budgets(2);
|
||||
for (size_t stage : schedule.processorStages) ++budgets[stage];
|
||||
TEST_CHECK(budgets == std::vector<size_t>({first, 40 - first}));
|
||||
for (size_t task = 0; task < graph.nodes.size(); ++task)
|
||||
TEST_CHECK(schedule.processorStages[schedule.computeToCpuMap.lookup(graph.nodes[task].instance)]
|
||||
== (task < first ? 0 : 1));
|
||||
module.erase();
|
||||
}
|
||||
|
||||
// Test-only workloads use stage-boundary host transfers and local direct links.
|
||||
// The same queue
|
||||
// engine and complete-state evidence rank reference and searched schedules.
|
||||
@@ -112,6 +184,176 @@ static PimInstructionTiming hardware(size_t profile) {
|
||||
return target;
|
||||
}
|
||||
|
||||
static void testInitializerPackingWitness() {
|
||||
mlir::MLIRContext context;
|
||||
context.loadDialect<spatial::SpatialDialect>();
|
||||
auto module = mlir::ModuleOp::create(mlir::UnknownLoc::get(&context));
|
||||
mlir::OpBuilder builder(module.getBodyRegion());
|
||||
std::vector<mlir::Operation *> operations;
|
||||
for (size_t i = 0; i < 3; ++i) operations.push_back(
|
||||
spatial::SpatGraphComputeBatch::create(builder, module.getLoc(),
|
||||
mlir::TypeRange{}, builder.getI32IntegerAttr(3), mlir::ValueRange{}, mlir::ValueRange{}));
|
||||
const std::vector<std::vector<size_t>> resident{{2,1,5},{2,4},{0,2},{0},{4,6},{1},{2},{2},{1,4}};
|
||||
const std::vector<Cost> costs{4,1,5,4,1,2,5,2,2};
|
||||
ComputeGraph graph;
|
||||
graph.predecessors.resize(9); graph.successors.resize(9);
|
||||
for (uint32_t task = 0; task < 9; ++task) {
|
||||
ResidentWeightSet weights;
|
||||
for (size_t id : resident[task]) {
|
||||
ResidentWeight w; w.opaqueLane = id; weights.push_back(w);
|
||||
}
|
||||
graph.nodes.push_back({{operations[task % 3], task / 3, 1}, costs[task], weights, task});
|
||||
}
|
||||
IndexedResidentWeights indexed(graph);
|
||||
TEST_CHECK(!indexed.estimatePackCost({1,2,4,5,7,8}, costs, 3, 2));
|
||||
std::vector<size_t> witness;
|
||||
TEST_CHECK(indexed.estimatePackCost({1,4,7,2,5,8}, costs, 3, 2, &witness));
|
||||
TEST_CHECK(witness.size() == 6);
|
||||
auto target = hardware(1);
|
||||
target.processorCount = 4; target.residentWeightCapacity = 3;
|
||||
target.interProcessorLatencyNs.assign(16, 1);
|
||||
MergeScheduleResult schedule;
|
||||
std::string error;
|
||||
TEST_CHECK(mlir::succeeded(runPipelineScheduler(graph, schedule, 2, target, error)));
|
||||
std::vector<ResidentWeightSet> actual(4);
|
||||
for (const auto &node : graph.nodes) {
|
||||
size_t core = schedule.computeToCpuMap.lookup(node.instance);
|
||||
TEST_CHECK(core < 4);
|
||||
insertResidentWeights(actual[core], node.residentWeights);
|
||||
TEST_CHECK(actual[core].size() <= 3);
|
||||
}
|
||||
// Exhaust all core assignments under the same stage map. The initialized
|
||||
// assignment must belong to this physical-capacity reference set.
|
||||
size_t feasible = 0;
|
||||
for (size_t encoded = 0; encoded < (size_t{1} << 18); ++encoded) {
|
||||
size_t choices = encoded;
|
||||
std::vector<ResidentWeightSet> weights(4);
|
||||
std::vector<size_t> groupStages(3, 2);
|
||||
bool valid = true;
|
||||
for (size_t task = 0; task < 9 && valid; ++task) {
|
||||
size_t core = choices % 4; choices /= 4;
|
||||
size_t stage = schedule.processorStages[core], group = task % 3;
|
||||
if (groupStages[group] == 2) groupStages[group] = stage;
|
||||
valid &= groupStages[group] == stage;
|
||||
insertResidentWeights(weights[core], graph.nodes[task].residentWeights);
|
||||
valid &= weights[core].size() <= 3;
|
||||
}
|
||||
feasible += valid;
|
||||
}
|
||||
TEST_CHECK(feasible > 0);
|
||||
MergeScheduleResult alternative;
|
||||
TEST_CHECK(mlir::succeeded(packPipelineSchedule(graph, std::vector<size_t>(9),
|
||||
{3, 1}, target, alternative, error)));
|
||||
std::cout << "initializer_physical_feasible_assignments=" << feasible << '\n';
|
||||
module.erase();
|
||||
}
|
||||
|
||||
static void testPhysicalReference() {
|
||||
auto target = hardware(1);
|
||||
target.processorCount = 3;
|
||||
target.sharedMemoryRequestLatencyNs.resize(3);
|
||||
target.sharedMemoryResponseLatencyNs.resize(3);
|
||||
target.interProcessorLatencyNs = {0, 2, 11, 2, 0, 7, 11, 7, 0};
|
||||
ComputeGraph graph;
|
||||
graph.predecessors.resize(3); graph.successors.resize(3);
|
||||
for (uint32_t task = 0; task < 3; ++task) {
|
||||
ResidentWeight weight; weight.opaqueLane = task % 2;
|
||||
graph.nodes.push_back({{nullptr, task, 1}, task == 1 ? 700u : 80u, {weight}, task});
|
||||
if (task) {
|
||||
graph.predecessors[task].push_back({task - 1, {64, 1}});
|
||||
graph.successors[task - 1].push_back({task, {64, 1}});
|
||||
}
|
||||
}
|
||||
double optimum = std::numeric_limits<double>::infinity();
|
||||
size_t evaluations = 0;
|
||||
for (size_t mask = 1; mask < 7; ++mask)
|
||||
for (size_t placement = 0; placement < 27; ++placement) {
|
||||
MergeScheduleResult schedule;
|
||||
for (size_t core = 0; core < 3; ++core) schedule.processorStages.push_back((mask >> core) & 1);
|
||||
size_t encoded = placement;
|
||||
std::vector<size_t> stages, slots(3);
|
||||
std::vector<ResidentWeightSet> resident(3);
|
||||
bool valid = true;
|
||||
for (const auto &node : graph.nodes) {
|
||||
size_t core = encoded % 3; encoded /= 3;
|
||||
schedule.computeToCpuMap[node.instance] = core;
|
||||
schedule.computeToCpuSlotMap[node.instance] = slots[core]++;
|
||||
stages.push_back(schedule.processorStages[core]);
|
||||
insertResidentWeights(resident[core], node.residentWeights);
|
||||
valid &= resident[core].size() <= target.residentWeightCapacity;
|
||||
}
|
||||
if (!valid || stages[0] != 0 || stages[1] < stages[0] || stages[2] < stages[1]) continue;
|
||||
auto cost = queueCost(graph, schedule, target);
|
||||
optimum = std::min(optimum, std::max(*cost.primary, *cost.alternative));
|
||||
++evaluations;
|
||||
}
|
||||
std::string error;
|
||||
MergeScheduleResult initial;
|
||||
TEST_CHECK(mlir::succeeded(runPipelineScheduler(graph, initial, 2, target, error)));
|
||||
auto evaluate = [&](const MergeScheduleResult &schedule) { return queueCost(graph, schedule, target); };
|
||||
auto search = optimizePipelineSchedule(graph, initial, 2, target, evaluate, error);
|
||||
TEST_CHECK(mlir::succeeded(search));
|
||||
size_t winner = search->costs.empty() ? 0 : selectPipelineCandidate(search->costs, error);
|
||||
auto selected = evaluate(search->schedules[winner]);
|
||||
double value = std::max(*selected.primary, *selected.alternative);
|
||||
TEST_CHECK(value + 1e-6 >= optimum);
|
||||
std::cout << "physical_reference_ns=" << optimum << " selected_ns=" << value
|
||||
<< " gap_percent=" << 100 * (value / optimum - 1)
|
||||
<< " physical_evaluations=" << evaluations
|
||||
<< " search_evaluations=" << search->costs.size()
|
||||
<< " packing_attempts=" << search->packingAttempts << '\n';
|
||||
}
|
||||
|
||||
static void testWorseningIntermediate() {
|
||||
// A controlled cost oracle isolates the search's non-monotone landscape.
|
||||
// Hardware queue objectives are covered separately by runReference().
|
||||
auto target = hardware(0);
|
||||
target.processorCount = 8;
|
||||
target.interProcessorLatencyNs.assign(64, 0);
|
||||
ComputeGraph graph;
|
||||
graph.predecessors.resize(4); graph.successors.resize(4);
|
||||
for (uint32_t task = 0; task < 4; ++task)
|
||||
graph.nodes.push_back({{nullptr, task, 1}, 10, {}, task});
|
||||
auto evaluate = [&](const MergeScheduleResult &schedule) {
|
||||
bool firstStage = llvm::all_of(graph.nodes, [&](const auto &node) {
|
||||
return schedule.processorStages[schedule.computeToCpuMap.lookup(node.instance)] == 0;
|
||||
});
|
||||
size_t cores = llvm::count(schedule.processorStages, 0);
|
||||
double value = !firstStage ? 120 : cores == 1 ? 80 : cores >= 6 ? 100 : 110;
|
||||
WholeScheduleCost cost;
|
||||
cost.primary = cost.alternative = value;
|
||||
cost.loweringSupport = StaticLoweringSupport::Supported;
|
||||
cost.selectionMargin = kPipelineSelectionMargin;
|
||||
for (auto &proof : cost.recurrence)
|
||||
proof = {ScheduleRecurrenceEvidence::Proved, 1, value, {}};
|
||||
return cost;
|
||||
};
|
||||
std::string error;
|
||||
MergeScheduleResult initial, intermediate;
|
||||
TEST_CHECK(mlir::succeeded(runPipelineScheduler(graph, initial, 2, target, error)));
|
||||
TEST_CHECK(evaluate(initial).primary == 100);
|
||||
const std::vector<size_t> stages(4);
|
||||
TEST_CHECK(mlir::succeeded(packPipelineSchedule(graph, stages, {3, 5}, target, intermediate, error)));
|
||||
TEST_CHECK(evaluate(intermediate).primary == 110);
|
||||
double reference = std::numeric_limits<double>::infinity();
|
||||
for (size_t cores = 1; cores < 8; ++cores) {
|
||||
MergeScheduleResult schedule;
|
||||
TEST_CHECK(mlir::succeeded(packPipelineSchedule(graph, stages, {cores, 8 - cores}, target, schedule, error)));
|
||||
reference = std::min(reference, *evaluate(schedule).primary);
|
||||
}
|
||||
TEST_CHECK(reference == 80);
|
||||
auto search = optimizePipelineSchedule(graph, initial, 2, target, evaluate, error);
|
||||
TEST_CHECK(mlir::succeeded(search));
|
||||
size_t winner = selectPipelineCandidate(search->costs, error);
|
||||
double selected = *search->costs[winner].primary;
|
||||
TEST_CHECK(selected >= reference && selected <= 100);
|
||||
TEST_CHECK(search->costs.size() <= kPipelineQueueEvaluationBudget);
|
||||
std::cout << "non_monotone_oracle_reference=" << reference << " selected=" << selected
|
||||
<< " gap_percent=" << 100 * (selected / reference - 1)
|
||||
<< " evaluations=" << search->costs.size()
|
||||
<< " packing_attempts=" << search->packingAttempts << '\n';
|
||||
}
|
||||
|
||||
static void runReference(size_t profile, size_t fixture) {
|
||||
auto target = hardware(profile);
|
||||
ComputeGraph graph;
|
||||
@@ -217,8 +459,10 @@ static void runReference(size_t profile, size_t fixture) {
|
||||
<< " gap_percent=" << 100 * (cost / reference - 1)
|
||||
<< " best_evaluated_ns=" << bestEvaluated
|
||||
<< " best_evaluated_gap_percent=" << 100 * (bestEvaluated / reference - 1)
|
||||
<< " reference_scope=logical_with_deterministic_packing"
|
||||
<< " reference_evaluations=" << referenceEvaluations
|
||||
<< " search_evaluations=" << search->costs.size() << " refinement_depth=" << depth
|
||||
<< " search_evaluations=" << search->costs.size()
|
||||
<< " packing_attempts=" << search->packingAttempts << " refinement_depth=" << depth
|
||||
<< " search_seconds=" << searchSeconds << " reference_seconds=" << referenceSeconds
|
||||
<< " total_seconds=" << std::chrono::duration<double>(std::chrono::steady_clock::now() - begin).count()
|
||||
<< '\n';
|
||||
@@ -246,6 +490,11 @@ static void runReference(size_t profile, size_t fixture) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
testInitializerPackingWitness();
|
||||
testPackingFeasibility();
|
||||
for (uint32_t first : {19u, 21u}) testQuantizedFeasibility(first);
|
||||
testPhysicalReference();
|
||||
testWorseningIntermediate();
|
||||
for (size_t profile = 0; profile < 2; ++profile)
|
||||
for (size_t fixture = 0; fixture < 6; ++fixture) runReference(profile, fixture);
|
||||
TEST_CHECK(sawJointMove && sawSuccessiveMoves);
|
||||
|
||||
@@ -1642,14 +1642,14 @@ static void testOrderedPackCostCurve() {
|
||||
if (fits && packs <= cores) optimum = std::min(optimum, std::max(maximum, work));
|
||||
}
|
||||
std::vector<size_t> assignment;
|
||||
Cost cost = estimateOrderedPackCost(costs, weights, 3, tasks, capacity, cores, &assignment);
|
||||
auto cost = estimateOrderedPackCost(costs, weights, 3, tasks, capacity, cores, &assignment);
|
||||
if (optimum == std::numeric_limits<Cost>::max()) {
|
||||
assert(assignment.empty());
|
||||
assert(!cost && assignment.empty());
|
||||
continue;
|
||||
}
|
||||
assert(cost == optimum && cost <= previous && assignment.size() == tasks.size());
|
||||
plateau |= cost == previous;
|
||||
previous = cost;
|
||||
assert(cost && *cost == optimum && *cost <= previous && assignment.size() == tasks.size());
|
||||
plateau |= *cost == previous;
|
||||
previous = *cost;
|
||||
std::vector<Cost> loads(cores);
|
||||
std::vector<llvm::SmallBitVector> resident(cores, llvm::SmallBitVector(3));
|
||||
for (size_t task : tasks) {
|
||||
@@ -1658,7 +1658,7 @@ static void testOrderedPackCostCurve() {
|
||||
for (size_t weight : weights[task]) resident[assignment[task]].set(weight);
|
||||
}
|
||||
for (size_t core = 0; core < cores; ++core) {
|
||||
assert(loads[core] <= cost && resident[core].count() <= capacity);
|
||||
assert(loads[core] <= *cost && resident[core].count() <= capacity);
|
||||
}
|
||||
}
|
||||
assert(plateau && previous == 11);
|
||||
|
||||
@@ -78,7 +78,7 @@ def main():
|
||||
parser.add_argument("--compiler", required=True)
|
||||
args = parser.parse_args()
|
||||
compiler = str(Path(args.compiler).resolve())
|
||||
model = REPO / "validation/networks/pimcomp_models/googlenet/googlenet-12-pimsim-nn.onnx"
|
||||
model = REPO / "validation/networks/pimcomp_models/googlenet/googlenet-12-no-lrn.onnx"
|
||||
with tempfile.TemporaryDirectory(prefix="raptor-static-selection-") as temporary:
|
||||
root = Path(temporary)
|
||||
history = root / "validation/tools/pim/pimcomp/compare/results_comparison.csv"
|
||||
|
||||
Reference in New Issue
Block a user