forked from Azure/msccl-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline_a100_ring.py
executable file
·49 lines (44 loc) · 2.28 KB
/
pipeline_a100_ring.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import argparse
from msccl.language import *
from msccl.topologies import *
from msccl.language.collectives import AllReduce
# Ring all reduce for A100s
# Vary channels from [1-8] to divide parts of the ring over multiple channels/tbs.
# channels=1 is standard ring, all chunks are assigned to the same tb/channel
# channels=8 devotes 1 tb/channel to handling 1 chunk of the data
def allreduce_ring(size, instances, channels, protocol):
topology = fully_connected(2*size)
collective = AllReduce(2*size, size, True)
with MSCCLProgram(f"allreduce_ring_{channels}channelsperring", topology, collective, instances,
protocol=protocol, threadblock_policy=ThreadblockPolicy.manual):
# Reduce ring
for step in range(0, size-1):
for index in range(0, size):
rank = (index + step) % size
next_rank = (index + step + 1) % size
channel = index%channels
c = chunk(next_rank, Buffer.input, index)
c.reduce(chunk(rank, Buffer.input, index), ch=channel, recvtb=channel, sendtb=channel)
# Propagate ring
for index in range(0, size):
rank = (index - 1) % size
c = chunk(rank, Buffer.input, index)
c.copy(rank+size, Buffer.input, index, ch=rank%2)
for step in range(-1, size-2):
for index in range(0, size):
rank = (index + step) % size
c = chunk(rank+size, Buffer.input, index)
next_rank = (index + step + 1) % size
channel = index%channels
c = c.copy(next_rank+size, Buffer.input, index, ch=channel, recvtb=channel, sendtb=channel)
XML()
# Check()
parser = argparse.ArgumentParser()
parser.add_argument('num_gpus', type=int, help ='number of gpus')
parser.add_argument('channels', type=int, help='Number of channels to use for 1 instance of the ring [1-8]')
parser.add_argument('instances', type=int, help='number of instances')
parser.add_argument('--protocol', type=str, default='LL128', choices=['Simple', 'LL', 'LL128'], help ='NCCL protocol. Default: LL128')
args = parser.parse_args()
allreduce_ring(args.num_gpus, args.instances, args.channels, args.protocol)