Commit 5fd0a2a5 authored by Mintz, Tiffany's avatar Mintz, Tiffany
Browse files

adding updates to shared ptr types and initial implementation of submit; still needs to be tested

parent 190255e8
#include "TensorRuntime.hpp"
#include "TensorGraph.hpp"
#include<memory>
namespace exatn {
namespace runtime {
void TensorRuntime::openScope(const std::string &scopeName) {
assert(scopeName.length() > 0);
// save currentScope name
currentScope = scopeName;
// create new graph with name given by scope name
TensorGraph tg;
// store it in the dags map
dags[currentScope]=tg;
// save currentScope name
dags[currentScope] = std::make_shared<TensorGraph>();
}
void TensorRuntime::closeScope() { currentScope = ""; }
void TensorRuntime::submit(TensorOp &op) {
// add on to the graph
void TensorRuntime::submit(std::shared_ptr<TensorOperation> op) {
//Call sync on a single operation for now
sync(op);
// work on graph at dags[currentScope]
// add on to the graph
std::shared_ptr<TensorGraph> tg=dags[currentScope];
if(tg->size()==0)
{
std::shared_ptr<TensorOpNode> dag_node=std:make_shared<TensorOpNode>(op);
tg->addVertex(dag_node);
//Create a dummy op node to start the graph
/* for now this won't be necessary
std::shared_ptr<TensorOpNode> dummy=std::make_shared<TensorOpNode>();
dummy->is_noop=true;
tg->addVertex(dummy);
tg->addEdge(dummy,dag_node);*/
}
else
{
int tg_sz=tg->size();
std::shared_ptr<TensorOpNode> op1=std::make_shared<TensorOpNode>(op);
tg->addVertex(op1);
unsigned int num_op1_operands = op->getNumOperands();
TensorOpNode op0;
bool no_edge=true;
for(int i=tg_sz-1; i>=0 && no_edge; i--)
{
op0=tg->getVertexProperties(i);
std::size_t op0_outid = op0.op->getTensorOperandId(0);
for(int j=1; j<num_op1_operands && no_edge; j++) {
if(op0_outid == op1.op->getTensorOperandId(j))
{
tg->addEdge(op0,op1);
no_edge=false;
}
}
}
}
}
void TensorRuntime::sync(const std::shared_ptr<TensorOperation> &op) {
// sync on a particular tensor, everything related to tensor
// must complete
}
void TensorRuntime::sync(const exatn::numerics::Tensor &tensor) {
......
......@@ -14,14 +14,16 @@ namespace runtime {
class TensorRuntime {
protected:
std::map<std::string, TensorGraph> dags;
std::map<std::string, std::shared_ptr<TensorGraph>> dags;
std::string currentScope;
public:
void openScope(const std::string &scopeName);
void closeScope();
void submit(TensorOp &op);
void submit(std::shared_ptr<TensorOperation> op);
void sync(const std::shared_ptr<TensorOperation> &op);
void sync(const exatn::numerics::Tensor &tensor);
......
......@@ -18,9 +18,10 @@ using TensorOp = int;
class TensorOpNode {
public:
TensorOpNode() : op(nullptr) {}
TensorOpNode(TensorOp *o) : op(o) {}
TensorOp *op;
TensorOpNode(std::shared_ptr<TensorOperation> o) : op(o) {}
std::shared_ptr<TensorOperation> op;
bool executed = false;
bool is_noop = false;
int id;
// Add any other info you need
};
......@@ -43,7 +44,7 @@ public:
// = 0;
// Get the TensorOpNode at the given index
virtual TensorOpNode &getVertexProperties(const int index) = 0;
virtual const std::shared_ptr<TensorOpNode> &getVertexProperties(const int index) = 0;
// Flip the bool on the TensorOpNode to indicate this
// node has been executed
......
......@@ -13,29 +13,31 @@ DirectedBoostGraph::DirectedBoostGraph() {
_graph = std::make_shared<d_adj_list>();
}
void DirectedBoostGraph::addEdge(const TensorOpNode &srcNode, const TensorOpNode &tgtNode) {
void DirectedBoostGraph::addEdge(const std::shared_ptr<TensorOpNode> &srcNode, const std::shared_ptr<TensorOpNode> &tgtNode) {
add_edge(vertex(srcNode.id, *_graph.get()), vertex(tgtNode.id, *_graph.get()),
*_graph.get());
}
/*
void DirectedBoostGraph::addVertex(TensorOpNode &&properties) {
auto v = add_vertex(*_graph.get());
(*_graph.get())[v].properties = properties;
(*_graph.get())[v].properties.id=v;
}
*/
void DirectedBoostGraph::addVertex(TensorOpNode &properties) {
void DirectedBoostGraph::addVertex(std::shared_ptr<TensorOpNode> properties) {
auto v = add_vertex(*_graph.get());
(*_graph.get())[v].properties = properties;
(*_graph.get())[v].properties.id=v;
(*_graph.get())[v].properties->id=v;
}
TensorOpNode &DirectedBoostGraph::getVertexProperties(const int index) {
const std::shared_ptr<TensorOpNode> &DirectedBoostGraph::getVertexProperties(const int index) {
return (*_graph.get())[index].properties;
}
void DirectedBoostGraph::setNodeExecuted(const int index) {
(*_graph.get())[index].properties.executed = true;
(*_graph.get())[index].properties->executed = true;
}
bool DirectedBoostGraph::edgeExists(const int srcIndex, const int tgtIndex) {
......
......@@ -31,7 +31,7 @@ namespace exatn {
class DirectedBoostVertex {
public:
TensorOpNode properties;
std::shared_ptr<TensorOpNode> properties;
};
using d_adj_list =
......@@ -56,12 +56,12 @@ protected:
public:
DirectedBoostGraph();
void addEdge(const TensorOpNode &srcNode, const TensorOpNode &tgtNode) override;
void addEdge(const std::shared_ptr<TensorOpNode> &srcNode, const std::shared_ptr<TensorOpNode> &tgtNode) override;
void addVertex(TensorOpNode &&properties) override;
void addVertex(TensorOpNode &properties) override;
//void addVertex(TensorOpNode &&properties) override;
void addVertex(std::shared_ptr<TensorOpNode> properties) override;
TensorOpNode &getVertexProperties(const int index) override;
const std::shared_ptr<TensorOpNode> &getVertexProperties(const int index) override;
void setNodeExecuted(const int index) override;
bool edgeExists(const int srcIndex, const int tgtIndex) override;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment