/* 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 #include "../basic_initialize/btOpenCLUtils.h" #include cl_context g_cxMainContext; cl_command_queue g_cqCommandQue; cl_kernel g_atomicsKernel; static const size_t workGroupSize = 128;//todo figure out an appropriate workgroup size suitable for the OpenCL platform/context/device/kernel #define NUM_OBJECTS 1024 #include "globalAtomicsKernel.h" char * findAndReplace( char const * const original, char const * const pattern, char const * const replacement); #include #include int main(int argc, char* argv[]) { int ciErrNum = 0; printf("press a key to start\n"); getchar(); const char* vendorSDK = btOpenCLUtils::getSdkVendorName(); printf("This program was compiled using the %s OpenCL SDK\n",vendorSDK); cl_device_type deviceType = CL_DEVICE_TYPE_GPU;//CL_DEVICE_TYPE_ALL void* glCtx=0; void* glDC = 0; printf("Initialize OpenCL using btOpenCLUtils::createContextFromType for CL_DEVICE_TYPE_GPU\n"); g_cxMainContext = btOpenCLUtils::createContextFromType(deviceType, &ciErrNum, glCtx, glDC); oclCHECKERROR(ciErrNum, CL_SUCCESS); int numDev = btOpenCLUtils::getNumDevices(g_cxMainContext); if (numDev>0) { int deviceIndex=0; cl_device_id device; device = btOpenCLUtils::getDevice(g_cxMainContext,deviceIndex); btOpenCLDeviceInfo clInfo; btOpenCLUtils::getDeviceInfo(device,clInfo); btOpenCLUtils::printDeviceInfo(device); const char* globalAtomicsKernelStringPatched = globalAtomicsKernelString; if (!strstr(clInfo.m_deviceExtensions,"cl_ext_atomic_counters_32")) { globalAtomicsKernelStringPatched = findAndReplace(globalAtomicsKernelString,"counter32_t", "volatile __global int*"); } // create a command-queue g_cqCommandQue = clCreateCommandQueue(g_cxMainContext, device, 0, &ciErrNum); oclCHECKERROR(ciErrNum, CL_SUCCESS); cl_mem counterBuffer = clCreateBuffer(g_cxMainContext, CL_MEM_READ_WRITE, sizeof(int), NULL, &ciErrNum); oclCHECKERROR(ciErrNum, CL_SUCCESS); char* kernelMethods[] = { "globalAtomicKernelOpenCL1_1", "counterAtomicKernelExt", "globalAtomicKernelExt", "globalAtomicKernelCounters32Broken" }; int numKernelMethods = sizeof(kernelMethods)/sizeof(char*); for (int i=0;i #include char * findAndReplace( char const * const original, char const * const pattern, char const * const replacement ) { size_t const replen = strlen(replacement); size_t const patlen = strlen(pattern); size_t const orilen = strlen(original); size_t patcnt = 0; const char * oriptr; const char * patloc; // find how many times the pattern occurs in the original string for (oriptr = original; patloc = strstr(oriptr, pattern); oriptr = patloc + patlen) { patcnt++; } { // allocate memory for the new string size_t const retlen = orilen + patcnt * (replen - patlen); char * const returned = (char *) malloc( sizeof(char) * (retlen + 1) ); if (returned != NULL) { // copy the original string, // replacing all the instances of the pattern char * retptr = returned; for (oriptr = original; patloc = strstr(oriptr, pattern); oriptr = patloc + patlen) { size_t const skplen = patloc - oriptr; // copy the section until the occurence of the pattern strncpy(retptr, oriptr, skplen); retptr += skplen; // copy the replacement strncpy(retptr, replacement, replen); retptr += replen; } // copy the rest of the string. strcpy(retptr, oriptr); } return returned; } } #ifdef _WIN32 #pragma warning( pop ) #endif //_WIN32