source: CLRX/CLRadeonExtender/trunk/CLRX/clhelper/CLHelper.h @ 3450

Last change on this file since 3450 was 3450, checked in by matszpk, 2 years ago

CLRadeonExtender: Add new library: CLRXCLHelper that facilitate creating binary/program for OpenCL. Use CLRXCLHelper in samples.

File size: 3.3 KB
Line 
1/*
2 *  CLRadeonExtender - Unofficial OpenCL Radeon Extensions Library
3 *  Copyright (C) 2014-2017 Mateusz Szpakowski
4 *
5 *  This library is free software; you can redistribute it and/or
6 *  modify it under the terms of the GNU Lesser General Public
7 *  License as published by the Free Software Foundation; either
8 *  version 2.1 of the License, or (at your option) any later version.
9 *
10 *  This library is distributed in the hope that it will be useful,
11 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 *  Lesser General Public License for more details.
14 *
15 *  You should have received a copy of the GNU Lesser General Public
16 *  License along with this library; if not, write to the Free Software
17 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19/*! \file CLHelper.h
20 * \brief CL helper for creating binaries
21 */
22
23#ifndef __CLRX_CLHELPER_H__
24#define __CLRX_CLHELPER_H__
25
26#include <CLRX/Config.h>
27#include <CL/cl.h>
28#include <CLRX/amdasm/Commons.h>
29#include <CLRX/utils/Containers.h>
30#include <CLRX/utils/CString.h>
31#include <CLRX/utils/Utilities.h>
32#include <CLRX/utils/GPUId.h>
33
34
35namespace CLRX
36{
37
38/// error class based on std::exception
39class CLError: public Exception
40{
41private:
42    cl_int error;
43public:
44    //// empty constructor
45    CLError();
46   
47    /// constructor with description
48    explicit CLError(const char* _description);
49   
50    /// constructor with description and OpenCL error
51    CLError(cl_int _error, const char* _description);
52   
53    /// destructor
54    virtual ~CLError() noexcept;
55   
56    /// get what
57    const char* what() const noexcept;
58   
59    /// get OpenCL error code
60    int code() const
61    { return error; }
62};
63   
64/// choose suitable OpenCL platform for CLRX assembler programs
65extern cl_platform_id chooseCLPlatformForCLRX();
66
67enum : Flags
68{
69    CLHELPER_USEAMDCL2 = 1,  ///< force using AMD OpenCL 2.0 binary format
70    CLHELPER_USEAMDLEGACY = 2,  ///< force using AMD OpenCL 1.2 binary format
71};
72
73/// structure that holds assembler setup for OpenCL programs
74struct CLAsmSetup
75{
76    GPUDeviceType deviceType;   ///< device typ
77    BinaryFormat binaryFormat;  ///< binary format
78    cxuint driverVersion;   ///< driver version
79    cxuint llvmVersion;     ///< LLVM version
80    bool is64Bit;        ///< if binary is 64-bit
81    CString options; ///< OpenCL base options
82};
83
84/// get assembler setup(compile assembler code) binary for OpenCL device
85extern CLAsmSetup assemblerSetupForCLDevice(cl_device_id clDevice, Flags flags = 0);
86
87/// create program binary for OpenCL
88extern Array<cxbyte> createBinaryForOpenCL(const CLAsmSetup& asmSetup,
89                const char* sourceCode, size_t sourceCodeLen = 0);
90
91/// create (build program) binary for OpenCL device
92extern cl_program createProgramForCLDevice(cl_context clContext, cl_device_id clDevice,
93            const CLAsmSetup& asmSetup, const Array<cxbyte>& binary,
94            CString* buildLog = nullptr);
95
96/// create (compile assembler code and build program) binary for OpenCL device
97extern cl_program createProgramForCLDevice(cl_context clContext, cl_device_id clDevice,
98            const CLAsmSetup& asmSetup, const char* sourceCode, size_t sourceCodeLen = 0,
99            CString* buildLog = nullptr);
100
101};
102
103#endif
Note: See TracBrowser for help on using the repository browser.