Skip to content

Commit 6516fe3

Browse files
author
abergeron
authored
Merge pull request #487 from obilaniu/trivialfixes
Muzzle -Wdeclaration-after-statement and upgrade warning flag strictness
2 parents 4614985 + 09bafc6 commit 6516fe3

File tree

7 files changed

+140
-111
lines changed

7 files changed

+140
-111
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
99
if(MSVC)
1010
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W3")
1111
else()
12-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
12+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -Werror=format-security -Wdeclaration-after-statement -std=gnu89")
1313
endif()
1414

1515
enable_testing()

tests/check_buffer_collectives.c

Lines changed: 75 additions & 47 deletions
Large diffs are not rendered by default.

tests/check_collectives.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
9394
START_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
*/
130131
START_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
*/
157158
START_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
*/
194196
START_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
*/
223225
START_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);

tests/check_elemwise.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,18 @@ START_TEST(test_contig_f16) {
8080
GpuElemwise *ge;
8181

8282
static uint16_t data1[3];
83+
static uint16_t data2[3];
84+
uint16_t data3[3] = {0};
85+
size_t dims[1];
86+
gpuelemwise_arg args[3] = {{0}};
87+
void *rargs[3];
88+
8389
data1[0] = F16[1];
8490
data1[1] = F16[2];
8591
data1[2] = F16[3];
86-
static uint16_t data2[3];
8792
data2[0] = F16[4];
8893
data2[1] = F16[5];
8994
data2[2] = F16[6];
90-
uint16_t data3[3] = {0};
91-
92-
size_t dims[1];
93-
94-
gpuelemwise_arg args[3] = {{0}};
95-
void *rargs[3];
9695

9796
dims[0] = 3;
9897

@@ -243,19 +242,19 @@ START_TEST(test_basic_f16) {
243242
GpuElemwise *ge;
244243

245244
static uint16_t data1[3];
245+
static uint16_t data2[3];
246+
uint16_t data3[3] = {0};
247+
size_t dims[2];
248+
gpuelemwise_arg args[3] = {{0}};
249+
void *rargs[3];
250+
246251
data1[0] = F16[1];
247252
data1[1] = F16[2];
248253
data1[2] = F16[3];
249-
static uint16_t data2[3];
250254
data2[0] = F16[4];
251255
data2[1] = F16[5];
252256
data2[2] = F16[6];
253-
uint16_t data3[3] = {0};
254-
255-
size_t dims[2];
256257

257-
gpuelemwise_arg args[3] = {{0}};
258-
void *rargs[3];
259258

260259
dims[0] = 1;
261260
dims[1] = 3;

tests/check_reduction.c

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ static double pcgRand01(void){
6868
*/
6969

7070
START_TEST(test_reduction){
71-
pcgSeed(1);
72-
7371
/**
7472
* We test here a reduction of some random 3D tensor on the first and
7573
* third dimensions.
7674
*/
7775

76+
GpuArray gaSrc;
77+
GpuArray gaMax;
78+
GpuArray gaArgmax;
7879
size_t i,j,k;
7980
size_t dims[3] = {32,50,79};
8081
size_t prodDims = dims[0]*dims[1]*dims[2];
@@ -93,6 +94,7 @@ START_TEST(test_reduction){
9394
* Initialize source data.
9495
*/
9596

97+
pcgSeed(1);
9698
for(i=0;i<prodDims;i++){
9799
pSrc[i] = pcgRand01();
98100
}
@@ -102,10 +104,6 @@ START_TEST(test_reduction){
102104
* Run the kernel.
103105
*/
104106

105-
GpuArray gaSrc;
106-
GpuArray gaMax;
107-
GpuArray gaArgmax;
108-
109107
ga_assert_ok(GpuArray_empty(&gaSrc, ctx, GA_FLOAT, 3, &dims[0], GA_C_ORDER));
110108
ga_assert_ok(GpuArray_empty(&gaMax, ctx, GA_FLOAT, 1, &dims[1], GA_C_ORDER));
111109
ga_assert_ok(GpuArray_empty(&gaArgmax, ctx, GA_SIZE, 1, &dims[1], GA_C_ORDER));
@@ -156,15 +154,16 @@ START_TEST(test_reduction){
156154
}END_TEST
157155

158156
START_TEST(test_idxtranspose){
159-
pcgSeed(1);
160-
161157
/**
162158
* We test here the same reduction as test_reduction, except with a
163159
* reversed reduxList {2,0} instead of {0,2}. That should lead to a
164160
* transposition of the argmax "coordinates" and thus a change in its
165161
* "flattened" output version.
166162
*/
167163

164+
GpuArray gaSrc;
165+
GpuArray gaMax;
166+
GpuArray gaArgmax;
168167
size_t i,j,k;
169168
size_t dims[3] = {32,50,79};
170169
size_t prodDims = dims[0]*dims[1]*dims[2];
@@ -185,6 +184,7 @@ START_TEST(test_idxtranspose){
185184
* Initialize source data.
186185
*/
187186

187+
pcgSeed(1);
188188
for(i=0;i<prodDims;i++){
189189
pSrc[i] = pcgRand01();
190190
}
@@ -194,10 +194,6 @@ START_TEST(test_idxtranspose){
194194
* Run the kernel.
195195
*/
196196

197-
GpuArray gaSrc;
198-
GpuArray gaMax;
199-
GpuArray gaArgmax;
200-
201197
ga_assert_ok(GpuArray_empty(&gaSrc, ctx, GA_FLOAT, 3, dims, GA_C_ORDER));
202198
ga_assert_ok(GpuArray_empty(&gaMax, ctx, GA_FLOAT, 1, rdxDims, GA_C_ORDER));
203199
ga_assert_ok(GpuArray_empty(&gaArgmax, ctx, GA_SIZE, 1, rdxDims, GA_C_ORDER));
@@ -248,12 +244,14 @@ START_TEST(test_idxtranspose){
248244
}END_TEST
249245

250246
START_TEST(test_veryhighrank){
251-
pcgSeed(1);
252-
253247
/**
254248
* Here we test a reduction of a random 8D tensor on four dimensions.
255249
*/
256250

251+
GpuArray gaSrc;
252+
GpuArray gaMax;
253+
GpuArray gaArgmax;
254+
size_t dstIdx;
257255
size_t i,j,k,l,m,n,o,p;
258256
size_t dims [8] = {1171,373,2,1,2,1,2,1};
259257
size_t prodDims = dims[0]*dims[1]*dims[2]*dims[3]*dims[4]*dims[5]*dims[6]*dims[7];
@@ -274,6 +272,7 @@ START_TEST(test_veryhighrank){
274272
* Initialize source data.
275273
*/
276274

275+
pcgSeed(1);
277276
for(i=0;i<prodDims;i++){
278277
pSrc[i] = pcgRand01();
279278
}
@@ -283,10 +282,6 @@ START_TEST(test_veryhighrank){
283282
* Run the kernel.
284283
*/
285284

286-
GpuArray gaSrc;
287-
GpuArray gaMax;
288-
GpuArray gaArgmax;
289-
290285
ga_assert_ok(GpuArray_empty(&gaSrc, ctx, GA_FLOAT, 8, dims, GA_C_ORDER));
291286
ga_assert_ok(GpuArray_empty(&gaMax, ctx, GA_FLOAT, 4, rdxDims, GA_C_ORDER));
292287
ga_assert_ok(GpuArray_empty(&gaArgmax, ctx, GA_SIZE, 4, rdxDims, GA_C_ORDER));
@@ -327,7 +322,7 @@ START_TEST(test_veryhighrank){
327322
}
328323
}
329324

330-
size_t dstIdx = (((i)*dims[1] + j)*dims[3] + l)*dims[6] + o;
325+
dstIdx = (((i)*dims[1] + j)*dims[3] + l)*dims[6] + o;
331326
ck_assert_msg(gtMax == pMax[dstIdx], "Max value mismatch!");
332327
ck_assert_msg(gtArgmax == pArgmax[dstIdx], "Argmax value mismatch!");
333328
}
@@ -349,16 +344,19 @@ START_TEST(test_veryhighrank){
349344
}END_TEST
350345

351346
START_TEST(test_alldimsreduced){
352-
pcgSeed(1);
353-
354347
/**
355348
* We test here a reduction of some random 3D tensor on all dimensions.
356349
*/
357350

351+
GpuArray gaSrc;
352+
GpuArray gaMax;
353+
GpuArray gaArgmax;
358354
size_t i,j,k;
359355
size_t dims[3] = {32,50,79};
360356
size_t prodDims = dims[0]*dims[1]*dims[2];
361357
const unsigned reduxList[] = {0,1,2};
358+
size_t gtArgmax;
359+
float gtMax;
362360

363361
float* pSrc = calloc(1, sizeof(*pSrc) * dims[0]*dims[1]*dims[2]);
364362
float* pMax = calloc(1, sizeof(*pMax) );
@@ -373,6 +371,7 @@ START_TEST(test_alldimsreduced){
373371
* Initialize source data.
374372
*/
375373

374+
pcgSeed(1);
376375
for(i=0;i<prodDims;i++){
377376
pSrc[i] = pcgRand01();
378377
}
@@ -382,10 +381,6 @@ START_TEST(test_alldimsreduced){
382381
* Run the kernel.
383382
*/
384383

385-
GpuArray gaSrc;
386-
GpuArray gaMax;
387-
GpuArray gaArgmax;
388-
389384
ga_assert_ok(GpuArray_empty(&gaSrc, ctx, GA_FLOAT, 3, &dims[0], GA_C_ORDER));
390385
ga_assert_ok(GpuArray_empty(&gaMax, ctx, GA_FLOAT, 0, NULL, GA_C_ORDER));
391386
ga_assert_ok(GpuArray_empty(&gaArgmax, ctx, GA_SIZE, 0, NULL, GA_C_ORDER));
@@ -404,8 +399,8 @@ START_TEST(test_alldimsreduced){
404399
* Check that the destination tensors are correct.
405400
*/
406401

407-
size_t gtArgmax = 0;
408-
float gtMax = pSrc[0];
402+
gtArgmax = 0;
403+
gtMax = pSrc[0];
409404

410405
for(i=0;i<dims[0];i++){
411406
for(j=0;j<dims[1];j++){

tests/communicator.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ extern void teardown(void);
2121
*/
2222
void setup_comm(void)
2323
{
24-
setup();
2524
int err;
25+
gpucommCliqueId comm_id;
26+
27+
setup();
2628

2729
MPI_Barrier(MPI_COMM_WORLD);
28-
gpucommCliqueId comm_id;
30+
2931
err = gpucomm_gen_clique_id(ctx, &comm_id);
3032
// Has successfully got a unique comm id.
3133
ck_assert_int_eq(err, GA_NO_ERROR);

0 commit comments

Comments
 (0)