summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-09-17 19:31:41 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-09-19 17:03:25 +0200
commit0093de75d1e2545803e63b35663cbed7bfc5b64f (patch)
tree893725feeae1ae8abf37904e0a2cf9da9f69778f /sc
parent8f0a558f580516a4810552060c3da69ff6e2aa23 (diff)
use $UserInstallation/cache to cache opencl kernels
Change-Id: I2ba1fb6172cfd0c725a45d4506b46e8f04a33093
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/opencl/openclwrapper.cxx36
-rw-r--r--sc/source/core/opencl/openclwrapper.hxx2
2 files changed, 29 insertions, 9 deletions
diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx
index 684abe602bb6..36106594418f 100644
--- a/sc/source/core/opencl/openclwrapper.cxx
+++ b/sc/source/core/opencl/openclwrapper.cxx
@@ -7,14 +7,18 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <config_folders.h>
+
#include "openclwrapper.hxx"
#include <rtl/ustring.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/digest.h>
+#include <rtl/bootstrap.hxx>
#include <boost/scoped_array.hpp>
#include "sal/config.h"
+#include <osl/file.hxx>
#include "oclkernels.hxx"
#include <stdio.h>
@@ -76,9 +80,20 @@ OString generateHashForSource()
return aBuffer.makeStringAndClear();
}
+OString getCacheFolder()
+{
+ OUString url("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/cache/");
+ rtl::Bootstrap::expandMacros(url);
+
+ osl::Directory::create(url);
+
+ return rtl::OUStringToOString(url, RTL_TEXTENCODING_UTF8);
+}
+
}
OString OpenclDevice::maSourceHash = generateHashForSource();
+OString OpenclDevice::maCacheFolder = getCacheFolder();
int OpenclDevice::releaseOpenclRunEnv()
{
@@ -195,7 +210,8 @@ OString createFileName(cl_device_id deviceId, const char* clFileName)
char deviceName[DEVICE_NAME_LENGTH] = {0};
clGetDeviceInfo(deviceId, CL_DEVICE_NAME,
sizeof(deviceName), deviceName, NULL);
- return fileName + "-" + deviceName + "-" + OpenclDevice::maSourceHash + ".bin";
+ return OpenclDevice::maCacheFolder + fileName + "-" +
+ deviceName + "-" + OpenclDevice::maSourceHash + ".bin";
}
}
@@ -242,17 +258,19 @@ int OpenclDevice::binaryGenerated( const char * clFileName, FILE ** fhandle )
}
-int OpenclDevice::writeBinaryToFile( const OString& rFileName, const char* birary, size_t numBytes )
+int OpenclDevice::writeBinaryToFile( const OString& rFileName, const char* binary, size_t numBytes )
{
- FILE *output = NULL;
- output = fopen( rFileName.getStr(), "wb" );
- if ( output == NULL )
- {
+ osl::File file(rtl::OStringToOUString(rFileName, RTL_TEXTENCODING_UTF8));
+ osl::FileBase::RC status = file.open(
+ osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
+
+ if(status != osl::FileBase::E_None)
return 0;
- }
- fwrite( birary, sizeof(char), numBytes, output );
- fclose( output );
+ sal_uInt64 nBytesWritten = 0;
+ file.write( binary, numBytes, nBytesWritten );
+
+ assert(numBytes == nBytesWritten);
return 1;
diff --git a/sc/source/core/opencl/openclwrapper.hxx b/sc/source/core/opencl/openclwrapper.hxx
index 5a89e6b910e8..7bcf5c4ee337 100644
--- a/sc/source/core/opencl/openclwrapper.hxx
+++ b/sc/source/core/opencl/openclwrapper.hxx
@@ -163,6 +163,8 @@ public:
static GPUEnv gpuEnv;
static int isInited;
static OString maSourceHash;
+ static OString maCacheFolder;
+
static int registOpenclKernel();
static int releaseOpenclRunEnv();
static int initOpenclRunEnv( GPUEnv *gpu );