1 // Copyright 2008 David Hilvert <dhilvert@auricle.dyndns.org>,
2 // <dhilvert@gmail.com>
4 /* This file is part of the Anti-Lamenessing Engine.
6 The Anti-Lamenessing Engine is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 The Anti-Lamenessing Engine is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with the Anti-Lamenessing Engine; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * accel.h: acceleration
38 static int accel_type
;
39 static ale_context _accel_context
;
43 static void set_accel() {
47 static void set_gpu() {
51 static void set_cpu() {
55 static void set_auto() {
57 * Set preference ACCELERATOR > GPU > DEFAULT > CPU
62 cc
= clCreateContextFromType(0, CL_DEVICE_TYPE_ACCELERATOR
, NULL
, NULL
, NULL
);
64 if (cc
== ((cl_context
) 0))
65 cc
= clCreateContextFromType(0, CL_DEVICE_TYPE_GPU
, NULL
, NULL
, NULL
);
67 if (cc
== ((cl_context
) 0))
68 cc
= clCreateContextFromType(0, CL_DEVICE_TYPE_DEFAULT
, NULL
, NULL
, NULL
);
70 if (cc
== ((cl_context
) 0))
71 cc
= clCreateContextFromType(0, CL_DEVICE_TYPE_CPU
, NULL
, NULL
, NULL
);
73 if (cc
== ((cl_context
) 0)) {
74 fprintf(stderr
, "Could not create an OpenCL context.\n");
78 _accel_context
= ale_new_context(cc
);
81 if (!_accel_context
) {
82 fprintf(stderr
, "Could not create an ALE context.\n");
87 static ale_context
context() {
89 return _accel_context
;
91 if (accel_type
== -1) {
93 return _accel_context
;
98 if (accel_type
== 0) {
99 cc
= clCreateContextFromType(0, CL_DEVICE_TYPE_ACCELERATOR
, NULL
, NULL
, NULL
);
100 } else if (accel_type
== 1) {
101 cc
= clCreateContextFromType(0, CL_DEVICE_TYPE_GPU
, NULL
, NULL
, NULL
);
103 cc
= clCreateContextFromType(0, CL_DEVICE_TYPE_CPU
, NULL
, NULL
, NULL
);
106 if (cc
== ((cl_context
) 0)) {
107 fprintf(stderr
, "Could not create an OpenCL context.\n");
111 _accel_context
= ale_new_context(cc
);
112 clReleaseContext(cc
);
114 if (!_accel_context
) {
115 fprintf(stderr
, "Could not create an ALE context.\n");
119 return _accel_context
;