@@ -32,7 +32,7 @@ int GpuArray_rdot(GpuArray *X, GpuArray *Y,
3232 n = X -> dimensions [0 ];
3333 if (!(X -> flags & GA_ALIGNED ) || !(Y -> flags & GA_ALIGNED ) ||
3434 !(Z -> flags & GA_ALIGNED ))
35- return GA_UNALIGNED_ERROR ;
35+ return error_set ( ctx -> err , GA_UNALIGNED_ERROR , "One of the inputs is unaligned" ) ;
3636 if (X -> dimensions [0 ] != Y -> dimensions [0 ])
3737 return error_fmt (ctx -> err , GA_VALUE_ERROR ,
3838 "Shape mismatch: X->dimensions[0] = %d != Y->dimensions[0] = %d" ,
@@ -41,7 +41,7 @@ int GpuArray_rdot(GpuArray *X, GpuArray *Y,
4141 elsize = gpuarray_get_elsize (X -> typecode );
4242 if (X -> strides [0 ] < 0 ) {
4343 if (nocopy )
44- return GA_COPY_ERROR ;
44+ return error_set ( ctx -> err , GA_COPY_ERROR , "Copy required for X" ) ;
4545 else {
4646 err = GpuArray_copy (& copyX , X , GA_ANY_ORDER );
4747 if (err != GA_NO_ERROR )
@@ -51,7 +51,7 @@ int GpuArray_rdot(GpuArray *X, GpuArray *Y,
5151 }
5252 if (Y -> strides [0 ] < 0 ) {
5353 if (nocopy )
54- return GA_COPY_ERROR ;
54+ return error_set ( ctx -> err , GA_COPY_ERROR , "Copy required for Y" ) ;
5555 else {
5656 err = GpuArray_copy (& copyY , Y , GA_ANY_ORDER );
5757 if (err != GA_NO_ERROR )
@@ -102,24 +102,24 @@ int GpuArray_rgemv(cb_transpose transA, double alpha, GpuArray *A,
102102 GpuArray * Xp = X ;
103103 GpuArray copyX ;
104104 GpuArray * Yp = Y ;
105- void * ctx ;
106105 size_t elsize ;
107106 size_t m , n , lda ;
108107 cb_order o ;
109108 int err ;
109+ void * ctx = gpudata_context (Ap -> data );
110110
111111 if (A -> typecode != GA_HALF &&
112112 A -> typecode != GA_FLOAT &&
113113 A -> typecode != GA_DOUBLE )
114- return GA_INVALID_ERROR ;
114+ return error_set ( ctx -> err , GA_INVALID_ERROR , "Unsupported data type" ) ;
115115
116116 if (A -> nd != 2 || X -> nd != 1 || Y -> nd != 1 ||
117117 X -> typecode != A -> typecode || Y -> typecode != A -> typecode )
118- return GA_VALUE_ERROR ;
118+ return error_set ( ctx -> err , GA_VALUE_ERROR , "Bad shape or inconsistent types" ) ;
119119
120120 if (!(A -> flags & GA_ALIGNED ) || !(X -> flags & GA_ALIGNED ) ||
121121 !(Y -> flags & GA_ALIGNED ))
122- return GA_UNALIGNED_ERROR ;
122+ return error_set ( ctx -> err , GA_UNALIGNED_ERROR , "Unaligned inputs" ) ;
123123
124124 if (transA == cb_no_trans ) {
125125 m = A -> dimensions [0 ];
@@ -130,7 +130,7 @@ int GpuArray_rgemv(cb_transpose transA, double alpha, GpuArray *A,
130130 }
131131
132132 if (Y -> dimensions [0 ] != m || X -> dimensions [0 ] != n )
133- return GA_VALUE_ERROR ;
133+ return error_set ( ctx -> err , GA_VALUE_ERROR , "Inconsistent shapes" ) ;
134134
135135 m = A -> dimensions [0 ];
136136 n = A -> dimensions [1 ];
@@ -139,7 +139,7 @@ int GpuArray_rgemv(cb_transpose transA, double alpha, GpuArray *A,
139139
140140 if (!GpuArray_ISONESEGMENT (A )) {
141141 if (nocopy )
142- return GA_COPY_ERROR ;
142+ return error_set ( ctx -> err , GA_COPY_ERROR , "Copy required for A" ) ;
143143 else {
144144 err = GpuArray_copy (& copyA , A , GA_F_ORDER );
145145 if (err != GA_NO_ERROR )
@@ -149,7 +149,7 @@ int GpuArray_rgemv(cb_transpose transA, double alpha, GpuArray *A,
149149 }
150150 if (X -> strides [0 ] < 0 ) {
151151 if (nocopy )
152- return GA_COPY_ERROR ;
152+ return error_set ( ctx -> err , GA_COPY_ERROR , "Copy required for X" ) ;
153153 else {
154154 err = GpuArray_copy (& copyX , X , GA_ANY_ORDER );
155155 if (err != GA_NO_ERROR )
@@ -158,7 +158,7 @@ int GpuArray_rgemv(cb_transpose transA, double alpha, GpuArray *A,
158158 }
159159 }
160160 if (Y -> strides [0 ] < 0 ) {
161- err = GA_VALUE_ERROR ;
161+ err = error_set ( ctx -> err , GA_VALUE_ERROR , "Negative strides for Y" ) ;
162162 goto cleanup ;
163163 }
164164
@@ -170,11 +170,10 @@ int GpuArray_rgemv(cb_transpose transA, double alpha, GpuArray *A,
170170 lda = Ap -> dimensions [1 ];
171171 } else {
172172 /* Might be worth looking at making degenerate matrices (1xn) work here. */
173- err = GA_VALUE_ERROR ;
173+ err = error_set ( ctx -> err , GA_VALUE_ERROR , "Noncontiguous A" ) ;
174174 goto cleanup ;
175175 }
176176
177- ctx = gpudata_context (Ap -> data );
178177 err = gpublas_setup (ctx );
179178 if (err != GA_NO_ERROR )
180179 goto cleanup ;
@@ -206,24 +205,24 @@ int GpuArray_rgemm(cb_transpose transA, cb_transpose transB, double alpha,
206205 GpuArray * Bp = B ;
207206 GpuArray copyB ;
208207 GpuArray * Cp = C ;
209- void * ctx ;
208+ void * ctx = gpudata_context ( Ap -> data ) ;
210209 size_t elsize ;
211210 size_t m , n , k , lda , ldb , ldc ;
212211 cb_order o ;
213212 int err ;
214213
215214 if (A -> typecode != GA_HALF && A -> typecode != GA_FLOAT &&
216215 A -> typecode != GA_DOUBLE )
217- return GA_INVALID_ERROR ;
216+ return error_set ( ctx -> err , GA_INVALID_ERROR , "Unsupported type" ) ;
218217
219218 if (A -> nd != 2 || B -> nd != 2 || C -> nd != 2 ||
220219 B -> typecode != A -> typecode ||
221220 C -> typecode != A -> typecode )
222- return GA_VALUE_ERROR ;
221+ return error_set ( ctx -> err , GA_VALUE_ERROR , "Inconsistent nd or types" ) ;
223222
224223 if (!(A -> flags & GA_ALIGNED ) || !(B -> flags & GA_ALIGNED ) ||
225224 !(C -> flags & GA_ALIGNED ))
226- return GA_UNALIGNED_ERROR ;
225+ return error_set ( ctx -> err , GA_UNALIGNED_ERROR , "Unaligned inputs" ) ;
227226
228227 if (transA == cb_no_trans ) {
229228 m = A -> dimensions [0 ];
@@ -236,21 +235,21 @@ int GpuArray_rgemm(cb_transpose transA, cb_transpose transB, double alpha,
236235 if (transB == cb_no_trans ) {
237236 n = B -> dimensions [1 ];
238237 if (B -> dimensions [0 ] != k )
239- return GA_VALUE_ERROR ;
238+ return error_set ( ctx -> err , GA_VALUE_ERROR , "mismatched shapes" ) ;
240239 } else {
241240 n = B -> dimensions [0 ];
242241 if (B -> dimensions [1 ] != k )
243- return GA_VALUE_ERROR ;
242+ return error_set ( ctx -> err , GA_VALUE_ERROR , "mismatched shapes" ) ;
244243 }
245244
246245 if (C -> dimensions [0 ] != m || C -> dimensions [1 ] != n )
247- return GA_VALUE_ERROR ;
246+ return error_set ( ctx -> err , GA_VALUE_ERROR , "mismatched shapes" ) ;
248247
249248 elsize = gpuarray_get_elsize (A -> typecode );
250249
251250 if (!GpuArray_ISONESEGMENT (A )) {
252251 if (nocopy )
253- return GA_COPY_ERROR ;
252+ return error_set ( ctx -> err , GA_COPY_ERROR , "Need copy for A" ) ;
254253 else {
255254 err = GpuArray_copy (& copyA , A , GA_F_ORDER );
256255 if (err != GA_NO_ERROR )
@@ -260,7 +259,7 @@ int GpuArray_rgemm(cb_transpose transA, cb_transpose transB, double alpha,
260259 }
261260 if (!GpuArray_ISONESEGMENT (B )) {
262261 if (nocopy )
263- return GA_COPY_ERROR ;
262+ return error_set ( ctx -> err , GA_COPY_ERROR , "Need copy for B" ) ;
264263 else {
265264 err = GpuArray_copy (& copyB , B , GA_F_ORDER );
266265 if (err != GA_NO_ERROR )
@@ -269,7 +268,7 @@ int GpuArray_rgemm(cb_transpose transA, cb_transpose transB, double alpha,
269268 }
270269 }
271270 if (!GpuArray_ISONESEGMENT (C )) {
272- err = GA_VALUE_ERROR ;
271+ err = error_set ( ctx -> err , GA_VALUE_ERROR , "Noncontiguous C" ) ;
273272 goto cleanup ;
274273 }
275274
@@ -280,7 +279,7 @@ int GpuArray_rgemm(cb_transpose transA, cb_transpose transB, double alpha,
280279 o = cb_c ;
281280 ldc = Cp -> dimensions [1 ];
282281 } else {
283- err = GA_VALUE_ERROR ;
282+ err = error_set ( ctx -> err , GA_VALUE_ERROR , "Noncontiguous C" ) ;
284283 goto cleanup ;
285284 }
286285 if (Ap -> flags & GA_F_CONTIGUOUS ) {
@@ -300,7 +299,7 @@ int GpuArray_rgemm(cb_transpose transA, cb_transpose transB, double alpha,
300299 transA = cb_no_trans ;
301300 }
302301 } else {
303- err = GA_VALUE_ERROR ;
302+ err = error_set ( ctx -> err , GA_VALUE_ERROR , "Noncontiguous A" ) ;
304303 goto cleanup ;
305304 }
306305 if (Bp -> flags & GA_F_CONTIGUOUS ) {
@@ -320,7 +319,7 @@ int GpuArray_rgemm(cb_transpose transA, cb_transpose transB, double alpha,
320319 transB = cb_no_trans ;
321320 }
322321 } else {
323- err = GA_VALUE_ERROR ;
322+ err = error_set ( ctx -> err , GA_VALUE_ERROR , "Noncontiguous B" ) ;
324323 goto cleanup ;
325324 }
326325
@@ -356,35 +355,35 @@ int GpuArray_rger(double alpha, GpuArray *X, GpuArray *Y, GpuArray *A,
356355 GpuArray * Yp = Y ;
357356 GpuArray copyY ;
358357 GpuArray * Ap = A ;
359- void * ctx ;
358+ void * ctx = gpudata_context ( Xp -> data ) ;
360359 size_t elsize ;
361360 size_t m , n , lda ;
362361 cb_order o ;
363362 int err ;
364363
365364 if (X -> typecode != GA_HALF && X -> typecode != GA_FLOAT &&
366365 X -> typecode != GA_DOUBLE )
367- return GA_INVALID_ERROR ;
366+ return error_set ( ctx -> err , GA_INVALID_ERROR , "Unsupported type" ) ;
368367
369368 if (X -> nd != 1 || Y -> nd != 1 || A -> nd != 2 ||
370369 Y -> typecode != X -> typecode ||
371370 A -> typecode != X -> typecode )
372- return GA_VALUE_ERROR ;
371+ return error_set ( ctx -> err , GA_VALUE_ERROR , "Invalid dims or inconsistent types" ) ;
373372
374373 if (!(X -> flags & GA_ALIGNED ) || !(Y -> flags & GA_ALIGNED ) ||
375374 !(A -> flags & GA_ALIGNED ))
376- return GA_UNALIGNED_ERROR ;
375+ return error_set ( ctx -> err , GA_UNALIGNED_ERROR , "Unaligned inputs" ;
377376
378377 m = X -> dimensions [0 ];
379378 n = Y -> dimensions [0 ];
380379 if (A -> dimensions [0 ] != m || A -> dimensions [1 ] != n )
381- return GA_VALUE_ERROR ;
380+ return error_set ( ctx -> err , GA_VALUE_ERROR , "Incompatible shapes" ;
382381
383382 elsize = gpuarray_get_elsize (X -> typecode );
384383
385384 if (X -> strides [0 ] < 0 ) {
386385 if (nocopy )
387- return GA_COPY_ERROR ;
386+ return error_set ( ctx -> err , GA_COPY_ERROR , "Need copy for X" ) ;
388387 else {
389388 err = GpuArray_copy (& copyX , X , GA_ANY_ORDER );
390389 if (err != GA_NO_ERROR )
@@ -394,7 +393,7 @@ int GpuArray_rger(double alpha, GpuArray *X, GpuArray *Y, GpuArray *A,
394393 }
395394 if (Y -> strides [0 ] < 0 ) {
396395 if (nocopy )
397- return GA_COPY_ERROR ;
396+ return error_set ( ctx -> err , GA_COPY_ERROR , "Need copy for Y" ) ;
398397 else {
399398 err = GpuArray_copy (& copyY , Y , GA_ANY_ORDER );
400399 if (err != GA_NO_ERROR )
@@ -403,7 +402,7 @@ int GpuArray_rger(double alpha, GpuArray *X, GpuArray *Y, GpuArray *A,
403402 }
404403 }
405404 if (!GpuArray_ISONESEGMENT (A )) {
406- err = GA_VALUE_ERROR ;
405+ err = error_set ( ctx -> err , GA_VALUE_ERROR , "Noncontiguous A" ) ;
407406 goto cleanup ;
408407 }
409408
@@ -415,7 +414,7 @@ int GpuArray_rger(double alpha, GpuArray *X, GpuArray *Y, GpuArray *A,
415414 lda = Ap -> dimensions [1 ];
416415 } else {
417416 /* Might be worth looking at making degenerate matrices (1xn) work here. */
418- err = GA_VALUE_ERROR ;
417+ err = error_set ( ctx -> err , GA_VALUE_ERROR , "Noncontiguous A" ) ;
419418 goto cleanup ;
420419 }
421420
@@ -469,7 +468,7 @@ int GpuArray_rgemmBatch_3d(cb_transpose transA, cb_transpose transB, double alph
469468 GpuArray * Bp = B ;
470469 GpuArray copyB ;
471470 GpuArray * Cp = C ;
472- void * ctx ;
471+ void * ctx = gpudata_context ( A -> data ) ;
473472 size_t elsize ;
474473 size_t batchCount , m , n , k , lda , ldb , ldc ;
475474 cb_order o ;
@@ -480,20 +479,20 @@ int GpuArray_rgemmBatch_3d(cb_transpose transA, cb_transpose transB, double alph
480479 size_t i ;
481480
482481 if (A -> typecode != GA_FLOAT && A -> typecode != GA_DOUBLE )
483- return GA_INVALID_ERROR ;
482+ return error_set ( ctx -> err , GA_INVALID_ERROR , "Unsupported type" ) ;
484483
485484 if (A -> nd != 3 || B -> nd != 3 || C -> nd != 3 ||
486485 B -> typecode != A -> typecode ||
487486 C -> typecode != A -> typecode )
488- return GA_VALUE_ERROR ;
487+ return error_set ( ctx -> err , GA_VALUE_ERROR , "Invalid dims or inconsistent types" ) ;
489488
490489 if (!(A -> flags & GA_ALIGNED ) || !(B -> flags & GA_ALIGNED ) ||
491490 !(C -> flags & GA_ALIGNED ))
492- return GA_UNALIGNED_ERROR ;
491+ return error_set ( ctx -> err , GA_UNALIGNED_ERROR , "Unaligned input" ) ;
493492
494493 batchCount = A -> dimensions [0 ];
495494 if (B -> dimensions [0 ] != batchCount || C -> dimensions [0 ] != batchCount )
496- return GA_VALUE_ERROR ;
495+ return error_set ( ctx -> err , GA_VALUE_ERROR , "Mismatched first dimension" ) ;
497496
498497 if (transA == cb_no_trans ) {
499498 m = A -> dimensions [1 ];
@@ -506,22 +505,22 @@ int GpuArray_rgemmBatch_3d(cb_transpose transA, cb_transpose transB, double alph
506505 if (transB == cb_no_trans ) {
507506 n = B -> dimensions [2 ];
508507 if (B -> dimensions [1 ] != k )
509- return GA_VALUE_ERROR ;
508+ return error_set ( ctx -> err , GA_VALUE_ERROR , "Mismatched shape" ) ;
510509 } else {
511510 n = B -> dimensions [1 ];
512511 if (B -> dimensions [2 ] != k )
513- return GA_VALUE_ERROR ;
512+ return error_set ( ctx -> err , GA_VALUE_ERROR , "Mismatched shape" ) ;
514513 }
515514
516515 if (C -> dimensions [1 ] != m || C -> dimensions [2 ] != n )
517- return GA_VALUE_ERROR ;
516+ return error_set ( ctx -> err , GA_VALUE_ERROR , "Mismatched shape" ) ;
518517
519518 elsize = gpuarray_get_elsize (A -> typecode );
520519
521520 cA = is_last_2d_contiguous (A );
522521 if (!cA ) {
523522 if (nocopy )
524- return GA_COPY_ERROR ;
523+ return error_set ( ctx -> err , GA_COPY_ERROR , "Need copy for A" ) ;
525524 else {
526525 err = GpuArray_copy (& copyA , A , GA_C_ORDER );
527526 cA = 1 ;
@@ -533,7 +532,7 @@ int GpuArray_rgemmBatch_3d(cb_transpose transA, cb_transpose transB, double alph
533532 cB = is_last_2d_contiguous (B );
534533 if (!cB ) {
535534 if (nocopy )
536- return GA_COPY_ERROR ;
535+ return error_set ( ctx -> err , GA_COPY_ERROR , "Need copy for B" ) ;
537536 else {
538537 err = GpuArray_copy (& copyB , B , GA_C_ORDER );
539538 cB = 1 ;
@@ -544,7 +543,7 @@ int GpuArray_rgemmBatch_3d(cb_transpose transA, cb_transpose transB, double alph
544543 }
545544 cC = is_last_2d_contiguous (C );
546545 if (!cC ) {
547- err = GA_VALUE_ERROR ;
546+ err = error_set ( ctx -> err , GA_VALUE_ERROR , "Noncontiguous last 2d C" ) ;
548547 goto cleanup ;
549548 }
550549
@@ -559,7 +558,7 @@ int GpuArray_rgemmBatch_3d(cb_transpose transA, cb_transpose transB, double alph
559558 ? Cp -> strides [1 ] / elsize
560559 : Cp -> dimensions [2 ];
561560 } else {
562- err = GA_VALUE_ERROR ;
561+ err = error_set ( ctx -> err , GA_VALUE_ERROR , "Invalid internal result for C" ) ;
563562 goto cleanup ;
564563 }
565564 if (cA == 2 ) {
@@ -583,7 +582,7 @@ int GpuArray_rgemmBatch_3d(cb_transpose transA, cb_transpose transB, double alph
583582 transA = cb_no_trans ;
584583 }
585584 } else {
586- err = GA_VALUE_ERROR ;
585+ err = error_set ( ctx -> err , GA_VALUE_ERROR , "Invalid internal result for A" ) ;
587586 goto cleanup ;
588587 }
589588 if (cB == 2 ) {
@@ -607,7 +606,7 @@ int GpuArray_rgemmBatch_3d(cb_transpose transA, cb_transpose transB, double alph
607606 transB = cb_no_trans ;
608607 }
609608 } else {
610- err = GA_VALUE_ERROR ;
609+ err = error_set ( ctx -> err , GA_VALUE_ERROR , "Invalid internal result for B" ) ;
611610 goto cleanup ;
612611 }
613612
0 commit comments