19 #define __PHYSICS_COMMON_H__ 1
55 if(num_platforms != NULL)
66 size_t param_value_size,
70 char* pId = (
char*)platform;
84 if(param_value_size_ret != NULL)
97 if(param_value_size_ret != NULL)
114 size_t param_value_size ,
123 char deviceName[] =
"MiniCL CPU";
124 unsigned int nameLen = (
unsigned int)strlen(deviceName)+1;
125 btAssert(param_value_size>strlen(deviceName));
126 if (nameLen < param_value_size)
128 const char* cpuName =
"MiniCL CPU";
129 sprintf((
char*)param_value,
"%s",cpuName);
132 printf(
"error: param_value_size should be at least %d, but it is %zu\n",nameLen,param_value_size);
145 printf(
"error: param_value_size should be at least %zu\n",
sizeof(
cl_device_type));
152 if (param_value_size>=
sizeof(
cl_uint))
158 printf(
"error: param_value_size should be at least %zu\n",
sizeof(
cl_uint));
166 size_t workitem_size[3];
168 if (param_value_size>=
sizeof(workitem_size))
170 size_t* workItemSize = (
size_t*)param_value;
171 workItemSize[0] = 64;
172 workItemSize[1] = 24;
173 workItemSize[2] = 16;
176 printf(
"error: param_value_size should be at least %zu\n",
sizeof(
cl_uint));
184 *clock_frequency = 3*1024;
195 if(param_value_size_ret != NULL)
208 if(param_value_size_ret != NULL)
224 *maxWorkGroupSize = 128;
236 *maxMemAlloc= 512*1024*1024;
242 *maxMemAlloc= 1024*1024*1024;
249 *error_correction_support =
CL_FALSE;
275 memset(queueProp,0,param_value_size);
299 size_t* maxSize = (
size_t*) param_value;
306 char* extensions = (
char*) param_value;
325 printf(
"error: unsupported param_name:%d\n",param_name);
372 memcpy(ptr,(
char*)buffer + offset,cb);
416 memcpy((
char*)buffer + offset, ptr,cb);
433 const size_t * global_work_size ,
442 for (
unsigned int ii=0;ii<work_dim;ii++)
445 int numWorkItems = global_work_size[ii];
449 int numWorkItemsPerTask = numWorkItems / maxTask;
450 if (!numWorkItemsPerTask) numWorkItemsPerTask = 1;
452 for (
int t=0;t<numWorkItems;)
455 int endIndex = (t+numWorkItemsPerTask) < numWorkItems ? t+numWorkItemsPerTask : numWorkItems;
472 #define LOCAL_BUF_SIZE 32768
478 int size16 = (size + 15) >> 4;
502 printf(
"error: clSetKernelArg arg_index (%u) exceeds %u\n",arg_index,
MINI_CL_MAX_ARG);
508 printf(
"error: clSetKernelArg argdata too large: %zu (maximum is %zu)\n",arg_size,
MINICL_MAX_ARGLENGTH);
512 if(arg_value == NULL)
519 memcpy(&(kernel->
m_argData[arg_index]), arg_value, arg_size);
534 const char * kernel_name ,
538 int nameLen = strlen(kernel_name);
547 strcpy(kernel->
m_name, kernel_name);
589 const unsigned char ** ,
607 memcpy(buf,host_ptr,
size);
625 size_t param_value_size ,
634 if (!param_value_size)
636 *param_value_size_ret = 13;
639 const char* testName =
"MiniCL_Test.";
640 sprintf((
char*)param_value,
"%s",testName);
646 printf(
"unsupported\n");
657 void (*pfn_notify)(
const char *,
const void *,
size_t,
void *) ,
661 int maxNumOutstandingTasks = 4;
665 const int maxNumOfThreadSupports = 8;
666 static int sUniqueThreadSupportIndex = 0;
667 static const char* sUniqueThreadSupportName[maxNumOfThreadSupports] =
669 "MiniCL_0",
"MiniCL_1",
"MiniCL_2",
"MiniCL_3",
"MiniCL_4",
"MiniCL_5",
"MiniCL_6",
"MiniCL_7"
682 btAssert(sUniqueThreadSupportIndex < maxNumOfThreadSupports);
683 const char* bla =
"MiniCL";
686 sUniqueThreadSupportName[sUniqueThreadSupportIndex++],
689 maxNumOutstandingTasks));
696 maxNumOutstandingTasks);
703 #endif //USE_PTHREADS
729 void (*pfn_notify)(
const char *,
const void *,
size_t,
void *),
744 delete threadSupport;
776 &&(sz ==
sizeof(
size_t))
#define CL_DEVICE_MAX_WORK_GROUP_SIZE
struct _cl_device_id * cl_device_id
#define CL_DEVICE_IMAGE3D_MAX_DEPTH
int m_argSizes[MINI_CL_MAX_ARG]
The SequentialThreadSupport is a portable non-parallel implementation of the btThreadSupportInterface...
static const char * spDriverVersion
struct _cl_context * cl_context
#define CL_PLATFORM_VERSION
#define CL_INVALID_KERNEL_NAME
char m_name[MINI_CL_MAX_KERNEL_NAME]
CL_API_ENTRY cl_command_queue CL_API_CALL clCreateCommandQueue(cl_context context, cl_device_id, cl_command_queue_properties, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0
cl_uint cl_program_build_info
CL_API_ENTRY cl_int CL_API_CALL clReleaseKernel(cl_kernel) CL_API_SUFFIX__VERSION_1_0
#define CL_MEM_COPY_HOST_PTR
#define CL_DEVICE_ADDRESS_BITS
#define CL_DEVICE_IMAGE_SUPPORT
#define CL_DEVICE_IMAGE2D_MAX_WIDTH
#define CL_DEVICE_MAX_CLOCK_FREQUENCY
CL_API_ENTRY cl_int CL_API_CALL clEnqueueWriteBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool, size_t offset, size_t cb, const void *ptr, cl_uint, const cl_event *, cl_event *) CL_API_SUFFIX__VERSION_1_0
#define CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
#define CL_KERNEL_WORK_GROUP_SIZE
#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
static void * localBufMalloc(int size)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
CL_API_ENTRY cl_kernel CL_API_CALL clCreateKernel(cl_program program, const char *kernel_name, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0
void processMiniCLTask(void *userPtr, void *lsMemory)
#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT
#define CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
cl_uint cl_device_local_mem_type
#define CL_DEVICE_ERROR_CORRECTION_SUPPORT
static const char * spPlatformID
CL_API_ENTRY cl_int clGetProgramBuildInfo(cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *) CL_API_SUFFIX__VERSION_1_0
struct _cl_platform_id * cl_platform_id
CL_API_ENTRY cl_mem CL_API_CALL clCreateBuffer(cl_context, cl_mem_flags flags, size_t size, void *host_ptr, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0
CL_API_ENTRY cl_int CL_API_CALL clReleaseCommandQueue(cl_command_queue) CL_API_SUFFIX__VERSION_1_0
#define MINICL_MAX_ARGLENGTH
CL_API_ENTRY cl_int CL_API_CALL clFlush(cl_command_queue command_queue)
#define CL_DEVICE_TYPE_ALL
MiniCLTaskScheduler handles SPU processing of collision pairs.
cl_bitfield cl_device_type
#define CL_PLATFORM_VENDOR
#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT
#define CL_DEVICE_MAX_MEM_ALLOC_SIZE
#define CL_DEVICE_GLOBAL_MEM_SIZE
Win32ThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication...
int getMaxNumOutstandingTasks() const
int gMiniCLNumOutstandingTasks
struct _cl_kernel * cl_kernel
cl_bitfield cl_command_queue_properties
CL_API_ENTRY cl_int CL_API_CALL clEnqueueNDRangeKernel(cl_command_queue, cl_kernel clKernel, cl_uint work_dim, const size_t *, const size_t *global_work_size, const size_t *, cl_uint, const cl_event *, cl_event *) CL_API_SUFFIX__VERSION_1_0
#define CL_INVALID_PLATFORM
CL_API_ENTRY cl_program clCreateProgramWithSource(cl_context context, cl_uint, const char **, const size_t *, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0
Setup and initialize SPU/CELL/Libspe2.
void * createMiniCLLocalStoreMemory()
#define CL_DEVICE_IMAGE3D_MAX_HEIGHT
#define CL_CONTEXT_DEVICES
#define CL_DEVICE_TYPE_DEBUG
#define CL_DEVICE_LOCAL_MEM_SIZE
#define CL_DEVICE_MAX_WRITE_IMAGE_ARGS
CL_API_ENTRY cl_int CL_API_CALL clGetDeviceIDs(cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *) CL_API_SUFFIX__VERSION_1_0
void issueTask(int firstWorkUnit, int lastWorkUnit, MiniCLKernel *kernel)
CL_API_ENTRY cl_int CL_API_CALL clReleaseProgram(cl_program) CL_API_SUFFIX__VERSION_1_0
#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG
CL_API_ENTRY cl_int CL_API_CALL clBuildProgram(cl_program, cl_uint, const cl_device_id *, const char *, void(*pfn_notify)(cl_program, void *), void *) CL_API_SUFFIX__VERSION_1_0
CL_API_ENTRY cl_int CL_API_CALL clGetProgramInfo(cl_program, cl_program_info, size_t, void *, size_t *) CL_API_SUFFIX__VERSION_1_0
static int * spLocalBufCurr
#define CL_DRIVER_VERSION
#define CL_DEVICE_MAX_COMPUTE_UNITS
CL_API_ENTRY cl_int CL_API_CALL clReleaseMemObject(cl_mem) CL_API_SUFFIX__VERSION_1_0
#define CL_DEVICE_MAX_READ_IMAGE_ARGS
intptr_t cl_context_properties
struct _cl_event * cl_event
struct _cl_command_queue * cl_command_queue
#define CL_DEVICE_IMAGE3D_MAX_WIDTH
CL_API_ENTRY cl_int CL_API_CALL clGetContextInfo(cl_context, cl_context_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0
CL_API_ENTRY cl_int CL_API_CALL clGetDeviceInfo(cl_device_id device, cl_device_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0
#define CL_DEVICE_IMAGE2D_MAX_HEIGHT
CL_API_ENTRY cl_int CL_API_CALL clFinish(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0
#define CL_DEVICE_LOCAL_MEM_TYPE
CL_API_ENTRY cl_int CL_API_CALL clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms) CL_API_SUFFIX__VERSION_1_0
class btThreadSupportInterface * getThreadSupportInterface()
Setup and initialize SPU/CELL/Libspe2.
#define CL_DEVICE_QUEUE_PROPERTIES
MiniCLTaskScheduler * m_scheduler
CL_API_ENTRY cl_context CL_API_CALL clCreateContextFromType(const cl_context_properties *, cl_device_type device_type, void(*pfn_notify)(const char *, const void *, size_t, void *), void *, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0
CL_API_ENTRY cl_int CL_API_CALL clGetPlatformInfo(cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) CL_API_SUFFIX__VERSION_1_0
CL_API_ENTRY cl_int CL_API_CALL clReleaseContext(cl_context context) CL_API_SUFFIX__VERSION_1_0
#define CL_DEVICE_MAX_WORK_ITEM_SIZES
cl_uint cl_kernel_work_group_info
void flush()
call flush to submit potential outstanding work to SPUs and wait for all involved SPUs to be finished...
struct _cl_program * cl_program
#define CL_DEVICE_EXTENSIONS
CL_API_ENTRY cl_int CL_API_CALL clGetKernelWorkGroupInfo(cl_kernel kernel, cl_device_id, cl_kernel_work_group_info wgi, size_t sz, void *ptr, size_t *) CL_API_SUFFIX__VERSION_1_0
static int sLocalMemBuf[LOCAL_BUF_SIZE *4+16]
CL_API_ENTRY cl_int CL_API_CALL clEnqueueReadBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool, size_t offset, size_t cb, void *ptr, cl_uint, const cl_event *, cl_event *) CL_API_SUFFIX__VERSION_1_0
#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT
CL_API_ENTRY cl_int CL_API_CALL clSetKernelArg(cl_kernel clKernel, cl_uint arg_index, size_t arg_size, const void *arg_value) CL_API_SUFFIX__VERSION_1_0
void * m_argData[MINI_CL_MAX_ARG]
#define CL_DEVICE_TYPE_CPU
CL_API_ENTRY cl_program CL_API_CALL clCreateProgramWithBinary(cl_context context, cl_uint, const cl_device_id *, const size_t *, const unsigned char **, cl_int *, cl_int *) CL_API_SUFFIX__VERSION_1_0
#define MINI_CL_MAX_KERNEL_NAME
#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE
MiniCLKernel * registerSelf()
CL_API_ENTRY cl_context CL_API_CALL clCreateContext(const cl_context_properties *properties, cl_uint num_devices, const cl_device_id *devices, void(*pfn_notify)(const char *, const void *, size_t, void *), void *user_data, cl_int *errcode_ret) CL_API_SUFFIX__VERSION_1_0