29 #ifndef EXATN_RUNTIME_TENSOR_GRAPH_HPP_
30 #define EXATN_RUNTIME_TENSOR_GRAPH_HPP_
32 #include "Identifiable.hpp"
34 #include "tensor_exec_state.hpp"
35 #include "tensor_operation.hpp"
53 op_(
nullptr), is_noop_(
true), executing_(
false), executed_(
false), error_(0)
57 op_(tens_op), is_noop_(
false), executing_(
false), executed_(
false), error_(0)
67 inline bool isDummy()
const {
return is_noop_;}
72 inline std::shared_ptr<TensorOperation> &
getOperation() {
return op_;}
75 inline VertexIdType
getId()
const {
return id_;}
82 bool ans = executed_.load();
83 if(error_code !=
nullptr && ans) *error_code = error_.load();
88 inline void setId(VertexIdType
id) {
95 auto executing = executing_.load();
96 auto executed = executed_.load();
97 assert(!executing && !executed);
98 executing_.store(
true);
104 auto executing = executing_.load();
105 auto executed = executed_.load();
106 assert(executing && !executed);
107 error_.store(error_code);
108 executed_.store(
true);
109 executing_.store(
false);
115 auto executed = executed_.load();
118 executing_.store(
false);
122 inline void lock() {mtx_.lock();}
123 inline void unlock() {mtx_.unlock();}
126 std::shared_ptr<TensorOperation> op_;
128 std::atomic<bool> executing_;
129 std::atomic<bool> executed_;
130 std::atomic<int> error_;
134 std::recursive_mutex mtx_;
150 virtual VertexIdType
addOperation(std::shared_ptr<TensorOperation> op) = 0;
155 VertexIdType dependee) = 0;
160 VertexIdType vertex_id2) = 0;
168 virtual std::size_t
getNodeDegree(VertexIdType vertex_id) = 0;
177 virtual std::vector<VertexIdType>
getNeighborList(VertexIdType vertex_id) = 0;
181 std::vector<double> & distances,
182 std::vector<VertexIdType> & paths) = 0;
188 virtual std::shared_ptr<TensorGraph>
clone() = 0;
201 auto & output_tensor = *(op->getTensorOperand(0));
220 bool nodeExecuted(VertexIdType vertex_id,
int * error_code =
nullptr) {
281 inline void lock() {mtx_.lock();}
282 inline void unlock() {mtx_.unlock();}
285 TensorExecState exec_state_;
288 std::recursive_mutex mtx_;
294 #endif //EXATN_RUNTIME_TENSOR_GRAPH_HPP_
Definition: tensor.hpp:63
void setNodeExecuting(VertexIdType vertex_id)
Definition: tensor_graph.hpp:192
bool isExecuted(int *error_code=nullptr)
Definition: tensor_graph.hpp:81
std::size_t registerWriteCompletion(const Tensor &tensor)
Definition: tensor_exec_state.cpp:62
bool hasUnexecutedNodes()
Definition: tensor_graph.hpp:277
virtual bool dependencyExists(VertexIdType vertex_id1, VertexIdType vertex_id2)=0
void registerExecutingNode(VertexIdType node_id)
Definition: tensor_exec_state.cpp:94
void setIdle()
Definition: tensor_graph.hpp:114
bool extractDependencyFreeNode(VertexIdType *node_id)
Definition: tensor_exec_state.cpp:84
VertexIdType getFrontNode() const
Definition: tensor_graph.hpp:272
VertexIdType getId() const
Definition: tensor_graph.hpp:75
bool nodeExecuting(VertexIdType vertex_id)
Definition: tensor_graph.hpp:214
VertexIdType getFrontNode() const
Definition: tensor_exec_state.cpp:117
void registerExecutingNode(VertexIdType node_id)
Definition: tensor_graph.hpp:250
virtual std::vector< VertexIdType > getNeighborList(VertexIdType vertex_id)=0
bool nodeExecuted(VertexIdType vertex_id, int *error_code=nullptr)
Definition: tensor_graph.hpp:220
virtual std::size_t getNodeDegree(VertexIdType vertex_id)=0
Definition: DriverClient.hpp:10
bool isExecuting()
Definition: tensor_graph.hpp:78
void setId(VertexIdType id)
Definition: tensor_graph.hpp:88
void setExecuted(int error_code=0)
Definition: tensor_graph.hpp:103
virtual std::size_t getNumNodes()=0
bool extractDependencyFreeNode(VertexIdType *node_id)
Definition: tensor_graph.hpp:242
Definition: Identifiable.hpp:18
void setNodeExecuted(VertexIdType vertex_id, int error_code=0)
Definition: tensor_graph.hpp:197
void registerDependencyFreeNode(VertexIdType node_id)
Definition: tensor_exec_state.cpp:78
virtual std::shared_ptr< TensorGraph > clone()=0
Definition: tensor_graph.hpp:49
bool progressFrontNode(VertexIdType node_executed)
Definition: tensor_graph.hpp:267
bool extractExecutingNode(VertexIdType *node_id)
Definition: tensor_graph.hpp:258
void setNodeIdle(VertexIdType vertex_id)
Definition: tensor_graph.hpp:209
virtual void computeShortestPath(VertexIdType startIndex, std::vector< double > &distances, std::vector< VertexIdType > &paths)=0
Definition: Identifiable.hpp:9
bool isDummy() const
Definition: tensor_graph.hpp:67
bool extractExecutingNode(VertexIdType *node_id)
Definition: tensor_exec_state.cpp:100
bool progressFrontNode(VertexIdType node_executed)
Definition: tensor_exec_state.cpp:110
virtual VertexIdType addOperation(std::shared_ptr< TensorOperation > op)=0
virtual std::size_t getNumDependencies()=0
std::size_t getTensorUpdateCount(const Tensor &tensor)
Definition: tensor_exec_state.cpp:70
virtual TensorOpNode & getNodeProperties(VertexIdType vertex_id)=0
void setExecuting()
Definition: tensor_graph.hpp:94
std::shared_ptr< TensorOperation > & getOperation()
Definition: tensor_graph.hpp:72
virtual void addDependency(VertexIdType dependent, VertexIdType dependee)=0
std::size_t getTensorUpdateCount(const Tensor &tensor)
Definition: tensor_graph.hpp:225
Definition: tensor_graph.hpp:139
void registerDependencyFreeNode(VertexIdType node_id)
Definition: tensor_graph.hpp:233