Repository navigation
Expand file tree
/
Copy pathdevice.c
More file actions
69 lines (62 loc) · 1.43 KB
/
Copy pathdevice.c
File metadata and controls
69 lines (62 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <check.h>
#include "gpuarray/buffer.h"
char* dev_name = NULL;
int get_env_dev(const char **name) {
char *dev = NULL;
char *end;
long no;
int d;
dev = dev_name;
if (dev == NULL) {
if ((dev = getenv("GPUARRAY_TEST_DEVICE")) == NULL) {
if ((dev = getenv("DEVICE")) == NULL) {
fprintf(stderr, "No device specified for testing, specify a device with DEVICE or GPUARRAY_TEST_DEVICE");
return -1;
}
}
}
if (strncmp(dev, "cuda", 4) == 0) {
*name = "cuda";
no = strtol(dev + 4, &end, 10);
if (end == dev || *end != '\0')
return -1;
if (no < 0 || no > INT_MAX)
return -1;
return (int)no;
}
if (strncmp(dev, "opencl", 6) == 0) {
*name = "opencl";
no = strtol(dev + 6, &end, 10);
if (end == dev || *end != ':')
return -1;
if (no < 0 || no > 32768)
return -1;
d = (int)no;
dev = end;
no = strtol(dev + 1, &end, 10);
if (end == dev || *end != '\0')
return -1;
if (no < 0 || no > 32768)
return -1;
d <<= 16;
d |= (int)no;
return d;
}
return -1;
}
gpucontext *ctx;
void setup(void) {
const char *name = NULL;
int dev = get_env_dev(&name);
if (dev == -1)
ck_abort_msg("Bad test device");
ctx = gpucontext_init(name, dev, 0, NULL);
ck_assert_ptr_ne(ctx, NULL);
}
void teardown(void) {
gpucontext_deref(ctx);
ctx = NULL;
}