desktop/source/app/opencl.cxx | 4 - include/opencl/OpenCLZone.hxx | 17 +++--- include/opencl/openclwrapper.hxx | 6 +- opencl/source/OpenCLZone.cxx | 6 ++ opencl/source/openclwrapper.cxx | 102 +++++++++++++++++++++++++-------------- vcl/source/app/svmain.cxx | 8 +++ 6 files changed, 96 insertions(+), 47 deletions(-)
New commits: commit dfddef4be7c1e0ccfa7b3d84f77856a9e3fe65bd Author: Tomaž Vajngerl <[email protected]> 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. Reviewed-on: https://gerrit.libreoffice.org/30025 Tested-by: Jenkins <[email protected]> Reviewed-by: Tomaž Vajngerl <[email protected]> (cherry picked from commit 21e8ed8b5f032f63012a7ee84bce64fac218154f) Change-Id: Icc216d4299d3a7942843117ab9b9411de8075b11 Reviewed-on: https://gerrit.libreoffice.org/30220 Tested-by: Jenkins <[email protected]> Reviewed-by: Michael Meeks <[email protected]> (cherry picked from commit 5f36c66183049522977a386d9afce462ac5d3ec0) 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 ff15818..c8b6217 100644 --- a/include/opencl/openclwrapper.hxx +++ b/include/opencl/openclwrapper.hxx @@ -28,7 +28,8 @@ #include <cstdio> -namespace opencl { +namespace opencl +{ struct KernelEnv { @@ -58,6 +59,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 a06e5ef..cced432 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; @@ -694,7 +697,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); @@ -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; commit d86a4f614575ae4faf9e6a165fe9a5f1ed27c3c8 Author: Tomaž Vajngerl <[email protected]> Date: Thu Oct 13 12:55:57 2016 +0200 tdf#103204 opencl: initialize command queue on demand Change-Id: Ie3da1d6ec91e951b1ffc15abf376c7af57789e47 Reviewed-on: https://gerrit.libreoffice.org/29802 Reviewed-by: Tomaž Vajngerl <[email protected]> Tested-by: Tomaž Vajngerl <[email protected]> (cherry picked from commit 4eea4af8924e3b1bb00c22cf1f9d21fc4dec6e83) Reviewed-on: https://gerrit.libreoffice.org/29994 Tested-by: Jenkins <[email protected]> Reviewed-by: Jan Holesovsky <[email protected]> (cherry picked from commit 4969015d138cbd9b20bf3a9bee0af9d6222f1a68) diff --git a/include/opencl/openclwrapper.hxx b/include/opencl/openclwrapper.hxx index ac86bea..ff15818 100644 --- a/include/opencl/openclwrapper.hxx +++ b/include/opencl/openclwrapper.hxx @@ -44,6 +44,7 @@ struct OPENCL_DLLPUBLIC GPUEnv cl_context mpContext; cl_device_id mpDevID; cl_command_queue mpCmdQueue[OPENCL_CMDQUEUE_SIZE]; + bool mbCommandQueueInitialized; cl_program mpArryPrograms[MAX_CLFILE_NUM]; //one program object maps one kernel source file int mnIsUserCreated; // 1: created , 0:no create and needed to create by opencl wrapper int mnCmdQueuePos; diff --git a/opencl/source/openclwrapper.cxx b/opencl/source/openclwrapper.cxx index de1ed26..a06e5ef 100644 --- a/opencl/source/openclwrapper.cxx +++ b/opencl/source/openclwrapper.cxx @@ -104,8 +104,54 @@ OString getCacheFolder() } +bool initializeCommandQueue(GPUEnv& aGpuEnv) +{ + OpenCLZone zone; + + cl_int nState; + cl_command_queue command_queue[OPENCL_CMDQUEUE_SIZE]; + + for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i) + { + command_queue[i] = clCreateCommandQueue(aGpuEnv.mpContext, aGpuEnv.mpDevID, 0, &nState); + if (nState != CL_SUCCESS) + SAL_WARN("opencl", "clCreateCommandQueue failed: " << errorString(nState)); + + if (command_queue[i] == nullptr || nState != CL_SUCCESS) + { + // Release all command queues created so far. + for (int j = 0; j <= i; ++j) + { + if (command_queue[j]) + { + clReleaseCommandQueue(command_queue[j]); + command_queue[j] = nullptr; + } + } + + clReleaseContext(aGpuEnv.mpContext); + SAL_WARN("opencl", "failed to set/switch opencl device"); + return false; + } + + SAL_INFO("opencl", "Created command queue " << command_queue[i] << " for context " << aGpuEnv.mpContext); + } + + for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i) + { + aGpuEnv.mpCmdQueue[i] = command_queue[i]; + } + aGpuEnv.mbCommandQueueInitialized = true; + return true; +} + void setKernelEnv( KernelEnv *envInfo ) { + if (!gpuEnv.mbCommandQueueInitialized) + { + initializeCommandQueue(gpuEnv); + } + envInfo->mpkContext = gpuEnv.mpContext; envInfo->mpkProgram = gpuEnv.mpArryPrograms[0]; @@ -266,8 +312,7 @@ bool initOpenCLAttr( OpenCLEnv * env ) gpuEnv.mnIsUserCreated = 1; - for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i) - gpuEnv.mpCmdQueue[i] = env->mpOclCmdQueue[i]; + gpuEnv.mbCommandQueueInitialized = false; gpuEnv.mnCmdQueuePos = 0; // default to 0. @@ -766,7 +811,6 @@ bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEv cl_context context; cl_platform_id platformId; - cl_command_queue command_queue[OPENCL_CMDQUEUE_SIZE]; { OpenCLZone zone; @@ -791,33 +835,6 @@ bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEv } SAL_INFO("opencl", "Created context " << context << " for platform " << platformId << ", device " << pDeviceId); - for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i) - { - command_queue[i] = clCreateCommandQueue( - context, pDeviceId, 0, &nState); - if (nState != CL_SUCCESS) - SAL_WARN("opencl", "clCreateCommandQueue failed: " << errorString(nState)); - - if (command_queue[i] == nullptr || nState != CL_SUCCESS) - { - // Release all command queues created so far. - for (int j = 0; j <= i; ++j) - { - if (command_queue[j]) - { - clReleaseCommandQueue(command_queue[j]); - command_queue[j] = nullptr; - } - } - - clReleaseContext(context); - SAL_WARN("opencl", "failed to set/switch opencl device"); - return false; - } - - SAL_INFO("opencl", "Created command queue " << command_queue[i] << " for context " << context); - } - OString sDeviceID = getDeviceInfoString(pDeviceId, CL_DEVICE_VENDOR) + " " + getDeviceInfoString(pDeviceId, CL_DRIVER_VERSION); rOutSelectedDeviceVersionIDString = OStringToOUString(sDeviceID, RTL_TEXTENCODING_UTF8); } @@ -825,14 +842,12 @@ bool switchOpenCLDevice(const OUString* pDevice, bool bAutoSelect, bool bForceEv setOpenCLCmdQueuePosition(0); // Call this just to avoid the method being deleted from unused function deleter. releaseOpenCLEnv(&gpuEnv); + OpenCLEnv env; env.mpOclPlatformID = platformId; env.mpOclContext = context; env.mpOclDevsID = pDeviceId; - for (int i = 0; i < OPENCL_CMDQUEUE_SIZE; ++i) - env.mpOclCmdQueue[i] = command_queue[i]; - initOpenCLAttr(&env); return !initOpenCLRunEnv(0); commit e47403fc779720c35930059c513320312ba41c59 Author: Tor Lillqvist <[email protected]> Date: Fri Aug 12 15:56:52 2016 +0300 tdf#100965: Restart on initialisation-time OpenCL crash Add a flag to the OpenCLZone indicating whether we are performing the first-start OpenCL functionality verification, so that if we run into a crash that is caught by the VCL VCLExceptionSignal_impl() handler, we terminate the process with the EXITHELPER_NORMAL_RESTART status after first having disabled OpenCL use. The wrapper process will then restart soffice.bin. This is for Windows only so far. This matches what we do if OpenGL fails early during start of LibreOffice. Also, the enter() and leave() functions are not used anywhere (cherry picked from commit 32881f01833dbcefd5600e1135dd8743178bfd96) (cherry picked from commit b9898f03eb05411c508b1b02588812074d40417a) Reviewed-on: https://gerrit.libreoffice.org/28138 Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Caolán McNamara <[email protected]> (cherry picked from commit e2d5eec6ad49bab6aac2295a1882bf75184aa50c) Change-Id: Ibb9bf3a86b7521bf16728de2a118ad4323be674b diff --git a/desktop/source/app/opencl.cxx b/desktop/source/app/opencl.cxx index 2b8d6d6..13161f3 100644 --- a/desktop/source/app/opencl.cxx +++ b/desktop/source/app/opencl.cxx @@ -123,6 +123,7 @@ void Desktop::CheckOpenCLCompute(const Reference< XDesktop2 > &xDesktop) SAL_INFO("opencl", "Initiating test of OpenCL device"); OpenCLZone aZone; + OpenCLZone::enterInitialTest(); OUString aDevice = officecfg::Office::Calc::Formula::Calculation::OpenCLDevice::get(); OUString aSelectedCLDeviceVersionID; diff --git a/include/opencl/OpenCLZone.hxx b/include/opencl/OpenCLZone.hxx index 1fbc666..0d2059d 100644 --- a/include/opencl/OpenCLZone.hxx +++ b/include/opencl/OpenCLZone.hxx @@ -19,15 +19,8 @@ class OPENCL_DLLPUBLIC OpenCLZone static volatile sal_uInt64 gnEnterCount; /// how many times have we left a new CL zone static volatile sal_uInt64 gnLeaveCount; + static volatile bool gbInInitialTest; - static void enter() - { - gnEnterCount++; - } - static void leave() - { - gnLeaveCount--; - } public: OpenCLZone() { @@ -37,6 +30,8 @@ public: ~OpenCLZone() { gnLeaveCount++; + if (!isInZone()) + gbInInitialTest = false; } static bool isInZone() @@ -44,7 +39,13 @@ public: return gnEnterCount != gnLeaveCount; } + static bool isInInitialTest() + { + return gbInInitialTest; + } + static void hardDisable(); + static void enterInitialTest(); }; #endif // INCLUDED_OPENCL_INC_OPENCL_ZONE_HXX diff --git a/opencl/source/OpenCLZone.cxx b/opencl/source/OpenCLZone.cxx index 03521a2..52d6ada 100644 --- a/opencl/source/OpenCLZone.cxx +++ b/opencl/source/OpenCLZone.cxx @@ -21,6 +21,7 @@ sal_uInt64 volatile OpenCLZone::gnEnterCount = 0; sal_uInt64 volatile OpenCLZone::gnLeaveCount = 0; +bool volatile OpenCLZone::gbInInitialTest = false; /** * Called from a signal handler if we get @@ -47,4 +48,9 @@ void OpenCLZone::hardDisable() } } +void OpenCLZone::enterInitialTest() +{ + gbInInitialTest = true; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx index 23e3fd9..7bd3c31 100644 --- a/vcl/source/app/svmain.cxx +++ b/vcl/source/app/svmain.cxx @@ -24,6 +24,8 @@ #include <osl/file.hxx> #include <osl/signal.h> +#include <desktop/exithelper.h> + #include "tools/debug.hxx" #include "tools/resmgr.hxx" @@ -115,7 +117,13 @@ oslSignalAction SAL_CALL VCLExceptionSignal_impl( void* /*pData*/, oslSignalInfo OpenGLZone::hardDisable(); #if HAVE_FEATURE_OPENCL if (OpenCLZone::isInZone()) + { OpenCLZone::hardDisable(); +#ifdef _WIN32 + if (OpenCLZone::isInInitialTest()) + TerminateProcess(GetCurrentProcess(), EXITHELPER_NORMAL_RESTART); +#endif + } #endif }
_______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
