Branch libreoffice-5-0-4
[LibreOffice.git] / include / opencl / openclwrapper.hxx
blobe3f967ee46c5557ba80b7694d1f2dc37e0f620c7
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 <config_features.h>
15 #include <cassert>
16 #include <vector>
18 #include <boost/shared_ptr.hpp>
19 #include <clew/clew.h>
21 #include <sal/detail/log.h>
22 #include <opencl/opencldllapi.h>
23 #include <opencl/platforminfo.hxx>
24 #include <osl/file.hxx>
25 #include <rtl/string.hxx>
27 #define MAX_CLFILE_NUM 50
28 #define OPENCL_CMDQUEUE_SIZE 1 // number of command queues per OpenCL device.
30 #include <cstdio>
32 namespace opencl {
34 struct KernelEnv
36 cl_context mpkContext;
37 cl_command_queue mpkCmdQueue;
38 cl_program mpkProgram;
41 struct GPUEnv
43 //share vb in all modules in hb library
44 cl_platform_id mpPlatformID;
45 cl_device_type mDevType;
46 cl_context mpContext;
47 cl_device_id *mpArryDevsID;
48 cl_device_id mpDevID;
49 cl_command_queue mpCmdQueue[OPENCL_CMDQUEUE_SIZE];
50 cl_program mpArryPrograms[MAX_CLFILE_NUM]; //one program object maps one kernel source file
51 int mnIsUserCreated; // 1: created , 0:no create and needed to create by opencl wrapper
52 int mnCmdQueuePos;
53 bool mnKhrFp64Flag;
54 bool mnAmdFp64Flag;
55 cl_uint mnPreferredVectorWidthFloat;
58 extern OPENCL_DLLPUBLIC GPUEnv gpuEnv;
59 OPENCL_DLLPUBLIC bool generatBinFromKernelSource( cl_program program, const char * clFileName );
60 OPENCL_DLLPUBLIC bool buildProgramFromBinary(const char* buildOption, GPUEnv* gpuEnv, const char* filename, int idx);
61 OPENCL_DLLPUBLIC void setKernelEnv( KernelEnv *envInfo );
62 OPENCL_DLLPUBLIC const std::vector<OpenCLPlatformInfo>& fillOpenCLInfo();
64 /**
65 * Used to set or switch between OpenCL devices.
67 * @param pDeviceId the id of the opencl device of type cl_device_id, NULL means use software calculation
68 * @param bAutoSelect use the algorithm to select the best OpenCL device
70 * @return returns true if there is a valid opencl device that has been set up
72 OPENCL_DLLPUBLIC bool switchOpenCLDevice(const OUString* pDeviceId, bool bAutoSelect,
73 bool bForceEvaluation);
75 OPENCL_DLLPUBLIC void getOpenCLDeviceInfo(size_t& rDeviceId, size_t& rPlatformId);
77 /**
78 * Set the current command queue position in case of multiple command queues
79 * for a given device.
81 OPENCL_DLLPUBLIC void setOpenCLCmdQueuePosition( int nPos );
83 /**
84 * Return a textual representation of an OpenCL error code.
85 * (Currently the symbolic name sans the CL_ prefix.)
87 OPENCL_DLLPUBLIC const char* errorString(cl_int nError);
91 #endif
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */