[gegl] opencl: Use GEGL_USE_OPENCL to change the default device



commit eee062781264deeb5f72410a2ace110b42751897
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Tue Nov 12 14:41:07 2013 -0800

    opencl: Use GEGL_USE_OPENCL to change the default device
    
    Setting GEGL_USE_OPENCL to CPU, GPU, or ACCELERATOR will change
    the default OpenCL device. This can also be set by the application
    by calling gegl_cl_set_default_device_type().

 gegl/gegl-init.c           |    7 +++++++
 gegl/opencl/gegl-cl-init.c |   13 +++++++++++--
 gegl/opencl/gegl-cl-init.h |    2 ++
 3 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/gegl/gegl-init.c b/gegl/gegl-init.c
index cff6edd..2fd5275 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -14,6 +14,7 @@
  * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
  *
  * Copyright 2003-2007 Calvin Williamson, Øyvind Kolås
+ *           2013      Daniel Sabo
  */
 
 #include "config.h"
@@ -370,6 +371,12 @@ static void gegl_config_parse_env (GeglConfig *config)
         ;
       else if (g_ascii_strcasecmp (opencl_env, "no") == 0)
         gegl_cl_hard_disable ();
+      else if (g_ascii_strcasecmp (opencl_env, "cpu") == 0)
+        gegl_cl_set_default_device_type (CL_DEVICE_TYPE_CPU);
+      else if (g_ascii_strcasecmp (opencl_env, "gpu") == 0)
+        gegl_cl_set_default_device_type (CL_DEVICE_TYPE_GPU);
+      else if (g_ascii_strcasecmp (opencl_env, "accelerator") == 0)
+        gegl_cl_set_default_device_type (CL_DEVICE_TYPE_ACCELERATOR);
       else
         g_warning ("Unknown value for GEGL_USE_OPENCL: %s", opencl_env);
     }
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index ea7b06a..d594c79 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -151,6 +151,7 @@ typedef struct
 }
 GeglClState;
 
+static cl_device_type gegl_cl_default_device_type = CL_DEVICE_TYPE_DEFAULT;
 static GeglClState cl_state = { 0, };
 static GHashTable *cl_program_hash = NULL;
 
@@ -229,6 +230,14 @@ gegl_cl_set_profiling (gboolean enable)
   cl_state.enable_profiling = enable;
 }
 
+void
+gegl_cl_set_default_device_type (cl_device_type default_device_type)
+{
+  g_return_if_fail (!cl_state.is_loaded);
+
+  gegl_cl_default_device_type = default_device_type;
+}
+
 static gboolean
 gegl_cl_device_has_extension (cl_device_id device, const char *extension_name)
 {
@@ -425,13 +434,13 @@ gegl_cl_init_common (cl_device_type          requested_device_type,
 gboolean
 gegl_cl_init_with_opengl  (GError **error)
 {
-  return gegl_cl_init_common (CL_DEVICE_TYPE_DEFAULT, TRUE, error);
+  return gegl_cl_init_common (gegl_cl_default_device_type, TRUE, error);
 }
 
 gboolean
 gegl_cl_init (GError **error)
 {
-  return gegl_cl_init_common (CL_DEVICE_TYPE_DEFAULT, FALSE, error);
+  return gegl_cl_init_common (gegl_cl_default_device_type, FALSE, error);
 }
 
 static gboolean
diff --git a/gegl/opencl/gegl-cl-init.h b/gegl/opencl/gegl-cl-init.h
index c10ef11..cfd2da1 100644
--- a/gegl/opencl/gegl-cl-init.h
+++ b/gegl/opencl/gegl-cl-init.h
@@ -51,6 +51,8 @@ size_t            gegl_cl_get_iter_height (void);
 
 void              gegl_cl_set_profiling (gboolean enable);
 
+void              gegl_cl_set_default_device_type (cl_device_type default_device_type);
+
 gboolean          gegl_cl_has_extension (const char *extension_name);
 
 typedef struct


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]