@@ -29,8 +29,8 @@ extern void teardown_comm(void);
2929#define _STR (x ) #x
3030#define COUNT_ERRORS (A , B , M , N , res ) \
3131 do { \
32- res = 0; \
3332 int loci, locj; \
33+ res = 0; \
3434 for (loci = 0; loci < (M); ++loci) { \
3535 for (locj = 0; locj < (N); ++locj) { \
3636 if ((A)[loci][locj] != (B)[loci][locj]) \
@@ -45,37 +45,38 @@ extern void teardown_comm(void);
4545
4646#define INIT_ARRAYS (inrows , incols , outrows , outcols ) \
4747 int(*A)[(incols)]; \
48+ int(*RES)[(outcols)]; \
49+ int(*EXP)[(outcols)]; \
50+ size_t indims[ND]; \
51+ size_t outdims[ND]; \
52+ const ssize_t instrds[ND] = {sizeof(*A), sizeof(int)}; \
53+ const ssize_t outstrds[ND] = {sizeof(*RES), sizeof(int)}; \
54+ int err; \
55+ size_t i, j, outsize; \
56+ GpuArray Adev; \
57+ GpuArray RESdev; \
58+ \
4859 A = (int(*)[(incols)])calloc((inrows), sizeof(*A)); \
4960 if (A == NULL) \
5061 ck_abort_msg("system memory allocation failed"); \
51- int(*RES)[(outcols)]; \
5262 RES = (int(*)[(outcols)])calloc((outrows), sizeof(*RES)); \
5363 if (RES == NULL) \
5464 ck_abort_msg("system memory allocation failed"); \
55- int(*EXP)[(outcols)]; \
5665 EXP = (int(*)[(outcols)])calloc((outrows), sizeof(*EXP)); \
5766 if (EXP == NULL) \
5867 ck_abort_msg("system memory allocation failed"); \
59- size_t indims[ND]; \
6068 indims[0] = (inrows); \
6169 indims[1] = (incols); \
62- size_t outdims[ND]; \
6370 outdims[0] = (outrows); \
6471 outdims[1] = (outcols); \
65- const ssize_t instrds[ND] = {sizeof(*A), sizeof(int)}; \
66- const ssize_t outstrds[ND] = {sizeof(*RES), sizeof(int)}; \
67- size_t outsize = outdims[0] * outstrds[0]; \
72+ outsize = outdims[0] * outstrds[0]; \
6873 \
69- size_t i, j; \
7074 for (i = 0; i < indims[0]; ++i) \
7175 for (j = 0; j < indims[1]; ++j) \
7276 A[i][j] = comm_rank + 2; \
7377 \
74- int err; \
75- GpuArray Adev; \
7678 err = GpuArray_copy_from_host(&Adev, ctx, A, GA_INT, ND, indims, instrds); \
7779 ck_assert_int_eq(err, GA_NO_ERROR); \
78- GpuArray RESdev; \
7980 err = GpuArray_empty(&RESdev, ctx, GA_INT, ND, outdims, GA_C_ORDER); \
8081 ck_assert_int_eq(err, GA_NO_ERROR);
8182
@@ -91,6 +92,7 @@ extern void teardown_comm(void);
9192 * aligned`.
9293 */
9394START_TEST (test_GpuArray_reduce ) {
95+ int res ;
9496 INIT_ARRAYS (ROWS , COLS , ROWS , COLS );
9597
9698 if (comm_rank == ROOT_RANK ) {
@@ -111,7 +113,6 @@ START_TEST(test_GpuArray_reduce) {
111113 if (comm_rank == ROOT_RANK ) {
112114 err = GpuArray_read (RES , outsize , & RESdev );
113115 ck_assert_int_eq (err , GA_NO_ERROR );
114- int res ;
115116 COUNT_ERRORS (RES , EXP , ROWS , COLS , res );
116117 ck_assert_msg (res == 0 ,
117118 "GpuArray_reduce with %s op produced errors in %d places" ,
@@ -128,6 +129,7 @@ END_TEST
128129 * aligned`.
129130 */
130131START_TEST (test_GpuArray_all_reduce ) {
132+ int res ;
131133 INIT_ARRAYS (ROWS , COLS , ROWS , COLS );
132134
133135 err = GpuArray_all_reduce (& Adev , & RESdev , GA_SUM , comm );
@@ -140,7 +142,6 @@ START_TEST(test_GpuArray_all_reduce) {
140142
141143 err = GpuArray_read (RES , outsize , & RESdev );
142144 ck_assert_int_eq (err , GA_NO_ERROR );
143- int res ;
144145 COUNT_ERRORS (RES , EXP , ROWS , COLS , res );
145146 ck_assert_msg (res == 0 ,
146147 "GpuArray_all_reduce with %s op produced errors in %d places" ,
@@ -155,6 +156,8 @@ END_TEST
155156 * aligned`.
156157 */
157158START_TEST (test_GpuArray_reduce_scatter ) {
159+ int res ;
160+ int * recvcounts ;
158161 // In order for C contiguous arrays to be combined/split successfully they
159162 // should
160163 // split along the smallest axis (the one with the bigger stride).
@@ -165,7 +168,7 @@ START_TEST(test_GpuArray_reduce_scatter) {
165168 GpuArray_sync (& RESdev );
166169 GpuArray_sync (& Adev );
167170
168- int * recvcounts = (int * )malloc (comm_ndev * sizeof (int ));
171+ recvcounts = (int * )malloc (comm_ndev * sizeof (int ));
169172 if (recvcounts == NULL )
170173 ck_abort_msg ("system memory allocation failed" );
171174 for (i = 0 ; i < (size_t )comm_ndev ; ++ i )
@@ -177,7 +180,6 @@ START_TEST(test_GpuArray_reduce_scatter) {
177180
178181 err = GpuArray_read (RES , outsize , & RESdev );
179182 ck_assert_int_eq (err , GA_NO_ERROR );
180- int res ;
181183 COUNT_ERRORS (RES , EXP , ROWS / comm_ndev , COLS , res );
182184 ck_assert_msg (
183185 res == 0 ,
@@ -192,6 +194,7 @@ END_TEST
192194 * \note Untested for `not aligned`.
193195 */
194196START_TEST (test_GpuArray_broadcast ) {
197+ int res ;
195198 INIT_ARRAYS (ROWS , COLS , ROWS , COLS );
196199
197200 for (i = 0 ; i < indims [0 ]; ++ i )
@@ -207,7 +210,6 @@ START_TEST(test_GpuArray_broadcast) {
207210
208211 err = GpuArray_read (RES , outsize , & Adev );
209212 ck_assert_int_eq (err , GA_NO_ERROR );
210- int res ;
211213 COUNT_ERRORS (RES , EXP , ROWS , COLS , res );
212214 ck_assert_msg (res == 0 , "GpuArray_broadcast produced errors in %d places" ,
213215 res );
@@ -221,6 +223,7 @@ END_TEST
221223 * aligned`.
222224 */
223225START_TEST (test_GpuArray_all_gather ) {
226+ int res ;
224227 // In order for C contiguous arrays to be combined/split successfully they
225228 // should
226229 // split along the smallest axis (the one with the bigger stride).
@@ -237,7 +240,6 @@ START_TEST(test_GpuArray_all_gather) {
237240
238241 err = GpuArray_read (RES , outsize , & RESdev );
239242 ck_assert_int_eq (err , GA_NO_ERROR );
240- int res ;
241243 COUNT_ERRORS (RES , EXP , ROWS , COLS , res );
242244 ck_assert_msg (res == 0 , "GpuArray_all_gather produced errors in %d places" ,
243245 res );
0 commit comments