add unit tests for OpenCL kernel compilation for all Bullet 3 kernels (using GoogleTest)

This commit is contained in:
erwincoumans 2014-01-31 20:41:13 -08:00
parent d37a40caf1
commit 863ac2c477
12 changed files with 1638 additions and 12 deletions

View File

@ -0,0 +1,252 @@
#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);
}
};

View File

@ -0,0 +1,159 @@
#include <gtest/gtest.h>
#include "Bullet3Common/b3Logging.h"
#include "Bullet3Common/b3CommandLineArgs.h"
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
#include "Bullet3OpenCL/RigidBody/kernels/integrateKernel.h"
#include "Bullet3OpenCL/RigidBody/kernels/updateAabbsKernel.h"
extern int gArgc;
extern char** gArgv;
namespace
{
struct testCompileBullet3IntegrateUpdateAabbKernels : 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;
testCompileBullet3IntegrateUpdateAabbKernels()
: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 ~testCompileBullet3IntegrateUpdateAabbKernels()
{
// 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(testCompileBullet3IntegrateUpdateAabbKernels,integrateKernelCL)
{
cl_int errNum=0;
cl_program prog = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,integrateKernelCL,&errNum,"",0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,integrateKernelCL, "integrateTransformsKernel",&errNum,prog);
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(prog);
}
TEST_F(testCompileBullet3IntegrateUpdateAabbKernels,updateAabbsKernelCL)
{
cl_int errNum=0;
cl_program prog = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,updateAabbsKernelCL,&errNum,"",0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,updateAabbsKernelCL, "initializeGpuAabbsFull",&errNum,prog);
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,updateAabbsKernelCL, "clearOverlappingPairsKernel",&errNum,prog);
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(prog);
}
};

View File

@ -0,0 +1,178 @@
#include <gtest/gtest.h>
#include "Bullet3Common/b3Logging.h"
#include "Bullet3Common/b3CommandLineArgs.h"
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
#include "Bullet3OpenCL/RigidBody/kernels/solverUtils.h"
extern int gArgc;
extern char** gArgv;
namespace
{
struct CompileBullet3JacobiContactSolverKernels : 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;
CompileBullet3JacobiContactSolverKernels()
: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 ~CompileBullet3JacobiContactSolverKernels()
{
// 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(CompileBullet3JacobiContactSolverKernels,jacobiContactKernels)
{
cl_int errNum=0;
const char* additionalMacros="";
cl_program solverUtilsProg= b3OpenCLUtils::compileCLProgramFromString( m_clContext, m_clDevice, solverUtilsCL, &errNum,additionalMacros, 0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "CountBodiesKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "ContactToConstraintSplitKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "ClearVelocitiesKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "AverageVelocitiesKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "UpdateBodyVelocitiesKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "SolveContactJacobiKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "SolveFrictionJacobiKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(solverUtilsProg);
}
};

View File

@ -0,0 +1,323 @@
#include <gtest/gtest.h>
#include "Bullet3Common/b3Logging.h"
#include "Bullet3Common/b3CommandLineArgs.h"
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
#include "Bullet3OpenCL/NarrowphaseCollision/kernels/satKernels.h"
#include "Bullet3OpenCL/NarrowphaseCollision/kernels/mprKernels.h"
#include "Bullet3OpenCL/NarrowphaseCollision/kernels/satConcaveKernels.h"
#include "Bullet3OpenCL/NarrowphaseCollision/kernels/satClipHullContacts.h"
#include "Bullet3OpenCL/NarrowphaseCollision/kernels/bvhTraversal.h"
#include "Bullet3OpenCL/NarrowphaseCollision/kernels/primitiveContacts.h"
extern int gArgc;
extern char** gArgv;
namespace
{
struct CompileBullet3NarrowphaseKernels : 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;
CompileBullet3NarrowphaseKernels()
: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 ~CompileBullet3NarrowphaseKernels()
{
// 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(CompileBullet3NarrowphaseKernels,satKernelsCL)
{
cl_int errNum=0;
char flags[1024]={0};
cl_program satProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,satKernelsCL,&errNum,flags,0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel m_findSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findSeparatingAxisKernel",&errNum,satProg );
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(m_findSeparatingAxisKernel );
}
{
cl_kernel m_findSeparatingAxisVertexFaceKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findSeparatingAxisVertexFaceKernel",&errNum,satProg );
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(m_findSeparatingAxisVertexFaceKernel);
}
{
cl_kernel m_findSeparatingAxisEdgeEdgeKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findSeparatingAxisEdgeEdgeKernel",&errNum,satProg );
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(m_findSeparatingAxisEdgeEdgeKernel);
}
{
cl_kernel m_findConcaveSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findConcaveSeparatingAxisKernel",&errNum,satProg );
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(m_findConcaveSeparatingAxisKernel );
}
{
cl_kernel m_findCompoundPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findCompoundPairsKernel",&errNum,satProg );
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(m_findCompoundPairsKernel);
}
{
cl_kernel m_processCompoundPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "processCompoundPairsKernel",&errNum,satProg );
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(m_processCompoundPairsKernel);
}
clReleaseProgram(satProg);
}
TEST_F(CompileBullet3NarrowphaseKernels,satConcaveKernelsCL)
{
cl_int errNum=0;
char flags[1024]={0};
cl_program satConcaveProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,satConcaveKernelsCL,&errNum,flags,0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel m_findConcaveSeparatingAxisVertexFaceKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satConcaveKernelsCL, "findConcaveSeparatingAxisVertexFaceKernel",&errNum,satConcaveProg );
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(m_findConcaveSeparatingAxisVertexFaceKernel);
}
{
cl_kernel m_findConcaveSeparatingAxisEdgeEdgeKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satConcaveKernelsCL, "findConcaveSeparatingAxisEdgeEdgeKernel",&errNum,satConcaveProg );
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(m_findConcaveSeparatingAxisEdgeEdgeKernel);
}
clReleaseProgram(satConcaveProg);
}
TEST_F(CompileBullet3NarrowphaseKernels,satClipKernelsCL)
{
char flags[1024]={0};
cl_int errNum=0;
//#ifdef CL_PLATFORM_INTEL
// sprintf(flags,"-g -s \"%s\"","C:/develop/bullet3_experiments2/opencl/gpu_narrowphase/kernels/satClipHullContacts.cl");
//#endif
cl_program satClipContactsProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,satClipKernelsCL,&errNum,flags,0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel m_clipHullHullKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "clipHullHullKernel",&errNum,satClipContactsProg);
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(m_clipHullHullKernel);
}
{
cl_kernel m_clipCompoundsHullHullKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "clipCompoundsHullHullKernel",&errNum,satClipContactsProg);
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(m_clipCompoundsHullHullKernel);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "findClippingFacesKernel",&errNum,satClipContactsProg);
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "clipFacesAndFindContactsKernel",&errNum,satClipContactsProg);
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "clipHullHullConcaveConvexKernel",&errNum,satClipContactsProg);
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL,
"newContactReductionKernel",&errNum,satClipContactsProg);
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(k);
}
clReleaseProgram(satClipContactsProg);
}
TEST_F(CompileBullet3NarrowphaseKernels,bvhTraversalKernels)
{
cl_int errNum=0;
cl_program bvhTraversalProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,bvhTraversalKernelCL,&errNum,"",0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,bvhTraversalKernelCL, "bvhTraversalKernel",&errNum,bvhTraversalProg,"");
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(k);
}
clReleaseProgram(bvhTraversalProg);
}
TEST_F(CompileBullet3NarrowphaseKernels,primitiveContactsKernelsCL)
{
cl_int errNum=0;
cl_program primitiveContactsProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,primitiveContactsKernelsCL,&errNum,"",0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,primitiveContactsKernelsCL, "primitiveContactsKernel",&errNum,primitiveContactsProg,"");
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,primitiveContactsKernelsCL, "findConcaveSphereContactsKernel",&errNum,primitiveContactsProg );
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,primitiveContactsKernelsCL, "processCompoundPairsPrimitivesKernel",&errNum,primitiveContactsProg,"");
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(k);
}
clReleaseProgram(primitiveContactsProg);
}
TEST_F(CompileBullet3NarrowphaseKernels,mprKernelsCL)
{
cl_int errNum=0;
const char* srcConcave = satConcaveKernelsCL;
char flags[1024]={0};
cl_program mprProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,mprKernelsCL,&errNum,flags,0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,mprKernelsCL, "mprPenetrationKernel",&errNum,mprProg );
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,mprKernelsCL, "findSeparatingAxisUnitSphereKernel",&errNum,mprProg );
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(k);
}
clReleaseProgram(mprProg);
}
};

View File

@ -0,0 +1,289 @@
#include <gtest/gtest.h>
#include "Bullet3Common/b3Logging.h"
#include "Bullet3Common/b3CommandLineArgs.h"
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
#include "Bullet3OpenCL/RigidBody/kernels/solverSetup.h"
#include "Bullet3OpenCL/RigidBody/kernels/solverSetup2.h"
#include "Bullet3OpenCL/RigidBody/kernels/solveContact.h"
#include "Bullet3OpenCL/RigidBody/kernels/solveFriction.h"
#include "Bullet3OpenCL/RigidBody/kernels/batchingKernels.h"
#include "Bullet3OpenCL/RigidBody/kernels/batchingKernelsNew.h"
extern int gArgc;
extern char** gArgv;
namespace
{
struct CompileBullet3PgsContactSolverKernels : 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;
CompileBullet3PgsContactSolverKernels()
: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 ~CompileBullet3PgsContactSolverKernels()
{
// 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(CompileBullet3PgsContactSolverKernels,solveFrictionCL)
{
const char* additionalMacros="";
cl_int errNum=0;
cl_program solveFrictionProg= b3OpenCLUtils::compileCLProgramFromString( m_clContext, m_clDevice, solveFrictionCL, &errNum,additionalMacros, 0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solveFrictionCL, "BatchSolveKernelFriction", &errNum, solveFrictionProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k =b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solveFrictionCL, "solveSingleFrictionKernel", &errNum, solveFrictionProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(solveFrictionProg);
}
TEST_F(CompileBullet3PgsContactSolverKernels,solverSetupCL)
{
const char* additionalMacros="";
cl_int errNum=0;
cl_program solverSetupProg= b3OpenCLUtils::compileCLProgramFromString( m_clContext, m_clDevice, solverSetupCL, &errNum,additionalMacros, 0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetupCL, "ContactToConstraintKernel", &errNum, solverSetupProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(solverSetupProg);
}
TEST_F(CompileBullet3PgsContactSolverKernels,solverSetup2CL)
{
const char* additionalMacros="";
cl_int errNum=0;
cl_program solverSetup2Prog= b3OpenCLUtils::compileCLProgramFromString( m_clContext, m_clDevice, solverSetup2CL, &errNum,additionalMacros, 0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "SetSortDataKernel", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataBodyA", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataBodyB", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataChildShapeA", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataChildShapeB", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "ReorderContactKernel", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "CopyConstraintKernel", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(solverSetup2Prog);
}
TEST_F(CompileBullet3PgsContactSolverKernels,solveContactCL)
{
const char* additionalMacros="";
cl_int errNum=0;
cl_program solveContactProg= b3OpenCLUtils::compileCLProgramFromString( m_clContext, m_clDevice, solveContactCL, &errNum,additionalMacros, 0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solveContactCL, "BatchSolveKernelContact", &errNum, solveContactProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solveContactCL, "solveSingleContactKernel", &errNum, solveContactProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(solveContactProg);
}
TEST_F(CompileBullet3PgsContactSolverKernels,batchingKernelsCL)
{
const char* additionalMacros="";
cl_int errNum=0;
cl_program batchingProg = b3OpenCLUtils::compileCLProgramFromString( m_clContext, m_clDevice, batchingKernelsCL, &errNum,additionalMacros, 0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, batchingKernelsCL, "CreateBatches", &errNum, batchingProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(batchingProg);
}
TEST_F(CompileBullet3PgsContactSolverKernels,batchingKernelsNewCL)
{
const char* additionalMacros="";
cl_int errNum=0;
cl_program batchingNewProg = b3OpenCLUtils::compileCLProgramFromString( m_clContext, m_clDevice, batchingKernelsNewCL, &errNum,additionalMacros, 0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, batchingKernelsNewCL, "CreateBatchesNew", &errNum, batchingNewProg,additionalMacros );
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(batchingNewProg);
}
};

View File

@ -0,0 +1,173 @@
#include <gtest/gtest.h>
#include "Bullet3Common/b3Logging.h"
#include "Bullet3Common/b3CommandLineArgs.h"
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
#include "Bullet3OpenCL/RigidBody/kernels/jointSolver.h"
extern int gArgc;
extern char** gArgv;
namespace
{
struct testCompileBullet3PgsJointSolverKernels : 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;
testCompileBullet3PgsJointSolverKernels()
: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 ~testCompileBullet3PgsJointSolverKernels()
{
// 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(testCompileBullet3PgsJointSolverKernels,solveConstraintRowsCL)
{
cl_int errNum=0;
cl_program prog = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,solveConstraintRowsCL,&errNum,"",0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,solveConstraintRowsCL, "solveJointConstraintRows",&errNum,prog);
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext,m_clDevice,solveConstraintRowsCL,"initSolverBodies",&errNum,prog);
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext,m_clDevice,solveConstraintRowsCL,"getInfo1Kernel",&errNum,prog);
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext,m_clDevice,solveConstraintRowsCL,"initBatchConstraintsKernel",&errNum,prog);
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k= b3OpenCLUtils::compileCLKernelFromString(m_clContext,m_clDevice,solveConstraintRowsCL,"getInfo2Kernel",&errNum,prog);
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext,m_clDevice,solveConstraintRowsCL,"writeBackVelocitiesKernel",&errNum,prog);
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext,m_clDevice,solveConstraintRowsCL,"breakViolatedConstraintsKernel",&errNum,prog);
ASSERT_EQ(errNum,CL_SUCCESS);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(prog);
}
};

View File

@ -0,0 +1,131 @@
#include <gtest/gtest.h>
#include "Bullet3Common/b3Logging.h"
#include "Bullet3Common/b3CommandLineArgs.h"
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
#include "Bullet3OpenCL/Raycast/kernels/rayCastKernels.h"
extern int gArgc;
extern char** gArgv;
namespace
{
struct CompileBullet3RaycastKernels : 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;
CompileBullet3RaycastKernels()
: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 ~CompileBullet3RaycastKernels()
{
// 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(CompileBullet3RaycastKernels,sapFastKernels)
{
cl_int errNum=0;
cl_program prog = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,rayCastKernelCL,&errNum,"",0,true);
ASSERT_EQ(errNum,CL_SUCCESS);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,rayCastKernelCL, "rayCastKernel",&errNum,prog);
ASSERT_EQ(errNum,CL_SUCCESS);
clReleaseKernel(k);
}
clReleaseProgram(prog);
}
};

View File

@ -0,0 +1,116 @@
#include <gtest/gtest.h>
#include "Bullet3Common/b3Logging.h"
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
TEST(b3OpenCLUtils, getNumPlatforms)
{
int numPlatforms = b3OpenCLUtils::getNumPlatforms();
ASSERT_GT(numPlatforms,0);
}
TEST(b3OpenCLUtils, getSdkVendorName)
{
const char* vendorSDK = b3OpenCLUtils::getSdkVendorName();
b3Printf("getSdkVendorName=%s\n",vendorSDK);
ASSERT_FALSE(vendorSDK==NULL);
}
TEST(b3OpenCLUtils, getPlatformInfo)
{
int numPlatforms = b3OpenCLUtils::getNumPlatforms();
ASSERT_GT(numPlatforms,0);
b3Printf("Num Platforms = %d\n", numPlatforms);
for (int i=0;i<numPlatforms;i++)
{
cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
ASSERT_FALSE(platform==NULL);
b3OpenCLPlatformInfo platformInfo;
b3OpenCLUtils::getPlatformInfo(platform,&platformInfo);
ASSERT_FALSE(platformInfo.m_platformName==NULL);
ASSERT_FALSE(platformInfo.m_platformVendor==NULL);
ASSERT_FALSE(platformInfo.m_platformVersion==NULL);
}
}
TEST(b3OpenCLUtils, createContextFromPlatform)
{
int numPlatforms = b3OpenCLUtils::getNumPlatforms();
b3Printf("Num Platforms = %d\n", numPlatforms);
cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
int ciErrNum = 0;
for (int i=0;i<numPlatforms;i++)
{
cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
b3OpenCLPlatformInfo platformInfo;
b3OpenCLUtils::getPlatformInfo(platform,&platformInfo);
b3Printf("--------------------------------\n");
b3Printf("Platform info for platform nr %d:\n",i);
b3Printf(" CL_PLATFORM_VENDOR: \t\t\t%s\n",platformInfo.m_platformVendor);
b3Printf(" CL_PLATFORM_NAME: \t\t\t%s\n",platformInfo.m_platformName);
b3Printf(" CL_PLATFORM_VERSION: \t\t\t%s\n",platformInfo.m_platformVersion);
cl_context ctx = b3OpenCLUtils::createContextFromPlatform(platform,deviceType,&ciErrNum);
ASSERT_FALSE(ctx==0);
ASSERT_EQ(ciErrNum,CL_SUCCESS);
clReleaseContext(ctx);
}
}
TEST(b3OpenCLUtils, getDeviceAndQueue)
{
int numPlatforms = b3OpenCLUtils::getNumPlatforms();
b3Printf("Num Platforms = %d\n", numPlatforms);
cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
int ciErrNum = 0;
for (int i=0;i<numPlatforms;i++)
{
cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
b3OpenCLPlatformInfo platformInfo;
b3OpenCLUtils::getPlatformInfo(platform,&platformInfo);
b3Printf("--------------------------------\n");
b3Printf("Platform info for platform nr %d:\n",i);
b3Printf(" CL_PLATFORM_VENDOR: \t\t\t%s\n",platformInfo.m_platformVendor);
b3Printf(" CL_PLATFORM_NAME: \t\t\t%s\n",platformInfo.m_platformName);
b3Printf(" CL_PLATFORM_VERSION: \t\t\t%s\n",platformInfo.m_platformVersion);
cl_context ctx = b3OpenCLUtils::createContextFromPlatform(platform,deviceType,&ciErrNum);
ASSERT_FALSE(ctx==0);
ASSERT_EQ(ciErrNum,CL_SUCCESS);
int numDevices = b3OpenCLUtils::getNumDevices(ctx);
ASSERT_GT(numDevices,0);
b3Printf("Num Devices = %d\n", numDevices);
for (int j=0;j<numDevices;j++)
{
cl_device_id device = b3OpenCLUtils::getDevice(ctx,j);
b3OpenCLDeviceInfo devInfo;
b3OpenCLUtils::getDeviceInfo(device,&devInfo);
ASSERT_GT(devInfo.m_clockFrequency,0);
ASSERT_GT(devInfo.m_addressBits,0);
ASSERT_GT(devInfo.m_computeUnits,0);
ASSERT_GT(devInfo.m_constantBufferSize,0);
ASSERT_FALSE(devInfo.m_deviceName==NULL);
ASSERT_FALSE(devInfo.m_deviceVendor==NULL);
ASSERT_FALSE(devInfo.m_driverVersion==NULL);
ASSERT_GT(devInfo.m_globalMemSize,0);
b3OpenCLUtils::printDeviceInfo(device);
cl_command_queue q = clCreateCommandQueue(ctx, device, 0, &ciErrNum);
ASSERT_FALSE(q==0);
clReleaseCommandQueue(q);
q=0;
}
clReleaseContext(ctx);
}
}

View File

@ -89,8 +89,12 @@
language "C++"
-- include "../Test/gtest-1.7.0"
include "../Test/gtest-1.7.0"
-- include "../Test/hello_gtest"
include "../Test/TestBullet3OpenCL"
include "../Demos3/AllBullet2Demos"
include "../Demos3/GpuDemos"
-- include "../Demos3/CpuDemos"

View File

@ -63,7 +63,7 @@ public:
};
template <typename T>
void b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
inline void b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
{
using namespace std;
map<string, string>::iterator itr;
@ -74,7 +74,7 @@ void b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
}
template <>
void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &val)
inline void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &val)
{
using namespace std;
map<string, string>::iterator itr;
@ -89,4 +89,5 @@ void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &v
}
}
#endif //COMMAND_LINE_ARGS_H

View File

@ -70,7 +70,7 @@ m_cellStartGpu(ctx,q)
{
cl_program gridProg = b3OpenCLUtils::compileCLProgramFromString(m_context,m_device,0,&errNum,"",B3_GRID_BROADPHASE_PATH,true);
cl_program gridProg = b3OpenCLUtils::compileCLProgramFromString(m_context,m_device,gridBroadphaseCL,&errNum,"",B3_GRID_BROADPHASE_PATH);
b3Assert(errNum==CL_SUCCESS);
kCalcHashAABB = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,gridBroadphaseCL, "kCalcHashAABB",&errNum,gridProg);

View File

@ -128,7 +128,7 @@ m_unitSphereDirections(m_context,m_queue)
if (1)
{
const char* mprSrc = mprKernelsCL;
const char* src = satKernelsCL;
const char* srcConcave = satConcaveKernelsCL;
char flags[1024]={0};
//#ifdef CL_PLATFORM_INTEL
@ -156,25 +156,25 @@ m_unitSphereDirections(m_context,m_queue)
}
cl_program satProg = b3OpenCLUtils::compileCLProgramFromString(m_context,m_device,src,&errNum,flags,BT_NARROWPHASE_SAT_PATH);
cl_program satProg = b3OpenCLUtils::compileCLProgramFromString(m_context,m_device,satKernelsCL,&errNum,flags,BT_NARROWPHASE_SAT_PATH);
b3Assert(errNum==CL_SUCCESS);
cl_program satConcaveProg = b3OpenCLUtils::compileCLProgramFromString(m_context,m_device,srcConcave,&errNum,flags,BT_NARROWPHASE_SAT_CONCAVE_PATH);
b3Assert(errNum==CL_SUCCESS);
m_findSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,src, "findSeparatingAxisKernel",&errNum,satProg );
m_findSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,satKernelsCL, "findSeparatingAxisKernel",&errNum,satProg );
b3Assert(m_findSeparatingAxisKernel);
b3Assert(errNum==CL_SUCCESS);
m_findSeparatingAxisVertexFaceKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,src, "findSeparatingAxisVertexFaceKernel",&errNum,satProg );
m_findSeparatingAxisVertexFaceKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,satKernelsCL, "findSeparatingAxisVertexFaceKernel",&errNum,satProg );
b3Assert(m_findSeparatingAxisVertexFaceKernel);
m_findSeparatingAxisEdgeEdgeKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,src, "findSeparatingAxisEdgeEdgeKernel",&errNum,satProg );
m_findSeparatingAxisEdgeEdgeKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,satKernelsCL, "findSeparatingAxisEdgeEdgeKernel",&errNum,satProg );
b3Assert(m_findSeparatingAxisVertexFaceKernel);
m_findConcaveSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,src, "findConcaveSeparatingAxisKernel",&errNum,satProg );
m_findConcaveSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,satKernelsCL, "findConcaveSeparatingAxisKernel",&errNum,satProg );
b3Assert(m_findConcaveSeparatingAxisKernel);
b3Assert(errNum==CL_SUCCESS);
@ -189,10 +189,10 @@ m_unitSphereDirections(m_context,m_queue)
m_findCompoundPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,src, "findCompoundPairsKernel",&errNum,satProg );
m_findCompoundPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,satKernelsCL, "findCompoundPairsKernel",&errNum,satProg );
b3Assert(m_findCompoundPairsKernel);
b3Assert(errNum==CL_SUCCESS);
m_processCompoundPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,src, "processCompoundPairsKernel",&errNum,satProg );
m_processCompoundPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_context, m_device,satKernelsCL, "processCompoundPairsKernel",&errNum,satProg );
b3Assert(m_processCompoundPairsKernel);
b3Assert(errNum==CL_SUCCESS);
}