d2/image_accel, gpu: Disable error-producing code in these obsolete modules.
[Ale.git] / accel.h
blobc514c9782964d8d90197cd9abd756f5e6b0d762c
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
25 #ifndef __accel_h__
26 #define __accel_h__
28 extern "C" {
29 #include <ale.h>
32 #include <assert.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <stdlib.h>
37 class accel {
38 static int accel_type;
39 static ale_context _accel_context;
41 public:
43 static void set_accel() {
44 accel_type = 0;
47 static void set_gpu() {
48 accel_type = 1;
51 static void set_cpu() {
52 accel_type = 2;
55 static void set_auto() {
57 * Set preference ACCELERATOR > GPU > DEFAULT > CPU
60 cl_context cc;
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");
75 exit(1);
78 _accel_context = ale_new_context(cc);
79 clReleaseContext(cc);
81 if (!_accel_context) {
82 fprintf(stderr, "Could not create an ALE context.\n");
83 exit(1);
87 static ale_context context() {
88 if (_accel_context)
89 return _accel_context;
91 if (accel_type == -1) {
92 set_auto();
93 return _accel_context;
96 cl_context cc;
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);
102 } else {
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");
108 exit(1);
111 _accel_context = ale_new_context(cc);
112 clReleaseContext(cc);
114 if (!_accel_context) {
115 fprintf(stderr, "Could not create an ALE context.\n");
116 exit(1);
119 return _accel_context;
123 #endif