bugs: Don't require client knowledge of flattened representations.
[libale.git] / src / context.c
blobe07f435a6bce6ac4849c0baf586ec82c69cc91c7
1 /*
2 * Copyright 2008, 2009 David Hilvert <dhilvert@gmail.com>
4 * This file is part of libale.
6 * libale is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU Affero General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
9 * any later version.
11 * libale is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
14 * more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with libale. If not, see <http://www.gnu.org/licenses/>.
20 #include "libale.h"
22 #include <string.h>
25 * API types.
28 TYPE_HOST(ale_context, \
29 cl_context cc; \
30 int compute_resident_size; \
31 int host_resident_size; \
32 int file_resident_size;, \
33 clReleaseContext(P(this)->cc);)
36 * API Implementation.
39 ale_context ale_new_context(cl_context cc) {
41 if (cc == ((cl_context) 0) || clRetainContext(cc) != CL_SUCCESS)
42 return N(ale_context);
44 ale_context ac = ale_context_alloc();
46 if (!ale_context_valid(ac)) {
47 clReleaseContext(cc);
48 return N(ale_context);
51 P(ac)->cc = cc;
52 P(ac)->compute_resident_size = 0;
53 P(ac)->host_resident_size = 0;
54 P(ac)->file_resident_size = 0;
56 return ac;
59 cl_context ale_context_retain_cl(ale_context ac) {
60 if (!ale_context_valid(ac))
61 return ((cl_context) 0);
63 clRetainContext(P(ac)->cc);
64 return P(ac)->cc;
67 int ale_context_set_property(ale_context ac, const char *name, const char *value) {
68 if (!strcmp(name, "compute_resident_size")) {
69 P(ac)->compute_resident_size = atoi(value);
70 } else if (!strcmp(name, "host_resident_size")) {
71 P(ac)->host_resident_size = atoi(value);
72 } else if (!strcmp(name, "file_resident_size")) {
73 P(ac)->file_resident_size = atoi(value);
74 } else {
75 return ALE_UNSPECIFIED_FAILURE;
78 return ALE_SUCCESS;