1 
2 #include <gtest/gtest.h>
3 #include "Bullet3Common/b3Logging.h"
4 #include "Bullet3Common/b3CommandLineArgs.h"
5 #include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
6 
7 #include "Bullet3OpenCL/RigidBody/kernels/solverSetup.h"
8 #include "Bullet3OpenCL/RigidBody/kernels/solverSetup2.h"
9 #include "Bullet3OpenCL/RigidBody/kernels/solveContact.h"
10 #include "Bullet3OpenCL/RigidBody/kernels/solveFriction.h"
11 #include "Bullet3OpenCL/RigidBody/kernels/batchingKernels.h"
12 #include "Bullet3OpenCL/RigidBody/kernels/batchingKernelsNew.h"
13 
14 extern int gArgc;
15 extern char** gArgv;
16 
17 namespace
18 {
19 struct CompileBullet3PgsContactSolverKernels : public ::testing::Test
20 {
21 	cl_context m_clContext;
22 	cl_device_id m_clDevice;
23 	cl_command_queue m_clQueue;
24 	char* m_clDeviceName;
25 	cl_platform_id m_platformId;
26 
CompileBullet3PgsContactSolverKernels__anon9b35ceab0111::CompileBullet3PgsContactSolverKernels27 	CompileBullet3PgsContactSolverKernels()
28 		: m_clDeviceName(0),
29 		  m_clContext(0),
30 		  m_clDevice(0),
31 		  m_clQueue(0),
32 		  m_platformId(0)
33 	{
34 		// You can do set-up work for each test here.
35 		b3CommandLineArgs args(gArgc, gArgv);
36 		int preferredDeviceIndex = -1;
37 		int preferredPlatformIndex = -1;
38 		bool allowCpuOpenCL = false;
39 
40 		initCL();
41 	}
42 
~CompileBullet3PgsContactSolverKernels__anon9b35ceab0111::CompileBullet3PgsContactSolverKernels43 	virtual ~CompileBullet3PgsContactSolverKernels()
44 	{
45 		// You can do clean-up work that doesn't throw exceptions here.
46 		exitCL();
47 	}
48 
49 	// If the constructor and destructor are not enough for setting up
50 	// and cleaning up each test, you can define the following methods:
51 
52 #include "initCL.h"
53 
SetUp__anon9b35ceab0111::CompileBullet3PgsContactSolverKernels54 	virtual void SetUp()
55 	{
56 		// Code here will be called immediately after the constructor (right
57 		// before each test).
58 	}
59 
TearDown__anon9b35ceab0111::CompileBullet3PgsContactSolverKernels60 	virtual void TearDown()
61 	{
62 		// Code here will be called immediately after each test (right
63 		// before the destructor).
64 	}
65 };
66 
TEST_F(CompileBullet3PgsContactSolverKernels,solveFrictionCL)67 TEST_F(CompileBullet3PgsContactSolverKernels, solveFrictionCL)
68 {
69 	const char* additionalMacros = "";
70 	cl_int errNum = 0;
71 	cl_program solveFrictionProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext, m_clDevice, solveFrictionCL, &errNum, additionalMacros, 0, true);
72 	ASSERT_EQ(CL_SUCCESS, errNum);
73 
74 	{
75 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveFrictionCL, "BatchSolveKernelFriction", &errNum, solveFrictionProg, additionalMacros);
76 		ASSERT_EQ(CL_SUCCESS, errNum);
77 		ASSERT_FALSE(k == 0);
78 		clReleaseKernel(k);
79 	}
80 
81 	{
82 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveFrictionCL, "solveSingleFrictionKernel", &errNum, solveFrictionProg, additionalMacros);
83 		ASSERT_EQ(CL_SUCCESS, errNum);
84 		ASSERT_FALSE(k == 0);
85 		clReleaseKernel(k);
86 	}
87 	clReleaseProgram(solveFrictionProg);
88 }
89 
TEST_F(CompileBullet3PgsContactSolverKernels,solverSetupCL)90 TEST_F(CompileBullet3PgsContactSolverKernels, solverSetupCL)
91 {
92 	const char* additionalMacros = "";
93 	cl_int errNum = 0;
94 	cl_program solverSetupProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext, m_clDevice, solverSetupCL, &errNum, additionalMacros, 0, true);
95 	ASSERT_EQ(CL_SUCCESS, errNum);
96 
97 	{
98 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetupCL, "ContactToConstraintKernel", &errNum, solverSetupProg, additionalMacros);
99 		ASSERT_EQ(CL_SUCCESS, errNum);
100 		ASSERT_FALSE(k == 0);
101 		clReleaseKernel(k);
102 	}
103 
104 	clReleaseProgram(solverSetupProg);
105 }
106 
TEST_F(CompileBullet3PgsContactSolverKernels,solverSetup2CL)107 TEST_F(CompileBullet3PgsContactSolverKernels, solverSetup2CL)
108 {
109 	const char* additionalMacros = "";
110 	cl_int errNum = 0;
111 
112 	cl_program solverSetup2Prog = b3OpenCLUtils::compileCLProgramFromString(m_clContext, m_clDevice, solverSetup2CL, &errNum, additionalMacros, 0, true);
113 	ASSERT_EQ(CL_SUCCESS, errNum);
114 
115 	{
116 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "SetSortDataKernel", &errNum, solverSetup2Prog, additionalMacros);
117 		ASSERT_EQ(CL_SUCCESS, errNum);
118 		ASSERT_FALSE(k == 0);
119 		clReleaseKernel(k);
120 	}
121 
122 	{
123 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataBodyA", &errNum, solverSetup2Prog, additionalMacros);
124 		ASSERT_EQ(CL_SUCCESS, errNum);
125 		ASSERT_FALSE(k == 0);
126 		clReleaseKernel(k);
127 	}
128 
129 	{
130 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataBodyB", &errNum, solverSetup2Prog, additionalMacros);
131 		ASSERT_EQ(CL_SUCCESS, errNum);
132 		ASSERT_FALSE(k == 0);
133 		clReleaseKernel(k);
134 	}
135 
136 	{
137 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataChildShapeA", &errNum, solverSetup2Prog, additionalMacros);
138 		ASSERT_EQ(CL_SUCCESS, errNum);
139 		ASSERT_FALSE(k == 0);
140 		clReleaseKernel(k);
141 	}
142 
143 	{
144 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataChildShapeB", &errNum, solverSetup2Prog, additionalMacros);
145 		ASSERT_EQ(CL_SUCCESS, errNum);
146 		ASSERT_FALSE(k == 0);
147 		clReleaseKernel(k);
148 	}
149 
150 	{
151 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "ReorderContactKernel", &errNum, solverSetup2Prog, additionalMacros);
152 		ASSERT_EQ(CL_SUCCESS, errNum);
153 		ASSERT_FALSE(k == 0);
154 		clReleaseKernel(k);
155 	}
156 
157 	{
158 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "CopyConstraintKernel", &errNum, solverSetup2Prog, additionalMacros);
159 		ASSERT_EQ(CL_SUCCESS, errNum);
160 		ASSERT_FALSE(k == 0);
161 		clReleaseKernel(k);
162 	}
163 
164 	clReleaseProgram(solverSetup2Prog);
165 }
166 
TEST_F(CompileBullet3PgsContactSolverKernels,solveContactCL)167 TEST_F(CompileBullet3PgsContactSolverKernels, solveContactCL)
168 {
169 	const char* additionalMacros = "";
170 	cl_int errNum = 0;
171 
172 	cl_program solveContactProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext, m_clDevice, solveContactCL, &errNum, additionalMacros, 0, true);
173 	ASSERT_EQ(CL_SUCCESS, errNum);
174 
175 	{
176 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveContactCL, "BatchSolveKernelContact", &errNum, solveContactProg, additionalMacros);
177 		ASSERT_EQ(CL_SUCCESS, errNum);
178 		ASSERT_FALSE(k == 0);
179 		clReleaseKernel(k);
180 	}
181 
182 	{
183 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveContactCL, "solveSingleContactKernel", &errNum, solveContactProg, additionalMacros);
184 		ASSERT_EQ(CL_SUCCESS, errNum);
185 		ASSERT_FALSE(k == 0);
186 		clReleaseKernel(k);
187 	}
188 
189 	clReleaseProgram(solveContactProg);
190 }
191 
TEST_F(CompileBullet3PgsContactSolverKernels,batchingKernelsCL)192 TEST_F(CompileBullet3PgsContactSolverKernels, batchingKernelsCL)
193 {
194 	const char* additionalMacros = "";
195 	cl_int errNum = 0;
196 
197 	cl_program batchingProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext, m_clDevice, batchingKernelsCL, &errNum, additionalMacros, 0, true);
198 	ASSERT_EQ(CL_SUCCESS, errNum);
199 
200 	{
201 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, batchingKernelsCL, "CreateBatches", &errNum, batchingProg, additionalMacros);
202 		ASSERT_EQ(CL_SUCCESS, errNum);
203 		ASSERT_FALSE(k == 0);
204 		clReleaseKernel(k);
205 	}
206 
207 	clReleaseProgram(batchingProg);
208 }
209 
TEST_F(CompileBullet3PgsContactSolverKernels,batchingKernelsNewCL)210 TEST_F(CompileBullet3PgsContactSolverKernels, batchingKernelsNewCL)
211 {
212 	const char* additionalMacros = "";
213 	cl_int errNum = 0;
214 
215 	cl_program batchingNewProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext, m_clDevice, batchingKernelsNewCL, &errNum, additionalMacros, 0, true);
216 	ASSERT_EQ(CL_SUCCESS, errNum);
217 
218 	{
219 		cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, batchingKernelsNewCL, "CreateBatchesNew", &errNum, batchingNewProg, additionalMacros);
220 		ASSERT_EQ(CL_SUCCESS, errNum);
221 		ASSERT_FALSE(k == 0);
222 		clReleaseKernel(k);
223 	}
224 	clReleaseProgram(batchingNewProg);
225 }
226 
227 };  // namespace
228