[Libreoffice-commits] core.git: 5 commits - sc/source

Markus Mohrhard markus.mohrhard at googlemail.com
Mon Sep 30 16:58:13 PDT 2013


 sc/source/core/data/bcaslot.cxx         |   22 +++----
 sc/source/core/inc/bcaslot.hxx          |   20 +++---
 sc/source/core/opencl/openclwrapper.cxx |   94 +++++++++++++++++++++++---------
 3 files changed, 89 insertions(+), 47 deletions(-)

New commits:
commit 0d0d3a0540dad2d0f417e21df1183dfc33964357
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Tue Oct 1 01:36:04 2013 +0200

    make source code opencl 1.0 compliant
    
    Change-Id: Id6055194eb225b85a5c66c5cf9fb44ad342df1a7

diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx
index 6d92708..c59f055 100644
--- a/sc/source/core/opencl/openclwrapper.cxx
+++ b/sc/source/core/opencl/openclwrapper.cxx
@@ -259,11 +259,12 @@ OString createFileName(cl_device_id deviceId, const char* clFileName)
 
 std::vector<boost::shared_ptr<osl::File> > OpenclDevice::binaryGenerated( const char * clFileName, cl_context context )
 {
-    cl_uint numDevices=0;
+    size_t numDevices=0;
 
     std::vector<boost::shared_ptr<osl::File> > aGeneratedFiles;
-    cl_int clStatus = clGetContextInfo( context, CL_CONTEXT_NUM_DEVICES,
-            sizeof(numDevices), &numDevices, NULL );
+    cl_int clStatus = clGetContextInfo( context, CL_CONTEXT_DEVICES,
+            0, NULL, &numDevices );
+    numDevices /= sizeof(numDevices);
 
     if(clStatus != CL_SUCCESS)
         return aGeneratedFiles;
@@ -465,9 +466,10 @@ int OpenclDevice::compileKernelFile( GPUEnv *gpuInfo, const char *buildOption )
 
     idx = gpuInfo->mnFileCount;
 
-    cl_uint numDevices;
-    clStatus = clGetContextInfo( gpuInfo->mpContext, CL_CONTEXT_NUM_DEVICES,
-            sizeof(numDevices), &numDevices, NULL );
+    size_t numDevices;
+    clStatus = clGetContextInfo( gpuInfo->mpContext, CL_CONTEXT_DEVICES,
+            0, NULL, &numDevices );
+    numDevices /= sizeof(numDevices);
     CHECK_OPENCL( clStatus, "clGetContextInfo" );
 
     std::vector<boost::shared_ptr<osl::File> > aGeneratedFiles = binaryGenerated(
commit 19e48764f7396e4a462d3a97c4bbe7848572b7d5
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Tue Oct 1 00:55:27 2013 +0200

    hash platform version, device name, driver version into binary name
    
    Change-Id: Id34e7c6dad0587e2a8ea583c6df9bdc145f193bc

diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx
index 58850ca..6d92708 100644
--- a/sc/source/core/opencl/openclwrapper.cxx
+++ b/sc/source/core/opencl/openclwrapper.cxx
@@ -36,6 +36,8 @@
 #endif
 
 #define DEVICE_NAME_LENGTH 1024
+#define DRIVER_VERSION_LENGTH 1024
+#define PLATFORM_VERSION_LENGTH 1024
 
 using namespace std;
 
@@ -48,16 +50,12 @@ int OpenclDevice::isInited =0;
 
 namespace {
 
-OString generateHashForSource()
+OString generateMD5(const void* pData, size_t length)
 {
     sal_uInt8 pBuffer[RTL_DIGEST_LENGTH_MD5];
-
-#ifndef NDEBUG
-    size_t nLength = strlen(kernel_src);
-    rtlDigestError aError = rtl_digest_MD5(kernel_src, nLength,
+    rtlDigestError aError = rtl_digest_MD5(pData, length,
             pBuffer, RTL_DIGEST_LENGTH_MD5);
-    assert(aError == rtl_Digest_E_None);
-#endif
+    SAL_WARN_IF(aError != rtl_Digest_E_None, "sc", "md5 generation failed");
 
     OStringBuffer aBuffer;
     const char* pString = "0123456789ABCDEF";
@@ -70,6 +68,12 @@ OString generateHashForSource()
     return aBuffer.makeStringAndClear();
 }
 
+OString generateHashForSource()
+{
+    size_t nLength = strlen(kernel_src);
+    return generateMD5(kernel_src, nLength);
+}
+
 OString getCacheFolder()
 {
     OUString url("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/cache/");
@@ -230,8 +234,25 @@ OString createFileName(cl_device_id deviceId, const char* clFileName)
     char deviceName[DEVICE_NAME_LENGTH] = {0};
     clGetDeviceInfo(deviceId, CL_DEVICE_NAME,
             sizeof(deviceName), deviceName, NULL);
+
+    char driverVersion[DRIVER_VERSION_LENGTH] = {0};
+    clGetDeviceInfo(deviceId, CL_DRIVER_VERSION,
+            sizeof(driverVersion), driverVersion, NULL);
+
+    cl_platform_id platformId;
+    clGetDeviceInfo(deviceId, CL_DEVICE_PLATFORM,
+            sizeof(platformId), &platformId, NULL);
+
+    char platformVersion[PLATFORM_VERSION_LENGTH] = {0};
+    clGetPlatformInfo(platformId, CL_PLATFORM_VERSION, sizeof(platformVersion),
+            platformVersion, NULL);
+
+    // create hash for deviceName + driver version + platform version
+    OString aString = OString(deviceName) + driverVersion + platformVersion;
+    OString aHash = generateMD5(aString.getStr(), aString.getLength());
+
     return OpenclDevice::maCacheFolder + fileName + "-" +
-        deviceName + "-" + OpenclDevice::maSourceHash + ".bin";
+        aHash + "-" + OpenclDevice::maSourceHash + ".bin";
 }
 
 }
commit 25580075e08f2e20f0c842cf7da96e280884c9de
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Sep 30 22:46:38 2013 +0200

    remove unused macros
    
    Change-Id: I8f195cf6f8f6962d73171fec65b46fbd96f74613

diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx
index b15dc73..58850ca 100644
--- a/sc/source/core/opencl/openclwrapper.cxx
+++ b/sc/source/core/opencl/openclwrapper.cxx
@@ -28,18 +28,6 @@
 
 #ifdef WIN32
 #include <Windows.h>
-
-#define TRUE 1
-#define FALSE 0
-
-#define OCL_INFO(str) \
-    printf("[OCL_INFO] %s\n",str);
-#define OCL_ERROR(str) \
-    fprintf(stderr,"[OCL_ERROR] %s\n",str);
-#define OCL_CHECK(value1,value2,str) \
-    if(value1!=value2) \
-        fprintf(stderr,"[OCL_ERROR] %s\n",str);
-
 #define OPENCL_DLL_NAME "OpenCL.dll"
 #elif defined(MACOSX)
 #define OPENCL_DLL_NAME NULL
commit 6c7cc9b637ef77a606d27f62aa5cc7f19550962b
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Sep 30 22:43:44 2013 +0200

    clear cache of old files when opencl source changes
    
    Change-Id: I67bc06f80c284c85d2bb409380ba3a43611ec31c

diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx
index 6fa86cc..b15dc73 100644
--- a/sc/source/core/opencl/openclwrapper.cxx
+++ b/sc/source/core/opencl/openclwrapper.cxx
@@ -92,6 +92,36 @@ OString getCacheFolder()
     return rtl::OUStringToOString(url, RTL_TEXTENCODING_UTF8);
 }
 
+void clearCache()
+{
+    OUString aCacheDirURL(rtl::OStringToOUString(OpenclDevice::maCacheFolder, RTL_TEXTENCODING_UTF8));
+    osl::Directory aCacheDir(aCacheDirURL);
+    osl::FileBase::RC status = aCacheDir.open();
+    if(status != osl::FileBase::E_None)
+        return;
+
+    osl::DirectoryItem aItem;
+    OUString aSourceString = rtl::OStringToOUString(OpenclDevice::maSourceHash + ".bin", RTL_TEXTENCODING_UTF8);
+    while(osl::FileBase::E_None == aCacheDir.getNextItem(aItem))
+    {
+        osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileName|osl_FileStatus_Mask_FileURL);
+        status = aItem.getFileStatus(aFileStatus);
+        if(status != osl::FileBase::E_None)
+            continue;
+
+        OUString aFileName = aFileStatus.getFileName();
+        if(aFileName.endsWith(".bin"))
+        {
+            if(!aFileName.endsWith(aSourceString))
+            {
+                // delete the file
+                OUString aFileUrl = aFileStatus.getFileURL();
+                osl::File::remove(aFileUrl);
+            }
+        }
+    }
+}
+
 }
 
 OString OpenclDevice::maSourceHash = generateHashForSource();
@@ -259,6 +289,7 @@ std::vector<boost::shared_ptr<osl::File> > OpenclDevice::binaryGenerated( const
 
 int OpenclDevice::writeBinaryToFile( const OString& rFileName, const char* binary, size_t numBytes )
 {
+    clearCache();
     osl::File file(rtl::OStringToOUString(rFileName, RTL_TEXTENCODING_UTF8));
     osl::FileBase::RC status = file.open(
             osl_File_OpenFlag_Write | osl_File_OpenFlag_Create );
commit d81286b78ff90cf4cde17c5000cd8eda6ea4a380
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Sep 22 02:19:36 2013 +0200

    sal_Bool to bool in bcaslot.[ch]xx
    
    Change-Id: Ic38f5421da373a68eeee8fe7863450dd5025e312

diff --git a/sc/source/core/data/bcaslot.cxx b/sc/source/core/data/bcaslot.cxx
index e55c183..b7ed7f5 100644
--- a/sc/source/core/data/bcaslot.cxx
+++ b/sc/source/core/data/bcaslot.cxx
@@ -255,13 +255,13 @@ ScBroadcastAreas::const_iterator ScBroadcastAreaSlot::FindBroadcastArea(
 }
 
 
-sal_Bool ScBroadcastAreaSlot::AreaBroadcast( const ScHint& rHint)
+bool ScBroadcastAreaSlot::AreaBroadcast( const ScHint& rHint)
 {
     if (aBroadcastAreaTbl.empty())
         return false;
     bool bInBroadcast = mbInBroadcastIteration;
     mbInBroadcastIteration = true;
-    sal_Bool bIsBroadcasted = false;
+    bool bIsBroadcasted = false;
     const ScAddress& rAddress = rHint.GetAddress();
     for (ScBroadcastAreas::const_iterator aIter( aBroadcastAreaTbl.begin()),
             aIterEnd( aBroadcastAreaTbl.end()); aIter != aIterEnd; ++aIter )
@@ -275,7 +275,7 @@ sal_Bool ScBroadcastAreaSlot::AreaBroadcast( const ScHint& rHint)
             if (!pBASM->IsInBulkBroadcast() || pBASM->InsertBulkArea( pArea))
             {
                 pArea->GetBroadcaster().Broadcast( rHint);
-                bIsBroadcasted = sal_True;
+                bIsBroadcasted = true;
             }
         }
     }
@@ -288,14 +288,14 @@ sal_Bool ScBroadcastAreaSlot::AreaBroadcast( const ScHint& rHint)
 }
 
 
-sal_Bool ScBroadcastAreaSlot::AreaBroadcastInRange( const ScRange& rRange,
+bool ScBroadcastAreaSlot::AreaBroadcastInRange( const ScRange& rRange,
         const ScHint& rHint)
 {
     if (aBroadcastAreaTbl.empty())
         return false;
     bool bInBroadcast = mbInBroadcastIteration;
     mbInBroadcastIteration = true;
-    sal_Bool bIsBroadcasted = false;
+    bool bIsBroadcasted = false;
     for (ScBroadcastAreas::const_iterator aIter( aBroadcastAreaTbl.begin()),
             aIterEnd( aBroadcastAreaTbl.end()); aIter != aIterEnd; ++aIter )
     {
@@ -308,7 +308,7 @@ sal_Bool ScBroadcastAreaSlot::AreaBroadcastInRange( const ScRange& rRange,
             if (!pBASM->IsInBulkBroadcast() || pBASM->InsertBulkArea( pArea))
             {
                 pArea->GetBroadcaster().Broadcast( rHint);
-                bIsBroadcasted = sal_True;
+                bIsBroadcasted = true;
             }
         }
     }
@@ -376,7 +376,7 @@ void ScBroadcastAreaSlot::UpdateRemove( UpdateRefMode eUpdateRefMode,
                 pArea->DecRef();
                 if (pBASM->IsInBulkBroadcast())
                     pBASM->RemoveBulkArea( pArea);
-                pArea->SetInUpdateChain( sal_True );
+                pArea->SetInUpdateChain( true );
                 ScBroadcastArea* pUC = pBASM->GetEOUpdateChain();
                 if ( pUC )
                     pUC->SetUpdateChainNext( pArea );
@@ -653,7 +653,7 @@ void ScBroadcastAreaSlotMachine::EndListeningArea( const ScRange& rRange,
 }
 
 
-sal_Bool ScBroadcastAreaSlotMachine::AreaBroadcast( const ScHint& rHint ) const
+bool ScBroadcastAreaSlotMachine::AreaBroadcast( const ScHint& rHint ) const
 {
     const ScAddress& rAddress = rHint.GetAddress();
     if ( rAddress == BCA_BRDCST_ALWAYS )
@@ -661,7 +661,7 @@ sal_Bool ScBroadcastAreaSlotMachine::AreaBroadcast( const ScHint& rHint ) const
         if ( pBCAlways )
         {
             pBCAlways->Broadcast( rHint );
-            return sal_True;
+            return true;
         }
         else
             return false;
@@ -681,10 +681,10 @@ sal_Bool ScBroadcastAreaSlotMachine::AreaBroadcast( const ScHint& rHint ) const
 }
 
 
-sal_Bool ScBroadcastAreaSlotMachine::AreaBroadcastInRange( const ScRange& rRange,
+bool ScBroadcastAreaSlotMachine::AreaBroadcastInRange( const ScRange& rRange,
         const ScHint& rHint ) const
 {
-    sal_Bool bBroadcasted = false;
+    bool bBroadcasted = false;
     SCTAB nEndTab = rRange.aEnd.Tab();
     for (TableSlotsMap::const_iterator iTab( aTableSlotsMap.lower_bound( rRange.aStart.Tab()));
             iTab != aTableSlotsMap.end() && (*iTab).first <= nEndTab; ++iTab)
diff --git a/sc/source/core/inc/bcaslot.hxx b/sc/source/core/inc/bcaslot.hxx
index 53e13d6..ca11dd9 100644
--- a/sc/source/core/inc/bcaslot.hxx
+++ b/sc/source/core/inc/bcaslot.hxx
@@ -39,7 +39,7 @@ private:
     SvtBroadcaster      aBroadcaster;
     ScRange             aRange;
     sal_uLong               nRefCount;
-    sal_Bool                bInUpdateChain;
+    bool                bInUpdateChain;
 
 public:
             ScBroadcastArea( const ScRange& rRange )
@@ -57,8 +57,8 @@ public:
     inline sal_uLong        GetRef() { return nRefCount; }
     inline ScBroadcastArea* GetUpdateChainNext() const { return pUpdateChainNext; }
     inline void         SetUpdateChainNext( ScBroadcastArea* p ) { pUpdateChainNext = p; }
-    inline sal_Bool         IsInUpdateChain() const { return bInUpdateChain; }
-    inline void         SetInUpdateChain( sal_Bool b ) { bInUpdateChain = b; }
+    inline bool         IsInUpdateChain() const { return bInUpdateChain; }
+    inline void         SetInUpdateChain( bool b ) { bInUpdateChain = b; }
 
     /** Equalness of this or range. */
     inline  bool        operator==( const ScBroadcastArea & rArea ) const;
@@ -139,7 +139,7 @@ private:
         whether there would be an overflow when adding an area, setting the
         proper state if so.
 
-        @return sal_True if a HardRecalcState is effective and area is not to be
+        @return true if a HardRecalcState is effective and area is not to be
         added.
       */
     bool                CheckHardRecalcStateCondition() const;
@@ -173,7 +173,7 @@ public:
             as InsertListeningArea(), so use that instead.
 
         @return
-            sal_True if rpArea passed was NULL and ScBroadcastArea is newly
+            true if rpArea passed was NULL and ScBroadcastArea is newly
             created.
      */
     bool                StartListeningArea( const ScRange& rRange,
@@ -189,9 +189,9 @@ public:
     void                EndListeningArea( const ScRange& rRange,
                                             SvtListener* pListener,
                                             ScBroadcastArea*& rpArea );
-    sal_Bool                AreaBroadcast( const ScHint& rHint );
-    /// @return sal_True if at least one broadcast occurred.
-    sal_Bool                AreaBroadcastInRange( const ScRange& rRange,
+    bool                AreaBroadcast( const ScHint& rHint );
+    /// @return true if at least one broadcast occurred.
+    bool                AreaBroadcastInRange( const ScRange& rRange,
                                               const ScHint& rHint );
     void                DelBroadcastAreasInRange( const ScRange& rRange );
     void                UpdateRemove( UpdateRefMode eUpdateRefMode,
@@ -281,9 +281,9 @@ public:
                                             SvtListener* pListener );
     void                EndListeningArea( const ScRange& rRange,
                                             SvtListener* pListener );
-    sal_Bool                AreaBroadcast( const ScHint& rHint ) const;
+    bool                AreaBroadcast( const ScHint& rHint ) const;
         // return: at least one broadcast occurred
-    sal_Bool                AreaBroadcastInRange( const ScRange& rRange, const ScHint& rHint ) const;
+    bool                AreaBroadcastInRange( const ScRange& rRange, const ScHint& rHint ) const;
     void                DelBroadcastAreasInRange( const ScRange& rRange );
     void                UpdateBroadcastAreas( UpdateRefMode eUpdateRefMode,
                                             const ScRange& rRange,


More information about the Libreoffice-commits mailing list