-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add barrier op to set barrier for multi threadblocks in same rank. The way to use: ```python r = rank(n) r.barrier(tb_list=list(range(gpus))) ```
- Loading branch information
1 parent
514a1c9
commit 8efa06f
Showing
10 changed files
with
187 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import argparse | ||
from msccl.language import * | ||
from msccl.topologies import * | ||
from msccl.language.collectives import AllGather | ||
|
||
|
||
def allgather_test(gpus, instances): | ||
size = gpus | ||
topology = fully_connected(size) | ||
collective = AllGather(size, 1, False) | ||
with MSCCLPPProgram( | ||
"allgather_test", | ||
topology, | ||
collective, | ||
instances, | ||
protocol="Simple", | ||
replication_policy=ReplicationPolicy.interleaved, | ||
): | ||
for n in range(gpus): | ||
c = chunk(n, Buffer.input, 0, 1) | ||
for peer in range(gpus): | ||
if n != peer: | ||
c.put(peer, Buffer.output, n, sendtb=peer, chan_type=ChannelType.sm) | ||
else: | ||
c.copy(n, Buffer.output, n, sendtb=peer) | ||
# explicit barrier | ||
r = rank(n) | ||
r.barrier(tb_list=list(range(gpus))) | ||
for peer in range(gpus): | ||
if n != peer: | ||
c.signal(peer, Buffer.output, n, sendtb=peer, chan_type=ChannelType.sm) | ||
|
||
for n in range(gpus): | ||
for peer in range(gpus): | ||
c = chunk(n, Buffer.output, peer, 1) | ||
if n != peer: | ||
c.wait(peer, Buffer.input, peer, recvtb=peer, chan_type=ChannelType.sm) | ||
|
||
Json() | ||
Check() | ||
|
||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("num_gpus", type=int, help="number of gpus") | ||
parser.add_argument("instances", type=int, help="number of instances") | ||
args = parser.parse_args() | ||
allgather_test(args.num_gpus, args.instances) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
from dataclasses import dataclass, field | ||
from typing import Dict | ||
|
||
|
||
class BarrierInfo: | ||
def __init__(self, tb_list): | ||
self.tb_list = tb_list | ||
|
||
def __eq__(self, other): | ||
return self.tb_list == other.tb_list | ||
|
||
def __hash__(self): | ||
return hash(tuple(self.tb_list)) | ||
|
||
|
||
@dataclass | ||
class Rank: | ||
rank_id: int | ||
current_max_barrier_id: int = 0 | ||
current_barriers: Dict[BarrierInfo, int] = field(default_factory=dict) | ||
|
||
def get_barrier_id(self, tb_list): | ||
barrier_info = BarrierInfo(tb_list) | ||
if barrier_info in self.current_barriers: | ||
return self.current_barriers[barrier_info] | ||
else: | ||
self.current_barriers[barrier_info] = self.current_max_barrier_id | ||
barrier_id = self.current_max_barrier_id | ||
self.current_max_barrier_id += 1 | ||
return barrier_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters