Skip to content

Commit

Permalink
tdf#103395 opencl: don't initialize OpenCL when disabled
Browse files Browse the repository at this point in the history
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
Reviewed-on: https://gerrit.libreoffice.org/30025
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
  • Loading branch information
quikee committed Oct 24, 2016
1 parent 38b895c commit 21e8ed8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 1 addition & 3 deletions desktop/source/app/opencl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ bool testOpenCLCompute(const Reference< XDesktop2 > &xDesktop, const OUString &r

void Desktop::CheckOpenCLCompute(const Reference< XDesktop2 > &xDesktop)
{
if (getenv("SAL_DISABLE_OPENCL") ||
Application::IsSafeModeEnabled() ||
!officecfg::Office::Common::Misc::UseOpenCL::get())
if (!opencl::canUseOpenCL() || Application::IsSafeModeEnabled())
return;

SAL_INFO("opencl", "Initiating test of OpenCL device");
Expand Down
5 changes: 4 additions & 1 deletion include/opencl/openclwrapper.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

#include <cstdio>

namespace opencl {
namespace opencl
{

struct KernelEnv
{
Expand Down Expand Up @@ -56,6 +57,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 );
Expand Down
21 changes: 18 additions & 3 deletions opencl/source/openclwrapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include <cmath>

#include <officecfg/Office/Common.hxx>

#ifdef _WIN32
#include <prewin.h>
#include <postwin.h>
Expand Down Expand Up @@ -64,7 +66,8 @@ namespace opencl {
GPUEnv gpuEnv;
sal_uInt64 kernelFailures = 0;

namespace {
namespace
{

bool bIsInited = false;

Expand Down Expand Up @@ -704,7 +707,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);
Expand Down Expand Up @@ -785,9 +790,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;
Expand Down Expand Up @@ -863,6 +875,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;
Expand Down

0 comments on commit 21e8ed8

Please sign in to comment.