summaryrefslogtreecommitdiff
path: root/opencl/source
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2014-11-27 17:43:55 +0200
committerTor Lillqvist <tml@collabora.com>2014-11-27 19:12:21 +0200
commit598f25c85793aab78b5ecce733c65a66860d0c5c (patch)
tree651e800bc1a74263d3bd32ce957ec6492e3e6907 /opencl/source
parenta02a54f51367f276544f45e67023338a32d22ee6 (diff)
Clean up confusing OpenCL code a bit
Get rid of the silly OpenCLDevice class that had only static members. We can as well just use namespacing. Remove functions only used internally in openclwrapper.cxx from the now public openclwrapper.hxx header. Change-Id: If7336edd262c772564dc13e64113d72d0b52428c
Diffstat (limited to 'opencl/source')
-rw-r--r--opencl/source/opencl_device.cxx3
-rw-r--r--opencl/source/openclwrapper.cxx133
2 files changed, 66 insertions, 70 deletions
diff --git a/opencl/source/opencl_device.cxx b/opencl/source/opencl_device.cxx
index 204ab345b5e0..14eb70358746 100644
--- a/opencl/source/opencl_device.cxx
+++ b/opencl/source/opencl_device.cxx
@@ -44,9 +44,8 @@
SAL_INFO("opencl.device", "Error code is " << status << " at " name); \
}
-namespace OpenCLDevice {
+namespace opencl {
-bool bIsInited = false;
bool bIsDeviceSelected = false;
ds_device selectedDevice;
diff --git a/opencl/source/openclwrapper.cxx b/opencl/source/openclwrapper.cxx
index 86ba6cd3a4e3..b1813754e6c4 100644
--- a/opencl/source/openclwrapper.cxx
+++ b/opencl/source/openclwrapper.cxx
@@ -48,11 +48,12 @@ using namespace std;
namespace opencl {
-GPUEnv OpenCLDevice::gpuEnv;
-bool OpenCLDevice::bIsInited = false;
+GPUEnv gpuEnv;
namespace {
+bool bIsInited = false;
+
OString generateMD5(const void* pData, size_t length)
{
sal_uInt8 pBuffer[RTL_DIGEST_LENGTH_MD5];
@@ -81,11 +82,11 @@ OString getCacheFolder()
return rtl::OUStringToOString(url, RTL_TEXTENCODING_UTF8);
}
-}
+OString maCacheFolder = getCacheFolder();
-OString OpenCLDevice::maCacheFolder = getCacheFolder();
+}
-void OpenCLDevice::setKernelEnv( KernelEnv *envInfo )
+void setKernelEnv( KernelEnv *envInfo )
{
envInfo->mpkContext = gpuEnv.mpContext;
envInfo->mpkCmdQueue = gpuEnv.mpCmdQueue;
@@ -121,13 +122,11 @@ OString createFileName(cl_device_id deviceId, const char* clFileName)
OString aString = OString(deviceName) + driverVersion + platformVersion;
OString aHash = generateMD5(aString.getStr(), aString.getLength());
- return OpenCLDevice::maCacheFolder + fileName + "-" +
+ return maCacheFolder + fileName + "-" +
aHash + ".bin";
}
-}
-
-std::vector<boost::shared_ptr<osl::File> > OpenCLDevice::binaryGenerated( const char * clFileName, cl_context context )
+std::vector<boost::shared_ptr<osl::File> > binaryGenerated( const char * clFileName, cl_context context )
{
size_t numDevices=0;
@@ -170,7 +169,7 @@ std::vector<boost::shared_ptr<osl::File> > OpenCLDevice::binaryGenerated( const
return aGeneratedFiles;
}
-bool OpenCLDevice::writeBinaryToFile( const OString& rFileName, const char* binary, size_t numBytes )
+bool writeBinaryToFile( const OString& rFileName, const char* binary, size_t numBytes )
{
osl::File file(rtl::OStringToOUString(rFileName, RTL_TEXTENCODING_UTF8));
osl::FileBase::RC status = file.open(
@@ -187,7 +186,9 @@ bool OpenCLDevice::writeBinaryToFile( const OString& rFileName, const char* bina
return true;
}
-bool OpenCLDevice::generatBinFromKernelSource( cl_program program, const char * clFileName )
+}
+
+bool generatBinFromKernelSource( cl_program program, const char * clFileName )
{
cl_uint numDevices;
@@ -251,7 +252,9 @@ bool OpenCLDevice::generatBinFromKernelSource( cl_program program, const char *
return true;
}
-bool OpenCLDevice::initOpenCLAttr( OpenCLEnv * env )
+namespace {
+
+bool initOpenCLAttr( OpenCLEnv * env )
{
if ( gpuEnv.mnIsUserCreated )
return true;
@@ -266,7 +269,7 @@ bool OpenCLDevice::initOpenCLAttr( OpenCLEnv * env )
return false;
}
-void OpenCLDevice::releaseOpenCLEnv( GPUEnv *gpuInfo )
+void releaseOpenCLEnv( GPUEnv *gpuInfo )
{
if ( !bIsInited )
{
@@ -290,8 +293,6 @@ void OpenCLDevice::releaseOpenCLEnv( GPUEnv *gpuInfo )
return;
}
-namespace {
-
bool buildProgram(const char* buildOption, GPUEnv* gpuInfo, int idx)
{
cl_int clStatus;
@@ -342,7 +343,7 @@ bool buildProgram(const char* buildOption, GPUEnv* gpuInfo, int idx)
return false;
}
- OString aBuildLogFileURL = OpenCLDevice::maCacheFolder + "kernel-build.log";
+ OString aBuildLogFileURL = maCacheFolder + "kernel-build.log";
osl::File aBuildLogFile(rtl::OStringToOUString(aBuildLogFileURL, RTL_TEXTENCODING_UTF8));
osl::FileBase::RC status = aBuildLogFile.open(
osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
@@ -361,7 +362,7 @@ bool buildProgram(const char* buildOption, GPUEnv* gpuInfo, int idx)
}
-bool OpenCLDevice::buildProgramFromBinary(const char* buildOption, GPUEnv* gpuInfo, const char* filename, int idx)
+bool buildProgramFromBinary(const char* buildOption, GPUEnv* gpuInfo, const char* filename, int idx)
{
size_t numDevices;
cl_int clStatus = clGetContextInfo( gpuInfo->mpContext, CL_CONTEXT_DEVICES,
@@ -428,45 +429,6 @@ bool OpenCLDevice::buildProgramFromBinary(const char* buildOption, GPUEnv* gpuIn
return buildProgram(buildOption, gpuInfo, idx);
}
-bool OpenCLDevice::initOpenCLRunEnv( int argc )
-{
- if ( ( argc > MAX_CLFILE_NUM ) || ( argc < 0 ) )
- return true;
-
- if ( !bIsInited )
- {
- if ( !gpuEnv.mnIsUserCreated )
- memset( &gpuEnv, 0, sizeof(gpuEnv) );
-
- //initialize devices, context, command_queue
- bool status = initOpenCLRunEnv( &gpuEnv );
- if ( status )
- {
- return true;
- }
- //initialize program, kernelName, kernelCount
- if( getenv( "SC_FLOAT" ) )
- {
- gpuEnv.mnKhrFp64Flag = false;
- gpuEnv.mnAmdFp64Flag = false;
- }
- if( gpuEnv.mnKhrFp64Flag )
- {
- SAL_INFO("opencl", "Use Khr double");
- }
- else if( gpuEnv.mnAmdFp64Flag )
- {
- SAL_INFO("opencl", "Use AMD double type");
- }
- else
- {
- SAL_INFO("opencl", "USE float type");
- }
- bIsInited = true;
- }
- return false;
-}
-
namespace {
void checkDeviceForDoubleSupport(cl_device_id deviceId, bool& bKhrFp64, bool& bAmdFp64)
@@ -501,9 +463,7 @@ void checkDeviceForDoubleSupport(cl_device_id deviceId, bool& bKhrFp64, bool& bA
}
}
-}
-
-bool OpenCLDevice::initOpenCLRunEnv( GPUEnv *gpuInfo )
+bool initOpenCLRunEnv( GPUEnv *gpuInfo )
{
bool bKhrFp64 = false;
bool bAmdFp64 = false;
@@ -516,7 +476,44 @@ bool OpenCLDevice::initOpenCLRunEnv( GPUEnv *gpuInfo )
return false;
}
-namespace {
+bool initOpenCLRunEnv( int argc )
+{
+ if ( ( argc > MAX_CLFILE_NUM ) || ( argc < 0 ) )
+ return true;
+
+ if ( !bIsInited )
+ {
+ if ( !gpuEnv.mnIsUserCreated )
+ memset( &gpuEnv, 0, sizeof(gpuEnv) );
+
+ //initialize devices, context, command_queue
+ bool status = initOpenCLRunEnv( &gpuEnv );
+ if ( status )
+ {
+ return true;
+ }
+ //initialize program, kernelName, kernelCount
+ if( getenv( "SC_FLOAT" ) )
+ {
+ gpuEnv.mnKhrFp64Flag = false;
+ gpuEnv.mnAmdFp64Flag = false;
+ }
+ if( gpuEnv.mnKhrFp64Flag )
+ {
+ SAL_INFO("opencl", "Use Khr double");
+ }
+ else if( gpuEnv.mnAmdFp64Flag )
+ {
+ SAL_INFO("opencl", "Use AMD double type");
+ }
+ else
+ {
+ SAL_INFO("opencl", "USE float type");
+ }
+ bIsInited = true;
+ }
+ return false;
+}
// based on crashes and hanging during kernel compilation
void createDeviceInfo(cl_device_id aDeviceId, OpenCLPlatformInfo& rPlatformInfo)
@@ -725,12 +722,12 @@ bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEv
OUString path;
osl::FileBase::getSystemPathFromFileURL(url,path);
OString dsFileName = rtl::OUStringToOString(path, RTL_TEXTENCODING_UTF8);
- ds_device pSelectedDevice = ::OpenCLDevice::getDeviceSelection(dsFileName.getStr(), bForceEvaluation);
+ ds_device pSelectedDevice = getDeviceSelection(dsFileName.getStr(), bForceEvaluation);
pDeviceId = pSelectedDevice.oclDeviceID;
}
- if(OpenCLDevice::gpuEnv.mpDevID == pDeviceId)
+ if(gpuEnv.mpDevID == pDeviceId)
{
// we don't need to change anything
// still the same device
@@ -769,13 +766,13 @@ bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEv
return false;
}
- OpenCLDevice::releaseOpenCLEnv(&OpenCLDevice::gpuEnv);
+ releaseOpenCLEnv(&gpuEnv);
OpenCLEnv env;
env.mpOclPlatformID = platformId;
env.mpOclContext = context;
env.mpOclDevsID = pDeviceId;
env.mpOclCmdQueue = command_queue;
- OpenCLDevice::initOpenCLAttr(&env);
+ initOpenCLAttr(&env);
// why do we need this at all?
@@ -783,10 +780,10 @@ bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEv
// initialisation below.) Because otherwise the code crashes in
// initOpenCLRunEnv(). Confused? You should be.
- OpenCLDevice::gpuEnv.mpArryDevsID = (cl_device_id*) malloc( sizeof(cl_device_id) );
- OpenCLDevice::gpuEnv.mpArryDevsID[0] = pDeviceId;
+ gpuEnv.mpArryDevsID = (cl_device_id*) malloc( sizeof(cl_device_id) );
+ gpuEnv.mpArryDevsID[0] = pDeviceId;
- return !OpenCLDevice::initOpenCLRunEnv(0);
+ return !initOpenCLRunEnv(0);
}
void getOpenCLDeviceInfo(size_t& rDeviceId, size_t& rPlatformId)
@@ -795,7 +792,7 @@ void getOpenCLDeviceInfo(size_t& rDeviceId, size_t& rPlatformId)
if (status < 0)
return;
- cl_device_id id = OpenCLDevice::gpuEnv.mpDevID;
+ cl_device_id id = gpuEnv.mpDevID;
findDeviceInfoFromDeviceId(id, rDeviceId, rPlatformId);
}