Skip to content

Commit 6c5611e

Browse files
committed
Add missing brackets around error condition.
1 parent 4452585 commit 6c5611e

1 file changed

Lines changed: 46 additions & 44 deletions

File tree

src/gpuarray_buffer_cuda.c

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,10 @@ cuda_context *cuda_make_ctx(CUcontext ctx, int flags) {
235235
(cache_hash_fn)strb_hash,
236236
(cache_freek_fn)strb_free,
237237
(cache_freev_fn)cuda_freekernel, global_err);
238-
if (res->kernel_cache == NULL)
238+
if (res->kernel_cache == NULL) {
239239
error_cuda(global_err, "cuStreamCreate", err);
240240
goto fail_cache;
241+
}
241242

242243
cache_path = getenv("GPUARRAY_CACHE_PATH");
243244
if (cache_path != NULL) {
@@ -246,10 +247,10 @@ cuda_context *cuda_make_ctx(CUcontext ctx, int flags) {
246247
(cache_hash_fn)key_hash,
247248
(cache_freek_fn)key_free,
248249
(cache_freev_fn)strb_free,
249-
res->err);
250+
global_err);
250251
if (mem_cache == NULL) {
251252
fprintf(stderr, "Error initializing mem cache for disk: %s\n",
252-
res->err->msg);
253+
global_err->msg);
253254
goto fail_disk_cache;
254255
}
255256
res->disk_cache = cache_disk(cache_path, mem_cache,
@@ -489,50 +490,51 @@ static const char CUDA_PREAMBLE[] =
489490
/* XXX: add vector types */
490491

491492
static cuda_context *do_init(CUdevice dev, int flags, error *e) {
492-
cuda_context *res;
493-
CUcontext ctx;
494-
CUresult err;
495-
unsigned int fl = CU_CTX_SCHED_AUTO;
496-
unsigned int cur_fl;
497-
int act;
498-
int i;
499-
500-
if (flags & GA_CTX_SINGLE_THREAD)
501-
fl = CU_CTX_SCHED_SPIN;
502-
if (flags & GA_CTX_MULTI_THREAD)
503-
fl = CU_CTX_SCHED_YIELD;
504-
err = cuDeviceGetAttribute(&i, CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING, dev);
505-
CHKFAIL(e, "cuDeviceGetAttribute", NULL);
506-
if (i != 1) {
507-
error_set(e, GA_UNSUPPORTED_ERROR, "device does not support unified addressing");
508-
return NULL;
509-
}
510-
err = cuDevicePrimaryCtxGetState(dev, &cur_fl, &act);
511-
CHKFAIL(e, "cuDevicePrimaryCtxGetState", NULL);
512-
if (act == 1) {
513-
if ((cur_fl & fl) != fl) {
514-
error_set(e, GA_INVALID_ERROR, "device is already active and has unsupported flags");
515-
return NULL;
516-
}
517-
} else {
518-
err = cuDevicePrimaryCtxSetFlags(dev, fl);
519-
CHKFAIL(e, "cuDevicePrimaryCtxSetFlags", NULL);
520-
}
521-
err = cuDevicePrimaryCtxRetain(&ctx, dev);
522-
CHKFAIL(e, "cuDevicePrimaryCtxRetain", NULL);
523-
err = cuCtxPushCurrent(ctx);
524-
CHKFAIL(e, "cuCtxPushCurrent", NULL);
525-
res = cuda_make_ctx(ctx, flags);
526-
if (res == NULL) {
527-
cuDevicePrimaryCtxRelease(dev);
528-
if (e != global_err)
529-
error_set(e, global_err->code, global_err->msg);
493+
cuda_context *res;
494+
CUcontext ctx;
495+
CUresult err;
496+
unsigned int fl = CU_CTX_SCHED_AUTO;
497+
unsigned int cur_fl;
498+
int act;
499+
int i;
500+
501+
if (flags & GA_CTX_SINGLE_THREAD)
502+
fl = CU_CTX_SCHED_SPIN;
503+
if (flags & GA_CTX_MULTI_THREAD)
504+
fl = CU_CTX_SCHED_YIELD;
505+
err = cuDeviceGetAttribute(&i, CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING, dev);
506+
CHKFAIL(e, "cuDeviceGetAttribute", NULL);
507+
if (i != 1) {
508+
error_set(e, GA_UNSUPPORTED_ERROR, "device does not support unified addressing");
509+
return NULL;
510+
}
511+
err = cuDevicePrimaryCtxGetState(dev, &cur_fl, &act);
512+
CHKFAIL(e, "cuDevicePrimaryCtxGetState", NULL);
513+
if (act == 1) {
514+
if ((cur_fl & fl) != fl) {
515+
error_set(e, GA_INVALID_ERROR, "device is already active and has unsupported flags");
530516
return NULL;
531517
}
532-
/* Don't leave the context on the thread stack */
533-
cuCtxPopCurrent(NULL);
518+
} else {
519+
err = cuDevicePrimaryCtxSetFlags(dev, fl);
520+
CHKFAIL(e, "cuDevicePrimaryCtxSetFlags", NULL);
521+
}
522+
err = cuDevicePrimaryCtxRetain(&ctx, dev);
523+
CHKFAIL(e, "cuDevicePrimaryCtxRetain", NULL);
524+
err = cuCtxPushCurrent(ctx);
525+
CHKFAIL(e, "cuCtxPushCurrent", NULL);
526+
res = cuda_make_ctx(ctx, flags);
527+
if (res == NULL) {
528+
fprintf(stderr, "res failed\n");
529+
cuDevicePrimaryCtxRelease(dev);
530+
if (e != global_err)
531+
error_set(e, global_err->code, global_err->msg);
532+
return NULL;
533+
}
534+
/* Don't leave the context on the thread stack */
535+
cuCtxPopCurrent(NULL);
534536

535-
return res;
537+
return res;
536538
}
537539

538540
static gpucontext *cuda_init(int ord, int flags) {

0 commit comments

Comments
 (0)