Skip to content

Commit 1137c81

Browse files
authored
Merge pull request #449 from abergeron/more_error
Add all the missing error messages and stop filtering in pygpu.
2 parents c5013b6 + e2f1f07 commit 1137c81

11 files changed

Lines changed: 173 additions & 145 deletions

pygpu/gpuarray.pyx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ cdef int array_take1(GpuArray r, GpuArray a, GpuArray i,
336336
err = GpuArray_take1(&r.ga, &a.ga, &i.ga, check_err)
337337
if err != GA_NO_ERROR:
338338
if err == GA_VALUE_ERROR:
339-
raise IndexError, "Index out of bounds"
339+
raise IndexError, GpuArray_error(&r.ga, err)
340340
raise get_exc(err), GpuArray_error(&r.ga, err)
341341

342342
cdef int array_setarray(GpuArray v, GpuArray a) except -1:
@@ -1054,10 +1054,7 @@ cdef class GpuContext:
10541054
self.kind = kind
10551055
self.ctx = gpucontext_init(<char *>self.kind, devno, flags, &err)
10561056
if (err != GA_NO_ERROR):
1057-
if err == GA_VALUE_ERROR:
1058-
raise get_exc(err), "No device %d"%(devno,)
1059-
else:
1060-
raise get_exc(err), gpucontext_error(NULL, err).decode('utf-8') + ": " + str(devno)
1057+
raise get_exc(err), gpucontext_error(NULL, err)
10611058

10621059
def __enter__(self):
10631060
if cuda_enter == NULL:
@@ -1415,10 +1412,7 @@ cdef GpuArray pygpu_index(GpuArray a, const ssize_t *starts,
14151412
const ssize_t *stops, const ssize_t *steps):
14161413
cdef GpuArray res
14171414
res = new_GpuArray(type(a), a.context, a.base)
1418-
try:
1419-
array_index(res, a, starts, stops, steps)
1420-
except ValueError, e:
1421-
raise IndexError, "index out of bounds"
1415+
array_index(res, a, starts, stops, steps)
14221416
return res
14231417

14241418
cdef GpuArray pygpu_reshape(GpuArray a, unsigned int nd, const size_t *newdims,
@@ -1430,7 +1424,7 @@ cdef GpuArray pygpu_reshape(GpuArray a, unsigned int nd, const size_t *newdims,
14301424
return res
14311425
cdef unsigned int caxis = <unsigned int>compute_axis
14321426
if caxis >= nd:
1433-
raise ValueError("You wanted us to compute the shape of a dimensions that don't exist")
1427+
raise ValueError("compute_axis is out of bounds")
14341428

14351429
cdef size_t *cdims
14361430
cdef size_t tot = 1
@@ -1554,7 +1548,7 @@ def open_ipc_handle(GpuContext c, bytes hpy, size_t l):
15541548

15551549
d = cuda_open_ipc_handle(c.ctx, &h, l)
15561550
if d is NULL:
1557-
raise GpuArrayException, "could not open handle"
1551+
raise GpuArrayException, gpucontext_error(c.ctx, 0)
15581552
return <size_t>d
15591553

15601554
cdef class GpuArray:

src/gpuarray_array.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)