[Libreoffice-commits] core.git: Branch 'feature/fixes36' - 2 commits - desktop/source include/opencl opencl/source

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Fri Oct 21 22:17:39 UTC 2016


 desktop/source/app/opencl.cxx    |    3 +--
 include/opencl/openclwrapper.hxx |    5 ++++-
 opencl/source/openclwrapper.cxx  |   21 +++++++++++++++++----
 3 files changed, 22 insertions(+), 7 deletions(-)

New commits:
commit 56ba1e97b3609c6156b0ca2183fe6f8d4fd5abb7
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue Oct 18 23:53:44 2016 +0200

    tdf#103395 opencl: don't initialize OpenCL when disabled
    
    If SAL_DISABLE_OPENCL is set we don't want to do any kind of
    OpenCL initialization. Put an extra guard in fillOpenCLInfo
    (and similar methods in opencl package) to prevent that.
    
    Put the check if OpenCL can be used into one place which checks
    SAL_DISABLE_OPENCL and UseOpenCL in configuration.
    
    Change-Id: Icc216d4299d3a7942843117ab9b9411de8075b11

diff --git a/desktop/source/app/opencl.cxx b/desktop/source/app/opencl.cxx
index 13161f3..791b7a9 100644
--- a/desktop/source/app/opencl.cxx
+++ b/desktop/source/app/opencl.cxx
@@ -117,8 +117,7 @@ bool testOpenCLCompute(const Reference< XDesktop2 > &xDesktop, const OUString &r
 
 void Desktop::CheckOpenCLCompute(const Reference< XDesktop2 > &xDesktop)
 {
-    if (getenv("SAL_DISABLE_OPENCL") ||
-        !officecfg::Office::Common::Misc::UseOpenCL::get())
+    if (!opencl::canUseOpenCL())
         return;
 
     SAL_INFO("opencl", "Initiating test of OpenCL device");
diff --git a/include/opencl/openclwrapper.hxx b/include/opencl/openclwrapper.hxx
index dae1192..5c8141e 100644
--- a/include/opencl/openclwrapper.hxx
+++ b/include/opencl/openclwrapper.hxx
@@ -26,7 +26,8 @@
 
 #include <cstdio>
 
-namespace opencl {
+namespace opencl
+{
 
 struct KernelEnv
 {
@@ -55,6 +56,8 @@ struct OPENCL_DLLPUBLIC GPUEnv
 extern OPENCL_DLLPUBLIC GPUEnv gpuEnv;
 extern OPENCL_DLLPUBLIC sal_uInt64 kernelFailures;
 
+OPENCL_DLLPUBLIC bool canUseOpenCL();
+
 OPENCL_DLLPUBLIC bool generatBinFromKernelSource( cl_program program, const char * clFileName );
 OPENCL_DLLPUBLIC bool buildProgramFromBinary(const char* buildOption, GPUEnv* gpuEnv, const char* filename, int idx);
 OPENCL_DLLPUBLIC void setKernelEnv( KernelEnv *envInfo );
diff --git a/opencl/source/openclwrapper.cxx b/opencl/source/openclwrapper.cxx
index d8d16c3..981816c 100644
--- a/opencl/source/openclwrapper.cxx
+++ b/opencl/source/openclwrapper.cxx
@@ -32,6 +32,8 @@
 
 #include <cmath>
 
+#include <officecfg/Office/Common.hxx>
+
 #ifdef _WIN32
 #include <prewin.h>
 #include <postwin.h>
@@ -64,7 +66,8 @@ namespace opencl {
 GPUEnv gpuEnv;
 sal_uInt64 kernelFailures = 0;
 
-namespace {
+namespace
+{
 
 bool bIsInited = false;
 
@@ -648,7 +651,9 @@ bool createPlatformInfo(cl_platform_id nPlatformId, OpenCLPlatformInfo& rPlatfor
 const std::vector<OpenCLPlatformInfo>& fillOpenCLInfo()
 {
     static std::vector<OpenCLPlatformInfo> aPlatforms;
-    if(!aPlatforms.empty())
+
+    // return early if we already initialized or can't use OpenCL
+    if (!aPlatforms.empty() || !canUseOpenCL())
         return aPlatforms;
 
     int status = clewInit(OPENCL_DLL_NAME);
@@ -731,9 +736,16 @@ void findDeviceInfoFromDeviceId(cl_device_id aDeviceId, size_t& rDeviceId, size_
 
 }
 
+bool canUseOpenCL()
+{
+    if (getenv("SAL_DISABLE_OPENCL") || !officecfg::Office::Common::Misc::UseOpenCL::get())
+        return false;
+    return true;
+}
+
 bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEvaluation, OUString& rOutSelectedDeviceVersionIDString)
 {
-    if(fillOpenCLInfo().empty() || getenv("SAL_DISABLE_OPENCL"))
+    if (!canUseOpenCL() || fillOpenCLInfo().empty())
         return false;
 
     cl_device_id pDeviceId = nullptr;
@@ -839,6 +851,9 @@ bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEv
 
 void getOpenCLDeviceInfo(size_t& rDeviceId, size_t& rPlatformId)
 {
+    if (!canUseOpenCL())
+        return;
+
     int status = clewInit(OPENCL_DLL_NAME);
     if (status < 0)
         return;
commit 63cc91290114c64a42505846919f54fb4ee01361
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Sat Oct 22 00:15:19 2016 +0200

    Revert "opencl: make sure we don't initialize OpenCL when disabled"
    
    This reverts commit c10d35e7b9135b98479b6188c2765dc661ba1e65.

diff --git a/opencl/source/openclwrapper.cxx b/opencl/source/openclwrapper.cxx
index abd5407..d8d16c3 100644
--- a/opencl/source/openclwrapper.cxx
+++ b/opencl/source/openclwrapper.cxx
@@ -648,9 +648,7 @@ bool createPlatformInfo(cl_platform_id nPlatformId, OpenCLPlatformInfo& rPlatfor
 const std::vector<OpenCLPlatformInfo>& fillOpenCLInfo()
 {
     static std::vector<OpenCLPlatformInfo> aPlatforms;
-
-    // return early if we already initialized or SAL_DISABLE_OPENCL is set
-    if (!aPlatforms.empty() || getenv("SAL_DISABLE_OPENCL"))
+    if(!aPlatforms.empty())
         return aPlatforms;
 
     int status = clewInit(OPENCL_DLL_NAME);
@@ -735,7 +733,7 @@ void findDeviceInfoFromDeviceId(cl_device_id aDeviceId, size_t& rDeviceId, size_
 
 bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEvaluation, OUString& rOutSelectedDeviceVersionIDString)
 {
-    if (getenv("SAL_DISABLE_OPENCL") || fillOpenCLInfo().empty())
+    if(fillOpenCLInfo().empty() || getenv("SAL_DISABLE_OPENCL"))
         return false;
 
     cl_device_id pDeviceId = nullptr;


More information about the Libreoffice-commits mailing list