Skip to content
Browse files

added basic OpenCL initialization test, using premake4 build system

still some issue: premake4 project info leaks from one project to the other (so GLSL_Instancing links wrongly to OpenCL)
  • Loading branch information...
1 parent a8ea478 commit 02071ef6c48600764086dcb5f34558bb2a3c9569 @erwincoumans committed Jun 1, 2011
View
2 .gitignore
@@ -4,4 +4,4 @@ build/vs2010/
build/vs2005/
build/lib/
build/.gitattributes
-/bin/GLSL_instancing.exe
+bin/GLSL_instancing.exe
View
BIN bin/GLSL_instancing.exe
Binary file not shown.
View
13 build/premake4.lua
@@ -1,6 +1,6 @@
solution "0MySolution"
- configurations {"Debug", "Release"}
+ configurations {"Release", "Debug"}
configuration "Release"
flags { "Optimize", "StaticRuntime", "NoRTTI", "NoExceptions"}
configuration "Debug"
@@ -24,7 +24,7 @@ solution "0MySolution"
configuration {}
local amdopenclpath = os.getenv("AMDAPPSDKROOT")
if (amdopenclpath) then
- defines { "ADL_ENABLE_CL" }
+ defines { "ADL_ENABLE_CL" , "CL_PLATFORM_AMD"}
includedirs {
"$(AMDAPPSDKROOT)/include"
}
@@ -33,13 +33,15 @@ solution "0MySolution"
configuration "x64"
libdirs {"$(AMDAPPSDKROOT)/lib/x86_64"}
configuration {}
+
+ links {"OpenCL"}
return true
end
configuration {}
local nvidiaopenclpath = os.getenv("CUDA_PATH")
if (nvidiaopenclpath) then
- defines { "ADL_ENABLE_CL" }
+ defines { "ADL_ENABLE_CL" , "CL_PLATFORM_NVIDIA"}
includedirs {
"$(CUDA_PATH)/include"
}
@@ -48,6 +50,9 @@ solution "0MySolution"
configuration "x64"
libdirs {"$(CUDA_PATH)/lib/x64"}
configuration {}
+
+ links {"OpenCL"}
+
return true
end
@@ -61,4 +66,6 @@ solution "0MySolution"
location "build"
targetdir "bin"
+ include "../opencl/basic_initialize"
include "../rendering/GLSL_Instancing"
+
View
296 opencl/basic_initialize/btOpenCLUtils.cpp
@@ -0,0 +1,296 @@
+/*
+Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org
+Copyright (C) 2006 - 2011 Sony Computer Entertainment Inc.
+
+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: Roman Ponomarev
+//cleanup by Erwin Coumans
+
+#include <string.h>
+
+#include "btOpenCLUtils.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+
+
+static char* spPlatformVendor =
+#if defined(CL_PLATFORM_MINI_CL)
+"MiniCL, SCEA";
+#elif defined(CL_PLATFORM_AMD)
+"Advanced Micro Devices, Inc.";
+#elif defined(CL_PLATFORM_NVIDIA)
+"NVIDIA Corporation";
+#else
+"Unknown Vendor";
+#endif
+
+#ifndef CL_PLATFORM_MINI_CL
+#ifdef _WIN32
+#include "CL/cl_gl.h"
+#endif //_WIN32
+#endif
+
+cl_context btOpenCLUtils::createContextFromType(cl_device_type deviceType, cl_int* pErrNum, void* pGLContext, void* pGLDC )
+{
+ cl_uint numPlatforms;
+ cl_platform_id platform = NULL;
+ cl_int ciErrNum = clGetPlatformIDs(0, NULL, &numPlatforms);
+ if(ciErrNum != CL_SUCCESS)
+ {
+ if(pErrNum != NULL) *pErrNum = ciErrNum;
+ return NULL;
+ }
+ if(numPlatforms > 0)
+ {
+ cl_platform_id* platforms = new cl_platform_id[numPlatforms];
+ ciErrNum = clGetPlatformIDs(numPlatforms, platforms, NULL);
+ if(ciErrNum != CL_SUCCESS)
+ {
+ if(pErrNum != NULL) *pErrNum = ciErrNum;
+ return NULL;
+ }
+ for (unsigned i = 0; i < numPlatforms; ++i)
+ {
+ char pbuf[128];
+ ciErrNum = clGetPlatformInfo( platforms[i],
+ CL_PLATFORM_VENDOR,
+ sizeof(pbuf),
+ pbuf,
+ NULL);
+ if(ciErrNum != CL_SUCCESS)
+ {
+ if(pErrNum != NULL) *pErrNum = ciErrNum;
+ return NULL;
+ }
+ platform = platforms[i];
+ if(!strcmp(pbuf, spPlatformVendor))
+ {
+ break;
+ }
+ }
+ delete[] platforms;
+ }
+ /*
+ * If we could find our platform, use it. Otherwise pass a NULL and get whatever the
+ * implementation thinks we should be using.
+ */
+ cl_context_properties cps[7] =
+ {
+ CL_CONTEXT_PLATFORM,
+ (cl_context_properties)platform,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0
+ };
+#ifndef CL_PLATFORM_MINI_CL
+#ifdef _WIN32
+ // If we have a gl context then enable interop
+ if( pGLContext )
+ {
+ cps[2] = CL_GL_CONTEXT_KHR;
+ cps[3] = (cl_context_properties)pGLContext;
+ cps[4] = CL_WGL_HDC_KHR;
+ cps[5] = (cl_context_properties)pGLDC;
+ }
+#endif
+#endif //CL_PLATFORM_MINI_CL
+
+ /* Use NULL for backward compatibility */
+ cl_context_properties* cprops = (NULL == platform) ? NULL : cps;
+ cl_context retContext = clCreateContextFromType(cprops,
+ deviceType,
+ NULL,
+ NULL,
+ &ciErrNum);
+ if(pErrNum != NULL) *pErrNum = ciErrNum;
+ return retContext;
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+//! Gets the id of the nth device from the context
+//!
+//! @return the id or -1 when out of range
+//! @param cxMainContext OpenCL context
+//! @param device_idx index of the device of interest
+//////////////////////////////////////////////////////////////////////////////
+cl_device_id btOpenCLUtils::getDevice(cl_context cxMainContext, int deviceIndex)
+{
+ size_t szParmDataBytes;
+ cl_device_id* cdDevices;
+
+ // get the list of GPU devices associated with context
+ clGetContextInfo(cxMainContext, CL_CONTEXT_DEVICES, 0, NULL, &szParmDataBytes);
+
+ if( szParmDataBytes / sizeof(cl_device_id) < deviceIndex ) {
+ return (cl_device_id)-1;
+ }
+
+ cdDevices = (cl_device_id*) malloc(szParmDataBytes);
+
+ clGetContextInfo(cxMainContext, CL_CONTEXT_DEVICES, szParmDataBytes, cdDevices, NULL);
+
+ cl_device_id device = cdDevices[deviceIndex];
+ free(cdDevices);
+
+ return device;
+}
+
+int btOpenCLUtils::getNumDevices(cl_context cxMainContext)
+{
+ size_t szParamDataBytes;
+ clGetContextInfo(cxMainContext, CL_CONTEXT_DEVICES, 0, NULL, &szParamDataBytes);
+ int device_count = (int) szParamDataBytes/ sizeof(cl_device_id);
+ return device_count;
+}
+
+void btOpenCLUtils::printDeviceInfo(cl_device_id device)
+{
+ btOpenCLDeviceInfo info;
+ getDeviceInfo(device,info);
+
+ printf(" CL_DEVICE_NAME: \t\t\t%s\n", info.m_deviceName);
+ printf(" CL_DEVICE_VENDOR: \t\t\t%s\n", info.m_deviceVendor);
+ printf(" CL_DRIVER_VERSION: \t\t\t%s\n", info.m_driverVersion);
+
+ if( info.m_deviceType & CL_DEVICE_TYPE_CPU )
+ printf(" CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_CPU");
+ if( info.m_deviceType & CL_DEVICE_TYPE_GPU )
+ printf(" CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_GPU");
+ if( info.m_deviceType & CL_DEVICE_TYPE_ACCELERATOR )
+ printf(" CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_ACCELERATOR");
+ if( info.m_deviceType & CL_DEVICE_TYPE_DEFAULT )
+ printf(" CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_DEFAULT");
+
+ printf(" CL_DEVICE_MAX_COMPUTE_UNITS:\t\t%u\n", info.m_computeUnits);
+ printf(" CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS:\t%u\n", info.m_workitemDims);
+ printf(" CL_DEVICE_MAX_WORK_ITEM_SIZES:\t%u / %u / %u \n", info.m_workItemSize[0], info.m_workItemSize[1], info.m_workItemSize[2]);
+ printf(" CL_DEVICE_MAX_WORK_GROUP_SIZE:\t%u\n", info.m_workgroupSize);
+ printf(" CL_DEVICE_MAX_CLOCK_FREQUENCY:\t%u MHz\n", info.m_clockFrequency);
+ printf(" CL_DEVICE_ADDRESS_BITS:\t\t%u\n", info.m_addressBits);
+ printf(" CL_DEVICE_MAX_MEM_ALLOC_SIZE:\t\t%u MByte\n", (unsigned int)(info.m_maxMemAllocSize/ (1024 * 1024)));
+ printf(" CL_DEVICE_GLOBAL_MEM_SIZE:\t\t%u MByte\n", (unsigned int)(info.m_globalMemSize/ (1024 * 1024)));
+ printf(" CL_DEVICE_ERROR_CORRECTION_SUPPORT:\t%s\n", info.m_errorCorrectionSupport== CL_TRUE ? "yes" : "no");
+ printf(" CL_DEVICE_LOCAL_MEM_TYPE:\t\t%s\n", info.m_localMemType == 1 ? "local" : "global");
+ printf(" CL_DEVICE_LOCAL_MEM_SIZE:\t\t%u KByte\n", (unsigned int)(info.m_localMemSize / 1024));
+ printf(" CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE:\t%u KByte\n", (unsigned int)(info.m_constantBufferSize / 1024));
+ if( info.m_queueProperties & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE )
+ printf(" CL_DEVICE_QUEUE_PROPERTIES:\t\t%s\n", "CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE");
+ if( info.m_queueProperties & CL_QUEUE_PROFILING_ENABLE )
+ printf(" CL_DEVICE_QUEUE_PROPERTIES:\t\t%s\n", "CL_QUEUE_PROFILING_ENABLE");
+
+ printf(" CL_DEVICE_IMAGE_SUPPORT:\t\t%u\n", info.m_imageSupport);
+
+ printf(" CL_DEVICE_MAX_READ_IMAGE_ARGS:\t%u\n", info.m_maxReadImageArgs);
+ printf(" CL_DEVICE_MAX_WRITE_IMAGE_ARGS:\t%u\n", info.m_maxWriteImageArgs);
+ printf("\n CL_DEVICE_IMAGE <dim>");
+ printf("\t\t\t2D_MAX_WIDTH\t %u\n", info.m_image2dMaxWidth);
+ printf("\t\t\t\t\t2D_MAX_HEIGHT\t %u\n", info.m_image2dMaxHeight);
+ printf("\t\t\t\t\t3D_MAX_WIDTH\t %u\n", info.m_image3dMaxWidth);
+ printf("\t\t\t\t\t3D_MAX_HEIGHT\t %u\n", info.m_image3dMaxHeight);
+ printf("\t\t\t\t\t3D_MAX_DEPTH\t %u\n", info.m_image3dMaxDepth);
+ if (info.m_deviceExtensions != 0)
+ printf("\n CL_DEVICE_EXTENSIONS:%s\n",info.m_deviceExtensions);
+ else
+ printf(" CL_DEVICE_EXTENSIONS: None\n");
+ printf(" CL_DEVICE_PREFERRED_VECTOR_WIDTH_<t>\t");
+ printf("CHAR %u, SHORT %u, INT %u,LONG %u, FLOAT %u, DOUBLE %u\n\n\n",
+ info.m_vecWidthChar, info.m_vecWidthShort, info.m_vecWidthInt, info.m_vecWidthLong,info.m_vecWidthFloat, info.m_vecWidthDouble);
+
+
+}
+
+void btOpenCLUtils::getDeviceInfo(cl_device_id device, btOpenCLDeviceInfo& info)
+{
+
+ // CL_DEVICE_NAME
+ clGetDeviceInfo(device, CL_DEVICE_NAME, BT_MAX_STRING_LENGTH, &info.m_deviceName, NULL);
+
+ // CL_DEVICE_VENDOR
+ clGetDeviceInfo(device, CL_DEVICE_VENDOR, BT_MAX_STRING_LENGTH, &info.m_deviceVendor, NULL);
+
+ // CL_DRIVER_VERSION
+ clGetDeviceInfo(device, CL_DRIVER_VERSION, BT_MAX_STRING_LENGTH, &info.m_driverVersion, NULL);
+
+ // CL_DEVICE_INFO
+ clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(cl_device_type), &info.m_deviceType, NULL);
+
+ // CL_DEVICE_MAX_COMPUTE_UNITS
+ clGetDeviceInfo(device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(info.m_computeUnits), &info.m_computeUnits, NULL);
+
+ // CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
+ clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(info.m_workitemDims), &info.m_workitemDims, NULL);
+
+ // CL_DEVICE_MAX_WORK_ITEM_SIZES
+ clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(info.m_workItemSize), &info.m_workItemSize, NULL);
+
+ // CL_DEVICE_MAX_WORK_GROUP_SIZE
+ clGetDeviceInfo(device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(info.m_workgroupSize), &info.m_workgroupSize, NULL);
+
+ // CL_DEVICE_MAX_CLOCK_FREQUENCY
+ clGetDeviceInfo(device, CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(info.m_clockFrequency), &info.m_clockFrequency, NULL);
+
+ // CL_DEVICE_ADDRESS_BITS
+ clGetDeviceInfo(device, CL_DEVICE_ADDRESS_BITS, sizeof(info.m_addressBits), &info.m_addressBits, NULL);
+
+ // CL_DEVICE_MAX_MEM_ALLOC_SIZE
+ clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(info.m_maxMemAllocSize), &info.m_maxMemAllocSize, NULL);
+
+ // CL_DEVICE_GLOBAL_MEM_SIZE
+ clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(info.m_globalMemSize), &info.m_globalMemSize, NULL);
+
+ // CL_DEVICE_ERROR_CORRECTION_SUPPORT
+ clGetDeviceInfo(device, CL_DEVICE_ERROR_CORRECTION_SUPPORT, sizeof(info.m_errorCorrectionSupport), &info.m_errorCorrectionSupport, NULL);
+
+ // CL_DEVICE_LOCAL_MEM_TYPE
+ clGetDeviceInfo(device, CL_DEVICE_LOCAL_MEM_TYPE, sizeof(info.m_localMemType), &info.m_localMemType, NULL);
+
+ // CL_DEVICE_LOCAL_MEM_SIZE
+ clGetDeviceInfo(device, CL_DEVICE_LOCAL_MEM_SIZE, sizeof(info.m_localMemSize), &info.m_localMemSize, NULL);
+
+ // CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
+ clGetDeviceInfo(device, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, sizeof(info.m_constantBufferSize), &info.m_constantBufferSize, NULL);
+
+ // CL_DEVICE_QUEUE_PROPERTIES
+ clGetDeviceInfo(device, CL_DEVICE_QUEUE_PROPERTIES, sizeof(info.m_queueProperties), &info.m_queueProperties, NULL);
+
+ // CL_DEVICE_IMAGE_SUPPORT
+ clGetDeviceInfo(device, CL_DEVICE_IMAGE_SUPPORT, sizeof(info.m_imageSupport), &info.m_imageSupport, NULL);
+
+ // CL_DEVICE_MAX_READ_IMAGE_ARGS
+ clGetDeviceInfo(device, CL_DEVICE_MAX_READ_IMAGE_ARGS, sizeof(info.m_maxReadImageArgs), &info.m_maxReadImageArgs, NULL);
+
+ // CL_DEVICE_MAX_WRITE_IMAGE_ARGS
+ clGetDeviceInfo(device, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, sizeof(info.m_maxWriteImageArgs), &info.m_maxWriteImageArgs, NULL);
+
+ // CL_DEVICE_IMAGE2D_MAX_WIDTH, CL_DEVICE_IMAGE2D_MAX_HEIGHT, CL_DEVICE_IMAGE3D_MAX_WIDTH, CL_DEVICE_IMAGE3D_MAX_HEIGHT, CL_DEVICE_IMAGE3D_MAX_DEPTH
+ clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof(size_t), &info.m_image2dMaxWidth, NULL);
+ clGetDeviceInfo(device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, sizeof(size_t), &info.m_image2dMaxHeight, NULL);
+ clGetDeviceInfo(device, CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof(size_t), &info.m_image3dMaxWidth, NULL);
+ clGetDeviceInfo(device, CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof(size_t), &info.m_image3dMaxHeight, NULL);
+ clGetDeviceInfo(device, CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof(size_t), &info.m_image3dMaxDepth, NULL);
+
+ // CL_DEVICE_EXTENSIONS: get device extensions, and if any then parse & log the string onto separate lines
+ clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, BT_MAX_STRING_LENGTH, &info.m_deviceExtensions, NULL);
+
+ // CL_DEVICE_PREFERRED_VECTOR_WIDTH_<type>
+ clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(cl_uint), &info.m_vecWidthChar, NULL);
+ clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, sizeof(cl_uint), &info.m_vecWidthShort, NULL);
+ clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, sizeof(cl_uint), &info.m_vecWidthInt, NULL);
+ clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, sizeof(cl_uint), &info.m_vecWidthLong, NULL);
+ clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, sizeof(cl_uint), &info.m_vecWidthFloat, NULL);
+ clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, sizeof(cl_uint), &info.m_vecWidthDouble, NULL);
+}
View
100 opencl/basic_initialize/btOpenCLUtils.h
@@ -0,0 +1,100 @@
+/*
+Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org
+Copyright (C) 2006 - 2011 Sony Computer Entertainment Inc.
+
+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: Roman Ponomarev
+//cleanup by Erwin Coumans
+
+#ifndef BT_OPENCL_UTILS_H
+#define BT_OPENCL_UTILS_H
+
+#ifdef __APPLE__
+#ifdef USE_MINICL
+#include <MiniCL/cl.h>
+#else
+#include <OpenCL/cl.h>
+#endif
+#else
+#ifdef USE_MINICL
+#include <MiniCL/cl.h>
+#else
+#include <CL/cl.h>
+#endif
+#endif //__APPLE__
+
+#include <assert.h>
+#include <stdio.h>
+#define oclCHECKERROR(a, b) if((a)!=(b)) { printf("OCL Error : %d\n", (a)); assert((a) == (b)); }
+
+#define BT_MAX_STRING_LENGTH 1024
+
+struct btOpenCLDeviceInfo
+{
+ char m_deviceName[BT_MAX_STRING_LENGTH];
+ char m_deviceVendor[BT_MAX_STRING_LENGTH];
+ char m_driverVersion[BT_MAX_STRING_LENGTH];
+ char m_deviceExtensions[BT_MAX_STRING_LENGTH];
+
+ cl_device_type m_deviceType;
+ cl_uint m_computeUnits;
+ size_t m_workitemDims;
+ size_t m_workItemSize[3];
+ size_t m_image2dMaxWidth;
+ size_t m_image2dMaxHeight;
+ size_t m_image3dMaxWidth;
+ size_t m_image3dMaxHeight;
+ size_t m_image3dMaxDepth;
+ size_t m_workgroupSize;
+ cl_uint m_clockFrequency;
+ cl_ulong m_constantBufferSize;
+ cl_ulong m_localMemSize;
+ cl_ulong m_globalMemSize;
+ cl_bool m_errorCorrectionSupport;
+ cl_device_local_mem_type m_localMemType;
+ cl_uint m_maxReadImageArgs;
+ cl_uint m_maxWriteImageArgs;
+
+
+
+ cl_uint m_addressBits;
+ cl_ulong m_maxMemAllocSize;
+ cl_command_queue_properties m_queueProperties;
+ cl_bool m_imageSupport;
+ cl_uint m_vecWidthChar;
+ cl_uint m_vecWidthShort;
+ cl_uint m_vecWidthInt;
+ cl_uint m_vecWidthLong;
+ cl_uint m_vecWidthFloat;
+ cl_uint m_vecWidthDouble;
+
+};
+
+
+class btOpenCLUtils
+{
+public:
+ // CL Context optionally takes a GL context. This is a generic type because we don't really want this code
+ // to have to understand GL types.
+ // It is a HGLRC in _WIN32 or a GLXContext otherwise.
+ static cl_context createContextFromType(cl_device_type deviceType, cl_int* pErrNum, void* pGLCtx = 0, void* pGLDC = 0);
+ static int getNumDevices(cl_context cxMainContext);
+ static cl_device_id getDevice(cl_context cxMainContext, int nr);
+ static void getDeviceInfo(cl_device_id device, btOpenCLDeviceInfo& info);
+ static void printDeviceInfo(cl_device_id device);
+
+};
+
+
+
+#endif // BT_OPENCL_UTILS_H
View
54 opencl/basic_initialize/main.cpp
@@ -0,0 +1,54 @@
+/*
+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 "btOpenCLUtils.h"
+#include <stdio.h>
+
+cl_context g_cxMainContext;
+cl_command_queue g_cqCommandQue;
+
+
+
+int main(int argc, char* argv[])
+{
+ int ciErrNum = 0;
+ cl_device_type deviceType = CL_DEVICE_TYPE_ALL;//GPU;
+ void* glCtx=0;
+ void* glDC = 0;
+ g_cxMainContext = btOpenCLUtils::createContextFromType(deviceType, &ciErrNum, glCtx, glDC);
+ oclCHECKERROR(ciErrNum, CL_SUCCESS);
+
+ int numDev = btOpenCLUtils::getNumDevices(g_cxMainContext);
+
+ for (int i=0;i<numDev;i++)
+ {
+ cl_device_id device;
+ device = btOpenCLUtils::getDevice(g_cxMainContext,i);
+ btOpenCLDeviceInfo clInfo;
+ btOpenCLUtils::getDeviceInfo(device,clInfo);
+ btOpenCLUtils::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
+
+ clReleaseCommandQueue(g_cqCommandQue);
+ }
+
+ clReleaseContext(g_cxMainContext);
+ return 0;
+}
View
21 opencl/basic_initialize/premake4.lua
@@ -0,0 +1,21 @@
+
+ hasCL = findOpenCL()
+
+ if (hasCL) then
+
+ project "OpenCL_intialize"
+
+ language "C++"
+
+ kind "ConsoleApp"
+ targetdir "../../bin"
+
+-- includedirs {"../../../include/gpu_research"}
+
+ files {
+ "main.cpp",
+ "btOpenCLUtils.cpp",
+ "btOpenCLUtils.h"
+ }
+
+ end
View
1 rendering/GLSL_Instancing/premake4.lua
@@ -7,7 +7,6 @@
{
"../GlutGlewWindows",
"../BulletMath"
-
}
libdirs {"../GlutGlewWindows"}

0 comments on commit 02071ef

Please sign in to comment.
Something went wrong with that request. Please try again.