2014-02-01 04:41:13 +00:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "Bullet3Common/b3Logging.h"
|
|
|
|
#include "Bullet3Common/b3CommandLineArgs.h"
|
|
|
|
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
|
|
|
|
#include "Bullet3OpenCL/BroadphaseCollision/kernels/sapKernels.h"
|
|
|
|
#include "Bullet3OpenCL/BroadphaseCollision/kernels/gridBroadphaseKernels.h"
|
|
|
|
|
|
|
|
extern int gArgc;
|
|
|
|
extern char** gArgv;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
struct CompileBullet3BroadphaseKernels : public ::testing::Test
|
|
|
|
{
|
|
|
|
cl_context m_clContext;
|
|
|
|
cl_device_id m_clDevice;
|
|
|
|
cl_command_queue m_clQueue;
|
|
|
|
char* m_clDeviceName;
|
|
|
|
cl_platform_id m_platformId;
|
|
|
|
|
|
|
|
CompileBullet3BroadphaseKernels()
|
|
|
|
:m_clDeviceName(0),
|
|
|
|
m_clContext(0),
|
|
|
|
m_clDevice(0),
|
|
|
|
m_clQueue(0),
|
|
|
|
m_platformId(0)
|
|
|
|
{
|
|
|
|
// You can do set-up work for each test here.
|
|
|
|
b3CommandLineArgs args(gArgc,gArgv);
|
|
|
|
int preferredDeviceIndex=-1;
|
|
|
|
int preferredPlatformIndex = -1;
|
|
|
|
bool allowCpuOpenCL = false;
|
|
|
|
|
|
|
|
|
2014-02-11 18:33:00 +00:00
|
|
|
initCL();
|
2014-02-01 04:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~CompileBullet3BroadphaseKernels()
|
|
|
|
{
|
|
|
|
// You can do clean-up work that doesn't throw exceptions here.
|
|
|
|
exitCL();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the constructor and destructor are not enough for setting up
|
|
|
|
// and cleaning up each test, you can define the following methods:
|
|
|
|
|
2014-02-11 18:33:00 +00:00
|
|
|
#include "initCL.h"
|
2014-02-01 04:41:13 +00:00
|
|
|
|
2014-02-11 18:33:00 +00:00
|
|
|
|
2014-02-01 04:41:13 +00:00
|
|
|
|
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// Code here will be called immediately after the constructor (right
|
|
|
|
// before each test).
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void TearDown()
|
|
|
|
{
|
|
|
|
// Code here will be called immediately after each test (right
|
|
|
|
// before the destructor).
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CompileBullet3BroadphaseKernels,sapKernels)
|
|
|
|
{
|
|
|
|
cl_int errNum=0;
|
|
|
|
cl_program sapProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,sapCL,&errNum,"",0,true);
|
|
|
|
{
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum );
|
2014-02-01 04:41:13 +00:00
|
|
|
cl_kernel copyAabbsKernel= b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "copyAabbsKernel",&errNum,sapProg );
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
ASSERT_FALSE(copyAabbsKernel==0);
|
|
|
|
clReleaseKernel(copyAabbsKernel);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
cl_kernel sap2Kernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "computePairsKernelTwoArrays",&errNum,sapProg );
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
ASSERT_FALSE(sap2Kernel==0);
|
|
|
|
clReleaseKernel(sap2Kernel);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
cl_kernel sapKernelBruteForce = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "computePairsKernelBruteForce",&errNum,sapProg );
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
ASSERT_FALSE(sapKernelBruteForce==0);
|
|
|
|
clReleaseKernel(sapKernelBruteForce);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
cl_kernel sapKernelOriginal = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "computePairsKernelOriginal",&errNum,sapProg );
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
ASSERT_FALSE(sapKernelOriginal==0);
|
|
|
|
clReleaseKernel(sapKernelOriginal);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
cl_kernel sapKernelBarrier = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "computePairsKernelBarrier",&errNum,sapProg );
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
ASSERT_FALSE(sapKernelBarrier==0);
|
|
|
|
clReleaseKernel(sapKernelBarrier);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
cl_kernel sapKernelLocalShared = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "computePairsKernelLocalSharedMemory",&errNum,sapProg );
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
ASSERT_FALSE(sapKernelLocalShared==0);
|
|
|
|
clReleaseKernel(sapKernelLocalShared);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
cl_kernel prepareSumVarianceKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "prepareSumVarianceKernel",&errNum,sapProg );
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
ASSERT_FALSE(prepareSumVarianceKernel==0);
|
|
|
|
clReleaseKernel(prepareSumVarianceKernel);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "flipFloatKernel",&errNum,sapProg );
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
ASSERT_FALSE(k==0);
|
|
|
|
clReleaseKernel(k);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "scatterKernel",&errNum,sapProg );
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
ASSERT_FALSE(k==0);
|
|
|
|
clReleaseKernel(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
clReleaseProgram(sapProg);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CompileBullet3BroadphaseKernels,gridBroadphaseKernels)
|
|
|
|
{
|
|
|
|
cl_int errNum=0;
|
|
|
|
cl_program gridProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,gridBroadphaseCL,&errNum,"",0,true);
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,gridBroadphaseCL, "kCalcHashAABB",&errNum,gridProg);
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
clReleaseKernel(k);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,gridBroadphaseCL, "kClearCellStart",&errNum,gridProg);
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
clReleaseKernel(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,gridBroadphaseCL, "kFindCellStart",&errNum,gridProg);
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
clReleaseKernel(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,gridBroadphaseCL, "kFindOverlappingPairs",&errNum,gridProg);
|
2014-08-12 19:18:32 +00:00
|
|
|
ASSERT_EQ(CL_SUCCESS,errNum);
|
2014-02-01 04:41:13 +00:00
|
|
|
clReleaseKernel(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
clReleaseProgram(gridProg);
|
|
|
|
}
|
|
|
|
};
|