Commit a170a002 authored by Mintz, Tiffany's avatar Mintz, Tiffany
Browse files

adding mutex for lock on dag and output tensor table

parent ea9f84b4
......@@ -2,6 +2,8 @@
#include "TensorGraph.hpp"
#include<memory>
#include <mutex>
namespace exatn {
namespace runtime {
......@@ -18,7 +20,13 @@ void TensorRuntime::closeScope() { currentScope = ""; }
void TensorRuntime::submit(std::shared_ptr<TensorOperation> op) {
//Call sync on a single operation for now
sync(op);
//TODO: add cthread code to lock and unlock
int newop_outid = op->op->getTensorOperandId(0);
mtx.lock();
if(outTensorExec.find(newop_outid)==outTensorExec.end())
outTensorExec[newop_outid]==1;
else
outTensorExec[newop_outid]+=1;
// work on graph at dags[currentScope]
// add on to the graph
......@@ -41,7 +49,9 @@ void TensorRuntime::submit(std::shared_ptr<TensorOperation> op) {
}
}
}
//add edge to dummy node if no edge added (may not be necessary)
mtx.unlock();
sync(op);
}
void TensorRuntime::sync(const std::shared_ptr<TensorOperation> &op) {
......
......@@ -3,6 +3,7 @@
#include <iostream>
#include <memory>
#include <mutex>
#include "TensorGraph.hpp"
#include "tensor.hpp"
......@@ -16,7 +17,8 @@ class TensorRuntime {
protected:
std::map<std::string, std::shared_ptr<TensorGraph>> dags;
std::string currentScope;
std::map<int, int> outTensorExec; //table for tracking output tensor execution
std::mutex mtx; // mutex for lock on outTensorExec and dags
public:
void openScope(const std::string &scopeName);
void closeScope();
......
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