Skip to content

Commit

Permalink
Fix performance downgrade issue & update doc (#229)
Browse files Browse the repository at this point in the history
For push function, we only need to make sure the instruction `st.global`
will be executed after the while loop. Since there is a Write-After-Read
hazard for `trigger.fst` (Check `this->triggers[curFifoHead % size].fst
!= 0` first then write value to `triggers[curFifoHead % size]`), we can
expect the compiler and hardware can handle this situation correctly.
Remove the `release.sys` there.

BTW, `st.global.release.sys.v2.u64` will cause perf regression issue.
Previous we use `st.global.release.cta.v2.u64`, but seems not necessary.
  • Loading branch information
Binyang2014 authored Dec 4, 2023
1 parent 351b95b commit f1b2c9d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ $ make -j allgather_test_perf allreduce_test_perf
For example, the following command runs the `allreduce5` algorithm with 8 GPUs starting from 3MB to 48MB messages, by doubling the message size in between. You can try different algorithms by changing the `-k 5` option to another value (e.g., `-k 3` runs `allreduce3`). Check all algorithms from the code: [allreduce_test.cu](https://github.com/microsoft/mscclpp/blob/main/test/mscclpp-test/allreduce_test.cu) and [allgather_test.cu](https://github.com/microsoft/mscclpp/blob/main/test/mscclpp-test/allgather_test.cu).

```bash
$ mpirun --bind-to-numa -np 8 ./test/mscclpp-test/allreduce_test_perf -b 3m -e 48m -G 100 -n 100 -w 20 -f 2 -k 5
$ mpirun --bind-to numa -np 8 ./test/mscclpp-test/allreduce_test_perf -b 3m -e 48m -G 100 -n 100 -w 20 -f 2 -k 5
```

*NOTE: a few algorithms set a condition on the total data size, such as to be a multiple of 3. If the condition is unmet, the command will throw a regarding error.*
Expand Down
8 changes: 5 additions & 3 deletions include/mscclpp/fifo_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ struct alignas(16) ProxyTrigger {
uint64_t fst, snd;
};

/// A concurrent FIFO where multiple device threads can push work elements and a single host proxy thread consumes them.
/// A concurrent FIFO where multiple device threads (the number of threads should not exceed the fifo size) can push
/// work elements and a single host proxy thread consumes them.
///
/// The FIFO has a head pointer allocated on the device which starts at 0 and goes up to 2^64-1, which is almost
/// infinity. There are two copies of the tail, one on the device, @ref FifoDeviceHandle::tailReplica, and another on
Expand Down Expand Up @@ -64,9 +65,10 @@ struct FifoDeviceHandle {

ProxyTrigger* triggerPtr = &(this->triggers[curFifoHead % size]);

// store with memory order release so that the while loop does not go pass this.
// There is a Write-After-Read hazard for the triggerPtr->fst. So the st instruction will not be executed
// before the loop.
#if defined(MSCCLPP_DEVICE_CUDA)
asm volatile("st.global.release.sys.v2.u64 [%0], {%1,%2};" ::"l"(triggerPtr), "l"(trigger.fst), "l"(trigger.snd));
asm volatile("st.global.relaxed.sys.v2.u64 [%0], {%1,%2};" ::"l"(triggerPtr), "l"(trigger.fst), "l"(trigger.snd));
#else // !defined(MSCCLPP_DEVICE_CUDA)
// TODO: both atomic and clang built-ins are buggy here
triggerPtr->fst = trigger.fst;
Expand Down

0 comments on commit f1b2c9d

Please sign in to comment.