[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58819] branches/soc-2013-vse/source/ blender/sequencer: Updating seqDevices

Alexander Kuznetsov kuzsasha at gmail.com
Fri Aug 2 08:02:01 CEST 2013


Revision: 58819
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58819
Author:   alexk
Date:     2013-08-02 06:02:00 +0000 (Fri, 02 Aug 2013)
Log Message:
-----------
Updating seqDevices
Resolved a race condition between buckets.
Made devices more simular in the way they work
Updated to nicer reference counter
Fixed an issue with seqDeviceCL code. Ported effects works in OpenCL, but require a cleaner structure.. 

Modified Paths:
--------------
    branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDevice.cpp
    branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDevice.h
    branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDeviceCL.cpp
    branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDeviceCL.h
    branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDeviceCPU.cpp
    branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDeviceCPU.h

Added Paths:
-----------
    branches/soc-2013-vse/source/blender/sequencer/sequencer_seqCLPlatform.cpp
    branches/soc-2013-vse/source/blender/sequencer/sequencer_seqCLPlatform.h

Added: branches/soc-2013-vse/source/blender/sequencer/sequencer_seqCLPlatform.cpp
===================================================================
--- branches/soc-2013-vse/source/blender/sequencer/sequencer_seqCLPlatform.cpp	                        (rev 0)
+++ branches/soc-2013-vse/source/blender/sequencer/sequencer_seqCLPlatform.cpp	2013-08-02 06:02:00 UTC (rev 58819)
@@ -0,0 +1,132 @@
+#include "sequencer_seqCLPlatform.h"
+#include <string.h>
+
+char *seq_vs_types[] = {datatoc_include_type_float_cl};
+
+
+seqCLPlatform::seqCLPlatform(seqEngine *engine):
+	next(NULL), prev(NULL),
+	cldm_p(NULL),
+	cl_this_context(0)
+{
+	refcount = 0;
+	memset(programs, 0, sizeof(*programs));
+
+}
+
+
+bool seqCLPlatform::init(cldm_platform *p)
+{
+
+
+	cl_uint num_devices, i;
+	cl_int err = 0;
+
+	cl_device_id *devices;
+
+	cldm_p = p;
+	refcount = 0;
+
+	num_devices = cldm_p->num_devices;
+	devices = new cl_device_id [num_devices];
+
+	for(i = 0; i < num_devices; i++)
+	{
+		devices[i] = cldm_p->devices[i].did;
+
+	}
+
+
+	cl_this_context = clCreateContext(NULL, num_devices, devices, NULL, NULL, &err);
+
+	delete []devices;
+
+
+	if(err == CL_SUCCESS)
+	{
+		uint j;
+
+		for(j = 0; j < NUM_SEQ_VS_TYPES; j++)
+		{
+			const char *cl_source[2] = {seq_vs_types[j], datatoc_kernel_main_cl};
+			programs[j].cl_program_pointer = clCreateProgramWithSource(cl_this_context, 2, cl_source, 0, &err);
+
+			if(err == CL_SUCCESS)
+			{
+				programs[j].status |= SEQ_CL_PROGRAM_STATUS_SOURCE;
+
+				err = clBuildProgram(programs[j].cl_program_pointer, 0, 0, 0, 0, 0);
+				if(err == CL_SUCCESS)
+				{
+					programs[j].status |= SEQ_CL_PROGRAM_STATUS_COMPILED;
+				} else
+				{
+
+
+					size_t len;
+					char buffer[2048];
+
+					programs[j].status |= SEQ_CL_PROGRAM_STATUS_ERROR;
+
+					printf("Error: Failed to build program executable!\n");
+					for(i = 0; i < num_devices; i++)
+					{
+						err =  clGetProgramBuildInfo(programs[j].cl_program_pointer,
+											  cldm_p->devices[i].did, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
+						fprintf(stdout, "%s\n", buffer);
+					}
+
+
+
+				}
+
+
+
+			} else
+			{
+				programs[j].status |= SEQ_CL_PROGRAM_STATUS_ERROR;
+			}
+
+		}
+
+
+
+
+		return true;
+	}
+
+
+	return false;
+
+
+}
+
+
+seqCLPlatform::~seqCLPlatform()
+{
+
+	int j;
+
+	if(refcount>0)
+	{
+		printf("Deleting platform with existing devices");
+
+	}
+
+	for(j = 0; j < NUM_SEQ_VS_TYPES; j++)
+	{
+		if(programs[j].status &
+				(SEQ_CL_PROGRAM_STATUS_COMPILED | SEQ_CL_PROGRAM_STATUS_SOURCE))
+		{
+			clReleaseProgram(programs[j].cl_program_pointer);
+		}
+
+
+	}
+
+
+
+	clReleaseContext(cl_this_context);
+
+
+}

Added: branches/soc-2013-vse/source/blender/sequencer/sequencer_seqCLPlatform.h
===================================================================
--- branches/soc-2013-vse/source/blender/sequencer/sequencer_seqCLPlatform.h	                        (rev 0)
+++ branches/soc-2013-vse/source/blender/sequencer/sequencer_seqCLPlatform.h	2013-08-02 06:02:00 UTC (rev 58819)
@@ -0,0 +1,39 @@
+#ifndef __SEQUEBCER_SEQCLPLATFORM_H__
+#define __SEQUEBCER_SEQCLPLATFORM_H__
+
+#include "sequencer_seqCLProgram.h"
+#include "sequencer_include.h"
+#include "CLDM_init.h"
+
+#define NUMOFELEM(a) (sizeof(a)/sizeof(*a))
+
+extern char datatoc_kernel_main_cl[];
+extern char datatoc_include_type_float_cl[];
+
+extern char *seq_vs_types[];
+
+#define NUM_SEQ_VS_TYPES (1)
+
+class seqCLPlatform
+{
+public:
+	struct seqCLPlatform *next, *prev;
+	cldm_platform * cldm_p;
+
+	cl_context cl_this_context;
+
+
+	seqCLProgram programs [NUM_SEQ_VS_TYPES];
+
+
+	int refcount;
+
+	seqCLPlatform(seqEngine *engine);
+	~seqCLPlatform();
+	bool init(cldm_platform *p);
+
+};
+
+
+
+#endif /* __SEQUEBCER_SEQCLPLATFORM_H__*/

Modified: branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDevice.cpp
===================================================================
--- branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDevice.cpp	2013-08-02 05:45:58 UTC (rev 58818)
+++ branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDevice.cpp	2013-08-02 06:02:00 UTC (rev 58819)
@@ -0,0 +1,115 @@
+#include "sequencer_seqDevice.h"
+
+
+
+#include "sequencer_seqBucket.h"
+#include "sequencer_seqCommand.h"
+#include "sequencer_seqEngine.h"
+
+
+seqDevice::seqDevice(seqEngine *engine):
+	type(0),
+	device_thread(0),
+	se(engine)
+{
+
+
+
+}
+
+
+
+void seqDevice::device_start_thread(void)
+{
+
+	prepare_thread();
+	se->buckets_notifiication.lock();
+
+	while(1)
+	{
+
+
+		if(!bucketqueuelist.empty())
+		{
+			se->buckets_notifiication.unlock();
+			int numdone =1;
+
+			while(numdone)
+			{
+
+				numdone = 0;
+
+				seqBucket *cb, *nb;
+				std::list<seqBucket*>::iterator icb, inb;
+
+
+				/* lock? */
+				for(icb = bucketqueuelist.begin(); icb!=bucketqueuelist.end(); icb = inb)
+				{
+					uint j;
+					inb = icb;
+					inb++;
+					cb = *icb;
+
+
+					for(j=0; j < cb->dl_num; j++)
+					{
+						if(!(cb->dl[j].buck->status & SEQ_BUCKET_STATUS_READY))
+						{
+
+							break;
+						}
+					}
+
+					if(j == cb->dl_num)
+					{
+						numdone++;
+						bucket_prepare(cb);
+						bucket_do(cb);
+						bucket_done(se, cb);
+
+						omutex.lock();
+						bucketqueuelist.erase(icb);
+						omutex.unlock();
+
+					}
+
+
+				}
+
+
+			}
+
+
+			se->buckets_notifiication.lock();
+
+		}else
+		{
+
+			se->buckets_notifiication.wait();
+		}
+
+	}
+
+	se->buckets_notifiication.unlock();
+
+	return;
+
+}
+
+
+static void * seq_thread_device(void *data)
+{
+	seqDevice *dev = (seqDevice *)data;
+
+	dev->device_start_thread();
+	return NULL;
+
+}
+
+void seqDevice::start()
+{
+	pthread_create(&device_thread, NULL, seq_thread_device, this);
+
+}
+

Modified: branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDevice.h
===================================================================
--- branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDevice.h	2013-08-02 05:45:58 UTC (rev 58818)
+++ branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDevice.h	2013-08-02 06:02:00 UTC (rev 58819)
@@ -2,17 +2,26 @@
 #define __SEQUENCER_SEQDEVICE_H__
 
 
-#include "sequencer_seqCLProgram.h"
 
+
 #ifdef __cplusplus
 extern "C" {
 #endif
+
+
 #include "CLDM_init.h"
+#include "BLI_threads.h"
+#include "DNA_listBase.h"
 
+
 #ifdef __cplusplus
 }
 #endif
 
+
+#include "sequencer_include.h"
+
+
 #define SEQ_KER_TYPE_CHAR (0)
 #define SEQ_KER_TYPE_HALFFLOAT (1)
 #define SEQ_KER_TYPE_FLOAT (2)
@@ -23,14 +32,7 @@
 #define SEQ_KER_SOURCE_MAIN (0)
 #define SEQ_KER_SOURCE_total_num (1)
 
-#define SEQ_KER_KERNELS_total_num (3)
 
-
-
-
-
-
-
 #define SEQ_DEVICE_TYPE_CPU (1<<0)
 #define SEQ_DEVICE_TYPE_CL (1<<1)
 
@@ -38,23 +40,22 @@
 
 
 #define SEQ_BUCKET_DEVT_CPU (1<<0)
-#define SEQ_BUCKET_DEVT_GPU (1<<0)
+#define SEQ_BUCKET_DEVT_GPU (1<<1)
 
 
 #define SEQ_DEVICE_CL_READY (1<<0)
 
+#include <list>
 
 
-
-class seqDeviceGen
+class seqDevice
 {
 public:
-	seqDeviceGen *next, *prev;
 	uint type;
 	char name[24];
 
-	ThreadMutex device_mutex;
-	ListBase bucketqueuelist;
+	smutex omutex;
+	std::list<seqBucket*> bucketqueuelist;
 
 	pthread_t device_thread;
 
@@ -62,63 +63,33 @@
 
 
 
-};
+	virtual void bucket_prepare(seqBucket *bucket) = 0;
+	virtual void bucket_do(seqBucket *bucket) = 0;
+	virtual void bucket_done(seqEngine *se, seqBucket *bucket) = 0;
 
+	virtual void device_start_thread(void);
 
+	virtual void start(void);
 
+	virtual void prepare_thread(void)
+	{
+		return;
+	}
 
-class seqDeviceCL
-{
-public:
-	seqDeviceGen gen;
-	seqCLPlatform* clpl;
+	seqDevice(seqEngine *engine);
+	virtual ~seqDevice()
+	{
 
-	struct cldm_device * cldm_device;
 
-	uint status; /* multi-threaded! */
+	}
 
+	MEM_CXX_CLASS_ALLOC_FUNCS("seqDevice");
 
-	cl_command_queue local_cl_queue;
-
-
-
-	pthread_cond_t device_pause_signal;
-
-	cl_kernel local_cl_main_kernels [SEQ_KER_TYPE_total_num][SEQ_KER_KERNELS_total_num];
-	uint kernel_main_status[SEQ_KER_TYPE_total_num];
-
-
-
-
-} ;
-
-
-
-
-
-
-
-class seqDeviceCPU
-{
-public:
-	seqDeviceGen gen;
-
-
-
 };
 
-typedef union seqDevice
-{
-	seqDeviceGen gen;
-	seqDeviceCL cl;
-	seqDeviceCPU cpu;
 
-} seqDevice;
 
 
 
 
-
-
-
 #endif /* __SEQUENCER_SEQDEVICE_H__ */

Modified: branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDeviceCL.cpp
===================================================================
--- branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDeviceCL.cpp	2013-08-02 05:45:58 UTC (rev 58818)
+++ branches/soc-2013-vse/source/blender/sequencer/sequencer_seqDeviceCL.cpp	2013-08-02 06:02:00 UTC (rev 58819)
@@ -0,0 +1,318 @@
+#include "sequencer_seqDeviceCL.h"
+
+#include <string.h>
+
+#include <unistd.h>
+
+
+#include "sequencer_seqEngine.h"
+#include "sequencer_seqBucket.h"
+
+
+extern const char *seq_kernels_main[];
+
+
+
+static seqCLPlatform *SEQ_add_new_cl_platform(seqEngine *engine, cldm_platform *p)
+{
+	seqCLPlatform * r = new seqCLPlatform(engine);
+
+	if(r->init(p))
+	{
+		//BLI_addtail(&engine->clplatformlist, r);
+		engine->clplatformlist.push_back(r);
+		return r;
+	}
+	else
+	{
+		delete r;
+		return NULL;
+	}
+
+
+
+
+}
+
+
+static CL_CALLBACK void seq_cl_callback(cl_event event, cl_int event_command_exec_status, void *user_data)
+{
+seqDeviceCL *devcl = (seqDeviceCL*)user_data;
+usleep(100000);
+	//printf("Tester boo\n");
+
+devcl->omutex.lock();
+	devcl->status |= SEQ_DEVICE_CL_READY;
+	pthread_cond_signal(&devcl->device_pause_signal);
+	devcl->omutex.unlock();
+
+
+}
+
+
+
+
+
+
+
+void seqDeviceCL::prepare_thread(void)
+{
+
+	uint i, j;
+	cl_int err;
+
+
+	for(i = 0; i < SEQ_KER_TYPE_total_num; i++)
+	{
+
+		seqCLProgram *prog = &clpl->programs[i];
+
+		if((prog->status & SEQ_CL_PROGRAM_STATUS_COMPILED) && !(prog->status & SEQ_CL_PROGRAM_STATUS_ERROR))
+		{
+
+			for(j = 0; j < SEQ_KER_KERNELS_total_num; j++)
+			{
+
+				local_cl_main_kernels[i][j] =
+				clCreateKernel(prog->cl_program_pointer,
+							   seq_kernels_main[j],
+							   &err);
+				if(err != CL_SUCCESS)
+				{
+					break;
+				}
+
+
+			}
+
+
+			if(j != SEQ_KER_KERNELS_total_num)
+			{
+				for(j--; j>=0; j--)
+				{
+
+					clReleaseKernel(local_cl_main_kernels[i][j]);
+
+
+				}
+
+			} else
+			{
+				kernel_main_status[i] |= SEQ_CL_KERNEL_STATUS_COMPILED;
+
+			}
+
+
+		}
+
+	}
+
+
+}
+
+
+seqDeviceCL * SEQ_create_device_cl(seqEngine *engine, cldm_device * cldevice, cldm_i_dparam *param)
+{
+
+	seqDeviceCL * r = new seqDeviceCL(engine);
+	seqCLPlatform *cp = NULL;
+	cl_int err = 0;
+
+
+
+	for(std::vector<seqCLPlatform*>::iterator icb = engine->clplatformlist.begin();
+		icb != engine->clplatformlist.end(); ++icb)
+	{
+
+		if((*icb)->cldm_p == cldevice->platform)
+		{
+			cp = *icb;
+			break;
+		}
+	}
+
+	if(cp == NULL)
+	{
+		cp = SEQ_add_new_cl_platform(engine, cldevice->platform);
+	}
+
+	if(cp)
+	{
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list