1 /*
2 Bullet Continuous Collision Detection and Physics Library, Copyright (c) 2007 Erwin Coumans
3 
4 This software is provided 'as-is', without any express or implied warranty.
5 In no event will the authors be held liable for any damages arising from the use of this software.
6 Permission is granted to anyone to use this software for any purpose,
7 including commercial applications, and to alter it and redistribute it freely,
8 subject to the following restrictions:
9 
10 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.
11 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
12 3. This notice may not be removed or altered from any source distribution.
13 
14 */
15 
16 
17 #include "MiniCLTask.h"
18 #include "../PlatformDefinitions.h"
19 #include "../SpuFakeDma.h"
20 #include "LinearMath/btMinMax.h"
21 #include "BulletMultiThreaded/MiniCLTask/MiniCLTask.h"
22 
23 #ifdef __SPU__
24 #include <spu_printf.h>
25 #else
26 #include <stdio.h>
27 #define spu_printf printf
28 #endif
29 
30 #define __kernel
31 #define __global
32 #define get_global_id(a) guid
33 
34 struct MiniCLTask_LocalStoreMemory
35 {
36 
37 };
38 
39 
40 ///////////////////////////////////////////////////
41 // OpenCL Kernel Function for element by element vector addition
VectorAdd(__global const float8 * a,__global const float8 * b,__global float8 * c,int guid)42 __kernel void VectorAdd(__global const float8* a, __global const float8* b, __global float8* c, int guid)
43 {
44     // get oct-float index into global data array
45     int iGID = get_global_id(0);
46 
47     // read inputs into registers
48     float8 f8InA = a[iGID];
49     float8 f8InB = b[iGID];
50     float8 f8Out = (float8)0.0f;
51 
52     // add the vector elements
53     f8Out.s0 = f8InA.s0 + f8InB.s0;
54     f8Out.s1 = f8InA.s1 + f8InB.s1;
55     f8Out.s2 = f8InA.s2 + f8InB.s2;
56     f8Out.s3 = f8InA.s3 + f8InB.s3;
57     f8Out.s4 = f8InA.s4 + f8InB.s4;
58     f8Out.s5 = f8InA.s5 + f8InB.s5;
59     f8Out.s6 = f8InA.s6 + f8InB.s6;
60     f8Out.s7 = f8InA.s7 + f8InB.s7;
61 
62     // write back out to GMEM
63     c[get_global_id(0)] = f8Out;
64 }
65 ///////////////////////////////////////////////////
66 
67 
68 //-- MAIN METHOD
processMiniCLTask(void * userPtr,void * lsMemory)69 void processMiniCLTask(void* userPtr, void* lsMemory)
70 {
71 	//	BT_PROFILE("processSampleTask");
72 
73 	MiniCLTask_LocalStoreMemory* localMemory = (MiniCLTask_LocalStoreMemory*)lsMemory;
74 
75 	MiniCLTaskDesc* taskDescPtr = (MiniCLTaskDesc*)userPtr;
76 	MiniCLTaskDesc& taskDesc = *taskDescPtr;
77 
78 	printf("Compute Unit[%d] executed kernel %d work items [%d..%d)\n",taskDesc.m_taskId,taskDesc.m_kernelProgramId,taskDesc.m_firstWorkUnit,taskDesc.m_lastWorkUnit);
79 
80 
81 	switch (taskDesc.m_kernelProgramId)
82 	{
83 	case CMD_MINICL_ADDVECTOR:
84 		{
85 			for (unsigned int i=taskDesc.m_firstWorkUnit;i<taskDesc.m_lastWorkUnit;i++)
86 			{
87 				VectorAdd(*(const float8**)&taskDesc.m_argData[0][0],*(const float8**)&taskDesc.m_argData[1][0],*(float8**)&taskDesc.m_argData[2][0],i);
88 			}
89 			break;
90 		}
91 
92 	default:
93 		{
94 			printf("error in processMiniCLTask: unknown command id: %d\n",taskDesc.m_kernelProgramId);
95 
96 		}
97 	};
98 
99 }
100 
101 
102 #if defined(__CELLOS_LV2__) || defined (LIBSPE2)
103 
104 ATTRIBUTE_ALIGNED16(MiniCLTask_LocalStoreMemory	gLocalStoreMemory);
105 
createMiniCLLocalStoreMemory()106 void* createMiniCLLocalStoreMemory()
107 {
108 	return &gLocalStoreMemory;
109 }
110 #else
createMiniCLLocalStoreMemory()111 void* createMiniCLLocalStoreMemory()
112 {
113 	return new MiniCLTask_LocalStoreMemory;
114 };
115 
116 #endif
117