From 863ac2c47794708c85811eabb7abbedfd5ca309e Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Fri, 31 Jan 2014 20:41:13 -0800 Subject: [PATCH] add unit tests for OpenCL kernel compilation for all Bullet 3 kernels (using GoogleTest) --- .../testCompileBullet3BroadphaseKernels.cpp | 252 ++++++++++++++ ...mpileBullet3IntegrateUpdateAabbKernels.cpp | 159 +++++++++ ...mpileBullet3JacobiContactSolverKernels.cpp | 178 ++++++++++ .../testCompileBullet3NarrowphaseKernels.cpp | 323 ++++++++++++++++++ ...tCompileBullet3PgsContactSolverKernels.cpp | 289 ++++++++++++++++ ...estCompileBullet3PgsJointSolverKernels.cpp | 173 ++++++++++ .../testCompileBullet3RaycastKernels.cpp | 131 +++++++ .../OpenCL/BasicInitialize/testInitOpenCL.cpp | 116 +++++++ build3/premake4.lua | 6 +- src/Bullet3Common/b3CommandLineArgs.h | 5 +- .../b3GpuGridBroadphase.cpp | 2 +- .../b3ConvexHullContact.cpp | 16 +- 12 files changed, 1638 insertions(+), 12 deletions(-) create mode 100644 Test/OpenCL/AllBullet3Kernels/testCompileBullet3BroadphaseKernels.cpp create mode 100644 Test/OpenCL/AllBullet3Kernels/testCompileBullet3IntegrateUpdateAabbKernels.cpp create mode 100644 Test/OpenCL/AllBullet3Kernels/testCompileBullet3JacobiContactSolverKernels.cpp create mode 100644 Test/OpenCL/AllBullet3Kernels/testCompileBullet3NarrowphaseKernels.cpp create mode 100644 Test/OpenCL/AllBullet3Kernels/testCompileBullet3PgsContactSolverKernels.cpp create mode 100644 Test/OpenCL/AllBullet3Kernels/testCompileBullet3PgsJointSolverKernels.cpp create mode 100644 Test/OpenCL/AllBullet3Kernels/testCompileBullet3RaycastKernels.cpp create mode 100644 Test/OpenCL/BasicInitialize/testInitOpenCL.cpp diff --git a/Test/OpenCL/AllBullet3Kernels/testCompileBullet3BroadphaseKernels.cpp b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3BroadphaseKernels.cpp new file mode 100644 index 000000000..66fec170b --- /dev/null +++ b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3BroadphaseKernels.cpp @@ -0,0 +1,252 @@ + +#include +#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); + } +}; diff --git a/Test/OpenCL/AllBullet3Kernels/testCompileBullet3IntegrateUpdateAabbKernels.cpp b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3IntegrateUpdateAabbKernels.cpp new file mode 100644 index 000000000..63396191d --- /dev/null +++ b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3IntegrateUpdateAabbKernels.cpp @@ -0,0 +1,159 @@ + +#include +#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); + } + +}; diff --git a/Test/OpenCL/AllBullet3Kernels/testCompileBullet3JacobiContactSolverKernels.cpp b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3JacobiContactSolverKernels.cpp new file mode 100644 index 000000000..175597f7a --- /dev/null +++ b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3JacobiContactSolverKernels.cpp @@ -0,0 +1,178 @@ + +#include +#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); + + } +}; diff --git a/Test/OpenCL/AllBullet3Kernels/testCompileBullet3NarrowphaseKernels.cpp b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3NarrowphaseKernels.cpp new file mode 100644 index 000000000..f8044dac4 --- /dev/null +++ b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3NarrowphaseKernels.cpp @@ -0,0 +1,323 @@ + +#include +#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); + } + + +}; diff --git a/Test/OpenCL/AllBullet3Kernels/testCompileBullet3PgsContactSolverKernels.cpp b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3PgsContactSolverKernels.cpp new file mode 100644 index 000000000..562902077 --- /dev/null +++ b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3PgsContactSolverKernels.cpp @@ -0,0 +1,289 @@ + +#include +#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); + } + +}; diff --git a/Test/OpenCL/AllBullet3Kernels/testCompileBullet3PgsJointSolverKernels.cpp b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3PgsJointSolverKernels.cpp new file mode 100644 index 000000000..f9dfeef22 --- /dev/null +++ b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3PgsJointSolverKernels.cpp @@ -0,0 +1,173 @@ + +#include +#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); + + } +}; diff --git a/Test/OpenCL/AllBullet3Kernels/testCompileBullet3RaycastKernels.cpp b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3RaycastKernels.cpp new file mode 100644 index 000000000..7e80dda33 --- /dev/null +++ b/Test/OpenCL/AllBullet3Kernels/testCompileBullet3RaycastKernels.cpp @@ -0,0 +1,131 @@ + +#include +#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); + } +}; diff --git a/Test/OpenCL/BasicInitialize/testInitOpenCL.cpp b/Test/OpenCL/BasicInitialize/testInitOpenCL.cpp new file mode 100644 index 000000000..37424d5f4 --- /dev/null +++ b/Test/OpenCL/BasicInitialize/testInitOpenCL.cpp @@ -0,0 +1,116 @@ + +#include +#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 -void b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val) +inline void b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val) { using namespace std; map::iterator itr; @@ -74,7 +74,7 @@ void b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val) } template <> -void b3CommandLineArgs::GetCmdLineArgument(const char* arg_name, char* &val) +inline void b3CommandLineArgs::GetCmdLineArgument(const char* arg_name, char* &val) { using namespace std; map::iterator itr; @@ -89,4 +89,5 @@ void b3CommandLineArgs::GetCmdLineArgument(const char* arg_name, char* &v } } + #endif //COMMAND_LINE_ARGS_H diff --git a/src/Bullet3OpenCL/BroadphaseCollision/b3GpuGridBroadphase.cpp b/src/Bullet3OpenCL/BroadphaseCollision/b3GpuGridBroadphase.cpp index bedd8d4d6..f5308ecf4 100644 --- a/src/Bullet3OpenCL/BroadphaseCollision/b3GpuGridBroadphase.cpp +++ b/src/Bullet3OpenCL/BroadphaseCollision/b3GpuGridBroadphase.cpp @@ -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); diff --git a/src/Bullet3OpenCL/NarrowphaseCollision/b3ConvexHullContact.cpp b/src/Bullet3OpenCL/NarrowphaseCollision/b3ConvexHullContact.cpp index 3ff077da0..4ca3a4dcb 100644 --- a/src/Bullet3OpenCL/NarrowphaseCollision/b3ConvexHullContact.cpp +++ b/src/Bullet3OpenCL/NarrowphaseCollision/b3ConvexHullContact.cpp @@ -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); }