2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
16 //#define __CELLOS_LV2__ 1
17 #define __BT_SKIP_UINT64_H 1
19 #define USE_SAMPLE_PROCESS 1
20 #ifdef USE_SAMPLE_PROCESS
23 #include "MiniCLTaskScheduler.h"
30 void SampleThreadFunc(void* userPtr,void* lsMemory)
33 printf("hello world\n");
37 void* SamplelsMemoryFunc()
39 //don't create local store memory, just return 0
47 #include "BulletMultiThreaded/btThreadSupportInterface.h"
49 //# include "SPUAssert.h"
52 #include "MiniCL/cl_platform.h"
55 extern char SPU_SAMPLE_ELF_SYMBOL[];
59 MiniCLTaskScheduler::MiniCLTaskScheduler(btThreadSupportInterface* threadInterface, int maxNumOutstandingTasks)
60 :m_threadInterface(threadInterface),
61 m_maxNumOutstandingTasks(maxNumOutstandingTasks)
64 m_taskBusy.resize(m_maxNumOutstandingTasks);
65 m_spuSampleTaskDesc.resize(m_maxNumOutstandingTasks);
69 for (int i = 0; i < m_maxNumOutstandingTasks; i++)
71 m_taskBusy[i] = false;
76 m_initialized = false;
78 m_threadInterface->startSPU();
83 MiniCLTaskScheduler::~MiniCLTaskScheduler()
85 m_threadInterface->stopSPU();
91 void MiniCLTaskScheduler::initialize()
93 #ifdef DEBUG_SPU_TASK_SCHEDULING
94 printf("MiniCLTaskScheduler::initialize()\n");
95 #endif //DEBUG_SPU_TASK_SCHEDULING
97 for (int i = 0; i < m_maxNumOutstandingTasks; i++)
99 m_taskBusy[i] = false;
103 m_initialized = true;
108 void MiniCLTaskScheduler::issueTask(int firstWorkUnit, int lastWorkUnit, MiniCLKernel* kernel)
111 #ifdef DEBUG_SPU_TASK_SCHEDULING
112 printf("MiniCLTaskScheduler::issueTask (m_currentTask= %d\)n", m_currentTask);
113 #endif //DEBUG_SPU_TASK_SCHEDULING
115 m_taskBusy[m_currentTask] = true;
118 MiniCLTaskDesc& taskDesc = m_spuSampleTaskDesc[m_currentTask];
120 // send task description in event message
121 taskDesc.m_firstWorkUnit = firstWorkUnit;
122 taskDesc.m_lastWorkUnit = lastWorkUnit;
123 taskDesc.m_kernel = kernel;
124 //some bookkeeping to recognize finished tasks
125 taskDesc.m_taskId = m_currentTask;
127 // for (int i=0;i<MINI_CL_MAX_ARG;i++)
128 for (unsigned int i=0; i < kernel->m_numArgs; i++)
130 taskDesc.m_argSizes[i] = kernel->m_argSizes[i];
131 if (taskDesc.m_argSizes[i])
133 taskDesc.m_argData[i] = kernel->m_argData[i];
134 // memcpy(&taskDesc.m_argData[i],&argData[MINICL_MAX_ARGLENGTH*i],taskDesc.m_argSizes[i]);
140 m_threadInterface->sendRequest(1, (ppu_address_t) &taskDesc, m_currentTask);
142 // if all tasks busy, wait for spu event to clear the task.
144 if (m_numBusyTasks >= m_maxNumOutstandingTasks)
147 unsigned int outputSize;
149 for (int i=0;i<m_maxNumOutstandingTasks;i++)
157 m_threadInterface->waitForResponse(&taskId, &outputSize);
159 //printf("PPU: after issue, received event: %u %d\n", taskId, outputSize);
161 postProcess(taskId, outputSize);
163 m_taskBusy[taskId] = false;
168 // find new task buffer
169 for (int i = 0; i < m_maxNumOutstandingTasks; i++)
180 ///Optional PPU-size post processing for each task
181 void MiniCLTaskScheduler::postProcess(int taskId, int outputSize)
187 void MiniCLTaskScheduler::flush()
189 #ifdef DEBUG_SPU_TASK_SCHEDULING
190 printf("\nSpuCollisionTaskProcess::flush()\n");
191 #endif //DEBUG_SPU_TASK_SCHEDULING
194 // all tasks are issued, wait for all tasks to be complete
195 while(m_numBusyTasks > 0)
197 // Consolidating SPU code
199 unsigned int outputSize;
201 for (int i=0;i<m_maxNumOutstandingTasks;i++)
211 m_threadInterface->waitForResponse(&taskId, &outputSize);
214 //printf("PPU: flushing, received event: %u %d\n", taskId, outputSize);
216 postProcess(taskId, outputSize);
218 m_taskBusy[taskId] = false;
228 typedef void (*MiniCLKernelLauncher0)(int);
229 typedef void (*MiniCLKernelLauncher1)(void*, int);
230 typedef void (*MiniCLKernelLauncher2)(void*, void*, int);
231 typedef void (*MiniCLKernelLauncher3)(void*, void*, void*, int);
232 typedef void (*MiniCLKernelLauncher4)(void*, void*, void*, void*, int);
233 typedef void (*MiniCLKernelLauncher5)(void*, void*, void*, void*, void*, int);
234 typedef void (*MiniCLKernelLauncher6)(void*, void*, void*, void*, void*, void*, int);
235 typedef void (*MiniCLKernelLauncher7)(void*, void*, void*, void*, void*, void*, void*, int);
236 typedef void (*MiniCLKernelLauncher8)(void*, void*, void*, void*, void*, void*, void*, void*, int);
237 typedef void (*MiniCLKernelLauncher9)(void*, void*, void*, void*, void*, void*, void*, void*, void*, int);
238 typedef void (*MiniCLKernelLauncher10)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, int);
239 typedef void (*MiniCLKernelLauncher11)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, int);
240 typedef void (*MiniCLKernelLauncher12)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, int);
241 typedef void (*MiniCLKernelLauncher13)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, int);
242 typedef void (*MiniCLKernelLauncher14)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, int);
243 typedef void (*MiniCLKernelLauncher15)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, int);
244 typedef void (*MiniCLKernelLauncher16)(void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, void*, int);
247 static void kernelLauncher0(MiniCLTaskDesc* taskDesc, int guid)
249 ((MiniCLKernelLauncher0)(taskDesc->m_kernel->m_launcher))(guid);
251 static void kernelLauncher1(MiniCLTaskDesc* taskDesc, int guid)
253 ((MiniCLKernelLauncher1)(taskDesc->m_kernel->m_pCode))( taskDesc->m_argData[0],
256 static void kernelLauncher2(MiniCLTaskDesc* taskDesc, int guid)
258 ((MiniCLKernelLauncher2)(taskDesc->m_kernel->m_pCode))( taskDesc->m_argData[0],
259 taskDesc->m_argData[1],
262 static void kernelLauncher3(MiniCLTaskDesc* taskDesc, int guid)
264 ((MiniCLKernelLauncher3)(taskDesc->m_kernel->m_pCode))( taskDesc->m_argData[0],
265 taskDesc->m_argData[1],
266 taskDesc->m_argData[2],
269 static void kernelLauncher4(MiniCLTaskDesc* taskDesc, int guid)
271 ((MiniCLKernelLauncher4)(taskDesc->m_kernel->m_pCode))( taskDesc->m_argData[0],
272 taskDesc->m_argData[1],
273 taskDesc->m_argData[2],
274 taskDesc->m_argData[3],
277 static void kernelLauncher5(MiniCLTaskDesc* taskDesc, int guid)
279 ((MiniCLKernelLauncher5)(taskDesc->m_kernel->m_pCode))( taskDesc->m_argData[0],
280 taskDesc->m_argData[1],
281 taskDesc->m_argData[2],
282 taskDesc->m_argData[3],
283 taskDesc->m_argData[4],
286 static void kernelLauncher6(MiniCLTaskDesc* taskDesc, int guid)
288 ((MiniCLKernelLauncher6)(taskDesc->m_kernel->m_pCode))( taskDesc->m_argData[0],
289 taskDesc->m_argData[1],
290 taskDesc->m_argData[2],
291 taskDesc->m_argData[3],
292 taskDesc->m_argData[4],
293 taskDesc->m_argData[5],
296 static void kernelLauncher7(MiniCLTaskDesc* taskDesc, int guid)
298 ((MiniCLKernelLauncher7)(taskDesc->m_kernel->m_pCode))( taskDesc->m_argData[0],
299 taskDesc->m_argData[1],
300 taskDesc->m_argData[2],
301 taskDesc->m_argData[3],
302 taskDesc->m_argData[4],
303 taskDesc->m_argData[5],
304 taskDesc->m_argData[6],
307 static void kernelLauncher8(MiniCLTaskDesc* taskDesc, int guid)
309 ((MiniCLKernelLauncher8)(taskDesc->m_kernel->m_pCode))( taskDesc->m_argData[0],
310 taskDesc->m_argData[1],
311 taskDesc->m_argData[2],
312 taskDesc->m_argData[3],
313 taskDesc->m_argData[4],
314 taskDesc->m_argData[5],
315 taskDesc->m_argData[6],
316 taskDesc->m_argData[7],
319 static void kernelLauncher9(MiniCLTaskDesc* taskDesc, int guid)
321 ((MiniCLKernelLauncher9)(taskDesc->m_kernel->m_pCode))( taskDesc->m_argData[0],
322 taskDesc->m_argData[1],
323 taskDesc->m_argData[2],
324 taskDesc->m_argData[3],
325 taskDesc->m_argData[4],
326 taskDesc->m_argData[5],
327 taskDesc->m_argData[6],
328 taskDesc->m_argData[7],
329 taskDesc->m_argData[8],
332 static void kernelLauncher10(MiniCLTaskDesc* taskDesc, int guid)
334 ((MiniCLKernelLauncher10)(taskDesc->m_kernel->m_pCode))(taskDesc->m_argData[0],
335 taskDesc->m_argData[1],
336 taskDesc->m_argData[2],
337 taskDesc->m_argData[3],
338 taskDesc->m_argData[4],
339 taskDesc->m_argData[5],
340 taskDesc->m_argData[6],
341 taskDesc->m_argData[7],
342 taskDesc->m_argData[8],
343 taskDesc->m_argData[9],
346 static void kernelLauncher11(MiniCLTaskDesc* taskDesc, int guid)
348 ((MiniCLKernelLauncher11)(taskDesc->m_kernel->m_pCode))(taskDesc->m_argData[0],
349 taskDesc->m_argData[1],
350 taskDesc->m_argData[2],
351 taskDesc->m_argData[3],
352 taskDesc->m_argData[4],
353 taskDesc->m_argData[5],
354 taskDesc->m_argData[6],
355 taskDesc->m_argData[7],
356 taskDesc->m_argData[8],
357 taskDesc->m_argData[9],
358 taskDesc->m_argData[10],
361 static void kernelLauncher12(MiniCLTaskDesc* taskDesc, int guid)
363 ((MiniCLKernelLauncher12)(taskDesc->m_kernel->m_pCode))(taskDesc->m_argData[0],
364 taskDesc->m_argData[1],
365 taskDesc->m_argData[2],
366 taskDesc->m_argData[3],
367 taskDesc->m_argData[4],
368 taskDesc->m_argData[5],
369 taskDesc->m_argData[6],
370 taskDesc->m_argData[7],
371 taskDesc->m_argData[8],
372 taskDesc->m_argData[9],
373 taskDesc->m_argData[10],
374 taskDesc->m_argData[11],
377 static void kernelLauncher13(MiniCLTaskDesc* taskDesc, int guid)
379 ((MiniCLKernelLauncher13)(taskDesc->m_kernel->m_pCode))(taskDesc->m_argData[0],
380 taskDesc->m_argData[1],
381 taskDesc->m_argData[2],
382 taskDesc->m_argData[3],
383 taskDesc->m_argData[4],
384 taskDesc->m_argData[5],
385 taskDesc->m_argData[6],
386 taskDesc->m_argData[7],
387 taskDesc->m_argData[8],
388 taskDesc->m_argData[9],
389 taskDesc->m_argData[10],
390 taskDesc->m_argData[11],
391 taskDesc->m_argData[12],
394 static void kernelLauncher14(MiniCLTaskDesc* taskDesc, int guid)
396 ((MiniCLKernelLauncher14)(taskDesc->m_kernel->m_pCode))(taskDesc->m_argData[0],
397 taskDesc->m_argData[1],
398 taskDesc->m_argData[2],
399 taskDesc->m_argData[3],
400 taskDesc->m_argData[4],
401 taskDesc->m_argData[5],
402 taskDesc->m_argData[6],
403 taskDesc->m_argData[7],
404 taskDesc->m_argData[8],
405 taskDesc->m_argData[9],
406 taskDesc->m_argData[10],
407 taskDesc->m_argData[11],
408 taskDesc->m_argData[12],
409 taskDesc->m_argData[13],
412 static void kernelLauncher15(MiniCLTaskDesc* taskDesc, int guid)
414 ((MiniCLKernelLauncher15)(taskDesc->m_kernel->m_pCode))(taskDesc->m_argData[0],
415 taskDesc->m_argData[1],
416 taskDesc->m_argData[2],
417 taskDesc->m_argData[3],
418 taskDesc->m_argData[4],
419 taskDesc->m_argData[5],
420 taskDesc->m_argData[6],
421 taskDesc->m_argData[7],
422 taskDesc->m_argData[8],
423 taskDesc->m_argData[9],
424 taskDesc->m_argData[10],
425 taskDesc->m_argData[11],
426 taskDesc->m_argData[12],
427 taskDesc->m_argData[13],
428 taskDesc->m_argData[14],
431 static void kernelLauncher16(MiniCLTaskDesc* taskDesc, int guid)
433 ((MiniCLKernelLauncher16)(taskDesc->m_kernel->m_pCode))(taskDesc->m_argData[0],
434 taskDesc->m_argData[1],
435 taskDesc->m_argData[2],
436 taskDesc->m_argData[3],
437 taskDesc->m_argData[4],
438 taskDesc->m_argData[5],
439 taskDesc->m_argData[6],
440 taskDesc->m_argData[7],
441 taskDesc->m_argData[8],
442 taskDesc->m_argData[9],
443 taskDesc->m_argData[10],
444 taskDesc->m_argData[11],
445 taskDesc->m_argData[12],
446 taskDesc->m_argData[13],
447 taskDesc->m_argData[14],
448 taskDesc->m_argData[15],
452 static kernelLauncherCB spLauncherList[MINI_CL_MAX_ARG+1] =
473 void MiniCLKernel::updateLauncher()
475 m_launcher = spLauncherList[m_numArgs];
478 struct MiniCLKernelDescEntry
483 static MiniCLKernelDescEntry spKernelDesc[256];
484 static int sNumKernelDesc = 0;
486 MiniCLKernelDesc::MiniCLKernelDesc(void* pCode, const char* pName)
488 for(int i = 0; i < sNumKernelDesc; i++)
490 if(!strcmp(pName, spKernelDesc[i].pName))
491 { // already registered
492 btAssert(spKernelDesc[i].pCode == pCode);
496 spKernelDesc[sNumKernelDesc].pCode = pCode;
497 spKernelDesc[sNumKernelDesc].pName = pName;
502 MiniCLKernel* MiniCLKernel::registerSelf()
504 m_scheduler->registerKernel(this);
505 for(int i = 0; i < sNumKernelDesc; i++)
507 if(!strcmp(m_name, spKernelDesc[i].pName))
509 m_pCode = spKernelDesc[i].pCode;
519 #endif //USE_SAMPLE_PROCESS