1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #ifndef INCLUDED_SC_SOURCE_CORE_OPENCL_OPENCLWRAPPER_HXX
11 #define INCLUDED_SC_SOURCE_CORE_OPENCL_OPENCLWRAPPER_HXX
15 #include <clew/clew.h>
17 #include <opencl/opencldllapi.h>
18 #include <rtl/ustring.hxx>
20 #define MAX_CLFILE_NUM 50
21 #define OPENCL_CMDQUEUE_SIZE 1 // number of command queues per OpenCL device.
25 struct OpenCLPlatformInfo
;
27 namespace openclwrapper
32 cl_context mpkContext
;
33 cl_command_queue mpkCmdQueue
;
34 cl_program mpkProgram
;
37 struct OPENCL_DLLPUBLIC GPUEnv
39 //share vb in all modules in hb library
40 cl_platform_id mpPlatformID
;
43 cl_command_queue mpCmdQueue
[OPENCL_CMDQUEUE_SIZE
];
44 bool mbCommandQueueInitialized
;
45 cl_program mpArryPrograms
[MAX_CLFILE_NUM
]; //one program object maps one kernel source file
46 int mnIsUserCreated
; // 1: created , 0:no create and needed to create by opencl wrapper
50 bool mbNeedsTDRAvoidance
;
52 static bool isOpenCLEnabled();
55 extern OPENCL_DLLPUBLIC GPUEnv gpuEnv
;
56 extern OPENCL_DLLPUBLIC sal_uInt64 kernelFailures
;
58 OPENCL_DLLPUBLIC
bool canUseOpenCL();
60 OPENCL_DLLPUBLIC
bool generatBinFromKernelSource( cl_program program
, const char * clFileName
);
61 OPENCL_DLLPUBLIC
bool buildProgramFromBinary(const char* buildOption
, GPUEnv
* gpuEnv
, const char* filename
, int idx
);
62 OPENCL_DLLPUBLIC
void setKernelEnv( KernelEnv
*envInfo
);
63 OPENCL_DLLPUBLIC
const std::vector
<OpenCLPlatformInfo
>& fillOpenCLInfo();
66 * Used to set or switch between OpenCL devices.
68 * @param pDeviceId the id of the opencl device of type cl_device_id, NULL means use software calculation
69 * @param bAutoSelect use the algorithm to select the best OpenCL device
70 * @param rOutSelectedDeviceVersionIDString returns the selected device's version string.
72 * @return returns true if there is a valid opencl device that has been set up
74 OPENCL_DLLPUBLIC
bool switchOpenCLDevice(const OUString
* pDeviceId
, bool bAutoSelect
,
75 bool bForceEvaluation
,
76 OUString
& rOutSelectedDeviceVersionIDString
);
78 OPENCL_DLLPUBLIC
void getOpenCLDeviceInfo(size_t& rDeviceId
, size_t& rPlatformId
);
80 OPENCL_DLLPUBLIC
void getOpenCLDeviceName(OUString
& rDeviceName
, OUString
& rPlatformName
);
83 * Set the current command queue position in case of multiple command queues
86 OPENCL_DLLPUBLIC
void setOpenCLCmdQueuePosition( int nPos
);
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
);
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */