From dfddef4be7c1e0ccfa7b3d84f77856a9e3fe65bd Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Tue, 18 Oct 2016 23:53:44 +0200 Subject: tdf#103395 opencl: don't initialize OpenCL when disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Reviewed-on: https://gerrit.libreoffice.org/30025 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl (cherry picked from commit 21e8ed8b5f032f63012a7ee84bce64fac218154f) Change-Id: Icc216d4299d3a7942843117ab9b9411de8075b11 Reviewed-on: https://gerrit.libreoffice.org/30220 Tested-by: Jenkins Reviewed-by: Michael Meeks (cherry picked from commit 5f36c66183049522977a386d9afce462ac5d3ec0) --- opencl/source/openclwrapper.cxx | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'opencl/source') diff --git a/opencl/source/openclwrapper.cxx b/opencl/source/openclwrapper.cxx index a06e5ef64326..cced43279a63 100644 --- a/opencl/source/openclwrapper.cxx +++ b/opencl/source/openclwrapper.cxx @@ -32,6 +32,8 @@ #include +#include + #ifdef _WIN32 #include #include @@ -64,7 +66,8 @@ namespace opencl { GPUEnv gpuEnv; sal_uInt64 kernelFailures = 0; -namespace { +namespace +{ bool bIsInited = false; @@ -694,7 +697,9 @@ bool createPlatformInfo(cl_platform_id nPlatformId, OpenCLPlatformInfo& rPlatfor const std::vector& fillOpenCLInfo() { static std::vector 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); @@ -777,9 +782,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; @@ -855,6 +867,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; -- cgit