Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / opencl / openclwrapper.hxx
blob5f71b2a205f3e86dca03af706281c9ffebf6e764
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_SC_SOURCE_CORE_OPENCL_OPENCLWRAPPER_HXX
11 #define INCLUDED_SC_SOURCE_CORE_OPENCL_OPENCLWRAPPER_HXX
13 #include <cassert>
14 #include <vector>
16 #include <clew/clew.h>
18 #include <sal/detail/log.h>
19 #include <opencl/opencldllapi.h>
20 #include <opencl/platforminfo.hxx>
21 #include <osl/file.hxx>
22 #include <rtl/string.hxx>
24 #define MAX_CLFILE_NUM 50
25 #define OPENCL_CMDQUEUE_SIZE 1 // number of command queues per OpenCL device.
27 #include <cstdio>
29 namespace opencl
32 struct KernelEnv
34 cl_context mpkContext;
35 cl_command_queue mpkCmdQueue;
36 cl_program mpkProgram;
39 struct OPENCL_DLLPUBLIC GPUEnv
41 //share vb in all modules in hb library
42 cl_platform_id mpPlatformID;
43 cl_context mpContext;
44 cl_device_id mpDevID;
45 cl_command_queue mpCmdQueue[OPENCL_CMDQUEUE_SIZE];
46 bool mbCommandQueueInitialized;
47 cl_program mpArryPrograms[MAX_CLFILE_NUM]; //one program object maps one kernel source file
48 int mnIsUserCreated; // 1: created , 0:no create and needed to create by opencl wrapper
49 int mnCmdQueuePos;
50 bool mnKhrFp64Flag;
51 bool mnAmdFp64Flag;
52 bool mbNeedsTDRAvoidance;
54 static bool isOpenCLEnabled();
57 extern OPENCL_DLLPUBLIC GPUEnv gpuEnv;
58 extern OPENCL_DLLPUBLIC sal_uInt64 kernelFailures;
60 OPENCL_DLLPUBLIC bool canUseOpenCL();
62 OPENCL_DLLPUBLIC bool generatBinFromKernelSource( cl_program program, const char * clFileName );
63 OPENCL_DLLPUBLIC bool buildProgramFromBinary(const char* buildOption, GPUEnv* gpuEnv, const char* filename, int idx);
64 OPENCL_DLLPUBLIC void setKernelEnv( KernelEnv *envInfo );
65 OPENCL_DLLPUBLIC const std::vector<OpenCLPlatformInfo>& fillOpenCLInfo();
67 /**
68 * Used to set or switch between OpenCL devices.
70 * @param pDeviceId the id of the opencl device of type cl_device_id, NULL means use software calculation
71 * @param bAutoSelect use the algorithm to select the best OpenCL device
72 * @param rOutSelectedDeviceVersionIDString returns the selected device's version string.
74 * @return returns true if there is a valid opencl device that has been set up
76 OPENCL_DLLPUBLIC bool switchOpenCLDevice(const OUString* pDeviceId, bool bAutoSelect,
77 bool bForceEvaluation,
78 OUString& rOutSelectedDeviceVersionIDString);
80 OPENCL_DLLPUBLIC void getOpenCLDeviceInfo(size_t& rDeviceId, size_t& rPlatformId);
82 /**
83 * Set the current command queue position in case of multiple command queues
84 * for a given device.
86 OPENCL_DLLPUBLIC void setOpenCLCmdQueuePosition( int nPos );
88 /**
89 * Return a textual representation of an OpenCL error code.
90 * (Currently the symbolic name sans the CL_ prefix.)
92 OPENCL_DLLPUBLIC const char* errorString(cl_int nError);
96 #endif
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */