Skip to content

Commit e2f1f07

Browse files
committed
Changes from review.
1 parent 6572cae commit e2f1f07

4 files changed

Lines changed: 46 additions & 34 deletions

File tree

src/gpuarray_array.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ int GpuArray_take1(GpuArray *a, const GpuArray *v, const GpuArray *i,
455455
int addr32 = 0;
456456

457457
if (!GpuArray_ISWRITEABLE(a))
458-
return error_set(ctx->err, GA_INVALID_ERROR, "Destination array (a) not writeable");
458+
return error_set(ctx->err, GA_VALUE_ERROR, "Destination array not writeable");
459459

460460
if (!GpuArray_ISALIGNED(a) || !GpuArray_ISALIGNED(v) ||
461461
!GpuArray_ISALIGNED(i))
@@ -578,7 +578,7 @@ int GpuArray_setarray(GpuArray *a, const GpuArray *v) {
578578
"a->nd = %llu, v->nd = %llu", a->nd, v->nd);
579579

580580
if (!GpuArray_ISWRITEABLE(a))
581-
return error_set(ctx->err, GA_INVALID_ERROR, "Destination array not writable");
581+
return error_set(ctx->err, GA_VALUE_ERROR, "Destination array not writable");
582582
if (!GpuArray_ISALIGNED(v) || !GpuArray_ISALIGNED(a))
583583
return error_set(ctx->err, GA_UNALIGNED_ERROR, "One of the inputs is unaligned");
584584

@@ -673,7 +673,7 @@ int GpuArray_reshape_inplace(GpuArray *a, unsigned int nd,
673673
newsize *= d;
674674
}
675675

676-
if (newsize != oldsize) return error_set(ctx->err, GA_INVALID_ERROR, "New shope differs in total size");
676+
if (newsize != oldsize) return error_set(ctx->err, GA_INVALID_ERROR, "New shape differs in total size");
677677

678678
/* If the source and desired layouts are the same, then just copy
679679
strides and dimensions */
@@ -1159,7 +1159,7 @@ int GpuArray_fdump(FILE *fd, const GpuArray *a) {
11591159
default:
11601160
free(buf);
11611161
fprintf(fd, "<unsupported data type %d>\n", a->typecode);
1162-
return error_set(ctx->err, GA_UNSUPPORTED_ERROR, "Unsupported data type for dump");
1162+
return error_fmt(ctx->err, GA_UNSUPPORTED_ERROR, "Unsupported data type for dump: %d", a->typecode);
11631163
}
11641164
s -= gpuarray_get_elsize(a->typecode);
11651165
p += gpuarray_get_elsize(a->typecode);

src/gpuarray_array_blas.c

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ int GpuArray_rdot(GpuArray *X, GpuArray *Y,
2424
X->typecode != GA_DOUBLE)
2525
return error_set(ctx->err, GA_INVALID_ERROR, "Data type not supported");
2626

27-
if (X->nd != 1 || Y->nd != 1 || Z->nd != 0 ||
28-
X->typecode != Y->typecode || X->typecode != Z->typecode)
27+
if (X->nd != 1 || Y->nd != 1 || Z->nd != 0)
2928
return error_fmt(ctx->err, GA_VALUE_ERROR,
30-
"Wrong number of dimensions: X->nd = %d (expected 1), Y->nd = %d (expected 1), Z->nd = %d (expected 0)",
29+
"Wrong number of dimensions: X->nd = %u (expected 1), Y->nd = %u (expected 1), Z->nd = %u (expected 0)",
3130
X->nd, Y->nd, Z->nd);
31+
if (X->typecode != Y->typecode || X->typecode != Z->typecode)
32+
error_set(ctx->err, GA_VALUE_ERROR, "Inconsistent dtypes");
3233
n = X->dimensions[0];
3334
if (!(X->flags & GA_ALIGNED) || !(Y->flags & GA_ALIGNED) ||
3435
!(Z->flags & GA_ALIGNED))
@@ -111,11 +112,14 @@ int GpuArray_rgemv(cb_transpose transA, double alpha, GpuArray *A,
111112
if (A->typecode != GA_HALF &&
112113
A->typecode != GA_FLOAT &&
113114
A->typecode != GA_DOUBLE)
114-
return error_set(ctx->err, GA_INVALID_ERROR, "Unsupported data type");
115+
return error_set(ctx->err, GA_INVALID_ERROR, "Unsupported dtype");
115116

116-
if (A->nd != 2 || X->nd != 1 || Y->nd != 1 ||
117-
X->typecode != A->typecode || Y->typecode != A->typecode)
118-
return error_set(ctx->err, GA_VALUE_ERROR, "Bad shape or inconsistent types");
117+
if (A->nd != 2 || X->nd != 1 || Y->nd != 1)
118+
return error_fmt(ctx->err, GA_VALUE_ERROR,
119+
"Wrong number of dimensions: A->nd = %u (expected 2), X->nd = %u (expected 1), Y->nd = %u (expected 1)",
120+
A->nd, X->nd, Y->nd);
121+
if (X->typecode != A->typecode || Y->typecode != A->typecode)
122+
return error_set(ctx->err, GA_VALUE_ERROR, "Inconsistent dtypes");
119123

120124
if (!(A->flags & GA_ALIGNED) || !(X->flags & GA_ALIGNED) ||
121125
!(Y->flags & GA_ALIGNED))
@@ -213,12 +217,14 @@ int GpuArray_rgemm(cb_transpose transA, cb_transpose transB, double alpha,
213217

214218
if (A->typecode != GA_HALF && A->typecode != GA_FLOAT &&
215219
A->typecode != GA_DOUBLE)
216-
return error_set(ctx->err, GA_INVALID_ERROR, "Unsupported type");
220+
return error_set(ctx->err, GA_INVALID_ERROR, "Unsupported dtype");
217221

218-
if (A->nd != 2 || B->nd != 2 || C->nd != 2 ||
219-
B->typecode != A->typecode ||
220-
C->typecode != A->typecode)
221-
return error_set(ctx->err, GA_VALUE_ERROR, "Inconsistent nd or types");
222+
if (A->nd != 2 || B->nd != 2 || C->nd != 2)
223+
return error_fmt(ctx->err, GA_VALUE_ERROR,
224+
"Wrong number of dimensions: A->nd = %u (expected 2), B->nd = %u (expected 2), C->nd = %u (expected 2)",
225+
A->nd, B->nd, C->nd);
226+
if (B->typecode != A->typecode || C->typecode != A->typecode)
227+
return error_set(ctx->err, GA_VALUE_ERROR, "Inconsistent dtypes");
222228

223229
if (!(A->flags & GA_ALIGNED) || !(B->flags & GA_ALIGNED) ||
224230
!(C->flags & GA_ALIGNED))
@@ -363,12 +369,14 @@ int GpuArray_rger(double alpha, GpuArray *X, GpuArray *Y, GpuArray *A,
363369

364370
if (X->typecode != GA_HALF && X->typecode != GA_FLOAT &&
365371
X->typecode != GA_DOUBLE)
366-
return error_set(ctx->err, GA_INVALID_ERROR, "Unsupported type");
372+
return error_set(ctx->err, GA_INVALID_ERROR, "Unsupported dtype");
367373

368-
if (X->nd != 1 || Y->nd != 1 || A->nd != 2 ||
369-
Y->typecode != X->typecode ||
370-
A->typecode != X->typecode)
371-
return error_set(ctx->err, GA_VALUE_ERROR, "Invalid dims or inconsistent types");
374+
if (X->nd != 1 || Y->nd != 1 || A->nd != 2)
375+
return error_fmt(ctx->err, GA_VALUE_ERROR,
376+
"Wrong number of dimensions: X->nd = %u (expected 1), Y->nd = %u (expected 1), A->nd = %u (expected 2)",
377+
X->nd, Y->nd, A->nd);
378+
if (Y->typecode != X->typecode || A->typecode != X->typecode)
379+
return error_set(ctx->err, GA_VALUE_ERROR, "Inconsistent dtypes");
372380

373381
if (!(X->flags & GA_ALIGNED) || !(Y->flags & GA_ALIGNED) ||
374382
!(A->flags & GA_ALIGNED))
@@ -479,12 +487,14 @@ int GpuArray_rgemmBatch_3d(cb_transpose transA, cb_transpose transB, double alph
479487
size_t i;
480488

481489
if (A->typecode != GA_FLOAT && A->typecode != GA_DOUBLE)
482-
return error_set(ctx->err, GA_INVALID_ERROR, "Unsupported type");
490+
return error_set(ctx->err, GA_INVALID_ERROR, "Unsupported dtype");
483491

484-
if (A->nd != 3 || B->nd != 3 || C->nd != 3 ||
485-
B->typecode != A->typecode ||
486-
C->typecode != A->typecode)
487-
return error_set(ctx->err, GA_VALUE_ERROR, "Invalid dims or inconsistent types");
492+
if (A->nd != 3 || B->nd != 3 || C->nd != 3)
493+
return error_fmt(ctx->err, GA_VALUE_ERROR,
494+
"Wrong number of dimensions: A->nd = %u (expected 3), B->nd = %u (expected 3), C->nd = %u (expected 3)",
495+
A->nd, B->nd, C->nd);
496+
if (B->typecode != A->typecode || C->typecode != A->typecode)
497+
return error_set(ctx->err, GA_VALUE_ERROR, "Inconsistent dtypes");
488498

489499
if (!(A->flags & GA_ALIGNED) || !(B->flags & GA_ALIGNED) ||
490500
!(C->flags & GA_ALIGNED))
@@ -558,7 +568,7 @@ int GpuArray_rgemmBatch_3d(cb_transpose transA, cb_transpose transB, double alph
558568
? Cp->strides[1] / elsize
559569
: Cp->dimensions[2];
560570
} else {
561-
err = error_set(ctx->err, GA_VALUE_ERROR, "Invalid internal result for C");
571+
err = error_set(ctx->err, GA_MISC_ERROR, "Invalid internal result for C");
562572
goto cleanup;
563573
}
564574
if (cA == 2) {
@@ -582,7 +592,7 @@ int GpuArray_rgemmBatch_3d(cb_transpose transA, cb_transpose transB, double alph
582592
transA = cb_no_trans;
583593
}
584594
} else {
585-
err = error_set(ctx->err, GA_VALUE_ERROR, "Invalid internal result for A");
595+
err = error_set(ctx->err, GA_MISC_ERROR, "Invalid internal result for A");
586596
goto cleanup;
587597
}
588598
if (cB == 2) {
@@ -606,7 +616,7 @@ int GpuArray_rgemmBatch_3d(cb_transpose transA, cb_transpose transB, double alph
606616
transB = cb_no_trans;
607617
}
608618
} else {
609-
err = error_set(ctx->err, GA_VALUE_ERROR, "Invalid internal result for B");
619+
err = error_set(ctx->err, GA_MISC_ERROR, "Invalid internal result for B");
610620
goto cleanup;
611621
}
612622

src/gpuarray_array_collectives.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ static inline int check_gpuarrays(int times_src, const GpuArray* src,
3737
return error_set(ctx->err, GA_VALUE_ERROR, "Size mismatch for transfer");
3838
if (src->typecode != dest->typecode)
3939
return error_set(ctx->err, GA_VALUE_ERROR, "Type mismatch");
40-
if (!GpuArray_ISALIGNED(src) || !GpuArray_CHKFLAGS(dest, GA_BEHAVED))
41-
return error_set(ctx->err, GA_UNALIGNED_ERROR, "Misbehaved arrays");
40+
if (!GpuArray_ISALIGNED(src) || !GpuArray_ISALIGNED(dest))
41+
return error_set(ctx->err, GA_UNALIGNED_ERROR, "Unaligned arrays");
42+
if (!GpuArray_ISWRITEABLE(dest))
43+
return error_set(ctx->err, GA_INVALID_ERROR, "Unwritable destination");
4244

4345
if (times_src >= times_dest)
4446
*count = count_src;

src/gpuarray_elemwise.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static int check_basic(GpuElemwise *ge, void **args, int flags,
330330
/* We can't broadcast outputs */
331331
if (ISCLR(flags, GE_BROADCAST) || is_output(ge->args[i]) ||
332332
v->dimensions[j] != 1) {
333-
return error_fmt(ctx->err, GA_VALUE_ERROR, "Mismatched dimension %u for input %u", j, i);
333+
return error_fmt(ctx->err, GA_VALUE_ERROR, "Mismatched dimension %u for input %u (expected %" SPREFIX "u got %" SPREFIX "u)", j, i, ge->dims[j], v->dimensions[j]);
334334
}
335335
}
336336
/* If the dimension is 1 set the strides to 0 regardless since
@@ -543,10 +543,10 @@ static int check_contig(GpuElemwise *ge, void **args,
543543
f_contig &= GpuArray_IS_F_CONTIGUOUS(v);
544544
if (a != v) {
545545
if (a->nd != v->nd)
546-
return error_set(ctx->err, GA_INVALID_ERROR, "Mismatched nd");
546+
return error_fmt(ctx->err, GA_INVALID_ERROR, "Mismatched nd for input %u (expected %u, got %u)", i, a->nd, v->nd);
547547
for (j = 0; j < a->nd; j++) {
548548
if (v->dimensions[j] != a->dimensions[j])
549-
return error_fmt(ctx->err, GA_VALUE_ERROR, "Mismatched dimension %u", j);
549+
return error_fmt(ctx->err, GA_VALUE_ERROR, "Mismatched dimension %u (expected %" SPREFIX "u, got %" SPREFIX "u)", j, a->dimensions[j], v->dimensions[j]);
550550
}
551551
}
552552
}

0 commit comments

Comments
 (0)