253 lines
7.7 KiB
C++
253 lines
7.7 KiB
C++
|
|
#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/sapFastKernels.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;
|
|
|
|
|
|
initCL(preferredDeviceIndex, preferredPlatformIndex, allowCpuOpenCL);
|
|
}
|
|
|
|
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:
|
|
|
|
void initCL(int preferredDeviceIndex, int preferredPlatformIndex, bool allowCpuOpenCL)
|
|
{
|
|
void* glCtx=0;
|
|
void* glDC = 0;
|
|
|
|
|
|
|
|
int ciErrNum = 0;
|
|
|
|
cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
|
|
if (allowCpuOpenCL)
|
|
deviceType = CL_DEVICE_TYPE_ALL;
|
|
|
|
|
|
|
|
// if (useInterop)
|
|
// {
|
|
// m_data->m_clContext = b3OpenCLUtils::createContextFromType(deviceType, &ciErrNum, glCtx, glDC);
|
|
// } else
|
|
{
|
|
m_clContext = b3OpenCLUtils::createContextFromType(deviceType, &ciErrNum, 0,0,preferredDeviceIndex, preferredPlatformIndex,&m_platformId);
|
|
ASSERT_FALSE(m_clContext==0);
|
|
}
|
|
|
|
|
|
ASSERT_EQ(ciErrNum, CL_SUCCESS);
|
|
|
|
int numDev = b3OpenCLUtils::getNumDevices(m_clContext);
|
|
EXPECT_GT(numDev,0);
|
|
|
|
if (numDev>0)
|
|
{
|
|
m_clDevice= b3OpenCLUtils::getDevice(m_clContext,0);
|
|
ASSERT_FALSE(m_clDevice==0);
|
|
|
|
m_clQueue = clCreateCommandQueue(m_clContext, m_clDevice, 0, &ciErrNum);
|
|
ASSERT_FALSE(m_clQueue==0);
|
|
|
|
ASSERT_EQ(ciErrNum, CL_SUCCESS);
|
|
|
|
|
|
b3OpenCLDeviceInfo info;
|
|
b3OpenCLUtils::getDeviceInfo(m_clDevice,&info);
|
|
m_clDeviceName = info.m_deviceName;
|
|
}
|
|
}
|
|
|
|
void exitCL()
|
|
{
|
|
clReleaseCommandQueue(m_clQueue);
|
|
clReleaseContext(m_clContext);
|
|
}
|
|
|
|
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,sapFastKernels)
|
|
{
|
|
cl_int errNum=0;
|
|
|
|
cl_program sapFastProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,sapFastCL,&errNum,"",0,true);
|
|
|
|
{
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapFastCL, "computePairsKernelLocalSharedMemoryBatchWrite",&errNum,sapFastProg );
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
ASSERT_FALSE(k==0);
|
|
clReleaseKernel(k);
|
|
}
|
|
{
|
|
cl_kernel k= b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapFastCL, "computePairsIncremental3dSapKernel",&errNum,sapFastProg );
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
ASSERT_FALSE(k==0);
|
|
clReleaseKernel(k);
|
|
}
|
|
|
|
{
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapFastCL, "computePairsKernelLocalSharedMemoryBatchWrite",&errNum,sapFastProg );
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
ASSERT_FALSE(k==0);
|
|
clReleaseKernel(k);
|
|
}
|
|
|
|
{
|
|
cl_kernel m_computePairsIncremental3dSapKernel= b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapFastCL, "computePairsIncremental3dSapKernel",&errNum,sapFastProg );
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
ASSERT_FALSE(m_computePairsIncremental3dSapKernel==0);
|
|
clReleaseKernel(m_computePairsIncremental3dSapKernel);
|
|
}
|
|
|
|
clReleaseProgram(sapFastProg);
|
|
|
|
}
|
|
|
|
TEST_F(CompileBullet3BroadphaseKernels,sapKernels)
|
|
{
|
|
cl_int errNum=0;
|
|
cl_program sapProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,sapCL,&errNum,"",0,true);
|
|
{
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
cl_kernel copyAabbsKernel= b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "copyAabbsKernel",&errNum,sapProg );
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
ASSERT_FALSE(copyAabbsKernel==0);
|
|
clReleaseKernel(copyAabbsKernel);
|
|
}
|
|
{
|
|
cl_kernel sap2Kernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "computePairsKernelTwoArrays",&errNum,sapProg );
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
ASSERT_FALSE(sap2Kernel==0);
|
|
clReleaseKernel(sap2Kernel);
|
|
}
|
|
{
|
|
cl_kernel sapKernelBruteForce = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "computePairsKernelBruteForce",&errNum,sapProg );
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
ASSERT_FALSE(sapKernelBruteForce==0);
|
|
clReleaseKernel(sapKernelBruteForce);
|
|
}
|
|
{
|
|
cl_kernel sapKernelOriginal = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "computePairsKernelOriginal",&errNum,sapProg );
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
ASSERT_FALSE(sapKernelOriginal==0);
|
|
clReleaseKernel(sapKernelOriginal);
|
|
}
|
|
|
|
{
|
|
cl_kernel sapKernelBarrier = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "computePairsKernelBarrier",&errNum,sapProg );
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
ASSERT_FALSE(sapKernelBarrier==0);
|
|
clReleaseKernel(sapKernelBarrier);
|
|
}
|
|
{
|
|
cl_kernel sapKernelLocalShared = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "computePairsKernelLocalSharedMemory",&errNum,sapProg );
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
ASSERT_FALSE(sapKernelLocalShared==0);
|
|
clReleaseKernel(sapKernelLocalShared);
|
|
}
|
|
{
|
|
cl_kernel prepareSumVarianceKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "prepareSumVarianceKernel",&errNum,sapProg );
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
ASSERT_FALSE(prepareSumVarianceKernel==0);
|
|
clReleaseKernel(prepareSumVarianceKernel);
|
|
}
|
|
{
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "flipFloatKernel",&errNum,sapProg );
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
ASSERT_FALSE(k==0);
|
|
clReleaseKernel(k);
|
|
}
|
|
{
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,sapCL, "scatterKernel",&errNum,sapProg );
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
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);
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
|
|
{
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,gridBroadphaseCL, "kCalcHashAABB",&errNum,gridProg);
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
clReleaseKernel(k);
|
|
}
|
|
{
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,gridBroadphaseCL, "kClearCellStart",&errNum,gridProg);
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
clReleaseKernel(k);
|
|
}
|
|
|
|
{
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,gridBroadphaseCL, "kFindCellStart",&errNum,gridProg);
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
clReleaseKernel(k);
|
|
}
|
|
|
|
{
|
|
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,gridBroadphaseCL, "kFindOverlappingPairs",&errNum,gridProg);
|
|
ASSERT_EQ(errNum,CL_SUCCESS);
|
|
clReleaseKernel(k);
|
|
}
|
|
|
|
clReleaseProgram(gridProg);
|
|
}
|
|
};
|