Skip to content

Commit d2a0d8a

Browse files
authored
Merge pull request #389 from abergeron/error_ctx
Add better error reporting from the backends
2 parents 211a73c + 4a0381c commit d2a0d8a

43 files changed

Lines changed: 1668 additions & 1747 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ debug: install-debugc py
1111

1212
.PHONY: install-debugc py debug install-relc rel config
1313

14-
Debug/Makefile: Debug Makefile.conf
14+
Debug/Makefile: Makefile.conf
1515
mkdir -p Debug
1616
ifndef INSTALL_PREFIX
1717
(cd Debug && NUM_DEVS=${NUM_DEVS} DEV_NAMES=${DEV_NAMES} cmake .. -DCMAKE_BUILD_TYPE=Debug)

src/cache.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <gpuarray/config.h>
66
#include "private_config.h"
77
#include "util/strb.h"
8+
#include "util/error.h"
89

910
typedef void *cache_key_t;
1011
typedef void *cache_value_t;
@@ -77,16 +78,19 @@ struct _cache {
7778

7879
cache *cache_lru(size_t max_size, size_t elasticity,
7980
cache_eq_fn keq, cache_hash_fn khash,
80-
cache_freek_fn kfree, cache_freev_fn vfree);
81+
cache_freek_fn kfree, cache_freev_fn vfree,
82+
error *e);
8183

8284
cache *cache_twoq(size_t hot_size, size_t warm_size,
8385
size_t cold_size, size_t elasticity,
8486
cache_eq_fn keq, cache_hash_fn khash,
85-
cache_freek_fn kfree, cache_freev_fn vfree);
87+
cache_freek_fn kfree, cache_freev_fn vfree,
88+
error *e);
8689

8790
cache *cache_disk(const char *dirpath, cache *mem,
8891
kwrite_fn kwrite, vwrite_fn vwrite,
89-
kread_fn kread, vread_fn vread);
92+
kread_fn kread, vread_fn vread,
93+
error *e);
9094

9195
/* API functions */
9296
static inline int cache_add(cache *c, cache_key_t k, cache_value_t v) {

src/cache/disk.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static void disk_destroy(cache *_c) {
397397

398398
cache *cache_disk(const char *dirpath, cache *mem,
399399
kwrite_fn kwrite, vwrite_fn vwrite,
400-
kread_fn kread, vread_fn vread) {
400+
kread_fn kread, vread_fn vread, error *e) {
401401
struct stat st;
402402
disk_cache *res;
403403
char *dirp;
@@ -414,7 +414,10 @@ cache *cache_disk(const char *dirpath, cache *mem,
414414

415415
dirp = malloc(dirl + 1); /* With the NUL */
416416

417-
if (dirp == NULL) return NULL;
417+
if (dirp == NULL) {
418+
error_sys(e, "malloc");
419+
return NULL;
420+
}
418421

419422
strlcpy(dirp, dirpath, dirl + 1);
420423

@@ -425,6 +428,7 @@ cache *cache_disk(const char *dirpath, cache *mem,
425428

426429
if (ensurep(NULL, dirp) != 0) {
427430
free(dirp);
431+
error_sys(e, "ensurep");
428432
return NULL;
429433
}
430434

@@ -433,18 +437,24 @@ cache *cache_disk(const char *dirpath, cache *mem,
433437

434438
mkdir(dirp, 0777); /* This may fail, but it's ok */
435439

436-
if (lstat(dirp, &st) != 0)
440+
if (lstat(dirp, &st) != 0) {
441+
error_sys(e, "lstat");
437442
return NULL;
443+
}
438444

439445
/* Restore the good path at the end */
440446
dirp[dirl - 1] = sep;
441447

442-
if (!(st.st_mode & S_IFDIR))
448+
if (!(st.st_mode & S_IFDIR)) {
449+
error_set(e, GA_SYS_ERROR, "Cache path exists but is not a directory");
443450
return NULL;
451+
}
444452

445453
res = calloc(sizeof(*res), 1);
446-
if (res == NULL)
454+
if (res == NULL) {
455+
error_sys(e, "calloc");
447456
return NULL;
457+
}
448458

449459
res->dirp = dirp;
450460
res->mem = mem;

src/cache/lru.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,11 @@ static inline size_t roundup2(size_t s) {
127127
return s;
128128
}
129129

130-
static inline int hash_init(hash *h, size_t size) {
130+
static inline int hash_init(hash *h, size_t size, error *e) {
131131
h->nbuckets = roundup2(size + (size/6));
132132
h->keyval = calloc(h->nbuckets, sizeof(*h->keyval));
133133
if (h->keyval == NULL) {
134+
error_sys(e, "calloc");
134135
return -1;
135136
}
136137
h->size = 0;
@@ -276,11 +277,15 @@ static void lru_destroy(cache *_c) {
276277

277278
cache *cache_lru(size_t max_size, size_t elasticity,
278279
cache_eq_fn keq, cache_hash_fn khash,
279-
cache_freek_fn kfree, cache_freev_fn vfree) {
280+
cache_freek_fn kfree, cache_freev_fn vfree,
281+
error *e) {
280282
lru_cache *res = malloc(sizeof(*res));
281-
if (res == NULL) return NULL;
283+
if (res == NULL) {
284+
error_sys(e, "malloc");
285+
return NULL;
286+
}
282287

283-
if (hash_init(&res->data, max_size+elasticity)) {
288+
if (hash_init(&res->data, max_size+elasticity, e)) {
284289
free(res);
285290
return NULL;
286291
}

src/cache/twoq.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <assert.h>
22
#include <stdlib.h>
33

4+
#include <gpuarray/error.h>
5+
46
#include "cache.h"
57
#include "private_config.h"
68

@@ -135,10 +137,11 @@ static inline size_t roundup2(size_t s) {
135137
return s;
136138
}
137139

138-
static inline int hash_init(hash *h, size_t size) {
140+
static inline int hash_init(hash *h, size_t size, error *e) {
139141
h->nbuckets = roundup2(size + (size/6));
140142
h->keyval = calloc(h->nbuckets, sizeof(*h->keyval));
141143
if (h->keyval == NULL) {
144+
error_sys(e, "calloc");
142145
return -1;
143146
}
144147
h->size = 0;
@@ -322,16 +325,21 @@ static void twoq_destroy(cache *_c) {
322325
}
323326

324327
cache *cache_twoq(size_t hot_size, size_t warm_size, size_t cold_size,
325-
size_t elasticity, cache_eq_fn keq, cache_hash_fn khash,
326-
cache_freek_fn kfree, cache_freev_fn vfree) {
328+
size_t elasticity, cache_eq_fn keq, cache_hash_fn khash,
329+
cache_freek_fn kfree, cache_freev_fn vfree, error *e) {
327330
twoq_cache *res;
328-
if (hot_size == 0 || warm_size == 0 || cold_size == 0)
331+
if (hot_size == 0 || warm_size == 0 || cold_size == 0) {
332+
error_set(e, GA_VALUE_ERROR, "cache_twoq: section size is 0");
329333
return NULL;
334+
}
330335

331336
res = malloc(sizeof(*res));
332-
if (res == NULL) return NULL;
337+
if (res == NULL) {
338+
error_sys(e, "malloc");
339+
return NULL;
340+
}
333341

334-
if (hash_init(&res->data, hot_size+warm_size+cold_size+elasticity)) {
342+
if (hash_init(&res->data, hot_size+warm_size+cold_size+elasticity, e)) {
335343
free(res);
336344
return NULL;
337345
}

src/gpuarray/buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ GPUARRAY_PUBLIC int gpukernel_call(gpukernel *k, unsigned int n,
500500
*
501501
* This can be use to cache kernel binaries after compilation of a
502502
* specific device. The kernel can be recreated by calling
503-
* kernel_alloc with the binary and size and passing `GA_USE_BINARY`
503+
* gpukernel_alloc with the binary and size and passing `GA_USE_BINARY`
504504
* as the use flags.
505505
*
506506
* The returned pointer is allocated and must be freed by the caller.

src/gpuarray_array.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ static int ga_extcopy(GpuArray *dst, const GpuArray *src) {
7171
if (ctx->extcopy_cache == NULL)
7272
ctx->extcopy_cache = cache_twoq(4, 8, 8, 2, extcopy_eq, extcopy_hash,
7373
extcopy_free,
74-
(cache_freev_fn)GpuElemwise_free);
74+
(cache_freev_fn)GpuElemwise_free,
75+
ctx->err);
7576
if (ctx->extcopy_cache == NULL)
7677
return GA_MISC_ERROR;
7778
if (cache_add(ctx->extcopy_cache, aa, k) != 0)

0 commit comments

Comments
 (0)