Skip to content

Commit 4acf1de

Browse files
committed
docs: guide to use allGather
1 parent d78dae4 commit 4acf1de

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
11
# collectiveSim
22

3-
A library for implementing collectives commonly used in machine learning tasks including allGather and AllReduce, in simulation mode as well as regular use mode.
3+
A library for implementing collectives commonly used in machine learning tasks including allGather and allReduce, in simulation mode as well as regular use mode.
4+
5+
## allGather
6+
7+
allGather lets you gather data distributed accross different chare array elements. The library provides 3 algorithms for doing the allGather operations, namely naive, hypercube and flooding.
8+
9+
### How to use
10+
11+
declare allGather as an extern module in your `.ci` file and include the `allGather.hh` header file in your `cc/hh` file. Then create an AllGather array object and bind it to your chare array. eg.
12+
13+
```C++
14+
CkArrayOptions opts(n);
15+
opts.bindTo(sim);
16+
AllGather_array = CProxy_AllGather::ckNew(k, n, (int)allGatherType::ALL_GATHER_DEFAULT, opts);
17+
```
18+
19+
Here n refers to the size of the chare array, k refers to the number of data elements present in each chare array element and the third parameter lets you choose the algorithm you want to run. The algorithms are:
20+
21+
```C++
22+
enum allGatherType {
23+
ALL_GATHER_DEFAULT,
24+
ALL_GATHER_HYPERCUBE,
25+
ALL_GATHER_FLOODING
26+
};
27+
```
28+
29+
##### [NOTE]: `ALL_GATHER_HYPERCUBE` only works when n(size of chare array) is a power of 2.
30+
31+
You must also declare a callback to a function which the library can return to after its done and it must only take a pointer to `allGatherMsg` as its argument. To start operations, each chare array element must call startGather:
32+
33+
```C++
34+
AllGather_array({{CHARE_ARRAY_INDEX}}).startGather(data, k, cb);
35+
void done(allGatherMsg *msg);
36+
```
37+
38+
Here data refers to per chare array element data and cb refers to the callback.
39+
40+
Once the library is done, it will call the callback function and give it the gathered data as an allGatherMsg. To extract data from it, simply call get_data and the data will always have a size of `n X k`. The structure of `allGatherMsg` is:
41+
42+
```C++
43+
class allGatherMsg : public CMessage_allGatherMsg {
44+
private:
45+
long int *data;
46+
public:
47+
long int *get_data();
48+
allGatherMsg(long int *d);
49+
};
50+
```

0 commit comments

Comments
 (0)