Code-style consistency improvement:

Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files.
make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type.
This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
erwincoumans
2018-09-23 14:17:31 -07:00
parent b73b05e9fb
commit ab8f16961e
1773 changed files with 1081087 additions and 474249 deletions

View File

@@ -2,78 +2,67 @@
#ifndef INIT_CL_H
#define INIT_CL_H
void initCL()
{
{
int preferredDeviceIndex = -1;
int preferredPlatformIndex = -1;
bool allowCpuOpenCL = false;
int preferredDeviceIndex=-1;
int preferredPlatformIndex=-1;
bool allowCpuOpenCL=false;
b3CommandLineArgs args(gArgc, gArgv);
args.GetCmdLineArgument("cl_device", preferredDeviceIndex);
args.GetCmdLineArgument("cl_platform", preferredPlatformIndex);
allowCpuOpenCL = args.CheckCmdLineFlag("allow_opencl_cpu");
b3CommandLineArgs args(gArgc,gArgv);
args.GetCmdLineArgument("cl_device", preferredDeviceIndex);
args.GetCmdLineArgument("cl_platform", preferredPlatformIndex);
allowCpuOpenCL = args.CheckCmdLineFlag("allow_opencl_cpu");
void* glCtx=0;
void* glDC = 0;
int ciErrNum = 0;
void* glCtx = 0;
void* glDC = 0;
cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
if (allowCpuOpenCL)
deviceType = CL_DEVICE_TYPE_ALL;
int ciErrNum = 0;
// 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);
}
b3OpenCLPlatformInfo platformInfo;
b3OpenCLUtils::getPlatformInfo(m_platformId,&platformInfo);
b3Printf("OpenCL Platform Name %s\n", platformInfo.m_platformName);
b3Printf("OpenCL Platform Vendor %s\n", platformInfo.m_platformVendor);
b3Printf("OpenCL Platform Version %s\n", platformInfo.m_platformVersion);
ASSERT_EQ(ciErrNum, CL_SUCCESS);
int numDev = b3OpenCLUtils::getNumDevices(m_clContext);
EXPECT_GT(numDev,0);
cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
if (allowCpuOpenCL)
deviceType = CL_DEVICE_TYPE_ALL;
if (numDev>0)
{
m_clDevice= b3OpenCLUtils::getDevice(m_clContext,0);
ASSERT_FALSE(m_clDevice==0);
// 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);
}
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);
b3OpenCLUtils::printDeviceInfo(m_clDevice);
m_clDeviceName = info.m_deviceName;
}
}
b3OpenCLPlatformInfo platformInfo;
b3OpenCLUtils::getPlatformInfo(m_platformId, &platformInfo);
b3Printf("OpenCL Platform Name %s\n", platformInfo.m_platformName);
b3Printf("OpenCL Platform Vendor %s\n", platformInfo.m_platformVendor);
b3Printf("OpenCL Platform Version %s\n", platformInfo.m_platformVersion);
void exitCL()
{
clReleaseCommandQueue(m_clQueue);
clReleaseContext(m_clContext);
}
ASSERT_EQ(ciErrNum, CL_SUCCESS);
#endif //INIT_CL_H
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);
b3OpenCLUtils::printDeviceInfo(m_clDevice);
m_clDeviceName = info.m_deviceName;
}
}
void exitCL()
{
clReleaseCommandQueue(m_clQueue);
clReleaseContext(m_clContext);
}
#endif //INIT_CL_H

View File

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

View File

@@ -7,103 +7,96 @@
#include "Bullet3OpenCL/RigidBody/kernels/integrateKernel.h"
#include "Bullet3OpenCL/RigidBody/kernels/updateAabbsKernel.h"
extern int gArgc;
extern char** gArgv;
namespace
{
struct testCompileBullet3IntegrateUpdateAabbKernels : public ::testing::Test
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)
{
cl_context m_clContext;
cl_device_id m_clDevice;
cl_command_queue m_clQueue;
char* m_clDeviceName;
cl_platform_id m_platformId;
// You can do set-up work for each test here.
b3CommandLineArgs args(gArgc, gArgv);
int preferredDeviceIndex = -1;
int preferredPlatformIndex = -1;
bool allowCpuOpenCL = false;
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();
}
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:
#include "initCL.h"
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(CL_SUCCESS,errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,integrateKernelCL, "integrateTransformsKernel",&errNum,prog);
ASSERT_EQ(CL_SUCCESS,errNum);
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(CL_SUCCESS,errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,updateAabbsKernelCL, "initializeGpuAabbsFull",&errNum,prog);
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,updateAabbsKernelCL, "clearOverlappingPairsKernel",&errNum,prog);
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(prog);
initCL();
}
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:
#include "initCL.h"
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, integrateKernelCL, "integrateTransformsKernel", &errNum, prog);
ASSERT_EQ(CL_SUCCESS, errNum);
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, updateAabbsKernelCL, "initializeGpuAabbsFull", &errNum, prog);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, updateAabbsKernelCL, "clearOverlappingPairsKernel", &errNum, prog);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
clReleaseProgram(prog);
}
}; // namespace

View File

@@ -11,118 +11,110 @@ extern char** gArgv;
namespace
{
struct CompileBullet3JacobiContactSolverKernels : public ::testing::Test
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)
{
cl_context m_clContext;
cl_device_id m_clDevice;
cl_command_queue m_clQueue;
char* m_clDeviceName;
cl_platform_id m_platformId;
// You can do set-up work for each test here.
b3CommandLineArgs args(gArgc, gArgv);
int preferredDeviceIndex = -1;
int preferredPlatformIndex = -1;
bool allowCpuOpenCL = false;
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();
}
initCL();
}
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:
#include "initCL.h"
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)
virtual ~CompileBullet3JacobiContactSolverKernels()
{
// You can do clean-up work that doesn't throw exceptions here.
exitCL();
}
cl_int errNum=0;
const char* additionalMacros="";
cl_program solverUtilsProg= b3OpenCLUtils::compileCLProgramFromString( m_clContext, m_clDevice, solverUtilsCL, &errNum,additionalMacros, 0,true);
ASSERT_EQ(CL_SUCCESS,errNum);
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
#include "initCL.h"
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "CountBodiesKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
virtual void SetUp()
{
// Code here will be called immediately after the constructor (right
// before each test).
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "ContactToConstraintSplitKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "ClearVelocitiesKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "AverageVelocitiesKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "UpdateBodyVelocitiesKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "SolveContactJacobiKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverUtilsCL, "SolveFrictionJacobiKernel", &errNum, solverUtilsProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(solverUtilsProg);
}
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverUtilsCL, "CountBodiesKernel", &errNum, solverUtilsProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverUtilsCL, "ContactToConstraintSplitKernel", &errNum, solverUtilsProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverUtilsCL, "ClearVelocitiesKernel", &errNum, solverUtilsProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverUtilsCL, "AverageVelocitiesKernel", &errNum, solverUtilsProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverUtilsCL, "UpdateBodyVelocitiesKernel", &errNum, solverUtilsProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverUtilsCL, "SolveContactJacobiKernel", &errNum, solverUtilsProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverUtilsCL, "SolveFrictionJacobiKernel", &errNum, solverUtilsProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
clReleaseProgram(solverUtilsProg);
}
}; // namespace

View File

@@ -11,262 +11,244 @@
#include "Bullet3OpenCL/NarrowphaseCollision/kernels/bvhTraversal.h"
#include "Bullet3OpenCL/NarrowphaseCollision/kernels/primitiveContacts.h"
extern int gArgc;
extern char** gArgv;
namespace
{
struct CompileBullet3NarrowphaseKernels : public ::testing::Test
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)
{
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();
}
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:
#include "initCL.h"
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(CL_SUCCESS,errNum);
{
cl_kernel m_findSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findSeparatingAxisKernel",&errNum,satProg );
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_findSeparatingAxisKernel );
}
{
cl_kernel m_findSeparatingAxisVertexFaceKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findSeparatingAxisVertexFaceKernel",&errNum,satProg );
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_findSeparatingAxisVertexFaceKernel);
}
{
cl_kernel m_findSeparatingAxisEdgeEdgeKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findSeparatingAxisEdgeEdgeKernel",&errNum,satProg );
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_findSeparatingAxisEdgeEdgeKernel);
}
{
cl_kernel m_findConcaveSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findConcaveSeparatingAxisKernel",&errNum,satProg );
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_findConcaveSeparatingAxisKernel );
}
{
cl_kernel m_findCompoundPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "findCompoundPairsKernel",&errNum,satProg );
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_findCompoundPairsKernel);
}
{
cl_kernel m_processCompoundPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satKernelsCL, "processCompoundPairsKernel",&errNum,satProg );
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_processCompoundPairsKernel);
}
clReleaseProgram(satProg);
// You can do set-up work for each test here.
b3CommandLineArgs args(gArgc, gArgv);
int preferredDeviceIndex = -1;
int preferredPlatformIndex = -1;
bool allowCpuOpenCL = false;
initCL();
}
TEST_F(CompileBullet3NarrowphaseKernels,satConcaveKernelsCL)
virtual ~CompileBullet3NarrowphaseKernels()
{
cl_int errNum=0;
char flags[1024]={0};
cl_program satConcaveProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,satConcaveKernelsCL,&errNum,flags,0,true);
ASSERT_EQ(CL_SUCCESS,errNum);
{
cl_kernel m_findConcaveSeparatingAxisVertexFaceKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satConcaveKernelsCL, "findConcaveSeparatingAxisVertexFaceKernel",&errNum,satConcaveProg );
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_findConcaveSeparatingAxisVertexFaceKernel);
}
{
cl_kernel m_findConcaveSeparatingAxisEdgeEdgeKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satConcaveKernelsCL, "findConcaveSeparatingAxisEdgeEdgeKernel",&errNum,satConcaveProg );
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_findConcaveSeparatingAxisEdgeEdgeKernel);
}
clReleaseProgram(satConcaveProg);
// 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:
TEST_F(CompileBullet3NarrowphaseKernels,satClipKernelsCL)
#include "initCL.h"
virtual void SetUp()
{
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(CL_SUCCESS,errNum);
{
cl_kernel m_clipHullHullKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "clipHullHullKernel",&errNum,satClipContactsProg);
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_clipHullHullKernel);
}
{
cl_kernel m_clipCompoundsHullHullKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "clipCompoundsHullHullKernel",&errNum,satClipContactsProg);
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(m_clipCompoundsHullHullKernel);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "findClippingFacesKernel",&errNum,satClipContactsProg);
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "clipFacesAndFindContactsKernel",&errNum,satClipContactsProg);
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL, "clipHullHullConcaveConvexKernel",&errNum,satClipContactsProg);
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,satClipKernelsCL,
"newContactReductionKernel",&errNum,satClipContactsProg);
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k);
}
clReleaseProgram(satClipContactsProg);
// Code here will be called immediately after the constructor (right
// before each test).
}
TEST_F(CompileBullet3NarrowphaseKernels,bvhTraversalKernels)
virtual void TearDown()
{
cl_int errNum=0;
cl_program bvhTraversalProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,bvhTraversalKernelCL,&errNum,"",0,true);
ASSERT_EQ(CL_SUCCESS,errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,bvhTraversalKernelCL, "bvhTraversalKernel",&errNum,bvhTraversalProg,"");
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k);
}
clReleaseProgram(bvhTraversalProg);
// Code here will be called immediately after each test (right
// before the destructor).
}
TEST_F(CompileBullet3NarrowphaseKernels,primitiveContactsKernelsCL)
{
cl_int errNum=0;
cl_program primitiveContactsProg = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,primitiveContactsKernelsCL,&errNum,"",0,true);
ASSERT_EQ(CL_SUCCESS,errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,primitiveContactsKernelsCL, "primitiveContactsKernel",&errNum,primitiveContactsProg,"");
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,primitiveContactsKernelsCL, "findConcaveSphereContactsKernel",&errNum,primitiveContactsProg );
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,primitiveContactsKernelsCL, "processCompoundPairsPrimitivesKernel",&errNum,primitiveContactsProg,"");
ASSERT_EQ(CL_SUCCESS,errNum);
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(CL_SUCCESS,errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,mprKernelsCL, "mprPenetrationKernel",&errNum,mprProg );
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,mprKernelsCL, "findSeparatingAxisUnitSphereKernel",&errNum,mprProg );
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k);
}
clReleaseProgram(mprProg);
}
};
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(CL_SUCCESS, errNum);
{
cl_kernel m_findSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satKernelsCL, "findSeparatingAxisKernel", &errNum, satProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(m_findSeparatingAxisKernel);
}
{
cl_kernel m_findSeparatingAxisVertexFaceKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satKernelsCL, "findSeparatingAxisVertexFaceKernel", &errNum, satProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(m_findSeparatingAxisVertexFaceKernel);
}
{
cl_kernel m_findSeparatingAxisEdgeEdgeKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satKernelsCL, "findSeparatingAxisEdgeEdgeKernel", &errNum, satProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(m_findSeparatingAxisEdgeEdgeKernel);
}
{
cl_kernel m_findConcaveSeparatingAxisKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satKernelsCL, "findConcaveSeparatingAxisKernel", &errNum, satProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(m_findConcaveSeparatingAxisKernel);
}
{
cl_kernel m_findCompoundPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satKernelsCL, "findCompoundPairsKernel", &errNum, satProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(m_findCompoundPairsKernel);
}
{
cl_kernel m_processCompoundPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satKernelsCL, "processCompoundPairsKernel", &errNum, satProg);
ASSERT_EQ(CL_SUCCESS, errNum);
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(CL_SUCCESS, errNum);
{
cl_kernel m_findConcaveSeparatingAxisVertexFaceKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satConcaveKernelsCL, "findConcaveSeparatingAxisVertexFaceKernel", &errNum, satConcaveProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(m_findConcaveSeparatingAxisVertexFaceKernel);
}
{
cl_kernel m_findConcaveSeparatingAxisEdgeEdgeKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satConcaveKernelsCL, "findConcaveSeparatingAxisEdgeEdgeKernel", &errNum, satConcaveProg);
ASSERT_EQ(CL_SUCCESS, errNum);
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(CL_SUCCESS, errNum);
{
cl_kernel m_clipHullHullKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satClipKernelsCL, "clipHullHullKernel", &errNum, satClipContactsProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(m_clipHullHullKernel);
}
{
cl_kernel m_clipCompoundsHullHullKernel = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satClipKernelsCL, "clipCompoundsHullHullKernel", &errNum, satClipContactsProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(m_clipCompoundsHullHullKernel);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satClipKernelsCL, "findClippingFacesKernel", &errNum, satClipContactsProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satClipKernelsCL, "clipFacesAndFindContactsKernel", &errNum, satClipContactsProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satClipKernelsCL, "clipHullHullConcaveConvexKernel", &errNum, satClipContactsProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, satClipKernelsCL,
"newContactReductionKernel", &errNum, satClipContactsProg);
ASSERT_EQ(CL_SUCCESS, errNum);
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, bvhTraversalKernelCL, "bvhTraversalKernel", &errNum, bvhTraversalProg, "");
ASSERT_EQ(CL_SUCCESS, errNum);
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, primitiveContactsKernelsCL, "primitiveContactsKernel", &errNum, primitiveContactsProg, "");
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, primitiveContactsKernelsCL, "findConcaveSphereContactsKernel", &errNum, primitiveContactsProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, primitiveContactsKernelsCL, "processCompoundPairsPrimitivesKernel", &errNum, primitiveContactsProg, "");
ASSERT_EQ(CL_SUCCESS, errNum);
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, mprKernelsCL, "mprPenetrationKernel", &errNum, mprProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, mprKernelsCL, "findSeparatingAxisUnitSphereKernel", &errNum, mprProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(k);
}
clReleaseProgram(mprProg);
}
}; // namespace

View File

@@ -11,228 +11,217 @@
#include "Bullet3OpenCL/RigidBody/kernels/batchingKernels.h"
#include "Bullet3OpenCL/RigidBody/kernels/batchingKernelsNew.h"
extern int gArgc;
extern char** gArgv;
namespace
{
struct CompileBullet3PgsContactSolverKernels : public ::testing::Test
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)
{
cl_context m_clContext;
cl_device_id m_clDevice;
cl_command_queue m_clQueue;
char* m_clDeviceName;
cl_platform_id m_platformId;
// You can do set-up work for each test here.
b3CommandLineArgs args(gArgc, gArgv);
int preferredDeviceIndex = -1;
int preferredPlatformIndex = -1;
bool allowCpuOpenCL = false;
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();
}
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:
#include "initCL.h"
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(CL_SUCCESS,errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solveFrictionCL, "BatchSolveKernelFriction", &errNum, solveFrictionProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k =b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solveFrictionCL, "solveSingleFrictionKernel", &errNum, solveFrictionProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(solveFrictionProg);
initCL();
}
TEST_F(CompileBullet3PgsContactSolverKernels,solverSetupCL)
virtual ~CompileBullet3PgsContactSolverKernels()
{
const char* additionalMacros="";
cl_int errNum=0;
cl_program solverSetupProg= b3OpenCLUtils::compileCLProgramFromString( m_clContext, m_clDevice, solverSetupCL, &errNum,additionalMacros, 0,true);
ASSERT_EQ(CL_SUCCESS,errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetupCL, "ContactToConstraintKernel", &errNum, solverSetupProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(solverSetupProg);
// You can do clean-up work that doesn't throw exceptions here.
exitCL();
}
TEST_F(CompileBullet3PgsContactSolverKernels,solverSetup2CL)
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
#include "initCL.h"
virtual void SetUp()
{
const char* additionalMacros="";
cl_int errNum=0;
cl_program solverSetup2Prog= b3OpenCLUtils::compileCLProgramFromString( m_clContext, m_clDevice, solverSetup2CL, &errNum,additionalMacros, 0,true);
ASSERT_EQ(CL_SUCCESS,errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "SetSortDataKernel", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataBodyA", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataBodyB", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataChildShapeA", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataChildShapeB", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "ReorderContactKernel", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solverSetup2CL, "CopyConstraintKernel", &errNum, solverSetup2Prog,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(solverSetup2Prog);
// Code here will be called immediately after the constructor (right
// before each test).
}
TEST_F(CompileBullet3PgsContactSolverKernels,solveContactCL)
virtual void TearDown()
{
const char* additionalMacros="";
cl_int errNum=0;
cl_program solveContactProg= b3OpenCLUtils::compileCLProgramFromString( m_clContext, m_clDevice, solveContactCL, &errNum,additionalMacros, 0,true);
ASSERT_EQ(CL_SUCCESS,errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solveContactCL, "BatchSolveKernelContact", &errNum, solveContactProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, solveContactCL, "solveSingleContactKernel", &errNum, solveContactProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(solveContactProg);
// Code here will be called immediately after each test (right
// before the destructor).
}
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(CL_SUCCESS,errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, batchingKernelsCL, "CreateBatches", &errNum, batchingProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
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(CL_SUCCESS,errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString( m_clContext, m_clDevice, batchingKernelsNewCL, "CreateBatchesNew", &errNum, batchingNewProg,additionalMacros );
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
clReleaseProgram(batchingNewProg);
}
};
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveFrictionCL, "BatchSolveKernelFriction", &errNum, solveFrictionProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveFrictionCL, "solveSingleFrictionKernel", &errNum, solveFrictionProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetupCL, "ContactToConstraintKernel", &errNum, solverSetupProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "SetSortDataKernel", &errNum, solverSetup2Prog, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataBodyA", &errNum, solverSetup2Prog, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataBodyB", &errNum, solverSetup2Prog, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataChildShapeA", &errNum, solverSetup2Prog, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "SetDeterminismSortDataChildShapeB", &errNum, solverSetup2Prog, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "ReorderContactKernel", &errNum, solverSetup2Prog, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solverSetup2CL, "CopyConstraintKernel", &errNum, solverSetup2Prog, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveContactCL, "BatchSolveKernelContact", &errNum, solveContactProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveContactCL, "solveSingleContactKernel", &errNum, solveContactProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, batchingKernelsCL, "CreateBatches", &errNum, batchingProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, batchingKernelsNewCL, "CreateBatchesNew", &errNum, batchingNewProg, additionalMacros);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
clReleaseProgram(batchingNewProg);
}
}; // namespace

View File

@@ -11,112 +11,105 @@ extern char** gArgv;
namespace
{
struct testCompileBullet3PgsJointSolverKernels : public ::testing::Test
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)
{
cl_context m_clContext;
cl_device_id m_clDevice;
cl_command_queue m_clQueue;
char* m_clDeviceName;
cl_platform_id m_platformId;
// You can do set-up work for each test here.
b3CommandLineArgs args(gArgc, gArgv);
int preferredDeviceIndex = -1;
int preferredPlatformIndex = -1;
bool allowCpuOpenCL = false;
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();
}
initCL();
}
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:
#include "initCL.h"
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)
virtual ~testCompileBullet3PgsJointSolverKernels()
{
cl_int errNum=0;
// You can do clean-up work that doesn't throw exceptions here.
exitCL();
}
cl_program prog = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,solveConstraintRowsCL,&errNum,"",0,true);
ASSERT_EQ(CL_SUCCESS,errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,solveConstraintRowsCL, "solveJointConstraintRows",&errNum,prog);
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext,m_clDevice,solveConstraintRowsCL,"initSolverBodies",&errNum,prog);
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext,m_clDevice,solveConstraintRowsCL,"getInfo1Kernel",&errNum,prog);
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext,m_clDevice,solveConstraintRowsCL,"initBatchConstraintsKernel",&errNum,prog);
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k= b3OpenCLUtils::compileCLKernelFromString(m_clContext,m_clDevice,solveConstraintRowsCL,"getInfo2Kernel",&errNum,prog);
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext,m_clDevice,solveConstraintRowsCL,"writeBackVelocitiesKernel",&errNum,prog);
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext,m_clDevice,solveConstraintRowsCL,"breakViolatedConstraintsKernel",&errNum,prog);
ASSERT_EQ(CL_SUCCESS,errNum);
ASSERT_FALSE(k==0);
clReleaseKernel(k);
}
#include "initCL.h"
virtual void SetUp()
{
// Code here will be called immediately after the constructor (right
// before each test).
}
clReleaseProgram(prog);
}
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveConstraintRowsCL, "solveJointConstraintRows", &errNum, prog);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveConstraintRowsCL, "initSolverBodies", &errNum, prog);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveConstraintRowsCL, "getInfo1Kernel", &errNum, prog);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveConstraintRowsCL, "initBatchConstraintsKernel", &errNum, prog);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveConstraintRowsCL, "getInfo2Kernel", &errNum, prog);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveConstraintRowsCL, "writeBackVelocitiesKernel", &errNum, prog);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, solveConstraintRowsCL, "breakViolatedConstraintsKernel", &errNum, prog);
ASSERT_EQ(CL_SUCCESS, errNum);
ASSERT_FALSE(k == 0);
clReleaseKernel(k);
}
clReleaseProgram(prog);
}
}; // namespace

View File

@@ -11,71 +11,66 @@ extern char** gArgv;
namespace
{
struct CompileBullet3RaycastKernels : public ::testing::Test
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)
{
cl_context m_clContext;
cl_device_id m_clDevice;
cl_command_queue m_clQueue;
char* m_clDeviceName;
cl_platform_id m_platformId;
// You can do set-up work for each test here.
b3CommandLineArgs args(gArgc, gArgv);
int preferredDeviceIndex = -1;
int preferredPlatformIndex = -1;
bool allowCpuOpenCL = false;
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();
}
initCL();
}
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:
#include "initCL.h"
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)
virtual ~CompileBullet3RaycastKernels()
{
cl_int errNum=0;
cl_program prog = b3OpenCLUtils::compileCLProgramFromString(m_clContext,m_clDevice,rayCastKernelCL,&errNum,"",0,true);
ASSERT_EQ(CL_SUCCESS,errNum);
// You can do clean-up work that doesn't throw exceptions here.
exitCL();
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,rayCastKernelCL, "rayCastKernel",&errNum,prog);
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k);
}
clReleaseProgram(prog);
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
#include "initCL.h"
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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, rayCastKernelCL, "rayCastKernel", &errNum, prog);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(k);
}
clReleaseProgram(prog);
}
}; // namespace

View File

@@ -21,51 +21,49 @@ extern char** gArgv;
namespace
{
struct ExecuteBullet3NarrowphaseKernels : public ::testing::Test
struct ExecuteBullet3NarrowphaseKernels : 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;
ExecuteBullet3NarrowphaseKernels()
: m_clDeviceName(0),
m_clContext(0),
m_clDevice(0),
m_clQueue(0),
m_platformId(0)
{
cl_context m_clContext;
cl_device_id m_clDevice;
cl_command_queue m_clQueue;
char* m_clDeviceName;
cl_platform_id m_platformId;
// You can do set-up work for each test here.
ExecuteBullet3NarrowphaseKernels()
: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.
initCL();
}
initCL();
}
virtual ~ExecuteBullet3NarrowphaseKernels()
{
// You can do clean-up work that doesn't throw exceptions here.
exitCL();
}
virtual ~ExecuteBullet3NarrowphaseKernels()
{
// 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:
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
#include "initCL.h"
#include "initCL.h"
virtual void SetUp()
{
// Code here will be called immediately after the constructor (right
// before each test).
}
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).
}
};
virtual void TearDown()
{
// Code here will be called immediately after each test (right
// before the destructor).
}
};
#if 0
TEST_F(ExecuteBullet3NarrowphaseKernels,satKernelsCL)
@@ -244,196 +242,191 @@ namespace
#endif
unsigned char* openFile(const char* fileName, int* sizeInBytesPtr)
{
*sizeInBytesPtr=0;
unsigned char* buffer = 0;
const char* prefix[]={"./","./data/","../data/","../../data/","../../../data/","../../../../data/"};
int numPrefixes = sizeof(prefix)/sizeof(const char*);
char relativeFileName[1024];
unsigned char* openFile(const char* fileName, int* sizeInBytesPtr)
{
*sizeInBytesPtr = 0;
unsigned char* buffer = 0;
const char* prefix[] = {"./", "./data/", "../data/", "../../data/", "../../../data/", "../../../../data/"};
int numPrefixes = sizeof(prefix) / sizeof(const char*);
char relativeFileName[1024];
#ifdef B3_USE_ZLIB
{
FILE* f = 0;
int result = 0;
for (int i = 0; !f && i < numPrefixes; i++)
{
FILE* f=0;
int result = 0;
sprintf(relativeFileName, "%s%s", prefix[i], "unittest_data.zip");
f = fopen(relativeFileName, "rb");
}
if (f)
{
fclose(f);
for (int i=0;!f && i<numPrefixes;i++)
unzFile zipfile = unzOpen(relativeFileName);
if (zipfile == NULL)
{
sprintf(relativeFileName,"%s%s",prefix[i],"unittest_data.zip");
f = fopen(relativeFileName,"rb");
printf("%s: not found\n", relativeFileName);
}
if (f)
// Get info about the zip file
unz_global_info global_info;
result = unzGetGlobalInfo(zipfile, &global_info);
if (result != UNZ_OK)
{
fclose(f);
unzFile zipfile = unzOpen( relativeFileName);
if ( zipfile == NULL )
b3Printf("could not read file global info\n");
unzClose(zipfile);
}
else
{
result = unzLocateFile(zipfile, fileName, 0);
if (result == UNZ_OK)
{
printf( "%s: not found\n" ,relativeFileName);
}
// Get info about the zip file
unz_global_info global_info;
result = unzGetGlobalInfo( zipfile, &global_info ) ;
if (result != UNZ_OK )
{
b3Printf( "could not read file global info\n" );
unzClose( zipfile );
} else
{
result = unzLocateFile(zipfile, fileName, 0);
if (result == UNZ_OK)
unz_file_info info;
result = unzGetCurrentFileInfo(zipfile, &info, NULL, 0, NULL, 0, NULL, 0);
if (result != UNZ_OK)
{
unz_file_info info;
result = unzGetCurrentFileInfo( zipfile, &info, NULL, 0, NULL, 0, NULL, 0 );
if ( result != UNZ_OK )
{
b3Printf("unzGetCurrentFileInfo() != UNZ_OK (%d)\n", result);
} else
{
result = unzOpenCurrentFile(zipfile);
if (result == UNZ_OK)
{
buffer = (unsigned char*)malloc(info.uncompressed_size);
result = unzReadCurrentFile(zipfile,buffer,info.uncompressed_size);
if (result <0)
{
free(buffer);
buffer=0;
} else
{
*sizeInBytesPtr= info.uncompressed_size;
}
unzCloseCurrentFile(zipfile);
} else
{
b3Printf("cannot open file %s!\n", fileName);
}
}
} else
{
b3Printf("cannot find file %s\n", fileName);
b3Printf("unzGetCurrentFileInfo() != UNZ_OK (%d)\n", result);
}
else
{
result = unzOpenCurrentFile(zipfile);
if (result == UNZ_OK)
{
buffer = (unsigned char*)malloc(info.uncompressed_size);
result = unzReadCurrentFile(zipfile, buffer, info.uncompressed_size);
if (result < 0)
{
free(buffer);
buffer = 0;
}
else
{
*sizeInBytesPtr = info.uncompressed_size;
}
unzCloseCurrentFile(zipfile);
}
else
{
b3Printf("cannot open file %s!\n", fileName);
}
}
unzClose( zipfile );
}
else
{
b3Printf("cannot find file %s\n", fileName);
}
unzClose(zipfile);
}
}
#endif//B3_USE_ZLIB
if (!buffer)
{
FILE* f=0;
int result = 0;
for (int i=0;!f && i<numPrefixes;i++)
{
sprintf(relativeFileName,"%s%s",prefix[i],fileName);
f = fopen(relativeFileName,"rb");
}
//first try from data.zip, otherwise directly load the file from disk
if (f)
{
int sizeInBytes=0;
if (fseek(f, 0, SEEK_END) || (sizeInBytes = ftell(f)) == EOF || fseek(f, 0, SEEK_SET))
{
b3Printf("error, cannot get file size\n");
}
buffer = (unsigned char*) malloc(sizeInBytes);
int actualRead = fread(buffer,sizeInBytes,1,f);
if (actualRead != 1)
{
free(buffer);
buffer=0;
} else
{
*sizeInBytesPtr = sizeInBytes;
}
fclose(f);
}
}
return buffer;
}
void testLauncher(const char* fileName2, b3LauncherCL& launcher, cl_context ctx)
#endif //B3_USE_ZLIB
if (!buffer)
{
FILE* f = 0;
int result = 0;
int sizeInBytes=0;
unsigned char* buf = openFile(fileName2,&sizeInBytes);
ASSERT_FALSE(buf==NULL);
if (buf)
for (int i = 0; !f && i < numPrefixes; i++)
{
int serializedBytes = launcher.deserializeArgs(buf, sizeInBytes,ctx);
int num = *(int*)&buf[serializedBytes];
launcher.launch1D( num);
free(buf);
//this clFinish is for testing on errors
sprintf(relativeFileName, "%s%s", prefix[i], fileName);
f = fopen(relativeFileName, "rb");
}
}
TEST_F(ExecuteBullet3NarrowphaseKernels,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(CL_SUCCESS,errNum);
//first try from data.zip, otherwise directly load the file from disk
if (f)
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,mprKernelsCL, "mprPenetrationKernel",&errNum,mprProg );
ASSERT_EQ(CL_SUCCESS,errNum);
if (1)
int sizeInBytes = 0;
if (fseek(f, 0, SEEK_END) || (sizeInBytes = ftell(f)) == EOF || fseek(f, 0, SEEK_SET))
{
const char* fileNames[]={"mprPenetrationKernel60.bin","mprPenetrationKernel61.bin","mprPenetrationKernel70.bin","mprPenetrationKernel128.bin"};
int results[] = {0,1,46,98};
int numTests = sizeof(fileNames)/sizeof(const char*);
for (int i=0;i<numTests;i++)
{
b3LauncherCL launcher(m_clQueue, k,fileNames[i]);
testLauncher(fileNames[i],launcher, m_clContext);
clFinish(m_clQueue);
ASSERT_EQ(launcher.getNumArguments(),11);
b3KernelArgData data = launcher.getArgument(8);
ASSERT_TRUE(data.m_isBuffer);
b3OpenCLArray<int> totalContactsOut(this->m_clContext,this->m_clQueue);
totalContactsOut.setFromOpenCLBuffer(data.m_clBuffer,1);
int numContacts = totalContactsOut.at(0);
ASSERT_EQ(results[i],numContacts);
}
//printf("numContacts = %d\n",numContacts);
//nContacts = m_totalContactsOut.at(0);
b3Printf("error, cannot get file size\n");
}
clReleaseKernel(k);
buffer = (unsigned char*)malloc(sizeInBytes);
int actualRead = fread(buffer, sizeInBytes, 1, f);
if (actualRead != 1)
{
free(buffer);
buffer = 0;
}
else
{
*sizeInBytesPtr = sizeInBytes;
}
fclose(f);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice,mprKernelsCL, "findSeparatingAxisUnitSphereKernel",&errNum,mprProg );
ASSERT_EQ(CL_SUCCESS,errNum);
clReleaseKernel(k);
}
clReleaseProgram(mprProg);
}
return buffer;
}
};
void testLauncher(const char* fileName2, b3LauncherCL& launcher, cl_context ctx)
{
int sizeInBytes = 0;
unsigned char* buf = openFile(fileName2, &sizeInBytes);
ASSERT_FALSE(buf == NULL);
if (buf)
{
int serializedBytes = launcher.deserializeArgs(buf, sizeInBytes, ctx);
int num = *(int*)&buf[serializedBytes];
launcher.launch1D(num);
free(buf);
//this clFinish is for testing on errors
}
}
TEST_F(ExecuteBullet3NarrowphaseKernels, 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(CL_SUCCESS, errNum);
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, mprKernelsCL, "mprPenetrationKernel", &errNum, mprProg);
ASSERT_EQ(CL_SUCCESS, errNum);
if (1)
{
const char* fileNames[] = {"mprPenetrationKernel60.bin", "mprPenetrationKernel61.bin", "mprPenetrationKernel70.bin", "mprPenetrationKernel128.bin"};
int results[] = {0, 1, 46, 98};
int numTests = sizeof(fileNames) / sizeof(const char*);
for (int i = 0; i < numTests; i++)
{
b3LauncherCL launcher(m_clQueue, k, fileNames[i]);
testLauncher(fileNames[i], launcher, m_clContext);
clFinish(m_clQueue);
ASSERT_EQ(launcher.getNumArguments(), 11);
b3KernelArgData data = launcher.getArgument(8);
ASSERT_TRUE(data.m_isBuffer);
b3OpenCLArray<int> totalContactsOut(this->m_clContext, this->m_clQueue);
totalContactsOut.setFromOpenCLBuffer(data.m_clBuffer, 1);
int numContacts = totalContactsOut.at(0);
ASSERT_EQ(results[i], numContacts);
}
//printf("numContacts = %d\n",numContacts);
//nContacts = m_totalContactsOut.at(0);
}
clReleaseKernel(k);
}
{
cl_kernel k = b3OpenCLUtils::compileCLKernelFromString(m_clContext, m_clDevice, mprKernelsCL, "findSeparatingAxisUnitSphereKernel", &errNum, mprProg);
ASSERT_EQ(CL_SUCCESS, errNum);
clReleaseKernel(k);
}
clReleaseProgram(mprProg);
}
}; // namespace

View File

@@ -20,13 +20,11 @@ subject to the following restrictions:
#include <stdio.h>
cl_context g_cxMainContext;
cl_command_queue g_cqCommandQue;
cl_context g_cxMainContext;
cl_command_queue g_cqCommandQue;
#include "Bullet3Common/b3Logging.h"
void myerrorwarningprintf(const char* msg)
{
//OutputDebugStringA(msg);
@@ -54,64 +52,63 @@ int main(int argc, char* argv[])
cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
const char* vendorSDK = b3OpenCLUtils::getSdkVendorName();
b3Printf("This program was compiled using the %s OpenCL SDK\n",vendorSDK);
b3Printf("This program was compiled using the %s OpenCL SDK\n", vendorSDK);
int numPlatforms = b3OpenCLUtils::getNumPlatforms();
b3Printf("Num Platforms = %d\n", numPlatforms);
for (int i=0;i<numPlatforms;i++)
for (int i = 0; i < numPlatforms; i++)
{
cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
b3OpenCLPlatformInfo platformInfo;
b3OpenCLUtils::getPlatformInfo(platform,&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);
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);
g_cxMainContext = b3OpenCLUtils::createContextFromPlatform(platform,deviceType,&ciErrNum);
g_cxMainContext = b3OpenCLUtils::createContextFromPlatform(platform, deviceType, &ciErrNum);
int numDevices = b3OpenCLUtils::getNumDevices(g_cxMainContext);
b3Printf("Num Devices = %d\n", numDevices);
for (int j=0;j<numDevices;j++)
for (int j = 0; j < numDevices; j++)
{
cl_device_id device = b3OpenCLUtils::getDevice(g_cxMainContext,j);
cl_device_id device = b3OpenCLUtils::getDevice(g_cxMainContext, j);
b3OpenCLDeviceInfo devInfo;
b3OpenCLUtils::getDeviceInfo(device,&devInfo);
b3OpenCLUtils::getDeviceInfo(device, &devInfo);
b3OpenCLUtils::printDeviceInfo(device);
g_cqCommandQue = clCreateCommandQueue(g_cxMainContext, device, 0, &ciErrNum);
b3OpenCLArray<char> memTester(g_cxMainContext,g_cqCommandQue,0,true);
b3OpenCLArray<char> memTester(g_cxMainContext, g_cqCommandQue, 0, true);
int maxMem = 0;
bool result=true;
for (size_t i=1;result;i++)
bool result = true;
for (size_t i = 1; result; i++)
{
size_t numBytes = i*1024*1024;
result = memTester.resize(numBytes,false);
size_t numBytes = i * 1024 * 1024;
result = memTester.resize(numBytes, false);
if (result)
{
maxMem = numBytes;
} else
}
else
{
break;
}
}
printf("allocated %d MB successfully\n",maxMem/(1024*1024));
printf("allocated %d MB successfully\n", maxMem / (1024 * 1024));
clReleaseCommandQueue(g_cqCommandQue);
g_cqCommandQue=0;
g_cqCommandQue = 0;
}
clReleaseContext(g_cxMainContext);
g_cxMainContext=0;
g_cxMainContext = 0;
}
///Easier method to initialize OpenCL using createContextFromType for a GPU
deviceType = CL_DEVICE_TYPE_GPU;
void* glCtx=0;
void* glCtx = 0;
void* glDC = 0;
b3Printf("Initialize OpenCL using b3OpenCLUtils::createContextFromType for CL_DEVICE_TYPE_GPU\n");
g_cxMainContext = b3OpenCLUtils::createContextFromType(deviceType, &ciErrNum, glCtx, glDC);
@@ -121,48 +118,47 @@ int main(int argc, char* argv[])
{
int numDev = b3OpenCLUtils::getNumDevices(g_cxMainContext);
for (int i=0;i<numDev;i++)
for (int i = 0; i < numDev; i++)
{
cl_device_id device;
device = b3OpenCLUtils::getDevice(g_cxMainContext,i);
cl_device_id device;
device = b3OpenCLUtils::getDevice(g_cxMainContext, i);
b3OpenCLDeviceInfo clInfo;
b3OpenCLUtils::getDeviceInfo(device,&clInfo);
b3OpenCLUtils::getDeviceInfo(device, &clInfo);
b3OpenCLUtils::printDeviceInfo(device);
// create a command-queue
g_cqCommandQue = clCreateCommandQueue(g_cxMainContext, device, 0, &ciErrNum);
oclCHECKERROR(ciErrNum, CL_SUCCESS);
//normally you would create and execute kernels using this command queue
int maxMem = 0;
int maxMem = 0;
{
b3OpenCLArray<char> memTester(g_cxMainContext,g_cqCommandQue,0,true);
bool result=true;
for (size_t i=1;result;i++)
{
size_t numBytes = i*1024*1024;
result = memTester.resize(numBytes,false);
b3OpenCLArray<char> memTester(g_cxMainContext, g_cqCommandQue, 0, true);
if (result)
{
maxMem=numBytes;
} else
{
bool result = true;
for (size_t i = 1; result; i++)
{
size_t numBytes = i * 1024 * 1024;
result = memTester.resize(numBytes, false);
if (result)
{
maxMem = numBytes;
}
else
{
break;
}
}
printf("allocated %d MB successfully\n",maxMem/(1024*1024));
}
}
printf("allocated %d MB successfully\n", maxMem / (1024 * 1024));
}
clReleaseCommandQueue(g_cqCommandQue);
}
clReleaseContext(g_cxMainContext);
}
else {
else
{
b3Printf("No OpenCL capable GPU found!");
}
b3Printf("press <Enter>\n");

View File

@@ -2,43 +2,40 @@
#include <gtest/gtest.h>
#include "Bullet3Common/b3Logging.h"
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
TEST(b3OpenCLUtils, getNumPlatforms)
TEST(b3OpenCLUtils, getNumPlatforms)
{
int numPlatforms = b3OpenCLUtils::getNumPlatforms();
ASSERT_GT(numPlatforms,0);
ASSERT_GT(numPlatforms, 0);
}
TEST(b3OpenCLUtils, getSdkVendorName)
TEST(b3OpenCLUtils, getSdkVendorName)
{
const char* vendorSDK = b3OpenCLUtils::getSdkVendorName();
b3Printf("getSdkVendorName=%s\n",vendorSDK);
ASSERT_FALSE(vendorSDK==NULL);
b3Printf("getSdkVendorName=%s\n", vendorSDK);
ASSERT_FALSE(vendorSDK == NULL);
}
TEST(b3OpenCLUtils, getPlatformInfo)
TEST(b3OpenCLUtils, getPlatformInfo)
{
int numPlatforms = b3OpenCLUtils::getNumPlatforms();
ASSERT_GT(numPlatforms,0);
ASSERT_GT(numPlatforms, 0);
b3Printf("Num Platforms = %d\n", numPlatforms);
for (int i=0;i<numPlatforms;i++)
for (int i = 0; i < numPlatforms; i++)
{
cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
ASSERT_FALSE(platform==NULL);
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);
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)
TEST(b3OpenCLUtils, createContextFromPlatform)
{
int numPlatforms = b3OpenCLUtils::getNumPlatforms();
b3Printf("Num Platforms = %d\n", numPlatforms);
@@ -46,71 +43,69 @@ TEST(b3OpenCLUtils, createContextFromPlatform)
cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
int ciErrNum = 0;
for (int i=0;i<numPlatforms;i++)
for (int i = 0; i < numPlatforms; i++)
{
cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
b3OpenCLPlatformInfo platformInfo;
b3OpenCLUtils::getPlatformInfo(platform,&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);
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(CL_SUCCESS,ciErrNum);
cl_context ctx = b3OpenCLUtils::createContextFromPlatform(platform, deviceType, &ciErrNum);
ASSERT_FALSE(ctx == 0);
ASSERT_EQ(CL_SUCCESS, ciErrNum);
clReleaseContext(ctx);
}
}
TEST(b3OpenCLUtils, getDeviceAndQueue)
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++)
for (int i = 0; i < numPlatforms; i++)
{
cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
b3OpenCLPlatformInfo platformInfo;
b3OpenCLUtils::getPlatformInfo(platform,&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(CL_SUCCESS,ciErrNum);
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(CL_SUCCESS, ciErrNum);
int numDevices = b3OpenCLUtils::getNumDevices(ctx);
ASSERT_GT(numDevices,0);
ASSERT_GT(numDevices, 0);
b3Printf("Num Devices = %d\n", numDevices);
for (int j=0;j<numDevices;j++)
for (int j = 0; j < numDevices; j++)
{
cl_device_id device = b3OpenCLUtils::getDevice(ctx,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::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);
ASSERT_FALSE(q == 0);
clReleaseCommandQueue(q);
q=0;
q = 0;
}
clReleaseContext(ctx);
}
}

View File

@@ -24,94 +24,80 @@ subject to the following restrictions:
#include "Bullet3Common/shared/b3Float4.h"
//typedef b3Vector3 b3Float4;
typedef struct b3Contact4Data b3Contact4Data_t;
typedef struct b3Contact4Data b3Contact4Data_t;
struct b3Contact4Data
{
b3Float4 m_worldPos[4];
b3Float4 m_localPosA[4];
b3Float4 m_localPosB[4];
b3Float4 m_worldNormal; // w: m_nPoints
unsigned short m_restituitionCoeffCmp;
unsigned short m_frictionCoeffCmp;
b3Float4 m_worldPos[4];
b3Float4 m_localPosA[4];
b3Float4 m_localPosB[4];
b3Float4 m_worldNormal; // w: m_nPoints
unsigned short m_restituitionCoeffCmp;
unsigned short m_frictionCoeffCmp;
int m_batchIdx;
int m_bodyAPtrAndSignBit;//x:m_bodyAPtr, y:m_bodyBPtr
int m_bodyAPtrAndSignBit; //x:m_bodyAPtr, y:m_bodyBPtr
int m_bodyBPtrAndSignBit;
int m_childIndexA;
int m_childIndexB;
int m_childIndexA;
int m_childIndexB;
int m_unused1;
int m_unused2;
};
#define MSTRINGIFY(A) #A
static const char* s_testKernelString= MSTRINGIFY(
static const char* s_testKernelString = MSTRINGIFY(
struct MyTest
{
int bla;
};
struct MyTest {
int bla;
};
typedef float4 b3Float4;
typedef struct b3Contact4Data b3Contact4Data_t;
struct b3Contact4Data
{
b3Float4 m_worldPos[4];
b3Float4 m_localPosA[4];
b3Float4 m_localPosB[4];
b3Float4 m_worldNormal; // w: m_nPoints
unsigned short m_restituitionCoeffCmp;
unsigned short m_frictionCoeffCmp;
int m_batchIdx;
int m_bodyAPtrAndSignBit;//x:m_bodyAPtr, y:m_bodyBPtr
int m_bodyBPtrAndSignBit;
int m_childIndexA;
int m_childIndexB;
int m_unused1;
int m_unused2;
typedef float4 b3Float4;
typedef struct b3Contact4Data b3Contact4Data_t;
struct b3Contact4Data {
b3Float4 m_worldPos[4];
b3Float4 m_localPosA[4];
b3Float4 m_localPosB[4];
b3Float4 m_worldNormal; // w: m_nPoints
unsigned short m_restituitionCoeffCmp;
unsigned short m_frictionCoeffCmp;
int m_batchIdx;
int m_bodyAPtrAndSignBit; //x:m_bodyAPtr, y:m_bodyBPtr
int m_bodyBPtrAndSignBit;
int m_childIndexA;
int m_childIndexB;
int m_unused1;
int m_unused2;
};
inline int b3Contact4Data_getNumPoints(const struct b3Contact4Data* contact) {
return (int)contact->m_worldNormal.w;
};
inline void b3Contact4Data_setNumPoints(struct b3Contact4Data* contact, int numPoints) {
contact->m_worldNormal.w = (float)numPoints;
};
};
inline int b3Contact4Data_getNumPoints(const struct b3Contact4Data* contact)
{
return (int)contact->m_worldNormal.w;
};
inline void b3Contact4Data_setNumPoints(struct b3Contact4Data* contact, int numPoints)
{
contact->m_worldNormal.w = (float)numPoints;
};
typedef volatile __global int* my_counter32_t;
typedef volatile __global int* my_counter32_t;
__kernel void testKernel(__global int* testData, __global b3Contact4Data_t* contactData, my_counter32_t numElements) {
int id = get_local_id(0);
int sz = sizeof(b3Contact4Data_t);
testData[id] = sz;
__kernel void testKernel( __global int* testData, __global b3Contact4Data_t* contactData, my_counter32_t numElements)
{
int id = get_local_id(0);
int sz = sizeof(b3Contact4Data_t);
testData[id]=sz;
__private b3Contact4Data_t tmp;
if (id==0)
{
tmp = contactData[1];
contactData[1] = contactData[0];
contactData[0] = tmp;
__private b3Contact4Data_t tmp;
if (id == 0)
{
tmp = contactData[1];
contactData[1] = contactData[0];
contactData[0] = tmp;
}
}
}
);
#include "Bullet3Common/b3Logging.h"
void myprintf(const char* msg)
{
//OutputDebugStringA(msg);
printf("%s",msg);
printf("%s", msg);
}
int main(int argc, char* argv[])
@@ -129,64 +115,62 @@ int main(int argc, char* argv[])
cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
const char* vendorSDK = b3OpenCLUtils::getSdkVendorName();
b3Printf("This program was compiled using the %s OpenCL SDK\n",vendorSDK);
b3Printf("This program was compiled using the %s OpenCL SDK\n", vendorSDK);
int numPlatforms = b3OpenCLUtils::getNumPlatforms();
b3Printf("Num Platforms = %d\n", numPlatforms);
for (int i=0;i<numPlatforms;i++)
for (int i = 0; i < numPlatforms; i++)
{
cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
b3OpenCLPlatformInfo platformInfo;
b3OpenCLUtils::getPlatformInfo(platform,&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);
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 context = b3OpenCLUtils::createContextFromPlatform(platform,deviceType,&ciErrNum);
cl_context context = b3OpenCLUtils::createContextFromPlatform(platform, deviceType, &ciErrNum);
if (context)
{
int numDevices = b3OpenCLUtils::getNumDevices(context);
b3Printf("Num Devices = %d\n", numDevices);
for (int j=0;j<numDevices;j++)
for (int j = 0; j < numDevices; j++)
{
cl_device_id dev = b3OpenCLUtils::getDevice(context,j);
cl_device_id dev = b3OpenCLUtils::getDevice(context, j);
b3OpenCLDeviceInfo devInfo;
b3OpenCLUtils::getDeviceInfo(dev,&devInfo);
b3OpenCLUtils::getDeviceInfo(dev, &devInfo);
b3OpenCLUtils::printDeviceInfo(dev);
int errNum;
cl_command_queue queue = clCreateCommandQueue(context, dev, 0, &errNum);
cl_program pairBenchProg = 0;
cl_program pairBenchProg=0;
cl_kernel testKernel = b3OpenCLUtils::compileCLKernelFromString(context,dev,s_testKernelString,"testKernel",&errNum,pairBenchProg);
cl_kernel testKernel = b3OpenCLUtils::compileCLKernelFromString(context, dev, s_testKernelString, "testKernel", &errNum, pairBenchProg);
if (testKernel)
{
printf("kernel compiled ok\n");
int numWorkItems = 64;
b3OpenCLArray<int> deviceElements(context,queue);
b3OpenCLArray<int> atomicCounter(context,queue);
b3OpenCLArray<b3Contact4Data> deviceContacts(context,queue);
b3OpenCLArray<int> deviceElements(context, queue);
b3OpenCLArray<int> atomicCounter(context, queue);
b3OpenCLArray<b3Contact4Data> deviceContacts(context, queue);
b3AlignedObjectArray<b3Contact4Data> hostContacts;
b3Contact4Data tmp;
int sz = sizeof(b3Contact4Data);
memset(&tmp,1,sz);
memset(&tmp, 1, sz);
deviceContacts.push_back(tmp);
b3Contact4Data tmp2 = tmp;
memset(&tmp,2,sz);
memset(&tmp, 2, sz);
deviceContacts.push_back(tmp);
b3Contact4Data tmp3 = tmp;
atomicCounter.push_back(0);
deviceElements.resize(numWorkItems);
b3LauncherCL run(queue,testKernel,"testKernel");
b3LauncherCL run(queue, testKernel, "testKernel");
run.setBuffer(deviceElements.getBufferCL());
run.setBuffer(deviceContacts.getBufferCL());
run.setBuffer(atomicCounter.getBufferCL());
@@ -199,16 +183,12 @@ int main(int argc, char* argv[])
tmp2 = hostContacts[0];
tmp3 = hostContacts[1];
printf("...\n");
} else
}
else
{
printf("kernel failed to compile\n");
}
}
}

View File

@@ -12,7 +12,6 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
#include <stdio.h>
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
#include "Bullet3OpenCL/ParallelPrimitives/b3FillCL.h"
@@ -27,13 +26,22 @@ int g_nFailed = 0;
bool g_testFailed = 0;
#define TEST_INIT g_testFailed = 0;
#define TEST_ASSERT(x) if( !(x) ){g_testFailed = 1;}
#define TEST_REPORT(testName) printf("[%s] %s\n",(g_testFailed)?"X":"O", testName); if(g_testFailed) g_nFailed++; else g_nPassed++;
#define NEXTMULTIPLEOF(num, alignment) (((num)/(alignment) + (((num)%(alignment)==0)?0:1))*(alignment))
#define TEST_ASSERT(x) \
if (!(x)) \
{ \
g_testFailed = 1; \
}
#define TEST_REPORT(testName) \
printf("[%s] %s\n", (g_testFailed) ? "X" : "O", testName); \
if (g_testFailed) \
g_nFailed++; \
else \
g_nPassed++;
#define NEXTMULTIPLEOF(num, alignment) (((num) / (alignment) + (((num) % (alignment) == 0) ? 0 : 1)) * (alignment))
cl_context g_context=0;
cl_device_id g_device=0;
cl_command_queue g_queue =0;
cl_context g_context = 0;
cl_device_id g_device = 0;
cl_command_queue g_queue = 0;
const char* g_deviceName = 0;
void initCL(int preferredDeviceIndex, int preferredPlatformIndex)
@@ -45,17 +53,17 @@ void initCL(int preferredDeviceIndex, int preferredPlatformIndex)
cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
g_context = b3OpenCLUtils::createContextFromType(deviceType, &ciErrNum, 0,0,preferredDeviceIndex, preferredPlatformIndex);
g_context = b3OpenCLUtils::createContextFromType(deviceType, &ciErrNum, 0, 0, preferredDeviceIndex, preferredPlatformIndex);
oclCHECKERROR(ciErrNum, CL_SUCCESS);
int numDev = b3OpenCLUtils::getNumDevices(g_context);
if (numDev>0)
if (numDev > 0)
{
b3OpenCLDeviceInfo info;
g_device= b3OpenCLUtils::getDevice(g_context,0);
g_device = b3OpenCLUtils::getDevice(g_context, 0);
g_queue = clCreateCommandQueue(g_context, g_device, 0, &ciErrNum);
oclCHECKERROR(ciErrNum, CL_SUCCESS);
b3OpenCLUtils::printDeviceInfo(g_device);
b3OpenCLUtils::getDeviceInfo(g_device,&info);
b3OpenCLUtils::printDeviceInfo(g_device);
b3OpenCLUtils::getDeviceInfo(g_device, &info);
g_deviceName = info.m_deviceName;
}
}
@@ -66,100 +74,90 @@ void exitCL()
clReleaseContext(g_context);
}
inline void fillIntTest()
{
TEST_INIT;
b3FillCL* fillCL = new b3FillCL(g_context,g_device,g_queue);
int maxSize=1024*256;
b3OpenCLArray<int> intBuffer(g_context,g_queue,maxSize);
b3FillCL* fillCL = new b3FillCL(g_context, g_device, g_queue);
int maxSize = 1024 * 256;
b3OpenCLArray<int> intBuffer(g_context, g_queue, maxSize);
intBuffer.resize(maxSize);
#define NUM_TESTS 7
int dx = maxSize/NUM_TESTS;
for (int iter=0;iter<NUM_TESTS;iter++)
int dx = maxSize / NUM_TESTS;
for (int iter = 0; iter < NUM_TESTS; iter++)
{
int size = b3Min( 11+dx*iter, maxSize );
int size = b3Min(11 + dx * iter, maxSize);
int value = 2;
int offset=0;
fillCL->execute(intBuffer,value,size,offset);
int offset = 0;
fillCL->execute(intBuffer, value, size, offset);
b3AlignedObjectArray<int> hostBuf2;
hostBuf2.resize(size);
fillCL->executeHost(hostBuf2,value,size,offset);
fillCL->executeHost(hostBuf2, value, size, offset);
b3AlignedObjectArray<int> hostBuf;
intBuffer.copyToHost(hostBuf);
for(int i=0; i<size; i++)
for (int i = 0; i < size; i++)
{
TEST_ASSERT( hostBuf[i] == hostBuf2[i] );
TEST_ASSERT( hostBuf[i] == hostBuf2[i] );
TEST_ASSERT(hostBuf[i] == hostBuf2[i]);
TEST_ASSERT(hostBuf[i] == hostBuf2[i]);
}
}
delete fillCL;
TEST_REPORT( "fillIntTest" );
TEST_REPORT("fillIntTest");
}
__inline
void seedRandom(int seed)
__inline void seedRandom(int seed)
{
srand( seed );
srand(seed);
}
template<typename T>
__inline
T getRandom(const T& minV, const T& maxV)
template <typename T>
__inline T getRandom(const T& minV, const T& maxV)
{
float r = (rand()%10000)/10000.f;
float r = (rand() % 10000) / 10000.f;
T range = maxV - minV;
return (T)(minV + r*range);
return (T)(minV + r * range);
}
struct b3SortDataCompare
{
inline bool operator()(const b3SortData& first, const b3SortData& second) const
{
return (first.m_key < second.m_key) || (first.m_key==second.m_key && first.m_value < second.m_value);
return (first.m_key < second.m_key) || (first.m_key == second.m_key && first.m_value < second.m_value);
}
};
void boundSearchTest( )
void boundSearchTest()
{
TEST_INIT;
int maxSize = 1024*256;
int maxSize = 1024 * 256;
int bucketSize = 256;
b3OpenCLArray<b3SortData> srcCL(g_context,g_queue,maxSize);
b3OpenCLArray<unsigned int> upperCL(g_context,g_queue,maxSize);
b3OpenCLArray<unsigned int> lowerCL(g_context,g_queue,maxSize);
b3OpenCLArray<b3SortData> srcCL(g_context, g_queue, maxSize);
b3OpenCLArray<unsigned int> upperCL(g_context, g_queue, maxSize);
b3OpenCLArray<unsigned int> lowerCL(g_context, g_queue, maxSize);
b3AlignedObjectArray<b3SortData> srcHost;
b3AlignedObjectArray<unsigned int> upperHost;
b3AlignedObjectArray<unsigned int> lowerHost;
b3AlignedObjectArray<unsigned int> upperHostCompare;
b3AlignedObjectArray<unsigned int> lowerHostCompare;
b3BoundSearchCL* search = new b3BoundSearchCL(g_context,g_device,g_queue, maxSize);
b3BoundSearchCL* search = new b3BoundSearchCL(g_context, g_device, g_queue, maxSize);
int dx = maxSize/NUM_TESTS;
for(int iter=0; iter<NUM_TESTS; iter++)
int dx = maxSize / NUM_TESTS;
for (int iter = 0; iter < NUM_TESTS; iter++)
{
int size = b3Min( 128+dx*iter, maxSize );
int size = b3Min(128 + dx * iter, maxSize);
upperHost.resize(bucketSize);
lowerHost.resize(bucketSize);
@@ -168,11 +166,11 @@ void boundSearchTest( )
srcHost.resize(size);
for(int i=0; i<size; i++)
for (int i = 0; i < size; i++)
{
b3SortData v;
// v.m_key = i<2? 0 : 5;
v.m_key = getRandom(0,bucketSize);
// v.m_key = i<2? 0 : 5;
v.m_key = getRandom(0, bucketSize);
v.m_value = i;
srcHost.at(i) = v;
@@ -182,8 +180,7 @@ void boundSearchTest( )
srcCL.copyFromHost(srcHost);
{
for(int i=0; i<bucketSize; i++)
for (int i = 0; i < bucketSize; i++)
{
lowerHost[i] = -1;
lowerHostCompare[i] = -1;
@@ -194,15 +191,15 @@ void boundSearchTest( )
lowerCL.copyFromHost(lowerHost);
}
search->execute(srcCL,size,upperCL,bucketSize,b3BoundSearchCL::BOUND_UPPER);
search->execute(srcCL,size,lowerCL,bucketSize,b3BoundSearchCL::BOUND_LOWER);
search->execute(srcCL, size, upperCL, bucketSize, b3BoundSearchCL::BOUND_UPPER);
search->execute(srcCL, size, lowerCL, bucketSize, b3BoundSearchCL::BOUND_LOWER);
search->executeHost(srcHost,size,upperHostCompare,bucketSize,b3BoundSearchCL::BOUND_UPPER);
search->executeHost(srcHost,size,lowerHostCompare,bucketSize,b3BoundSearchCL::BOUND_LOWER);
search->executeHost(srcHost, size, upperHostCompare, bucketSize, b3BoundSearchCL::BOUND_UPPER);
search->executeHost(srcHost, size, lowerHostCompare, bucketSize, b3BoundSearchCL::BOUND_LOWER);
lowerCL.copyToHost(lowerHost);
upperCL.copyToHost(upperHost);
for(int i=0; i<bucketSize; i++)
for (int i = 0; i < bucketSize; i++)
{
TEST_ASSERT(upperHostCompare[i] == upperHost[i]);
TEST_ASSERT(lowerHostCompare[i] == lowerHost[i]);
@@ -230,127 +227,120 @@ void boundSearchTest( )
}
*/
for(int i=0; i<bucketSize; i++)
for (int i = 0; i < bucketSize; i++)
{
int lhi = lowerHost[i];
int uhi = upperHost[i];
for(int j=lhi; j<uhi; j++)
for (int j = lhi; j < uhi; j++)
{
if ( srcHost[j].m_key != i )
if (srcHost[j].m_key != i)
{
printf("error %d != %d\n",srcHost[j].m_key,i);
printf("error %d != %d\n", srcHost[j].m_key, i);
}
TEST_ASSERT( srcHost[j].m_key == i );
TEST_ASSERT(srcHost[j].m_key == i);
}
}
}
delete search;
TEST_REPORT( "boundSearchTest" );
TEST_REPORT("boundSearchTest");
}
void prefixScanTest()
{
TEST_INIT;
int maxSize = 1024*256;
int maxSize = 1024 * 256;
b3AlignedObjectArray<unsigned int> buf0Host;
b3AlignedObjectArray<unsigned int> buf1Host;
b3OpenCLArray<unsigned int> buf2CL(g_context,g_queue,maxSize);
b3OpenCLArray<unsigned int> buf3CL(g_context,g_queue,maxSize);
b3PrefixScanCL* scan = new b3PrefixScanCL(g_context,g_device,g_queue,maxSize);
int dx = maxSize/NUM_TESTS;
for(int iter=0; iter<NUM_TESTS; iter++)
b3OpenCLArray<unsigned int> buf2CL(g_context, g_queue, maxSize);
b3OpenCLArray<unsigned int> buf3CL(g_context, g_queue, maxSize);
b3PrefixScanCL* scan = new b3PrefixScanCL(g_context, g_device, g_queue, maxSize);
int dx = maxSize / NUM_TESTS;
for (int iter = 0; iter < NUM_TESTS; iter++)
{
int size = b3Min( 128+dx*iter, maxSize );
int size = b3Min(128 + dx * iter, maxSize);
buf0Host.resize(size);
buf1Host.resize(size);
for(int i=0; i<size; i++)
for (int i = 0; i < size; i++)
buf0Host[i] = 1;
buf2CL.copyFromHost( buf0Host);
buf2CL.copyFromHost(buf0Host);
unsigned int sumHost, sumGPU;
scan->executeHost(buf0Host, buf1Host, size, &sumHost );
scan->execute( buf2CL, buf3CL, size, &sumGPU );
scan->executeHost(buf0Host, buf1Host, size, &sumHost);
scan->execute(buf2CL, buf3CL, size, &sumGPU);
buf3CL.copyToHost(buf0Host);
TEST_ASSERT( sumHost == sumGPU );
for(int i=0; i<size; i++)
TEST_ASSERT( buf1Host[i] == buf0Host[i] );
TEST_ASSERT(sumHost == sumGPU);
for (int i = 0; i < size; i++)
TEST_ASSERT(buf1Host[i] == buf0Host[i]);
}
delete scan;
TEST_REPORT( "scanTest" );
TEST_REPORT("scanTest");
}
bool radixSortTest()
{
TEST_INIT;
int maxSize = 1024*256;
int maxSize = 1024 * 256;
b3AlignedObjectArray<b3SortData> buf0Host;
buf0Host.resize(maxSize);
b3AlignedObjectArray<b3SortData> buf1Host;
buf1Host.resize(maxSize );
b3OpenCLArray<b3SortData> buf2CL(g_context,g_queue,maxSize);
buf1Host.resize(maxSize);
b3OpenCLArray<b3SortData> buf2CL(g_context, g_queue, maxSize);
b3RadixSort32CL* sort = new b3RadixSort32CL(g_context,g_device,g_queue,maxSize);
b3RadixSort32CL* sort = new b3RadixSort32CL(g_context, g_device, g_queue, maxSize);
int dx = maxSize/NUM_TESTS;
for(int iter=0; iter<NUM_TESTS; iter++)
int dx = maxSize / NUM_TESTS;
for (int iter = 0; iter < NUM_TESTS; iter++)
{
int size = b3Min( 128+dx*iter, maxSize-512 );
size = NEXTMULTIPLEOF( size, 512 );//not necessary
int size = b3Min(128 + dx * iter, maxSize - 512);
size = NEXTMULTIPLEOF(size, 512); //not necessary
buf0Host.resize(size);
for(int i=0; i<size; i++)
for (int i = 0; i < size; i++)
{
b3SortData v;
v.m_key = getRandom(0,0xff);
v.m_key = getRandom(0, 0xff);
v.m_value = i;
buf0Host[i] = v;
}
buf2CL.copyFromHost( buf0Host);
buf2CL.copyFromHost(buf0Host);
sort->executeHost( buf0Host);
sort->executeHost(buf0Host);
sort->execute(buf2CL);
buf2CL.copyToHost(buf1Host);
for(int i=0; i<size; i++)
for (int i = 0; i < size; i++)
{
TEST_ASSERT( buf0Host[i].m_value == buf1Host[i].m_value && buf0Host[i].m_key == buf1Host[i].m_key );
TEST_ASSERT(buf0Host[i].m_value == buf1Host[i].m_value && buf0Host[i].m_key == buf1Host[i].m_key);
}
}
delete sort;
TEST_REPORT( "radixSort" );
TEST_REPORT("radixSort");
return g_testFailed;
}
int main(int argc, char** argv)
{
int preferredDeviceIndex = -1;
@@ -360,7 +350,7 @@ int main(int argc, char** argv)
args.GetCmdLineArgument("deviceId", preferredDeviceIndex);
args.GetCmdLineArgument("platformId", preferredPlatformIndex);
initCL(preferredDeviceIndex,preferredPlatformIndex);
initCL(preferredDeviceIndex, preferredPlatformIndex);
fillIntTest();
@@ -372,7 +362,7 @@ int main(int argc, char** argv)
exitCL();
printf("%d tests passed, %d tests failed\n",g_nPassed, g_nFailed);
printf("%d tests passed, %d tests failed\n", g_nPassed, g_nFailed);
printf("End, press <enter>\n");
getchar();
}

View File

@@ -47,17 +47,16 @@
* Converted from CUDA to OpenCL/DirectCompute by Erwin Coumans
******************************************************************************/
#ifdef _WIN32
#pragma warning (disable:4996)
#pragma warning(disable : 4996)
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <float.h>
#include <algorithm>
#include <string>
//#include <iostream>
#include <sstream>
/**********************
@@ -77,19 +76,16 @@ cl_command_queue g_cqCommandQueue;
*/
bool g_verbose;
///Preferred OpenCL device/platform. When < 0 then no preference is used.
///Preferred OpenCL device/platform. When < 0 then no preference is used.
///Note that b3OpenCLUtils might still use the preference of using a platform vendor that matches the SDK vendor used to build the application.
///Preferred device/platform take priority over this platform-vendor match
int gPreferredDeviceId = -1;
int gPreferredPlatformId = -1;
/******************************************************************************
* Routines
******************************************************************************/
/**
* Keys-only sorting. Uses the GPU to sort the specified vector of elements for the given
* number of iterations, displaying runtime information.
@@ -105,7 +101,7 @@ int gPreferredPlatformId = -1;
*/
template <typename K>
void TimedSort(
unsigned int num_elements,
unsigned int num_elements,
K *h_keys,
unsigned int iterations)
{
@@ -114,21 +110,21 @@ void TimedSort(
int max_elements = num_elements;
b3AlignedObjectArray<unsigned int> hostData;
hostData.resize(num_elements);
for (int i=0;i<num_elements;i++)
for (int i = 0; i < num_elements; i++)
{
hostData[i] = h_keys[i];
}
b3RadixSort32CL sorter(g_cxMainContext,g_device,g_cqCommandQueue);
b3RadixSort32CL sorter(g_cxMainContext, g_device, g_cqCommandQueue);
b3OpenCLArray<unsigned int> gpuData(g_cxMainContext,g_cqCommandQueue);
b3OpenCLArray<unsigned int> gpuData(g_cxMainContext, g_cqCommandQueue);
gpuData.copyFromHost(hostData);
//sorter.executeHost(gpuData);
sorter.execute(gpuData);
sorter.execute(gpuData);
b3AlignedObjectArray<unsigned int> hostDataSorted;
gpuData.copyToHost(hostDataSorted);
clFinish(g_cqCommandQueue);
{
@@ -148,44 +144,38 @@ void TimedSort(
watch.reset();
for (int i = 0; i < iterations; i++)
for (int i = 0; i < iterations; i++)
{
// Move a fresh copy of the problem into device storage
gpuData.copyFromHost(hostData);
clFinish(g_cqCommandQueue);
// Start GPU timing record
double startMs = watch.getTimeMicroseconds()/1e3;
double startMs = watch.getTimeMicroseconds() / 1e3;
// Call the sorting API routine
sorter.execute(gpuData);
clFinish(g_cqCommandQueue);
double stopMs = watch.getTimeMicroseconds()/1e3;
double stopMs = watch.getTimeMicroseconds() / 1e3;
duration = stopMs - startMs;
// End GPU timing record
elapsed += (double) duration;
elapsed += (double)duration;
printf("duration = %f\n", duration);
}
// Display timing information
double avg_runtime = elapsed / iterations;
// double throughput = ((double) num_elements) / avg_runtime / 1000.0 / 1000.0;
// printf(", %f GPU ms, %f x10^9 elts/sec\n", avg_runtime, throughput);
double throughput = ((double) num_elements) / avg_runtime / 1000.0 ;
printf(", %f GPU ms, %f x10^6 elts/sec\n", avg_runtime, throughput);
// double throughput = ((double) num_elements) / avg_runtime / 1000.0 / 1000.0;
// printf(", %f GPU ms, %f x10^9 elts/sec\n", avg_runtime, throughput);
double throughput = ((double)num_elements) / avg_runtime / 1000.0;
printf(", %f GPU ms, %f x10^6 elts/sec\n", avg_runtime, throughput);
gpuData.copyToHost(hostData);
for (int i=0;i<num_elements;i++)
for (int i = 0; i < num_elements; i++)
{
h_keys[i] = hostData[i];
}
@@ -209,30 +199,29 @@ void TimedSort(
*/
template <typename K, typename V>
void TimedSort(
unsigned int num_elements,
unsigned int num_elements,
K *h_keys,
V *h_values,
unsigned int iterations)
V *h_values,
unsigned int iterations)
{
printf("Key-values, %d iterations, %d elements\n", iterations, num_elements);
int max_elements = num_elements;
b3AlignedObjectArray<b3SortData> hostData;
hostData.resize(num_elements);
for (int i=0;i<num_elements;i++)
for (int i = 0; i < num_elements; i++)
{
hostData[i].m_key = h_keys[i];
hostData[i].m_value = h_values[i];
}
b3RadixSort32CL sorter(g_cxMainContext,g_device,g_cqCommandQueue);
b3RadixSort32CL sorter(g_cxMainContext, g_device, g_cqCommandQueue);
b3OpenCLArray<b3SortData> gpuData(g_cxMainContext,g_cqCommandQueue);
b3OpenCLArray<b3SortData> gpuData(g_cxMainContext, g_cqCommandQueue);
gpuData.copyFromHost(hostData);
//sorter.executeHost(gpuData);
sorter.execute(gpuData);
sorter.execute(gpuData);
b3AlignedObjectArray<b3SortData> hostDataSorted;
gpuData.copyToHost(hostDataSorted);
#if 0
@@ -242,8 +231,8 @@ void TimedSort(
printf("hostData[%d].m_value = %d\n",i,hostDataSorted[i].m_value);
}
#endif
clFinish(g_cqCommandQueue);
clFinish(g_cqCommandQueue);
{
//printf("Key-values, %d iterations, %d elements", iterations, num_elements);
@@ -254,7 +243,7 @@ clFinish(g_cqCommandQueue);
double elapsed = 0;
float duration = 0;
b3Clock watch;
//warm-start
gpuData.copyFromHost(hostData);
sorter.execute(gpuData);
@@ -262,41 +251,37 @@ clFinish(g_cqCommandQueue);
watch.reset();
for (int i = 0; i < iterations; i++)
for (int i = 0; i < iterations; i++)
{
// Move a fresh copy of the problem into device storage
gpuData.copyFromHost(hostData);
clFinish(g_cqCommandQueue);
// Start GPU timing record
double startMs = watch.getTimeMicroseconds()/1e3;
double startMs = watch.getTimeMicroseconds() / 1e3;
// Call the sorting API routine
sorter.execute(gpuData);
clFinish(g_cqCommandQueue);
double stopMs = watch.getTimeMicroseconds()/1e3;
double stopMs = watch.getTimeMicroseconds() / 1e3;
duration = stopMs - startMs;
// End GPU timing record
elapsed += (double) duration;
elapsed += (double)duration;
printf("duration = %f\n", duration);
}
// Display timing information
double avg_runtime = elapsed / iterations;
// double throughput = ((double) num_elements) / avg_runtime / 1000.0 / 1000.0;
// printf(", %f GPU ms, %f x10^9 elts/sec\n", avg_runtime, throughput);
double throughput = ((double) num_elements) / avg_runtime / 1000.0 ;
printf(", %f GPU ms, %f x10^6 elts/sec\n", avg_runtime, throughput);
// double throughput = ((double) num_elements) / avg_runtime / 1000.0 / 1000.0;
// printf(", %f GPU ms, %f x10^9 elts/sec\n", avg_runtime, throughput);
double throughput = ((double)num_elements) / avg_runtime / 1000.0;
printf(", %f GPU ms, %f x10^6 elts/sec\n", avg_runtime, throughput);
gpuData.copyToHost(hostData);
for (int i=0;i<num_elements;i++)
for (int i = 0; i < num_elements; i++)
{
h_keys[i] = hostData[i].m_key;
h_values[i] = hostData[i].m_value;
@@ -304,8 +289,6 @@ clFinish(g_cqCommandQueue);
}
}
/**
* Generates random 32-bit keys.
*
@@ -333,110 +316,124 @@ void RandomBits(K &key, int entropy_reduction = 0, int lower_key_bits = sizeof(K
{
const unsigned int NUM_UCHARS = (sizeof(K) + sizeof(unsigned char) - 1) / sizeof(unsigned char);
unsigned char key_bits[NUM_UCHARS];
do {
for (int j = 0; j < NUM_UCHARS; j++) {
do
{
for (int j = 0; j < NUM_UCHARS; j++)
{
unsigned char quarterword = 0xff;
for (int i = 0; i <= entropy_reduction; i++) {
for (int i = 0; i <= entropy_reduction; i++)
{
quarterword &= (rand() >> 7);
}
key_bits[j] = quarterword;
}
if (lower_key_bits < sizeof(K) * 8) {
if (lower_key_bits < sizeof(K) * 8)
{
unsigned long long base = 0;
memcpy(&base, key_bits, sizeof(K));
base &= (1 << lower_key_bits) - 1;
memcpy(key_bits, &base, sizeof(K));
}
memcpy(&key, key_bits, sizeof(K));
} while (key != key); // avoids NaNs when generating random floating point numbers
}
memcpy(&key, key_bits, sizeof(K));
} while (key != key); // avoids NaNs when generating random floating point numbers
}
/******************************************************************************
* Templated routines for printing keys/values to the console
******************************************************************************/
template<typename T>
void PrintValue(T val) {
template <typename T>
void PrintValue(T val)
{
printf("%d", val);
}
template<>
void PrintValue<float>(float val) {
template <>
void PrintValue<float>(float val)
{
printf("%f", val);
}
template<>
void PrintValue<double>(double val) {
template <>
void PrintValue<double>(double val)
{
printf("%f", val);
}
template<>
void PrintValue<unsigned char>(unsigned char val) {
template <>
void PrintValue<unsigned char>(unsigned char val)
{
printf("%u", val);
}
template<>
void PrintValue<unsigned short>(unsigned short val) {
template <>
void PrintValue<unsigned short>(unsigned short val)
{
printf("%u", val);
}
template<>
void PrintValue<unsigned int>(unsigned int val) {
template <>
void PrintValue<unsigned int>(unsigned int val)
{
printf("%u", val);
}
template<>
void PrintValue<long>(long val) {
template <>
void PrintValue<long>(long val)
{
printf("%ld", val);
}
template<>
void PrintValue<unsigned long>(unsigned long val) {
template <>
void PrintValue<unsigned long>(unsigned long val)
{
printf("%lu", val);
}
template<>
void PrintValue<long long>(long long val) {
template <>
void PrintValue<long long>(long long val)
{
printf("%lld", val);
}
template<>
void PrintValue<unsigned long long>(unsigned long long val) {
template <>
void PrintValue<unsigned long long>(unsigned long long val)
{
printf("%llu", val);
}
/**
* Compares the equivalence of two arrays
*/
template <typename T, typename SizeT>
int CompareResults(T* computed, T* reference, SizeT len, bool verbose = true)
int CompareResults(T *computed, T *reference, SizeT len, bool verbose = true)
{
printf("\n");
for (SizeT i = 0; i < len; i++) {
if (computed[i] != reference[i]) {
printf("INCORRECT: [%lu]: ", (unsigned long) i);
for (SizeT i = 0; i < len; i++)
{
if (computed[i] != reference[i])
{
printf("INCORRECT: [%lu]: ", (unsigned long)i);
PrintValue<T>(computed[i]);
printf(" != ");
PrintValue<T>(reference[i]);
if (verbose) {
if (verbose)
{
printf("\nresult[...");
for (size_t j = (i >= 5) ? i - 5 : 0; (j < i + 5) && (j < len); j++) {
for (size_t j = (i >= 5) ? i - 5 : 0; (j < i + 5) && (j < len); j++)
{
PrintValue<T>(computed[j]);
printf(", ");
}
printf("...]");
printf("\nreference[...");
for (size_t j = (i >= 5) ? i - 5 : 0; (j < i + 5) && (j < len); j++) {
for (size_t j = (i >= 5) ? i - 5 : 0; (j < i + 5) && (j < len); j++)
{
PrintValue<T>(reference[j]);
printf(", ");
}
@@ -463,71 +460,74 @@ int CompareResults(T* computed, T* reference, SizeT len, bool verbose = true)
* @param[in] cfg
* Config
*/
template<typename K, typename V>
template <typename K, typename V>
void TestSort(
unsigned int iterations,
int num_elements,
bool keys_only)
{
// Allocate the sorting problem on the host and fill the keys with random bytes
// Allocate the sorting problem on the host and fill the keys with random bytes
K *h_keys = NULL;
K *h_reference_keys = NULL;
V *h_values = NULL;
h_keys = (K*) malloc(num_elements * sizeof(K));
h_reference_keys = (K*) malloc(num_elements * sizeof(K));
if (!keys_only) h_values = (V*) malloc(num_elements * sizeof(V));
h_keys = (K *)malloc(num_elements * sizeof(K));
h_reference_keys = (K *)malloc(num_elements * sizeof(K));
if (!keys_only) h_values = (V *)malloc(num_elements * sizeof(V));
// Use random bits
for (unsigned int i = 0; i < num_elements; ++i) {
for (unsigned int i = 0; i < num_elements; ++i)
{
RandomBits<K>(h_keys[i], 0);
//h_keys[i] = num_elements-i;
//h_keys[i] = 0xffffffffu-i;
//h_keys[i] = 0xffffffffu-i;
if (!keys_only)
h_values[i] = h_keys[i];//0xffffffffu-i;
h_values[i] = h_keys[i]; //0xffffffffu-i;
h_reference_keys[i] = h_keys[i];
}
// Run the timing test
if (keys_only) {
// Run the timing test
if (keys_only)
{
TimedSort<K>(num_elements, h_keys, iterations);
} else {
}
else
{
TimedSort<K, V>(num_elements, h_keys, h_values, iterations);
}
// cudaThreadSynchronize();
// cudaThreadSynchronize();
// Display sorted key data
if (g_verbose) {
if (g_verbose)
{
printf("\n\nKeys:\n");
for (int i = 0; i < num_elements; i++) {
for (int i = 0; i < num_elements; i++)
{
PrintValue<K>(h_keys[i]);
printf(", ");
}
printf("\n\n");
}
// Verify solution
std::sort(h_reference_keys, h_reference_keys + num_elements);
}
// Verify solution
std::sort(h_reference_keys, h_reference_keys + num_elements);
CompareResults<K>(h_keys, h_reference_keys, num_elements, true);
printf("\n");
fflush(stdout);
// Free our allocated host memory
// Free our allocated host memory
if (h_keys != NULL) free(h_keys);
if (h_values != NULL) free(h_values);
if (h_values != NULL) free(h_values);
}
/**
* Displays the commandline usage for this tool
*/
void Usage()
void Usage()
{
printf("\ntest_large_problem_sorting [--device=<device index>] [--v] [--i=<num-iterations>] [--n=<num-elements>] [--key-values] [--deviceId=<int>] [--platformId=<int>]\n");
printf("\ntest_large_problem_sorting [--device=<device index>] [--v] [--i=<num-iterations>] [--n=<num-elements>] [--key-values] [--deviceId=<int>] [--platformId=<int>]\n");
printf("\n");
printf("\t--v\tDisplays sorted results to the console.\n");
printf("\n");
@@ -541,7 +541,6 @@ void Usage()
printf("\n");
}
/******************************************************************************
* Command-line parsing
******************************************************************************/
@@ -552,44 +551,47 @@ void Usage()
class b3CommandLineArgs
{
protected:
std::map<std::string, std::string> pairs;
public:
// Constructor
b3CommandLineArgs(int argc, char **argv)
{
using namespace std;
for (int i = 1; i < argc; i++)
{
string arg = argv[i];
for (int i = 1; i < argc; i++)
{
string arg = argv[i];
if ((arg[0] != '-') || (arg[1] != '-')) {
continue;
}
if ((arg[0] != '-') || (arg[1] != '-'))
{
continue;
}
string::size_type pos;
string key, val;
if ((pos = arg.find( '=')) == string::npos) {
key = string(arg, 2, arg.length() - 2);
val = "";
} else {
key = string(arg, 2, pos - 2);
val = string(arg, pos + 1, arg.length() - 1);
}
pairs[key] = val;
}
string::size_type pos;
string key, val;
if ((pos = arg.find('=')) == string::npos)
{
key = string(arg, 2, arg.length() - 2);
val = "";
}
else
{
key = string(arg, 2, pos - 2);
val = string(arg, pos + 1, arg.length() - 1);
}
pairs[key] = val;
}
}
bool CheckCmdLineFlag(const char* arg_name)
bool CheckCmdLineFlag(const char *arg_name)
{
using namespace std;
map<string, string>::iterator itr;
if ((itr = pairs.find(arg_name)) != pairs.end()) {
if ((itr = pairs.find(arg_name)) != pairs.end())
{
return true;
}
}
return false;
}
@@ -607,31 +609,29 @@ void b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
{
using namespace std;
map<string, string>::iterator itr;
if ((itr = pairs.find(arg_name)) != pairs.end()) {
if ((itr = pairs.find(arg_name)) != pairs.end())
{
istringstream strstream(itr->second);
strstream >> val;
}
}
template <>
void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &val)
{
using namespace std;
map<string, string>::iterator itr;
if ((itr = pairs.find(arg_name)) != pairs.end()) {
string s = itr->second;
val = (char*) malloc(sizeof(char) * (s.length() + 1));
strcpy(val, s.c_str());
} else {
val = NULL;
}
}
template <>
void b3CommandLineArgs::GetCmdLineArgument<char *>(const char *arg_name, char *&val)
{
using namespace std;
map<string, string>::iterator itr;
if ((itr = pairs.find(arg_name)) != pairs.end())
{
string s = itr->second;
val = (char *)malloc(sizeof(char) * (s.length() + 1));
strcpy(val, s.c_str());
}
else
{
val = NULL;
}
}
/******************************************************************************
* Main
@@ -639,28 +639,28 @@ void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &v
extern bool gDebugSkipLoadingBinary;
void myprintf(const char* msg)
void myprintf(const char *msg)
{
(void*) msg;
(void *)msg;
}
int main( int argc, char** argv)
int main(int argc, char **argv)
{
//gDebugSkipLoadingBinary = true;
// b3SetCustomPrintfFunc(myprintf);
// b3SetCustomPrintfFunc(myprintf);
cl_int ciErrNum;
b3CommandLineArgs args(argc,argv);
b3CommandLineArgs args(argc, argv);
args.GetCmdLineArgument("deviceId", gPreferredDeviceId);
args.GetCmdLineArgument("platformId", gPreferredPlatformId);
b3Printf("Initialize OpenCL using b3OpenCLUtils_createContextFromType\n");
cl_platform_id platformId;
// g_cxMainContext = b3OpenCLUtils_createContextFromType(CL_DEVICE_TYPE_ALL, &ciErrNum, 0, 0,gPreferredDeviceId,gPreferredPlatformId,&platformId);
g_cxMainContext = b3OpenCLUtils_createContextFromType(CL_DEVICE_TYPE_GPU, &ciErrNum, 0, 0,gPreferredDeviceId,gPreferredPlatformId,&platformId);
// g_cxMainContext = b3OpenCLUtils_createContextFromType(CL_DEVICE_TYPE_ALL, &ciErrNum, 0, 0,gPreferredDeviceId,gPreferredPlatformId,&platformId);
g_cxMainContext = b3OpenCLUtils_createContextFromType(CL_DEVICE_TYPE_GPU, &ciErrNum, 0, 0, gPreferredDeviceId, gPreferredPlatformId, &platformId);
//g_cxMainContext = b3OpenCLUtils_createContextFromType(CL_DEVICE_TYPE_CPU, &ciErrNum, 0, 0,gPreferredDeviceId,gPreferredPlatformId,&platformId);
oclCHECKERROR(ciErrNum, CL_SUCCESS);
int numDev = b3OpenCLUtils_getNumDevices(g_cxMainContext);
@@ -671,47 +671,37 @@ int main( int argc, char** argv)
exit(0);
}
int devId = 0;
g_device = b3OpenCLUtils_getDevice(g_cxMainContext,devId);
g_device = b3OpenCLUtils_getDevice(g_cxMainContext, devId);
b3OpenCLUtils_printDeviceInfo(g_device);
// create a command-queue
g_cqCommandQueue = clCreateCommandQueue(g_cxMainContext, g_device, 0, &ciErrNum);
oclCHECKERROR(ciErrNum, CL_SUCCESS);
//srand(time(NULL));
srand(0); // presently deterministic
unsigned int num_elements = 8 * 1024 * 1024; //4*1024*1024;//4*1024*1024;//257;//8*524288;//2048;//512;//524288;
unsigned int iterations = 10;
bool keys_only = true;
//srand(time(NULL));
srand(0); // presently deterministic
unsigned int num_elements = 8*1024*1024;//4*1024*1024;//4*1024*1024;//257;//8*524288;//2048;//512;//524288;
unsigned int iterations = 10;
bool keys_only = true;
//
//
// Check command line arguments
//
//
if (args.CheckCmdLineFlag("help"))
{
Usage();
return 0;
}
args.GetCmdLineArgument("i", iterations);
args.GetCmdLineArgument("n", num_elements);
keys_only = !args.CheckCmdLineFlag("key-values");
g_verbose = args.CheckCmdLineFlag("v");
TestSort<unsigned int, unsigned int>(
iterations,
num_elements,
keys_only);
iterations,
num_elements,
keys_only);
}