@@ -150,7 +150,7 @@ static int gen_elemwise_basic_kernel(GpuKernel *k, gpucontext *ctx,
150150
151151 ktypes = calloc (p , sizeof (int ));
152152 if (ktypes == NULL )
153- return GA_MEMORY_ERROR ;
153+ return error_sys ( ctx -> err , "calloc" ) ;
154154
155155 p = 0 ;
156156
@@ -282,23 +282,22 @@ static int check_basic(GpuElemwise *ge, void **args, int flags,
282282 if (num_arrays == 0 )
283283 nd = ((GpuArray * )args [i ])-> nd ;
284284 else if (((GpuArray * )args [i ])-> nd != nd )
285- return GA_VALUE_ERROR ;
285+ return error_fmt ( ctx -> err , GA_VALUE_ERROR , "Arg %u has differing nd = %u" , i , (( GpuArray * ) args [ i ]) -> nd ) ;
286286 ++ num_arrays ;
287287 if (a == NULL && is_output (ge -> args [i ]))
288288 a = (GpuArray * )args [i ];
289289 }
290290 }
291291
292- /* No output arrays, this is an error */
293292 if (a == NULL )
294- return GA_VALUE_ERROR ;
293+ return error_set ( ctx -> err , GA_VALUE_ERROR , "No output arrays" ) ;
295294
296295 /* Check if we need to grow the internal buffers */
297296 if (nd > ge -> nd ) {
298297 nnd = ge -> nd * 2 ;
299298 while (nd > nnd ) nnd *= 2 ;
300299 if (ge_grow (ge , nnd ))
301- return GA_MEMORY_ERROR ;
300+ return error_sys ( ctx -> err , "ge_grow" ) ;
302301 }
303302
304303 /* Now we know that all array arguments have the same number of
@@ -330,7 +329,7 @@ static int check_basic(GpuElemwise *ge, void **args, int flags,
330329 /* We can't broadcast outputs */
331330 if (ISCLR (flags , GE_BROADCAST ) || is_output (ge -> args [i ]) ||
332331 v -> dimensions [j ] != 1 ) {
333- return GA_VALUE_ERROR ;
332+ return error_fmt ( ctx -> err , GA_VALUE_ERROR , "Mismatched dimension %u for input %u" , j , i ) ;
334333 }
335334 }
336335 /* If the dimension is 1 set the strides to 0 regardless since
@@ -370,7 +369,7 @@ static int call_basic(GpuElemwise *ge, void **args, size_t n, unsigned int nd,
370369 unsigned int p = 0 , i , j , l ;
371370 int err ;
372371
373- if (nd == 0 ) return GA_VALUE_ERROR ;
372+ if (nd == 0 ) return error_set ( GpuKernel_context ( & ge -> k_contig ) -> err , GA_VALUE_ERROR , "nd == 0" ) ;
374373
375374 if (call32 )
376375 k = & ge -> k_basic_32 [nd - 1 ];
@@ -434,7 +433,7 @@ static int gen_elemwise_contig_kernel(GpuKernel *k,
434433 unsigned int p ;
435434 unsigned int j ;
436435 int flags = GA_USE_CLUDA ;
437- int res = GA_MEMORY_ERROR ;
436+ int res ;
438437
439438 flags |= gpuarray_type_flagsa (n , args );
440439
@@ -443,8 +442,10 @@ static int gen_elemwise_contig_kernel(GpuKernel *k,
443442 p += ISSET (args [j ].flags , GE_SCALAR ) ? 1 : 2 ;
444443
445444 ktypes = calloc (p , sizeof (int ));
446- if (ktypes == NULL )
445+ if (ktypes == NULL ) {
446+ res = error_fmt (ctx -> err , "calloc" );
447447 goto bail ;
448+ }
448449
449450 p = 0 ;
450451
@@ -509,8 +510,10 @@ static int gen_elemwise_contig_kernel(GpuKernel *k,
509510 }
510511 strb_appends (& sb , "}\n}\n" );
511512
512- if (strb_error (& sb ))
513+ if (strb_error (& sb )) {
514+ error_set (ctx -> err , GA_MISC_ERROR , "Formatting error creating kernel source" );
513515 goto bail ;
516+ }
514517
515518 res = GpuKernel_init (k , ctx , 1 , (const char * * )& sb .s , & sb .l , "elem" ,
516519 p , ktypes , flags , err_str );
@@ -523,6 +526,7 @@ static int gen_elemwise_contig_kernel(GpuKernel *k,
523526static int check_contig (GpuElemwise * ge , void * * args ,
524527 size_t * _n , int * contig ) {
525528 GpuArray * a = NULL , * v ;
529+ gpucontext * ctx = GpuKernel_context (& ge -> k_contig );
526530 size_t n = 1 ;
527531 unsigned int i , j ;
528532 int c_contig = 1 , f_contig = 1 ;
@@ -538,10 +542,10 @@ static int check_contig(GpuElemwise *ge, void **args,
538542 f_contig &= GpuArray_IS_F_CONTIGUOUS (v );
539543 if (a != v ) {
540544 if (a -> nd != v -> nd )
541- return GA_INVALID_ERROR ;
545+ return error_set ( ctx -> err , GA_INVALID_ERROR , "Mismatched nd" ) ;
542546 for (j = 0 ; j < a -> nd ; j ++ ) {
543547 if (v -> dimensions [j ] != a -> dimensions [j ])
544- return GA_VALUE_ERROR ;
548+ return error_fmt ( ctx -> err , GA_VALUE_ERROR , "Mismatched dimension %u" , j ) ;
545549 }
546550 }
547551 }
0 commit comments