add computation graph (#75)

This commit is contained in:
Robert Nishihara
2016-06-02 16:35:46 -07:00
committed by Philipp Moritz
parent 23d202bb73
commit 6d97c55299
8 changed files with 108 additions and 17 deletions
+25
View File
@@ -0,0 +1,25 @@
#include "computation_graph.h"
OperationId ComputationGraph::add_operation(std::unique_ptr<Operation> operation) {
OperationId operationid = operations_.size();
OperationId creator_operationid = operation->creator_operationid();
if (spawned_operations_.size() != operationid) {
ORCH_LOG(ORCH_FATAL, "ComputationGraph is attempting to call add_operation, but spawned_operations_.size() != operationid.");
}
operations_.emplace_back(std::move(operation));
if (creator_operationid != NO_OPERATION && creator_operationid != ROOT_OPERATION) {
spawned_operations_[creator_operationid].push_back(operationid);
}
spawned_operations_.push_back(std::vector<OperationId>());
return operationid;
}
const Task& ComputationGraph::get_task(OperationId operationid) {
if (operationid >= operations_.size()) {
ORCH_LOG(ORCH_FATAL, "ComputationGraph attempting to get_task with operationid " << operationid << ", but operationid >= operations_.size().");
}
if (!operations_[operationid]->has_task()) {
ORCH_LOG(ORCH_FATAL, "Calling get_task with operationid " << operationid << ", but this corresponds to a push not a task.");
}
return operations_[operationid]->task();
}