Permalink
Browse files

Added the ability to actually run a reduce kernel and get the output …

…back
  • Loading branch information...
1 parent 23b81cc commit 2d8020197252cf35b985b9df179bac1af97e6771 @rjw57-demo rjw57-demo committed Sep 28, 2009
@@ -69,9 +69,11 @@ _wrap_firtree_cpu_renderer_render_into_cairo_surface(PyGObject *self,
&PycairoSurface_Type, &cairo_surface))
return NULL;
+ Py_BEGIN_ALLOW_THREADS
ret = firtree_cpu_renderer_render_into_cairo_surface(
FIRTREE_CPU_RENDERER(self->obj),
(FirtreeVec4*)extents, cairo_surface->surface);
+ Py_END_ALLOW_THREADS
return PyBool_FromLong(ret);
}
@@ -109,13 +111,59 @@ _wrap_firtree_cpu_renderer_render_into_buffer(PyGObject *self, PyObject *args, P
return NULL;
}
+ Py_BEGIN_ALLOW_THREADS
ret = firtree_cpu_renderer_render_into_buffer(
FIRTREE_CPU_RENDERER(self->obj),
(FirtreeVec4*)extents,
buffer, width, height, stride, (FirtreeBufferFormat)format_val);
+ Py_END_ALLOW_THREADS
return PyBool_FromLong(ret);
}
%%
+override firtree_cpu_reduce_engine_run
+static PyObject *
+_wrap_firtree_cpu_reduce_engine_run(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "extents", "width", "height", NULL };
+
+ float extents[4];
+ unsigned long width, height;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "(ffff)kk:FirtreeCpuReduceEngine.run", kwlist,
+ &extents[0], &extents[1], &extents[2], &extents[3],
+ &width, &height))
+ return NULL;
+
+ FirtreeLockFreeSet* output = firtree_lock_free_set_new(sizeof(FirtreeVec4));
+
+ Py_BEGIN_ALLOW_THREADS
+ firtree_cpu_reduce_engine_run(
+ FIRTREE_CPU_REDUCE_ENGINE(self->obj),
+ output, (FirtreeVec4*)extents,
+ width, height);
+ Py_END_ALLOW_THREADS
+
+ gint element_count =
+ firtree_lock_free_set_get_element_count(output);
+ PyObject* output_tuple = PyTuple_New(element_count);
+
+ Py_ssize_t element_idx = 0;
+ FirtreeVec4* element = (FirtreeVec4*) firtree_lock_free_set_get_first_element(output);
+ while(element) {
+ g_assert(element_idx < element_count);
+ PyTuple_SET_ITEM(output_tuple, element_idx,
+ Py_BuildValue("(ffff)",
+ element->x, element->y, element->z, element->w));
+ ++element_idx;
+ element = (FirtreeVec4*) firtree_lock_free_set_get_next_element(output, element);
+ }
+ g_assert(element_idx == element_count);
+ firtree_lock_free_set_free(output);
+
+ return output_tuple;
+}
+%%
// vim:sw=4:ts=4:cindent:et:filetype=c
@@ -68,5 +68,28 @@ _wrap_firtree_debug_dump_cpu_renderer_function(PyObject *self, PyObject *args, P
return str;
}
%%
+override firtree_debug_dump_cpu_reduce_engine_function
+static PyObject *
+_wrap_firtree_debug_dump_cpu_reduce_engine_function(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "engine", NULL };
+ PyGObject *cpu_reduce_engine;
+ GString* ret;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!:debug_dump_cpu_reduce_engine_function", kwlist, &PyFirtreeCpuReduceEngine_Type, &cpu_reduce_engine))
+ return NULL;
+
+ ret = firtree_debug_dump_cpu_reduce_engine_function(FIRTREE_CPU_REDUCE_ENGINE(cpu_reduce_engine->obj));
+
+ if(!ret) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+ PyObject* str = PyString_FromString(ret->str);
+ g_string_free(ret, TRUE);
+ return str;
+}
+%%
// vim:sw=4:ts=4:cindent:et:filetype=c
@@ -5,6 +5,13 @@
; object definitions ...
+(define-object CpuReduceEngine
+ (in-module "Firtree")
+ (parent "GObject")
+ (c-name "FirtreeCpuReduceEngine")
+ (gtype-id "FIRTREE_TYPE_CPU_REDUCE_ENGINE")
+)
+
(define-object CpuRenderer
(in-module "Firtree")
(parent "GObject")
@@ -1,4 +1,53 @@
+;; From firtree-cpu-reduce-engine.h
+
+(define-function cpu_reduce_engine_get_type
+ (c-name "firtree_cpu_reduce_engine_get_type")
+ (return-type "GType")
+)
+
+(define-function cpu_reduce_engine_new
+ (c-name "firtree_cpu_reduce_engine_new")
+ (is-constructor-of "FirtreeCpuReduceEngine")
+ (return-type "FirtreeCpuReduceEngine*")
+)
+
+(define-method set_kernel
+ (of-object "FirtreeCpuReduceEngine")
+ (c-name "firtree_cpu_reduce_engine_set_kernel")
+ (return-type "none")
+ (parameters
+ '("FirtreeKernel*" "kernel")
+ )
+)
+
+(define-method get_kernel
+ (of-object "FirtreeCpuReduceEngine")
+ (c-name "firtree_cpu_reduce_engine_get_kernel")
+ (return-type "FirtreeKernel*")
+)
+
+(define-method run
+ (of-object "FirtreeCpuReduceEngine")
+ (c-name "firtree_cpu_reduce_engine_run")
+ (return-type "none")
+ (parameters
+ '("FirtreeVec4*" "extents")
+ '("guint" "width")
+ '("guint" "height")
+ )
+)
+
+(define-function debug_dump_cpu_reduce_engine_function
+ (c-name "firtree_debug_dump_cpu_reduce_engine_function")
+ (return-type "GString*")
+ (parameters
+ '("FirtreeCpuReduceEngine*" "engine")
+ )
+)
+
+
+
;; From firtree-cpu-renderer.h
(define-function cpu_renderer_get_type
@@ -10,6 +10,7 @@ headers
#include <firtree/firtree-pixbuf-sampler.h>
#include <firtree/engines/cpu/firtree-cpu-renderer.h>
+#include <firtree/engines/cpu/firtree-cpu-reduce-engine.h>
#if FIRTREE_HAVE_CAIRO
# include <pycairo/pycairo.h>
View
@@ -5,7 +5,6 @@
# See LICENSE file for distribution rights.
add_library(common
- lock-free.h lock-free.c
system-info.h system-info.c
threading.h threading.c
uuid.h uuid.cpp
View
@@ -1,112 +0,0 @@
-/* lock-free.h Lock-free data structures. */
-
-/* FIRTREE - A generic image processing library
- * Copyright (C) 2009 Rich Wareham <richwareham@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as published
- * by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-
-#ifndef FIRTREE_LOCK_FREE_H
-#define FIRTREE_LOCK_FREE_H
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-/**
- * LockFreeSet:
- *
- * A lock-free set is one which is safe for multiple threads to add elements to.
- * The ordering of elements is not guranteed. Adding an element is lock-free but
- * assumes that the contents of memory the element value is copied from does
- * not change over the lifetime of the lock_free_set_add_element() call.
- *
- * Once added, an element cannot be removed. The LockFreeSet structure is designed
- * to only ever be added to.
- *
- * Concurrent access is only supported by the lock_free_set_add_element() call.
- */
-typedef struct _LockFreeSet LockFreeSet;
-
-/**
- * lock_free_set_new:
- * @element_size: The size, in bytes, of a set element.
- *
- * Allocate a new LockFreeSet structure which will hold elements of @element_size.
- *
- * Returns: A newly allocated LockFreeSet structure.
- */
-LockFreeSet*
-lock_free_set_new(gsize element_size);
-
-/**
- * lock_free_set_free:
- * @set: A LockFreeSet structure.
- *
- * Frees the set @set releasing any memory resources associated with it.
- */
-void
-lock_free_set_free(LockFreeSet* set);
-
-/**
- * lock_free_set_add_element:
- * @set: A LockFreeSet structure.
- * @element: A pointer to the element to add.
- *
- * A new element is added to the set and it's data is copied from the @element
- * pointer. The number of bytes copied is specified in the lock_free_set_new() call.
- *
- * Note: This is the only method on LockFreeSet which is thread-safe. Other calls must
- * be surrounded by appropriate locking if concurrent access is expected.
- */
-void
-lock_free_set_add_element(LockFreeSet* set, gpointer element);
-
-/**
- * lock_free_set_get_first_element:
- * @set: A LockFreeSet structure.
- *
- * Retrieve the first element in the set or NULL if the set is empty.
- *
- * Together with lock_free_set_get_next_element(), this call may be used to iterate
- * over all items in the set.
- *
- * Returns: A pointer to a set element or NULL.
- */
-gpointer
-lock_free_set_get_first_element(LockFreeSet* set);
-
-/**
- * lock_free_set_get_next_element:
- * @set: A LockFreeSet structure.
- * @element: A set element.
- *
- * Retrieve the next element based upon @element which should have been returned from
- * lock_free_set_get_first_element() or lock_free_set_get_next_element(). Returns NULL
- * if there are no more elements.
- *
- * Together with lock_free_set_get_first_element(), this call may be used to iterate
- * over all items in the set.
- *
- * Returns: A pointer to a set element or NULL.
- */
-gpointer
-lock_free_set_get_next_element(LockFreeSet* set, gpointer element);
-
-G_END_DECLS
-
-#endif /* FIRTREE_LOCK_FREE_H */
-
-/* vim:cindent:sw=4:ts=4:et
- */
View
@@ -58,6 +58,7 @@ set(_firtree_public_headers
firtree-affine-transform.h
firtree-buffer-sampler.h
firtree-debug.h
+ firtree-lock-free-set.h
firtree-kernel.h
firtree-kernel-sampler.h
firtree-sampler.h
@@ -72,6 +73,7 @@ set(_firtree_source_files
firtree-buffer-sampler.cc
firtree-debug.cc
firtree-engine.cc
+ firtree-lock-free-set.c
firtree-kernel.cc
firtree-kernel-sampler.cc
firtree-sampler.cc
@@ -58,7 +58,8 @@ add_custom_command(
render-buffer.c)
set(_firtree_cpu_public_headers
- firtree-cpu-renderer.h)
+ firtree-cpu-renderer.h
+ firtree-cpu-reduce-engine.h)
add_custom_command(OUTPUT firtree-type-builtins.h ${CMAKE_CURRENT_BINARY_DIR}/firtree-type-builtins.c
COMMAND ${GLIB_MKENUMS}
@@ -84,12 +85,13 @@ add_library(firtree-engine-cpu SHARED
llvm-cpu-support.bc.h
firtree-cpu-renderer.cc
+ firtree-cpu-reduce-engine.cc
firtree-cpu-jit.cc firtree-cpu-jit.hh
+ firtree-cpu-common.cc firtree-cpu-common.hh
)
set_source_files_properties(
engines/cpu/llvm-cpu-support.bc.h
- engines/cpu/firtree-cpu-renderer.h
PROPERTIES GENERATED TRUE)
# set the library version.
@@ -0,0 +1,44 @@
+/* firtree-cpu-common.cc */
+
+/* Firtree - A generic image processing library
+ * Copyright (C) 2009 Rich Wareham <richwareham@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "firtree-cpu-common.hh"
+#include <firtree/firtree-lock-free-set.h>
+
+#include <cmath>
+
+void*
+firtree_cpu_common_lazy_function_creator(const std::string& name) {
+ if(name == "exp_f") {
+ return (void*)expf;
+ }
+ if(name == "atan_f") {
+ return (void*)atanf;
+ }
+ if(name == "atan_ff") {
+ return (void*)atan2f;
+ }
+ if(name == "firtree_lock_free_set_add_element") {
+ return (void*)firtree_lock_free_set_add_element;
+ }
+ g_debug("Do not know what function to use for '%s'.", name.c_str());
+ return NULL;
+}
+
+/* vim:sw=4:ts=4:et:cindent
+ */
Oops, something went wrong.

0 comments on commit 2d80201

Please sign in to comment.