2 #include <hip/hip_runtime.h>
8 int main(int argc
, char* argv
[])
10 ncclComm_t comms
[NDEV
];
14 for(int i
= 0; i
< NDEV
; i
++){
18 float* hsend
= (float*) malloc(size
* sizeof *hsend
);
19 float* hrecv
= (float*) malloc(size
* sizeof *hrecv
);
21 for (int i
= 0; i
< size
; i
++) {
26 float* sendbuff
[NDEV
];
27 float* recvbuff
[NDEV
];
29 for (int i
= 0; i
< NDEV
; i
++) {
31 hipMalloc(sendbuff
+ i
, size
* sizeof(float));
32 hipMalloc(recvbuff
+ i
, size
* sizeof(float));
33 hipMemcpy(sendbuff
[i
], hsend
, size
* sizeof *hsend
, hipMemcpyHostToDevice
);
34 hipMemcpy(recvbuff
[i
], hrecv
, size
* sizeof *hrecv
, hipMemcpyHostToDevice
);
36 hipDeviceSynchronize();
39 ncclCommInitAll(comms
, NDEV
, devs
);
42 for (int i
= 0; i
< NDEV
; i
++)
43 ncclAllReduce(&sendbuff
[i
][0], &recvbuff
[i
][0], size
, ncclFloat
, ncclSum
,
48 for (int i
= 0; i
< NDEV
; i
++) {
50 hipStreamSynchronize(s
[i
]);
54 hipMemcpy(hrecv
, recvbuff
[0], size
* sizeof *hrecv
, hipMemcpyDeviceToHost
);
55 hipDeviceSynchronize();
56 for (int i
= 0; i
< size
; i
++) {
57 if(fabsf(NDEV
* hsend
[i
] - hrecv
[i
]) > 0.001f
){
58 printf("At entry %i\n", i
);
59 printf("Expected %f\n", hsend
[i
]);
60 printf("Received %f\n", hrecv
[i
]);
64 printf("TESTS PASSED!\n");
66 for (int i
= 0; i
< NDEV
; i
++) {
72 for(int i
= 0; i
< NDEV
; ++i
){
73 ncclCommDestroy(comms
[i
]);