2013-03-11 21:03:27 +00:00
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
|
|
|
Copyright (c) 2011 Advanced Micro Devices, Inc. http://bulletphysics.org
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
///original author: Erwin Coumans
|
|
|
|
|
2013-04-30 02:04:08 +00:00
|
|
|
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
|
2013-03-11 21:03:27 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
cl_context g_cxMainContext;
|
|
|
|
cl_command_queue g_cqCommandQue;
|
|
|
|
|
|
|
|
|
2013-06-03 20:10:27 +00:00
|
|
|
#include "Bullet3Common/b3Logging.h"
|
|
|
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
|
|
|
void myprintf(const char* msg)
|
|
|
|
{
|
|
|
|
#ifdef _WINDOWS
|
|
|
|
OutputDebugStringA(msg);
|
|
|
|
#else
|
|
|
|
printf(msg);
|
|
|
|
#endif
|
|
|
|
}
|
2013-03-11 21:03:27 +00:00
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2013-06-03 20:10:27 +00:00
|
|
|
b3SetCustomPrintfFunc(myprintf);
|
|
|
|
b3SetCustomWarningMessageFunc(myprintf);
|
|
|
|
b3SetCustomErrorMessageFunc(myprintf);
|
|
|
|
|
|
|
|
b3Printf("test b3Printf\n");
|
|
|
|
b3Warning("test warning\n");
|
|
|
|
b3Error("test error\n");
|
|
|
|
|
2013-03-11 21:03:27 +00:00
|
|
|
int ciErrNum = 0;
|
|
|
|
|
|
|
|
cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
|
2013-04-16 01:26:09 +00:00
|
|
|
const char* vendorSDK = b3OpenCLUtils::getSdkVendorName();
|
2013-03-11 21:03:27 +00:00
|
|
|
|
2013-06-03 20:10:27 +00:00
|
|
|
b3Printf("This program was compiled using the %s OpenCL SDK\n",vendorSDK);
|
2013-04-16 01:26:09 +00:00
|
|
|
int numPlatforms = b3OpenCLUtils::getNumPlatforms();
|
2013-06-03 20:10:27 +00:00
|
|
|
b3Printf("Num Platforms = %d\n", numPlatforms);
|
2013-03-11 21:03:27 +00:00
|
|
|
|
|
|
|
for (int i=0;i<numPlatforms;i++)
|
|
|
|
{
|
2013-04-16 01:26:09 +00:00
|
|
|
cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
|
2013-04-29 06:11:10 +00:00
|
|
|
b3OpenCLPlatformInfo platformInfo;
|
2013-04-16 01:26:09 +00:00
|
|
|
b3OpenCLUtils::getPlatformInfo(platform,&platformInfo);
|
2013-06-03 20:10:27 +00:00
|
|
|
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);
|
2013-03-11 21:03:27 +00:00
|
|
|
|
2013-04-16 01:26:09 +00:00
|
|
|
cl_context context = b3OpenCLUtils::createContextFromPlatform(platform,deviceType,&ciErrNum);
|
2013-03-11 21:03:27 +00:00
|
|
|
|
2013-04-16 01:26:09 +00:00
|
|
|
int numDevices = b3OpenCLUtils::getNumDevices(context);
|
2013-06-03 20:10:27 +00:00
|
|
|
b3Printf("Num Devices = %d\n", numDevices);
|
2013-03-11 21:03:27 +00:00
|
|
|
for (int j=0;j<numDevices;j++)
|
|
|
|
{
|
2013-04-16 01:26:09 +00:00
|
|
|
cl_device_id dev = b3OpenCLUtils::getDevice(context,j);
|
2013-04-29 06:11:10 +00:00
|
|
|
b3OpenCLDeviceInfo devInfo;
|
2013-04-16 01:26:09 +00:00
|
|
|
b3OpenCLUtils::getDeviceInfo(dev,&devInfo);
|
|
|
|
b3OpenCLUtils::printDeviceInfo(dev);
|
2013-03-11 21:03:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clReleaseContext(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
///Easier method to initialize OpenCL using createContextFromType for a GPU
|
|
|
|
deviceType = CL_DEVICE_TYPE_GPU;
|
|
|
|
|
|
|
|
void* glCtx=0;
|
|
|
|
void* glDC = 0;
|
2013-06-03 20:10:27 +00:00
|
|
|
b3Printf("Initialize OpenCL using b3OpenCLUtils::createContextFromType for CL_DEVICE_TYPE_GPU\n");
|
2013-04-16 01:26:09 +00:00
|
|
|
g_cxMainContext = b3OpenCLUtils::createContextFromType(deviceType, &ciErrNum, glCtx, glDC);
|
2013-03-11 21:03:27 +00:00
|
|
|
oclCHECKERROR(ciErrNum, CL_SUCCESS);
|
|
|
|
|
|
|
|
if (g_cxMainContext)
|
|
|
|
{
|
2013-04-16 01:26:09 +00:00
|
|
|
int numDev = b3OpenCLUtils::getNumDevices(g_cxMainContext);
|
2013-03-11 21:03:27 +00:00
|
|
|
|
|
|
|
for (int i=0;i<numDev;i++)
|
|
|
|
{
|
|
|
|
cl_device_id device;
|
2013-04-16 01:26:09 +00:00
|
|
|
device = b3OpenCLUtils::getDevice(g_cxMainContext,i);
|
2013-04-29 06:11:10 +00:00
|
|
|
b3OpenCLDeviceInfo clInfo;
|
2013-04-16 01:26:09 +00:00
|
|
|
b3OpenCLUtils::getDeviceInfo(device,&clInfo);
|
|
|
|
b3OpenCLUtils::printDeviceInfo(device);
|
2013-03-11 21:03:27 +00:00
|
|
|
// 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
|
|
|
|
|
|
|
|
clReleaseCommandQueue(g_cqCommandQue);
|
|
|
|
}
|
|
|
|
|
|
|
|
clReleaseContext(g_cxMainContext);
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
2013-06-03 20:10:27 +00:00
|
|
|
b3Printf("No OpenCL capable GPU found!");
|
2013-03-11 21:03:27 +00:00
|
|
|
}
|
2013-06-03 20:10:27 +00:00
|
|
|
b3Printf("press <Enter>\n");
|
2013-04-30 02:04:08 +00:00
|
|
|
getchar();
|
2013-03-11 21:03:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|