11#include " perf_common.h"
22
33static void collFn (PerfContext &ctx, size_t count) {
4- flagcxAllReduce (ctx.sendbuff , ctx.recvbuff , count, flagcxFloat, flagcxSum ,
4+ flagcxAllReduce (ctx.sendbuff , ctx.recvbuff , count, ctx. datatype , ctx. op ,
55 ctx.comm , ctx.stream );
66}
77
@@ -18,97 +18,23 @@ static double bwFactorFn(int totalProcs) {
1818}
1919
2020static void dataInitFn (PerfContext &ctx, size_t size, size_t count) {
21+ size_t typeSize = getFlagcxDataTypeSize (ctx.datatype );
22+ memset (ctx.hello , 0 , size);
2123 for (size_t i = 0 ; i < count; i++) {
22- ((float *)ctx.hello )[i] = i % 10 * (1 << ctx.proc );
24+ float val = (float )(i % 10 ) * (1ULL << (ctx.proc % 30 ));
25+ memcpy ((char *)ctx.hello + i * typeSize, &val,
26+ sizeof (float ) < typeSize ? sizeof (float ) : typeSize);
2327 }
2428 ctx.devHandle ->deviceMemcpy (ctx.sendbuff , ctx.hello , size,
2529 flagcxMemcpyHostToDevice, NULL );
2630 ctx.devHandle ->deviceMemcpy (ctx.recvbuff , ctx.hello , size,
2731 flagcxMemcpyHostToDevice, NULL );
28- if (ctx.color == 0 && ctx.printBuffer ) {
29- printf (" rank %d sendbuff = " , ctx.proc );
30- for (size_t i = 0 ; i < 10 ; i++) {
31- printf (" %f " , ((float *)ctx.hello )[i]);
32- }
33- printf (" \n " );
34- }
3532}
3633
3734static void postIterFn (PerfContext &ctx, size_t size, size_t count) {
38- const char *envLocRed = getenv (" FLAGCX_UNIRUNNER_USE_LOCRED" );
39- const char *envRingAG = getenv (" FLAGCX_UNIRUNNER_USE_RINGAG" );
4035 memset (ctx.hello , 0 , size);
4136 ctx.devHandle ->deviceMemcpy (ctx.hello , ctx.recvbuff , size,
4237 flagcxMemcpyDeviceToHost, NULL );
43- if (ctx.color == 0 && ctx.printBuffer ) {
44- printf (" rank %d recvbuff = " , ctx.proc );
45- for (size_t i = 0 ; i < 10 ; i++) {
46- printf (" %f " , ((float *)ctx.hello )[i]);
47- }
48- printf (" \n " );
49-
50- if (envLocRed != NULL && atoi (envLocRed) == 1 ) {
51- /* red correctness check */
52- int redCorrect = 1 ;
53- for (size_t i = 0 ; i < count; i++) {
54- if (i * ctx.totalProcs / count == (size_t )ctx.proc )
55- continue ;
56- if (((float *)ctx.hello )[i] != (float )(i % 10 * (1 << ctx.proc ))) {
57- printf (" rank %d wrong output at offset %lu, expected %f, got %f\n " ,
58- ctx.proc , i, (float )(i % 10 * (1 << ctx.proc )),
59- ((float *)ctx.hello )[i]);
60- redCorrect = 0 ;
61- break ;
62- }
63- }
64- for (size_t i = ctx.proc * count / ctx.totalProcs ;
65- i < (ctx.proc + 1 ) * count / ctx.totalProcs ; i++) {
66- if (((float *)ctx.hello )[i] !=
67- (float )(i % 10 * (1 << (ctx.proc + 1 )))) {
68- printf (" rank %d wrong output at offset %lu, expected %f, got %f\n " ,
69- ctx.proc , i, (float )(i % 10 * (1 << (ctx.proc + 1 ))),
70- ((float *)ctx.hello )[i]);
71- redCorrect = 0 ;
72- break ;
73- }
74- }
75- printf (" rank %d reduce correctness = %d\n " , ctx.proc , redCorrect);
76- } else if (envRingAG != NULL && atoi (envRingAG) == 1 ) {
77- /* p2p correctness check */
78- int p2pCorrect = 1 ;
79- for (size_t i = 0 ; i < count; i++) {
80- if (((float *)ctx.hello )[i] !=
81- (float )(i % 10 * (1 << (i * ctx.totalProcs / count)))) {
82- printf (" rank %d wrong output at offset %lu, expected %f, got %f\n " ,
83- ctx.proc , i,
84- (float )(i % 10 * (1 << (i * ctx.totalProcs / count))),
85- ((float *)ctx.hello )[i]);
86- p2pCorrect = 0 ;
87- break ;
88- }
89- }
90- printf (" rank %d p2p correctness = %d\n " , ctx.proc , p2pCorrect);
91- } else {
92- /* all-reduce correctness check */
93- int arCorrect = 1 ;
94- for (size_t i = 0 ; i < count; i++) {
95- if ((i % 10 == 0 && ((float *)ctx.hello )[i] != 0 ) ||
96- ((float *)ctx.hello )[i] /
97- (float )(i % 10 * ((1 << ctx.totalProcs ) - 1 )) >
98- 1 + 1e-5 ||
99- ((float *)ctx.hello )[i] /
100- (float )(i % 10 * ((1 << ctx.totalProcs ) - 1 )) <
101- 1 - 1e-5 ) {
102- printf (" rank %d wrong output at offset %lu, expected %f, got %f\n " ,
103- ctx.proc , i, (float )(i % 10 * ((1 << ctx.totalProcs ) - 1 )),
104- ((float *)ctx.hello )[i]);
105- arCorrect = 0 ;
106- break ;
107- }
108- }
109- printf (" rank %d all-reduce correctness = %d\n " , ctx.proc , arCorrect);
110- }
111- }
11238}
11339
11440int main (int argc, char *argv[]) {
0 commit comments