[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32151] branches/particles-2010/source/ blender/nodes/intern/simulation: - added kernel execution tasks, sim_enqueue_kernel adds a task, which in turn executes the kernel function for a work group when called by a worker thread .

Lukas Toenne lukas.toenne at googlemail.com
Mon Sep 27 13:48:17 CEST 2010


Revision: 32151
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32151
Author:   lukastoenne
Date:     2010-09-27 13:48:16 +0200 (Mon, 27 Sep 2010)

Log Message:
-----------
- added kernel execution tasks, sim_enqueue_kernel adds a task, which in turn executes the kernel function for a work group when called by a worker thread.
- actually execute tasks in the worker threads.

Modified Paths:
--------------
    branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.c
    branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.h
    branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c
    branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_math.c

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.c	2010-09-27 10:53:41 UTC (rev 32150)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.c	2010-09-27 11:48:16 UTC (rev 32151)
@@ -549,10 +549,8 @@
 static void exec_copy_task(void *data, int start, int total)
 {
 	BufferTaskData *td= (BufferTaskData*)data;
-	/* not really necessary, since all items are copied at once */
-	int num_copy= MIN2(td->num, start+total) - start;
-	if (num_copy > 0)
-		memcpy((char*)td->dst + (td->dst_start+start)*td->stride, (char*)td->src + (td->src_start+start)*td->stride, num_copy*td->stride);
+	if (total > 0)
+		memcpy((char*)td->dst + (td->dst_start+start)*td->stride, (char*)td->src + (td->src_start+start)*td->stride, total*td->stride);
 }
 
 /* note: work group size is the same as number of items, since copying is best done in one go.
@@ -879,6 +877,14 @@
 	}
 }
 
+static void exec_kernel_task(void *data, int start, int total)
+{
+	SimKernel *kernel= (SimKernel*)data;
+	int i;
+	for (i=0; i < total; ++i)
+		kernel->impl(i+start, i, kernel->args);
+}
+
 void sim_enqueue_kernel(struct SimExecData *execdata, SimKernel *kernel, size_t total, int num_wait_events, SimEvent *wait_events, SimEvent *event)
 {
 	if (execdata->error)
@@ -907,7 +913,7 @@
 	else
 #endif
 	{
-		/* TODO */
+		sim_enqueue_task(execdata, exec_kernel_task, kernel, (int)total, 0, num_wait_events, wait_events, event);
 	}
 }
 

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.h
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.h	2010-09-27 10:53:41 UTC (rev 32150)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.h	2010-09-27 11:48:16 UTC (rev 32151)
@@ -158,7 +158,7 @@
 	struct SimTaskEvent *impl;
 } SimEvent;
 
-typedef void (*KernelFunction)(void **args);
+typedef void (*KernelFunction)(int global_id, int local_id, void **args);
 
 typedef struct SimKernel {
 	#ifdef WITH_OPENCL

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c	2010-09-27 10:53:41 UTC (rev 32150)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c	2010-09-27 11:48:16 UTC (rev 32151)
@@ -736,7 +736,7 @@
 	SimWorkerThread *thread= (SimWorkerThread*)data;
 	SimExecData *execdata= thread->execdata;
 	SimTask *task;
-	int items;
+	int start, total;
 	
 	pthread_mutex_lock(&execdata->hostmutex);
 	++execdata->active;
@@ -773,13 +773,15 @@
 		if (execdata->stop)
 			break;
 		else if (task) {
-			items = MIN2(task->workgroupsize, task->totitems-task->startitem);
-			task->startitem += items;
+			start = task->startitem;
+			total = MIN2(task->workgroupsize, task->totitems - start);
+			task->startitem += total;
 			task->event.impl->status = SIM_RUNNING;
 			++task->active;
 			pthread_mutex_unlock(&execdata->hostmutex);
 			
-			/* WORKWORKWORK here */
+			/* actual work (this is where the thread should spend most of its time!) */
+			task->execfunc(task->data, start, total);
 			
 			pthread_mutex_lock(&execdata->hostmutex);
 			--task->active;

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_math.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_math.c	2010-09-27 10:53:41 UTC (rev 32150)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_math.c	2010-09-27 11:48:16 UTC (rev 32151)
@@ -103,27 +103,27 @@
 	return source;
 }
 
-void node_add_float(void **args)
+void node_add_float(int global_id, int local_id, void **args)
 {
 //	*(float*)args[0] = *(float*)args[1] + *(float*)args[2];
 }
 
-void node_add_int(void **args)
+void node_add_int(int global_id, int local_id, void **args)
 {
 //	*(int*)args[0] = *(int*)args[1] + *(int*)args[2];
 }
 
-void node_add_bool(void **args)
+void node_add_bool(int global_id, int local_id, void **args)
 {
 //	*(char*)args[0] = *(char*)args[1] + *(char*)args[2];
 }
 
-void node_add_vector(void **args)
+void node_add_vector(int global_id, int local_id, void **args)
 {
 //	add_v3_v3v3((float*)args[0], (float*)args[1], (float*)args[2]);
 }
 
-void node_add_rgba(void **args)
+void node_add_rgba(int global_id, int local_id, void **args)
 {
 //	((float*)args[0])[0] = ((float*)args[1])[0] + ((float*)args[2])[0];
 //	((float*)args[0])[1] = ((float*)args[1])[1] + ((float*)args[2])[1];





More information about the Bf-blender-cvs mailing list