Skip to content

Commit e4082c6

Browse files
authored
Merge pull request #687 from XJDKC/master
fix bugs of recycling
2 parents 12efad4 + 61d1ee5 commit e4082c6

File tree

5 files changed

+303
-176
lines changed

5 files changed

+303
-176
lines changed

examples/rnn/train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def train(data,
197197
cuda = device.create_cuda_gpu()
198198
model = CharRNN(data.vocab_size, hidden_size)
199199
model.on_device(cuda)
200-
model.graph(True, True)
200+
model.graph(True, False)
201201

202202
inputs, labels = None, None
203203

include/singa/core/scheduler.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,16 @@ class Edge {
9797
class BlkInfo {
9898
public:
9999
BlkInfo(int id, Block *blk, BlockType type = BlockType::kUnknow)
100-
: id_(id),
101-
blk_(blk),
102-
type_(type),
103-
graph_ref_(0),
104-
write_node_(nullptr),
105-
last_node_(nullptr) {}
100+
: id_(id), blk_(blk), type_(type), graph_ref_(0), write_edge_(nullptr) {}
106101

107102
// getters of BlkInfo
108103
int id() const { return id_; }
109104
Block *block() const { return blk_; }
110105
BlockType type() const { return type_; }
111106
int graph_ref() const { return graph_ref_; }
112-
Node *write_node() const { return write_node_; }
113-
Node *last_node() const { return last_node_; }
107+
Edge *write_edge() const { return write_edge_; }
108+
const NodeVec &used_nodes() const { return used_nodes_; }
109+
Node *used_node(const size_t idx) const;
114110

115111
private:
116112
friend Graph;
@@ -119,8 +115,8 @@ class BlkInfo {
119115
Block *blk_;
120116
BlockType type_;
121117
int graph_ref_;
122-
Node *write_node_; // last node that writes the block
123-
Node *last_node_; // last node that uses the block
118+
Edge *write_edge_; // the edge of last node that writes data into blk
119+
NodeVec used_nodes_; // the nodes that use this block(in order of execution)
124120
};
125121

126122
class Graph {
@@ -165,8 +161,10 @@ class Graph {
165161
const BlockVec &free_blocks(const size_t idx) const;
166162

167163
private:
168-
void Analysis();
164+
void Analyze();
169165
void FreeLoop();
166+
void AnalyzeNodes();
167+
void AnalyzeEdges();
170168
void AddSyncOp(function<void(Context *)> &&op);
171169

172170
// static void CUDART_CB Callback(cudaStream_t stream, cudaError_t status,
@@ -185,6 +183,7 @@ class Graph {
185183

186184
// Calculation graph analysis
187185
bool dirty_ = false;
186+
bool in_serial_ = false;
188187
NodeVec begin_nodes_;
189188
std::vector<NodeVec> next_nodes_;
190189
std::vector<BlockVec> free_blocks_;

python/singa/module.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ def wrapper(self, *args, **kwargs):
4848
# deconstruct Operations before running the entire graph
4949
if name == 'optim':
5050
for fname in self._results:
51-
self._results[fname].creator = None
51+
if isinstance(self._results[fname], list):
52+
for _matrix in self._results[fname]:
53+
_matrix.creator = None
54+
else:
55+
self._results[fname].creator = None
5256
# make sure all Operations are deallocated
5357
gc.collect()
5458
# add result tensor

0 commit comments

Comments
 (0)