Linux fixes
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||||
#include "Bullet3OpenCL/Initialize/b3OpenCLInclude.h"
|
#include "Bullet3OpenCL/Initialize/b3OpenCLInclude.h"
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class b3OpenCLArray
|
class b3OpenCLArray
|
||||||
{
|
{
|
||||||
size_t m_size;
|
size_t m_size;
|
||||||
@@ -59,9 +59,9 @@ public:
|
|||||||
m_size = sizeInElements;
|
m_size = sizeInElements;
|
||||||
m_capacity = sizeInElements;
|
m_capacity = sizeInElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we could enable this assignment, but need to make sure to avoid accidental deep copies
|
// we could enable this assignment, but need to make sure to avoid accidental deep copies
|
||||||
// b3OpenCLArray<T>& operator=(const b3AlignedObjectArray<T>& src)
|
// b3OpenCLArray<T>& operator=(const b3AlignedObjectArray<T>& src)
|
||||||
// {
|
// {
|
||||||
// copyFromArray(src);
|
// copyFromArray(src);
|
||||||
// return *this;
|
// return *this;
|
||||||
@@ -73,16 +73,16 @@ public:
|
|||||||
return m_clBuffer;
|
return m_clBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual ~b3OpenCLArray()
|
virtual ~b3OpenCLArray()
|
||||||
{
|
{
|
||||||
deallocate();
|
deallocate();
|
||||||
m_size=0;
|
m_size=0;
|
||||||
m_capacity=0;
|
m_capacity=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
B3_FORCE_INLINE bool push_back(const T& _Val,bool waitForCompletion=true)
|
B3_FORCE_INLINE bool push_back(const T& _Val,bool waitForCompletion=true)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
size_t sz = size();
|
size_t sz = size();
|
||||||
if( sz == capacity() )
|
if( sz == capacity() )
|
||||||
@@ -147,7 +147,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
B3_FORCE_INLINE size_t capacity() const
|
B3_FORCE_INLINE size_t capacity() const
|
||||||
{
|
{
|
||||||
return m_capacity;
|
return m_capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +167,6 @@ public:
|
|||||||
if (ciErrNum!=CL_SUCCESS)
|
if (ciErrNum!=CL_SUCCESS)
|
||||||
{
|
{
|
||||||
b3Error("OpenCL out-of-memory\n");
|
b3Error("OpenCL out-of-memory\n");
|
||||||
b3Assert(0);
|
|
||||||
_Count = 0;
|
_Count = 0;
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
@@ -192,7 +191,7 @@ public:
|
|||||||
deallocate();
|
deallocate();
|
||||||
|
|
||||||
m_clBuffer = buf;
|
m_clBuffer = buf;
|
||||||
|
|
||||||
m_capacity = _Count;
|
m_capacity = _Count;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
@@ -213,14 +212,14 @@ public:
|
|||||||
|
|
||||||
b3Assert(m_clBuffer);
|
b3Assert(m_clBuffer);
|
||||||
b3Assert(destination);
|
b3Assert(destination);
|
||||||
|
|
||||||
//likely some error, destination is same as source
|
//likely some error, destination is same as source
|
||||||
b3Assert(m_clBuffer != destination);
|
b3Assert(m_clBuffer != destination);
|
||||||
|
|
||||||
b3Assert((firstElem+numElements)<=m_size);
|
b3Assert((firstElem+numElements)<=m_size);
|
||||||
|
|
||||||
cl_int status = 0;
|
cl_int status = 0;
|
||||||
|
|
||||||
|
|
||||||
b3Assert(numElements>0);
|
b3Assert(numElements>0);
|
||||||
b3Assert(numElements<=m_size);
|
b3Assert(numElements<=m_size);
|
||||||
@@ -228,7 +227,7 @@ public:
|
|||||||
size_t srcOffsetBytes = sizeof(T)*firstElem;
|
size_t srcOffsetBytes = sizeof(T)*firstElem;
|
||||||
size_t dstOffsetInBytes = sizeof(T)*dstOffsetInElems;
|
size_t dstOffsetInBytes = sizeof(T)*dstOffsetInElems;
|
||||||
|
|
||||||
status = clEnqueueCopyBuffer( m_commandQueue, m_clBuffer, destination,
|
status = clEnqueueCopyBuffer( m_commandQueue, m_clBuffer, destination,
|
||||||
srcOffsetBytes, dstOffsetInBytes, sizeof(T)*numElements, 0, 0, 0 );
|
srcOffsetBytes, dstOffsetInBytes, sizeof(T)*numElements, 0, 0, 0 );
|
||||||
|
|
||||||
b3Assert( status == CL_SUCCESS );
|
b3Assert( status == CL_SUCCESS );
|
||||||
@@ -237,7 +236,7 @@ public:
|
|||||||
void copyFromHost(const b3AlignedObjectArray<T>& srcArray, bool waitForCompletion=true)
|
void copyFromHost(const b3AlignedObjectArray<T>& srcArray, bool waitForCompletion=true)
|
||||||
{
|
{
|
||||||
size_t newSize = srcArray.size();
|
size_t newSize = srcArray.size();
|
||||||
|
|
||||||
bool copyOldContents = false;
|
bool copyOldContents = false;
|
||||||
resize (newSize,copyOldContents);
|
resize (newSize,copyOldContents);
|
||||||
if (newSize)
|
if (newSize)
|
||||||
@@ -263,7 +262,7 @@ public:
|
|||||||
b3Error("copyFromHostPointer invalid range\n");
|
b3Error("copyFromHostPointer invalid range\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void copyToHost(b3AlignedObjectArray<T>& destArray, bool waitForCompletion=true) const
|
void copyToHost(b3AlignedObjectArray<T>& destArray, bool waitForCompletion=true) const
|
||||||
{
|
{
|
||||||
@@ -275,7 +274,7 @@ public:
|
|||||||
void copyToHostPointer(T* destPtr, size_t numElem, size_t srcFirstElem=0, bool waitForCompletion=true) const
|
void copyToHostPointer(T* destPtr, size_t numElem, size_t srcFirstElem=0, bool waitForCompletion=true) const
|
||||||
{
|
{
|
||||||
b3Assert(numElem+srcFirstElem <= capacity());
|
b3Assert(numElem+srcFirstElem <= capacity());
|
||||||
|
|
||||||
if(numElem+srcFirstElem <= capacity())
|
if(numElem+srcFirstElem <= capacity())
|
||||||
{
|
{
|
||||||
cl_int status = 0;
|
cl_int status = 0;
|
||||||
@@ -290,7 +289,7 @@ public:
|
|||||||
b3Error("copyToHostPointer invalid range\n");
|
b3Error("copyToHostPointer invalid range\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void copyFromOpenCLArray(const b3OpenCLArray& src)
|
void copyFromOpenCLArray(const b3OpenCLArray& src)
|
||||||
{
|
{
|
||||||
size_t newSize = src.size();
|
size_t newSize = src.size();
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ Copyright (c) 2011 Advanced Micro Devices, Inc. http://bulletphysics.org
|
|||||||
|
|
||||||
This software is provided 'as-is', without any express or implied warranty.
|
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.
|
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,
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
including commercial applications, and to alter it and redistribute it freely,
|
including commercial applications, and to alter it and redistribute it freely,
|
||||||
subject to the following restrictions:
|
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.
|
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.
|
||||||
@@ -44,7 +44,7 @@ int main(int argc, char* argv[])
|
|||||||
b3Error("test error\n");
|
b3Error("test error\n");
|
||||||
|
|
||||||
int ciErrNum = 0;
|
int ciErrNum = 0;
|
||||||
|
|
||||||
cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
|
cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
|
||||||
const char* vendorSDK = b3OpenCLUtils::getSdkVendorName();
|
const char* vendorSDK = b3OpenCLUtils::getSdkVendorName();
|
||||||
|
|
||||||
@@ -62,9 +62,9 @@ int main(int argc, char* argv[])
|
|||||||
b3Printf(" CL_PLATFORM_VENDOR: \t\t\t%s\n",platformInfo.m_platformVendor);
|
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_NAME: \t\t\t%s\n",platformInfo.m_platformName);
|
||||||
b3Printf(" CL_PLATFORM_VERSION: \t\t\t%s\n",platformInfo.m_platformVersion);
|
b3Printf(" CL_PLATFORM_VERSION: \t\t\t%s\n",platformInfo.m_platformVersion);
|
||||||
|
|
||||||
cl_context context = b3OpenCLUtils::createContextFromPlatform(platform,deviceType,&ciErrNum);
|
cl_context context = b3OpenCLUtils::createContextFromPlatform(platform,deviceType,&ciErrNum);
|
||||||
|
|
||||||
int numDevices = b3OpenCLUtils::getNumDevices(context);
|
int numDevices = b3OpenCLUtils::getNumDevices(context);
|
||||||
b3Printf("Num Devices = %d\n", numDevices);
|
b3Printf("Num Devices = %d\n", numDevices);
|
||||||
for (int j=0;j<numDevices;j++)
|
for (int j=0;j<numDevices;j++)
|
||||||
@@ -82,7 +82,7 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
size_t numBytes = i*1024*1024;
|
size_t numBytes = i*1024*1024;
|
||||||
result = memTester.resize(numBytes,false);
|
result = memTester.resize(numBytes,false);
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
printf("allocated %d MB successfully\n",i);
|
printf("allocated %d MB successfully\n",i);
|
||||||
@@ -101,7 +101,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
///Easier method to initialize OpenCL using createContextFromType for a GPU
|
///Easier method to initialize OpenCL using createContextFromType for a GPU
|
||||||
deviceType = CL_DEVICE_TYPE_GPU;
|
deviceType = CL_DEVICE_TYPE_GPU;
|
||||||
|
|
||||||
void* glCtx=0;
|
void* glCtx=0;
|
||||||
void* glDC = 0;
|
void* glDC = 0;
|
||||||
b3Printf("Initialize OpenCL using b3OpenCLUtils::createContextFromType for CL_DEVICE_TYPE_GPU\n");
|
b3Printf("Initialize OpenCL using b3OpenCLUtils::createContextFromType for CL_DEVICE_TYPE_GPU\n");
|
||||||
@@ -124,21 +124,25 @@ int main(int argc, char* argv[])
|
|||||||
oclCHECKERROR(ciErrNum, CL_SUCCESS);
|
oclCHECKERROR(ciErrNum, CL_SUCCESS);
|
||||||
//normally you would create and execute kernels using this command queue
|
//normally you would create and execute kernels using this command queue
|
||||||
|
|
||||||
b3OpenCLArray<char> memTester(g_cxMainContext,g_cqCommandQue,0,true);
|
|
||||||
int maxMem = 8192;
|
|
||||||
bool result=true;
|
|
||||||
for (size_t i=1;result;i++)
|
|
||||||
{
|
{
|
||||||
size_t numBytes = i*1024*1024;
|
b3OpenCLArray<char> memTester(g_cxMainContext,g_cqCommandQue,0,true);
|
||||||
result = memTester.resize(numBytes,false);
|
int maxMem = 8192;
|
||||||
|
bool result=true;
|
||||||
if (result)
|
for (size_t i=1;result;i++)
|
||||||
{
|
{
|
||||||
printf("allocated %d MB successfully\n",i);
|
size_t numBytes = i*1024*1024;
|
||||||
} else
|
result = memTester.resize(numBytes,false);
|
||||||
{
|
|
||||||
printf("allocated %d MB failed\n", i);
|
if (result)
|
||||||
}
|
{
|
||||||
|
printf("allocated %d MB successfully\n",i);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
printf("allocated %d MB failed\n", i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ function createProject(vendor)
|
|||||||
files {
|
files {
|
||||||
"main.cpp",
|
"main.cpp",
|
||||||
"../../../src/Bullet3OpenCL/Initialize/b3OpenCLUtils.cpp",
|
"../../../src/Bullet3OpenCL/Initialize/b3OpenCLUtils.cpp",
|
||||||
|
"../../../src/Bullet3Common/b3AlignedAllocator.cpp",
|
||||||
"../../../src/Bullet3OpenCL/Initialize/b3OpenCLUtils.h",
|
"../../../src/Bullet3OpenCL/Initialize/b3OpenCLUtils.h",
|
||||||
"../../../src/Bullet3Common/b3Logging.cpp",
|
"../../../src/Bullet3Common/b3Logging.cpp",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user