[Libreoffice-commits] core.git: sc/source
Markus Mohrhard
markus.mohrhard at googlemail.com
Mon Sep 30 21:10:29 PDT 2013
sc/source/core/opencl/openclwrapper.cxx | 205 +++++++++++++++++---------------
sc/source/core/opencl/openclwrapper.hxx | 2
2 files changed, 115 insertions(+), 92 deletions(-)
New commits:
commit e000b3fc7852b7879729694436170c01cb6b9fa8
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Tue Oct 1 05:56:34 2013 +0200
make sure that we really fall back to new compile if binary failed
If anything during binary import fails fall back to compiling from
source. That includes a failure during building the binary file.
Change-Id: I0f021f17c9be061fc9eb9f28ab470257d61f03cb
diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx
index c59f055..77f802e 100644
--- a/sc/source/core/opencl/openclwrapper.cxx
+++ b/sc/source/core/opencl/openclwrapper.cxx
@@ -453,21 +453,104 @@ int OpenclDevice::cachedOfKernerPrg( const GPUEnv *gpuEnvCached, const char * cl
return 0;
}
-int OpenclDevice::compileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
+namespace {
+
+bool buildProgram(const char* buildOption, GPUEnv* gpuInfo, int idx)
{
- cl_int clStatus = 0;
- int binary_status, idx;
- const char* filename = "kernel.cl";
- fprintf(stderr, "compileKernelFile ... \n");
- if ( cachedOfKernerPrg(gpuInfo, filename) == 1 )
+ cl_int clStatus;
+ //char options[512];
+ // create a cl program executable for all the devices specified
+ printf("BuildProgram.\n");
+ if (!gpuInfo->mnIsUserCreated)
{
- return 1;
+ clStatus = clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, gpuInfo->mpArryDevsID,
+ buildOption, NULL, NULL);
+ }
+ else
+ {
+ clStatus = clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, &(gpuInfo->mpDevID),
+ buildOption, NULL, NULL);
}
- idx = gpuInfo->mnFileCount;
+ if ( clStatus != CL_SUCCESS )
+ {
+ size_t length;
+ printf ("BuildProgram error!\n");
+ if ( !gpuInfo->mnIsUserCreated )
+ {
+ clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpArryDevsID[0],
+ CL_PROGRAM_BUILD_LOG, 0, NULL, &length );
+ }
+ else
+ {
+ clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpDevID,
+ CL_PROGRAM_BUILD_LOG, 0, NULL, &length);
+ }
+ if ( clStatus != CL_SUCCESS )
+ {
+ printf("opencl create build log fail\n");
+ return 0;
+ }
+
+ boost::scoped_array<char> buildLog(new char[length]);
+ if ( !gpuInfo->mnIsUserCreated )
+ {
+ clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpArryDevsID[0],
+ CL_PROGRAM_BUILD_LOG, length, buildLog.get(), &length );
+ }
+ else
+ {
+ clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpDevID,
+ CL_PROGRAM_BUILD_LOG, length, buildLog.get(), &length );
+ }
+ if ( clStatus != CL_SUCCESS )
+ {
+ printf("opencl program build info fail\n");
+ return false;
+ }
+
+ OString aBuildLogFileURL = OpenclDevice::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 );
+
+ if(status != osl::FileBase::E_None)
+ return false;
+
+ sal_uInt64 nBytesWritten = 0;
+ aBuildLogFile.write( buildLog.get(), length, nBytesWritten );
+
+ return false;
+ }
+
+ return true;
+}
+
+}
+
+bool OpenclDevice::buildProgramFromSource(const char* buildOption, GPUEnv* gpuInfo, const char* filename, int idx)
+{
+ cl_int clStatus = 0;
+ // create a CL program using the kernel source
+ fprintf(stderr, "Create kernel from source\n");
+ size_t source_size[1];
+
+ source_size[0] = strlen( kernel_src );
+ gpuInfo->mpArryPrograms[idx] = clCreateProgramWithSource( gpuInfo->mpContext, 1, &kernel_src,
+ source_size, &clStatus);
+
+ if(clStatus != CL_SUCCESS)
+ return false;
+ bool bSuccess = buildProgram(buildOption, gpuInfo, idx);
+ generatBinFromKernelSource( gpuInfo->mpArryPrograms[idx], filename );
+ return bSuccess;
+}
+
+bool OpenclDevice::buildProgramFromBinary(const char* buildOption, GPUEnv* gpuInfo, const char* filename, int idx)
+{
size_t numDevices;
- clStatus = clGetContextInfo( gpuInfo->mpContext, CL_CONTEXT_DEVICES,
+ cl_int clStatus = clGetContextInfo( gpuInfo->mpContext, CL_CONTEXT_DEVICES,
0, NULL, &numDevices );
numDevices /= sizeof(numDevices);
CHECK_OPENCL( clStatus, "clGetContextInfo" );
@@ -475,10 +558,8 @@ int OpenclDevice::compileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
std::vector<boost::shared_ptr<osl::File> > aGeneratedFiles = binaryGenerated(
filename, gpuInfo->mpContext );
- bool bBinaryExisted = false;
if (aGeneratedFiles.size() == numDevices)
{
- bBinaryExisted = true;
boost::scoped_array<size_t> length(new size_t[numDevices]);
boost::scoped_array<unsigned char*> pBinary(new unsigned char*[numDevices]);
for(size_t i = 0; i < numDevices; ++i)
@@ -507,8 +588,10 @@ int OpenclDevice::compileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
{
delete[] pBinary[i];
}
+ return false;
}
- CHECK_OPENCL( clStatus, "clGetContextInfo" );
+
+ cl_int binary_status;
fprintf(stderr, "Create kernel from binary\n");
gpuInfo->mpArryPrograms[idx] = clCreateProgramWithBinary( gpuInfo->mpContext,numDevices,
@@ -517,7 +600,7 @@ int OpenclDevice::compileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
if(clStatus != CL_SUCCESS)
{
// something went wrong, fall back to compiling from source
- bBinaryExisted = false;
+ return false;
}
for(size_t i = 0; i < numDevices; ++i)
{
@@ -525,96 +608,34 @@ int OpenclDevice::compileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
}
}
- if(!bBinaryExisted)
+ if ( !gpuInfo->mpArryPrograms[idx] )
{
- // create a CL program using the kernel source
- fprintf(stderr, "Create kernel from source\n");
- size_t source_size[1];
-
- source_size[0] = strlen( kernel_src );
- gpuEnv.mpArryPrograms[idx] = clCreateProgramWithSource( gpuEnv.mpContext, 1, &kernel_src,
- source_size, &clStatus);
- CHECK_OPENCL( clStatus, "clCreateProgramWithSource" );
- }
-
- if ( gpuInfo->mpArryPrograms[idx] == (cl_program) NULL )
- {
- return 0;
+ return false;
}
+ return buildProgram(buildOption, gpuInfo, idx);
+}
- //char options[512];
- // create a cl program executable for all the devices specified
- printf("BuildProgram.\n");
- if (!gpuInfo->mnIsUserCreated)
- {
- clStatus = clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, gpuInfo->mpArryDevsID,
- buildOption, NULL, NULL);
- }
- else
+int OpenclDevice::compileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
+{
+ int idx;
+ const char* filename = "kernel.cl";
+ fprintf(stderr, "compileKernelFile ... \n");
+ if ( cachedOfKernerPrg(gpuInfo, filename) == 1 )
{
- clStatus = clBuildProgram(gpuInfo->mpArryPrograms[idx], 1, &(gpuInfo->mpDevID),
- buildOption, NULL, NULL);
+ return 1;
}
- if ( clStatus != CL_SUCCESS )
- {
- size_t length;
- printf ("BuildProgram error!\n");
- if ( !gpuInfo->mnIsUserCreated )
- {
- clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpArryDevsID[0],
- CL_PROGRAM_BUILD_LOG, 0, NULL, &length );
- }
- else
- {
- clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpDevID,
- CL_PROGRAM_BUILD_LOG, 0, NULL, &length);
- }
- if ( clStatus != CL_SUCCESS )
- {
- printf("opencl create build log fail\n");
- return 0;
- }
-
- boost::scoped_array<char> buildLog(new char[length]);
- if ( !gpuInfo->mnIsUserCreated )
- {
- clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpArryDevsID[0],
- CL_PROGRAM_BUILD_LOG, length, buildLog.get(), &length );
- }
- else
- {
- clStatus = clGetProgramBuildInfo( gpuInfo->mpArryPrograms[idx], gpuInfo->mpDevID,
- CL_PROGRAM_BUILD_LOG, length, buildLog.get(), &length );
- }
- if ( clStatus != CL_SUCCESS )
- {
- printf("opencl program build info fail\n");
- return 0;
- }
-
- 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 );
-
- if(status != osl::FileBase::E_None)
- return 0;
-
- sal_uInt64 nBytesWritten = 0;
- aBuildLogFile.write( buildLog.get(), length, nBytesWritten );
-
- return 0;
- }
+ idx = gpuInfo->mnFileCount;
- strcpy( gpuEnv.mArryKnelSrcFile[idx], filename );
+ bool bSuccess = buildProgramFromBinary(buildOption, gpuInfo, filename, idx);
+ if(!bSuccess)
+ bSuccess = buildProgramFromSource(buildOption, gpuInfo, filename, idx);
- if ( !bBinaryExisted )
- generatBinFromKernelSource( gpuEnv.mpArryPrograms[idx], filename );
+ strcpy( gpuInfo->mArryKnelSrcFile[idx], filename );
gpuInfo->mnFileCount += 1;
- return 1;
+ return bSuccess;
}
int OpenclDevice::initOpenclRunEnv( int argc )
diff --git a/sc/source/core/opencl/openclwrapper.hxx b/sc/source/core/opencl/openclwrapper.hxx
index c81c313..dd95954 100644
--- a/sc/source/core/opencl/openclwrapper.hxx
+++ b/sc/source/core/opencl/openclwrapper.hxx
@@ -179,6 +179,8 @@ public:
static int writeBinaryToFile( const OString& rName, const char* birary, size_t numBytes );
static std::vector<boost::shared_ptr<osl::File> > binaryGenerated( const char * clFileName, cl_context context);
static int compileKernelFile( const char *filename, GPUEnv *gpuInfo, const char *buildOption );
+ static bool buildProgramFromSource(const char* buildOption, GPUEnv* gpuEnv, const char* filename, int idx);
+ static bool buildProgramFromBinary(const char* buildOption, GPUEnv* gpuEnv, const char* filename, int idx);
static int initOpenclAttr( OpenCLEnv * env );
static int setKernelEnv( KernelEnv *envInfo );
More information about the Libreoffice-commits
mailing list