implement barrier/critical section for OSX (PosixThreadSupport)

enable Demos/ThreadingDemo for OSX
add cmake build support for VectorAdd_OpenCL for OSX
This commit is contained in:
erwin.coumans
2010-06-28 23:03:14 +00:00
parent 8bf91f735c
commit 7bfa94b6a3
8 changed files with 234 additions and 14 deletions

View File

@@ -2,7 +2,7 @@
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src
${BULLET_PHYSICS_SOURCE_DIR}/Extras/OpenCL/Shared
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL
${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
)
@@ -42,15 +42,15 @@ IF (USE_GLUT)
${BULLET_PHYSICS_SOURCE_DIR}/Demos/ParticlesOpenCL/btParticlesSharedDefs.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/ParticlesOpenCL/btParticlesSharedTypes.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/ParticlesOpenCL/ParticlesDemo.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/ParticlesOpenCL/btOclUtils.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclUtils.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/ParticlesOpenCL/shaders.h
${BULLET_PHYSICS_SOURCE_DIR}/Extras/OpenCL/Shared/btOclCommon.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/ParticlesOpenCL/btOclUtils.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclUtils.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/ParticlesOpenCL/btParticlesDemoDynamicsWorld.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/ParticlesOpenCL/main.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/ParticlesOpenCL/ParticlesDemo.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/ParticlesOpenCL/shaders.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Extras/OpenCL/Shared/btOclCommon.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/ParticlesOpenCL/ParticlesOCL.cl
)
ELSE (USE_GLUT)

View File

@@ -12,7 +12,7 @@ SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
########################################################
#currently this demo has only been tested under Windows 32bit
IF (WIN32)
#IF (WIN32)
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
@@ -42,4 +42,4 @@ IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(AppThreadingDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
ENDIF(WIN32)
#ENDIF(WIN32)

View File

@@ -20,8 +20,40 @@ subject to the following restrictions:
/// June 2010
/// New: critical section/barriers and non-blocking pollingn for completion, currently Windows only
void SampleThreadFunc(void* userPtr,void* lsMemory);
void* SamplelsMemoryFunc();
#ifdef __APPLE__
#include "BulletMultiThreaded/PosixThreadSupport.h"
btThreadSupportInterface* createThreadSupport(int numThreads)
{
PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads",
SampleThreadFunc,
SamplelsMemoryFunc,
numThreads);
btThreadSupportInterface* threadSupport = new PosixThreadSupport(constructionInfo);
return threadSupport;
}
#elif defined( _WIN32)
#include "BulletMultiThreaded/Win32ThreadSupport.h"
btThreadSupportInterface* createThreadSupport(int numThreads)
{
Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",SampleThreadFunc,SamplelsMemoryFunc,numThreads);
Win32ThreadSupport* threadSupport = new Win32ThreadSupport(threadConstructionInfo);
return threadSupport;
}
#endif
struct SampleArgs
{
btCriticalSection* m_cs;
@@ -64,19 +96,26 @@ void* SamplelsMemoryFunc()
int main(int argc,char** argv)
{
int numThreads = 4;
Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",SampleThreadFunc,SamplelsMemoryFunc,numThreads);
btThreadSupportInterface* threadSupport = createThreadSupport(numThreads);
Win32ThreadSupport* threadSupport = new Win32ThreadSupport(threadConstructionInfo);
threadSupport->startSPU();
for (int i=0;i<threadSupport->getNumTasks();i++)
{
SampleThreadLocalStorage* storage = (SampleThreadLocalStorage*)threadSupport->getThreadLocalMemory(i);
btAssert(storage);
storage->threadId = i;
}
@@ -93,7 +132,7 @@ int main(int argc,char** argv)
threadSupport->sendRequest(1, (ppu_address_t) &args, i);
}
bool blockingWait = false;
bool blockingWait =true;
if (blockingWait)
{
for (i=0;i<numThreads;i++)
@@ -102,6 +141,7 @@ int main(int argc,char** argv)
}
} else
{
#if 0
int numActiveThreads = numThreads;
while (numActiveThreads)
{
@@ -115,6 +155,7 @@ int main(int argc,char** argv)
printf("polling\n");
}
};
#endif
}
threadSupport->stopSPU();
@@ -122,4 +163,4 @@ int main(int argc,char** argv)
printf("Press ENTER to quit\n");
getchar();
return 0;
}
}

View File

@@ -0,0 +1,25 @@
# AppVectorAdd is a very basic test OpenCL/MiniCL.
IF (APPLE)
FIND_LIBRARY(OPENCL_LIBRARY OpenCL DOC "OpenCL lib for OSX")
FIND_PATH(OPENCL_INCLUDE_DIR OpenCL/cl.h DOC "Include for OpenCL on OSX")
ENDIF (APPLE)
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src
)
LINK_LIBRARIES(
LinearMath ${OPENCL_LIBRARY}
)
ADD_EXECUTABLE(AppVectorAdd_Apple
../MiniCL_VectorAdd.cpp
../VectorAddKernels.cl
)
IF (UNIX)
TARGET_LINK_LIBRARIES(AppVectorAdd_Apple pthread)
ENDIF(UNIX)