Skip to content

Commit e7cff89

Browse files
Adjusting BFS to seek circular dependencies in the msccl-tools DAG (#459)
Co-authored-by: Binyang Li <binyli@microsoft.com>
1 parent 7f3b088 commit e7cff89

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

python/mscclpp/language/ir.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,9 @@ class _NopConverter(_OpConverter):
331331
def to_json(self, op: Op, tb_channel_dict: dict) -> _JsonInstruction:
332332
return _JsonInstruction(
333333
name=op.inst.value,
334-
deps=list(map(lambda dep: {"tb": dep.tb, "step": dep.step}, op.depends)),
334+
deps=sorted(
335+
list(map(lambda dep: {"tb": dep.tb, "step": dep.step}, op.depends)), key=lambda x: (x["tb"], x["step"])
336+
),
335337
)
336338

337339

python/mscclpp/language/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def merge_op(op: Op, other_op: Op):
3737
def circular_dep_after_merge(op: Op, other_op: Op):
3838
root = set([op, other_op])
3939
frontier = set(op.next)
40+
visited = set()
4041
if other_op in frontier:
4142
frontier.remove(other_op)
4243
frontier = list(frontier.union(other_op.next))
@@ -46,7 +47,9 @@ def circular_dep_after_merge(op: Op, other_op: Op):
4647
# The root node will be visited again if there is a circular dependency
4748
if n in root:
4849
return True
49-
frontier.append(n)
50+
if n not in visited:
51+
frontier.append(n)
52+
visited.add(n)
5053
frontier = frontier[1:]
5154

5255

0 commit comments

Comments
 (0)