diff options
Diffstat (limited to 'include/opencl')
-rw-r--r-- | include/opencl/OpenCLZone.hxx | 32 | ||||
-rw-r--r-- | include/opencl/openclconfig.hxx | 101 | ||||
-rw-r--r-- | include/opencl/opencldllapi.h | 34 | ||||
-rw-r--r-- | include/opencl/openclwrapper.hxx | 98 | ||||
-rw-r--r-- | include/opencl/platforminfo.hxx | 51 |
5 files changed, 316 insertions, 0 deletions
diff --git a/include/opencl/OpenCLZone.hxx b/include/opencl/OpenCLZone.hxx new file mode 100644 index 0000000000..8247e667d0 --- /dev/null +++ b/include/opencl/OpenCLZone.hxx @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_OPENCL_INC_OPENCL_ZONE_HXX +#define INCLUDED_OPENCL_INC_OPENCL_ZONE_HXX + +#include <sal/config.h> + +#include <opencl/opencldllapi.h> + +#include <comphelper/crashzone.hxx> + +class OPENCL_DLLPUBLIC OpenCLZone : public CrashZone<OpenCLZone> +{ +public: + static void hardDisable(); +}; + +// Used during initial testing of OpenCL. +class OPENCL_DLLPUBLIC OpenCLInitialZone : public CrashZone<OpenCLInitialZone> +{ +}; + +#endif // INCLUDED_OPENCL_INC_OPENCL_ZONE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/opencl/openclconfig.hxx b/include/opencl/openclconfig.hxx new file mode 100644 index 0000000000..2e099bafe6 --- /dev/null +++ b/include/opencl/openclconfig.hxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_OPENCL_OPENCLCONFIG_HXX +#define INCLUDED_OPENCL_OPENCLCONFIG_HXX + +#include <ostream> +#include <set> + +#include <opencl/opencldllapi.h> +#include <rtl/ustring.hxx> +#include <utility> + +struct OpenCLDeviceInfo; +struct OpenCLPlatformInfo; + +struct OPENCL_DLLPUBLIC OpenCLConfig +{ + struct ImplMatcher + { + OUString maOS; + OUString maOSVersion; + OUString maPlatformVendor; + OUString maDevice; + OUString maDriverVersion; + + ImplMatcher() + { + } + + ImplMatcher(OUString aOS, + OUString aOSVersion, + OUString aPlatformVendor, + OUString aDevice, + OUString aDriverVersion) + : maOS(std::move(aOS)), + maOSVersion(std::move(aOSVersion)), + maPlatformVendor(std::move(aPlatformVendor)), + maDevice(std::move(aDevice)), + maDriverVersion(std::move(aDriverVersion)) + { + } + + bool operator==(const ImplMatcher& r) const + { + return maOS == r.maOS && + maOSVersion == r.maOSVersion && + maPlatformVendor == r.maPlatformVendor && + maDevice == r.maDevice && + maDriverVersion == r.maDriverVersion; + } + bool operator!=(const ImplMatcher& r) const + { + return !operator==(r); + } + bool operator<(const ImplMatcher& r) const + { + return (maOS < r.maOS || + (maOS == r.maOS && + (maOSVersion < r.maOSVersion || + (maOSVersion == r.maOSVersion && + (maPlatformVendor < r.maPlatformVendor || + (maPlatformVendor == r.maPlatformVendor && + (maDevice < r.maDevice || + (maDevice == r.maDevice && + (maDriverVersion < r.maDriverVersion))))))))); + } + }; + + bool mbUseOpenCL; + + typedef std::set<ImplMatcher> ImplMatcherSet; + + ImplMatcherSet maDenyList; + ImplMatcherSet maAllowList; + + OpenCLConfig(); + + bool operator== (const OpenCLConfig& r) const; + bool operator!= (const OpenCLConfig& r) const; + + static OpenCLConfig get(); + + void set(); + + bool checkImplementation(const OpenCLPlatformInfo& rPlatform, const OpenCLDeviceInfo& rDevice) const; +}; + +OPENCL_DLLPUBLIC std::ostream& operator<<(std::ostream& rStream, const OpenCLConfig& rConfig); +OPENCL_DLLPUBLIC std::ostream& operator<<(std::ostream& rStream, const OpenCLConfig::ImplMatcher& rImpl); +OPENCL_DLLPUBLIC std::ostream& operator<<(std::ostream& rStream, const OpenCLConfig::ImplMatcherSet& rSet); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/opencl/opencldllapi.h b/include/opencl/opencldllapi.h new file mode 100644 index 0000000000..99bfd6cb9e --- /dev/null +++ b/include/opencl/opencldllapi.h @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_OPENCL_OPENCLDLLAPI_H +#define INCLUDED_OPENCL_OPENCLDLLAPI_H + +#include <sal/types.h> + +#if defined(OPENCL_DLLIMPLEMENTATION) +#define OPENCL_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define OPENCL_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif +#define OPENCL_DLLPRIVATE SAL_DLLPRIVATE + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/opencl/openclwrapper.hxx b/include/opencl/openclwrapper.hxx new file mode 100644 index 0000000000..bfaa49e99b --- /dev/null +++ b/include/opencl/openclwrapper.hxx @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_SC_SOURCE_CORE_OPENCL_OPENCLWRAPPER_HXX +#define INCLUDED_SC_SOURCE_CORE_OPENCL_OPENCLWRAPPER_HXX + +#include <vector> + +#include <clew/clew.h> + +#include <opencl/opencldllapi.h> +#include <rtl/ustring.hxx> + +#define MAX_CLFILE_NUM 50 +#define OPENCL_CMDQUEUE_SIZE 1 // number of command queues per OpenCL device. + +#include <cstdio> + +struct OpenCLPlatformInfo; + +namespace openclwrapper +{ + +struct KernelEnv +{ + cl_context mpkContext; + cl_command_queue mpkCmdQueue; + cl_program mpkProgram; +}; + +struct OPENCL_DLLPUBLIC GPUEnv +{ + //share vb in all modules in hb library + cl_platform_id mpPlatformID; + 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; + bool mnKhrFp64Flag; + bool mnAmdFp64Flag; + bool mbNeedsTDRAvoidance; + + static bool isOpenCLEnabled(); +}; + +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 ); +OPENCL_DLLPUBLIC const std::vector<OpenCLPlatformInfo>& fillOpenCLInfo(); + +/** + * Used to set or switch between OpenCL devices. + * + * @param aDeviceId the id of the opencl device of type cl_device_id, "" means use software calculation + * @param bAutoSelect use the algorithm to select the best OpenCL device + * @param rOutSelectedDeviceVersionIDString returns the selected device's version string. + * + * @return returns true if there is a valid opencl device that has been set up + */ +OPENCL_DLLPUBLIC bool switchOpenCLDevice(std::u16string_view aDevice, bool bAutoSelect, + bool bForceEvaluation, + OUString& rOutSelectedDeviceVersionIDString); + +OPENCL_DLLPUBLIC void getOpenCLDeviceInfo(size_t& rDeviceId, size_t& rPlatformId); + +OPENCL_DLLPUBLIC void getOpenCLDeviceName(OUString& rDeviceName, OUString& rPlatformName); + +/** + * Set the current command queue position in case of multiple command queues + * for a given device. + */ +OPENCL_DLLPUBLIC void setOpenCLCmdQueuePosition( int nPos ); + +/** + * Return a textual representation of an OpenCL error code. + * (Currently the symbolic name sans the CL_ prefix.) + */ +OPENCL_DLLPUBLIC const char* errorString(cl_int nError); + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/opencl/platforminfo.hxx b/include/opencl/platforminfo.hxx new file mode 100644 index 0000000000..5e54c052fc --- /dev/null +++ b/include/opencl/platforminfo.hxx @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_OPENCL_PLATFORMINFO_HXX +#define INCLUDED_OPENCL_PLATFORMINFO_HXX + +#include <ostream> +#include <vector> + +#include <clew/clew.h> + +#include <opencl/opencldllapi.h> +#include <rtl/ustring.hxx> + +// Struct that describs an actual instance of an OpenCL device + +struct OpenCLDeviceInfo +{ + cl_device_id device; + OUString maName; + OUString maVendor; + OUString maDriver; + size_t mnMemory; + size_t mnComputeUnits; + size_t mnFrequency; + + OpenCLDeviceInfo(); +}; + +// Struct that describs an actual instance of an OpenCL platform implementation + +struct OpenCLPlatformInfo +{ + cl_platform_id platform; + OUString maVendor; + OUString maName; + std::vector<OpenCLDeviceInfo> maDevices; + + OpenCLPlatformInfo(); +}; + +OPENCL_DLLPUBLIC std::ostream& operator<<(std::ostream& rStream, const OpenCLPlatformInfo& rPlatform); +OPENCL_DLLPUBLIC std::ostream& operator<<(std::ostream& rStream, const OpenCLDeviceInfo& rDevice); + +#endif |