Skip to content

Commit 90c704c

Browse files
committed
Fixes after code review and segfault
1 parent 2effb4b commit 90c704c

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/gpuarray_array.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ static int ga_extcopy(GpuArray *dst, const GpuArray *src) {
7676
(cache_freev_fn)GpuElemwise_free,
7777
ctx->err);
7878
if (ctx->extcopy_cache == NULL)
79-
return error_set(ctx->err, GA_MISC_ERROR,
80-
"No context cache");
79+
return ctx->err->code;
8180
if (cache_add(ctx->extcopy_cache, aa, k) != 0)
8281
return error_set(ctx->err, GA_MISC_ERROR,
8382
"Could not store GpuElemwise copy kernel in context cache");
@@ -472,11 +471,14 @@ int GpuArray_take1(GpuArray *a, const GpuArray *v, const GpuArray *i,
472471
return error_set(ctx->err, GA_INVALID_ERROR, "Index array (i) not C-contiguous");
473472

474473
/* Check that the dimensions match namely a[0] == i[0] and a[>0] == v[>0] */
475-
if (v->nd == 0 || a->nd == 0 || i->nd != 1 || a->nd != v->nd ||
476-
a->dimensions[0] != i->dimensions[0])
474+
if (v->nd == 0 || a->nd == 0 || i->nd != 1 || a->nd != v->nd)
475+
return error_fmt(ctx->err, GA_INVALID_ERROR, "Dimension mismatch. "
476+
"v->nd = %llu, a->nd = %llu, i->nd = %llu",
477+
v->nd, a->nd, i->nd);
478+
if (a->dimensions[0] != i->dimensions[0])
477479
return error_fmt(ctx->err, GA_INVALID_ERROR, "Dimension mismatch. "
478-
"v->nd = %llu, a->nd = %llu, i->nd = %llu, a->dimensions[0] = %llu, i->dimensions[0] = %llu",
479-
v->nd, a->nd, i->nd, a->nd > 0 ? a->dimensions[0] : 0, i->nd > 1 ? i->dimensions[0] : 1);
480+
"a->dimensions[0] = %llu, i->dimensions[0] = %llu",
481+
a->dimensions[0], i->dimensions[0]);
480482

481483
n[0] = i->dimensions[0];
482484
n[1] = 1;
@@ -994,7 +996,7 @@ int GpuArray_split(GpuArray **rs, const GpuArray *a, size_t n, size_t *p,
994996

995997
int GpuArray_concatenate(GpuArray *r, const GpuArray **as, size_t n,
996998
unsigned int axis, int restype) {
997-
gpucontext *ctx = GpuArray_context(r);
999+
gpucontext *ctx = GpuArray_context(as[0]);
9981000
size_t *dims, *res_dims;
9991001
size_t i, res_off;
10001002
unsigned int p;

0 commit comments

Comments
 (0)