@@ -63,12 +63,11 @@ static int ga_extcopy(GpuArray *dst, const GpuArray *src) {
6363 gargs [1 ].flags = GE_WRITE ;
6464 k = GpuElemwise_new (ctx , "" , "dst = src" , 2 , gargs , 0 , 0 );
6565 if (k == NULL )
66- return error_set (ctx -> err , GA_MISC_ERROR ,
67- "Could not instantiate GpuElemwise copy kernel" );
66+ return ctx -> err -> code ;
6867 aa = memdup (& a , sizeof (a ));
6968 if (aa == NULL ) {
7069 GpuElemwise_free (k );
71- return error_set (ctx -> err , GA_MEMORY_ERROR , "Out of memory " );
70+ return error_sys (ctx -> err , "memdup " );
7271 }
7372 if (ctx -> extcopy_cache == NULL )
7473 ctx -> extcopy_cache = cache_twoq (4 , 8 , 8 , 2 , extcopy_eq , extcopy_hash ,
@@ -120,7 +119,7 @@ int GpuArray_empty(GpuArray *a, gpucontext *ctx, int typecode,
120119 }
121120
122121 a -> data = gpudata_alloc (ctx , size , NULL , 0 , & res );
123- if (a -> data == NULL ) return res ;
122+ if (a -> data == NULL ) return ctx -> err -> code ;
124123 a -> nd = nd ;
125124 a -> offset = 0 ;
126125 a -> typecode = typecode ;
@@ -130,7 +129,7 @@ int GpuArray_empty(GpuArray *a, gpucontext *ctx, int typecode,
130129 a -> flags = GA_BEHAVED ;
131130 if (a -> dimensions == NULL || a -> strides == NULL ) {
132131 GpuArray_clear (a );
133- return error_set (ctx -> err , GA_MEMORY_ERROR , "Out of memory " );
132+ return error_sys (ctx -> err , "calloc " );
134133 }
135134 /* Mult will not overflow since calloc succeded */
136135 memcpy (a -> dimensions , dims , sizeof (size_t )* nd );
@@ -279,7 +278,7 @@ int GpuArray_index_inplace(GpuArray *a, const ssize_t *starts,
279278 if (newdims == NULL || newstrs == NULL ) {
280279 free (newdims );
281280 free (newstrs );
282- return error_set (ctx -> err , GA_MEMORY_ERROR , "Out of memory " );
281+ return error_sys (ctx -> err , "calloc " );
283282 }
284283
285284 new_i = 0 ;
@@ -456,7 +455,7 @@ int GpuArray_take1(GpuArray *a, const GpuArray *v, const GpuArray *i,
456455 int addr32 = 0 ;
457456
458457 if (!GpuArray_ISWRITEABLE (a ))
459- 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" );
460459
461460 if (!GpuArray_ISALIGNED (a ) || !GpuArray_ISALIGNED (v ) ||
462461 !GpuArray_ISALIGNED (i ))
@@ -579,9 +578,9 @@ int GpuArray_setarray(GpuArray *a, const GpuArray *v) {
579578 "a->nd = %llu, v->nd = %llu" , a -> nd , v -> nd );
580579
581580 if (!GpuArray_ISWRITEABLE (a ))
582- return GA_VALUE_ERROR ;
581+ return error_set ( ctx -> err , GA_VALUE_ERROR , "Destination array not writable" ) ;
583582 if (!GpuArray_ISALIGNED (v ) || !GpuArray_ISALIGNED (a ))
584- return GA_UNALIGNED_ERROR ;
583+ return error_set ( ctx -> err , GA_UNALIGNED_ERROR , "One of the inputs is unaligned" ) ;
585584
586585 off = a -> nd - v -> nd ;
587586
@@ -674,7 +673,7 @@ int GpuArray_reshape_inplace(GpuArray *a, unsigned int nd,
674673 newsize *= d ;
675674 }
676675
677- if (newsize != oldsize ) return GA_INVALID_ERROR ;
676+ if (newsize != oldsize ) return error_set ( ctx -> err , GA_INVALID_ERROR , "New shape differs in total size" ) ;
678677
679678 /* If the source and desired layouts are the same, then just copy
680679 strides and dimensions */
@@ -685,7 +684,7 @@ int GpuArray_reshape_inplace(GpuArray *a, unsigned int nd,
685684
686685 newstrides = calloc (nd , sizeof (ssize_t ));
687686 if (newstrides == NULL )
688- return error_set (ctx -> err , GA_MEMORY_ERROR , "Out of memory " );
687+ return error_sys (ctx -> err , "calloc " );
689688
690689 while (ni < nd && oi < a -> nd ) {
691690 np = newdims [ni ];
@@ -739,7 +738,7 @@ int GpuArray_reshape_inplace(GpuArray *a, unsigned int nd,
739738 Can't do the same with newdims (which is a parameter). */
740739 tmpdims = calloc (nd , sizeof (size_t ));
741740 if (tmpdims == NULL ) {
742- return error_set (ctx -> err , GA_MEMORY_ERROR , "Out of memory " );
741+ return error_sys (ctx -> err , "calloc " );
743742 }
744743 memcpy (tmpdims , newdims , nd * sizeof (size_t ));
745744 a -> nd = nd ;
@@ -759,7 +758,7 @@ int GpuArray_reshape_inplace(GpuArray *a, unsigned int nd,
759758 if (tmpdims == NULL || newstrides == NULL ) {
760759 free (tmpdims );
761760 free (newstrides );
762- return error_set (ctx -> err , GA_MEMORY_ERROR , "Out of memory " );
761+ return error_sys (ctx -> err , "calloc " );
763762 }
764763 memcpy (tmpdims , newdims , nd * sizeof (size_t ));
765764 if (nd > 0 ) {
@@ -959,7 +958,7 @@ int GpuArray_split(GpuArray **rs, const GpuArray *a, size_t n, size_t *p,
959958 free (starts );
960959 free (stops );
961960 free (steps );
962- return error_set (ctx -> err , GA_MEMORY_ERROR , "Out of memory " );
961+ return error_sys (ctx -> err , "calloc " );
963962 }
964963
965964 for (i = 0 ; i < a -> nd ; i ++ ) {
@@ -1160,7 +1159,7 @@ int GpuArray_fdump(FILE *fd, const GpuArray *a) {
11601159 default :
11611160 free (buf );
11621161 fprintf (fd , "<unsupported data type %d>\n" , a -> typecode );
1163- return GA_UNSUPPORTED_ERROR ;
1162+ return error_fmt ( ctx -> err , GA_UNSUPPORTED_ERROR , "Unsupported data type for dump: %d" , a -> typecode ) ;
11641163 }
11651164 s -= gpuarray_get_elsize (a -> typecode );
11661165 p += gpuarray_get_elsize (a -> typecode );
0 commit comments