Skip to content

Commit c31a29b

Browse files
committed
Fix declaration issues in collectives files and in macros
- Add warning compilation flag -Wdeclaration-after-statement in CMakeLists
1 parent 003a740 commit c31a29b

3 files changed

Lines changed: 41 additions & 27 deletions

File tree

‎src/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include(CheckFunctionExists)
22

33
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
4+
add_definitions(-Wdeclaration-after-statement)
45

56
find_package(CUDA)
67
find_package(OpenCL)

‎src/gpuarray_buffer_cuda.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ static int cuda_get_platform_count(unsigned int* platcount) {
5858

5959
static int cuda_get_device_count(unsigned int platform,
6060
unsigned int* devcount) {
61+
int dv;
6162
// platform number gets ignored in CUDA implementation
6263
if (!init_done) {
6364
err = cuInit(0);
6465
if (err != CUDA_SUCCESS)
6566
return GA_IMPL_ERROR;
6667
init_done = 1;
6768
}
68-
int dv;
6969
err = cuDeviceGetCount(&dv);
7070
if (err != CUDA_SUCCESS)
7171
return GA_IMPL_ERROR;

‎src/gpuarray_collectives_cuda_nccl.c‎

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
} \
4242
} while (0)
4343

44-
extern const gpuarray_buffer_ops
45-
cuda_ops; //!< Link wrapped cuda core operations
44+
//!< Link wrapped cuda core operations
45+
extern const gpuarray_buffer_ops cuda_ops;
4646

4747
/**
4848
* Definition of struct _gpucomm
@@ -73,19 +73,20 @@ static void comm_clear(gpucomm* comm) {
7373
*/
7474
static int comm_new(gpucomm** comm_ptr, gpucontext* ctx,
7575
gpucommCliqueId comm_id, int ndev, int rank) {
76-
ASSERT_CTX(ctx);
7776
gpucomm* comm;
77+
ncclResult_t nccl_err;
78+
79+
ASSERT_CTX(ctx);
7880
comm = calloc(1, sizeof(*comm)); // Allocate memory
7981
if (comm == NULL) {
8082
*comm_ptr = NULL; // Set to NULL if failed
8183
return GA_MEMORY_ERROR;
8284
}
8385
comm->ctx = (cuda_context*)ctx; // convert to underlying cuda context
84-
comm->ctx
85-
->refcnt++; // So that context would not be destroyed before communicator
86+
// So that context would not be destroyed before communicator
87+
comm->ctx->refcnt++;
8688
cuda_enter(comm->ctx); // Use device
87-
ncclResult_t nccl_err =
88-
ncclCommInitRank(&comm->c, ndev, *((ncclUniqueId*)&comm_id), rank);
89+
nccl_err = ncclCommInitRank(&comm->c, ndev, *((ncclUniqueId*)&comm_id), rank);
8990
cuda_exit(comm->ctx);
9091
TAG_COMM(comm);
9192
if (nccl_err != ncclSuccess) {
@@ -181,6 +182,7 @@ static inline int check_restrictions(gpudata* src, size_t offsrc, gpudata* dest,
181182
int opcode, gpucomm* comm,
182183
ncclDataType_t* datatype,
183184
ncclRedOp_t* op) {
185+
size_t op_size;
184186
// Check if count is larger than INT_MAX
185187
// TODO remove whenif nccl adapts to size_t
186188
if (count > INT_MAX)
@@ -207,7 +209,7 @@ static inline int check_restrictions(gpudata* src, size_t offsrc, gpudata* dest,
207209
assert(!(offsrc > src->sz));
208210
assert(!(dest != NULL && offdest > dest->sz));
209211
// size to operate upon must be able to fit inside the gpudata (incl offsets)
210-
size_t op_size = count * gpuarray_get_elsize(typecode);
212+
op_size = count * gpuarray_get_elsize(typecode);
211213
if ((src->sz - offsrc) < op_size)
212214
return GA_VALUE_ERROR;
213215
if (dest != NULL && (dest->sz - offdest) < op_size)
@@ -223,10 +225,12 @@ static int reduce(gpudata* src, size_t offsrc, gpudata* dest, size_t offdest,
223225
gpucomm* comm) {
224226
ncclRedOp_t op;
225227
ncclDataType_t datatype;
226-
ASSERT_BUF(src);
227-
ASSERT_COMM(comm);
228228
gpudata* dst = NULL;
229229
int rank = 0;
230+
cuda_context* ctx;
231+
232+
ASSERT_BUF(src);
233+
ASSERT_COMM(comm);
230234
GA_CHECK(get_rank(comm, &rank));
231235
if (rank == root) {
232236
dst = dest;
@@ -235,7 +239,7 @@ static int reduce(gpudata* src, size_t offsrc, gpudata* dest, size_t offdest,
235239
GA_CHECK(check_restrictions(src, offsrc, dst, offdest, count, typecode,
236240
opcode, comm, &datatype, &op));
237241

238-
cuda_context* ctx = comm->ctx;
242+
ctx = comm->ctx;
239243
cuda_enter(ctx);
240244

241245
// sync: wait till a write has finished (out of concurrent kernels)
@@ -270,13 +274,15 @@ static int all_reduce(gpudata* src, size_t offsrc, gpudata* dest,
270274
gpucomm* comm) {
271275
ncclRedOp_t op;
272276
ncclDataType_t datatype;
277+
cuda_context* ctx;
278+
273279
ASSERT_BUF(src);
274280
ASSERT_COMM(comm);
275281
ASSERT_BUF(dest);
276282
GA_CHECK(check_restrictions(src, offsrc, dest, offdest, count, typecode,
277283
opcode, comm, &datatype, &op));
278284

279-
cuda_context* ctx = comm->ctx;
285+
ctx = comm->ctx;
280286
cuda_enter(ctx);
281287

282288
// sync: wait till a write has finished (out of concurrent kernels)
@@ -303,23 +309,26 @@ static int all_reduce(gpudata* src, size_t offsrc, gpudata* dest,
303309
static int reduce_scatter(gpudata* src, size_t offsrc, gpudata* dest,
304310
size_t offdest, size_t count, int typecode,
305311
int opcode, gpucomm* comm) {
306-
ASSERT_BUF(src);
307-
ASSERT_COMM(comm);
308-
ASSERT_BUF(dest);
309312
ncclRedOp_t op;
310313
ncclDataType_t datatype;
311314
int ndev = 0;
315+
size_t resc_size;
316+
cuda_context* ctx;
317+
318+
ASSERT_BUF(src);
319+
ASSERT_COMM(comm);
320+
ASSERT_BUF(dest);
312321
GA_CHECK(get_count(comm, &ndev));
313322
GA_CHECK(check_restrictions(src, offsrc, NULL, 0, count * ndev, typecode,
314323
opcode, comm, &datatype, &op));
315324
if (dest->ctx != comm->ctx)
316325
return GA_VALUE_ERROR;
317-
size_t resc_size = count * gpuarray_get_elsize(typecode);
326+
resc_size = count * gpuarray_get_elsize(typecode);
318327
if ((dest->sz - offdest) < resc_size)
319328
return GA_VALUE_ERROR;
320329
assert(!(offdest > dest->sz));
321330

322-
cuda_context* ctx = comm->ctx;
331+
ctx = comm->ctx;
323332
cuda_enter(ctx);
324333

325334
// sync: wait till a write has finished (out of concurrent kernels)
@@ -345,15 +354,17 @@ static int reduce_scatter(gpudata* src, size_t offsrc, gpudata* dest,
345354
*/
346355
static int broadcast(gpudata* array, size_t offset, size_t count, int typecode,
347356
int root, gpucomm* comm) {
357+
ncclDataType_t datatype;
358+
int rank = 0;
359+
cuda_context* ctx;
360+
348361
ASSERT_BUF(array);
349362
ASSERT_COMM(comm);
350-
ncclDataType_t datatype;
351363
GA_CHECK(check_restrictions(array, offset, NULL, 0, count, typecode, 0, comm,
352364
&datatype, NULL));
353-
int rank = 0;
354365
GA_CHECK(get_rank(comm, &rank));
355366

356-
cuda_context* ctx = comm->ctx;
367+
ctx = comm->ctx;
357368
cuda_enter(ctx);
358369

359370
// sync: wait till a write has finished (out of concurrent kernels)
@@ -382,22 +393,25 @@ static int broadcast(gpudata* array, size_t offset, size_t count, int typecode,
382393
static int all_gather(gpudata* src, size_t offsrc, gpudata* dest,
383394
size_t offdest, size_t count, int typecode,
384395
gpucomm* comm) {
396+
ncclDataType_t datatype;
397+
int ndev = 0;
398+
size_t resc_size;
399+
cuda_context* ctx;
400+
385401
ASSERT_BUF(src);
386402
ASSERT_COMM(comm);
387403
ASSERT_BUF(dest);
388-
ncclDataType_t datatype;
389404
GA_CHECK(check_restrictions(src, offsrc, NULL, 0, count, typecode, 0, comm,
390405
&datatype, NULL));
391406
if (dest->ctx != comm->ctx)
392407
return GA_VALUE_ERROR;
393-
int ndev = 0;
394408
GA_CHECK(get_count(comm, &ndev));
395-
size_t resc_size = ndev * count * gpuarray_get_elsize(typecode);
409+
resc_size = ndev * count * gpuarray_get_elsize(typecode);
396410
if ((dest->sz - offdest) < resc_size)
397411
return GA_VALUE_ERROR;
398412
assert(!(offdest > dest->sz));
399413

400-
cuda_context* ctx = comm->ctx;
414+
ctx = comm->ctx;
401415
cuda_enter(ctx);
402416

403417
// sync: wait till a write has finished (out of concurrent kernels)
@@ -420,8 +434,7 @@ static int all_gather(gpudata* src, size_t offsrc, gpudata* dest,
420434

421435
/**
422436
* Instance of `gpuarray_comm_ops` which contains NCCL implementations. To be
423-
* linked
424-
* in \ref gpuarray_buffer_cuda.c, in order to fill a /ref gpucontext's
437+
* linked in \ref gpuarray_buffer_cuda.c, in order to fill a /ref gpucontext's
425438
* comm_ops.
426439
*/
427440
GPUARRAY_LOCAL gpuarray_comm_ops nccl_ops = {

0 commit comments

Comments
 (0)