-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenCLUtils.h
More file actions
96 lines (79 loc) · 2.99 KB
/
OpenCLUtils.h
File metadata and controls
96 lines (79 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (C) 2020 Universitat Autonoma de Barcelona - David Castells-Rufas <david.castells@uab.cat>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <stdexcept>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <CL/cl.h>
#include <stdarg.h>
#include "scoped_ptrs.h"
char* readCodeFromFile(const char* srcFile);
using namespace std;
template <typename T>
std::string to_string(T value)
{
ostringstream os ;
os << value ;
return os.str() ;
}
string format(const char *fmt, ...);
// Report about an OpenCL problem.
// Macro is used instead of a function here
// to report source file name and line number.
#define SAMPLE_CHECK_ERRORS(ERR) \
if(ERR != CL_SUCCESS) \
{ \
throw Error( \
string("OpenCL error ") + \
string(opencl_error_to_str(ERR)) \
+ string(" happened in file ") \
+ string((const char*)(__FILE__)) \
+ string(" at line ") + to_string(__LINE__) \
); \
}
string opencl_error_to_str(cl_int error);
cl_platform_id selectPlatform(cl_uint selected_platform_index);
cl_device_id selectDevice(cl_platform_id platform, cl_uint selected_device_index);
string getDeviceName(cl_device_id device_id);
string getPlatformName(cl_platform_id platform_id);
cl_context createContext(cl_platform_id platform, cl_device_id device/*const cl_context_properties* additional_context_props*/);
cl_command_queue createQueue(cl_device_id device, cl_context context, cl_command_queue_properties queue_properties);
class OpenCLUtils
{
public:
OpenCLUtils();
~OpenCLUtils();
public:
};
// Base class for all exception in samples
class Error : public std::runtime_error
{
public:
Error(const string& msg) :
std::runtime_error(msg)
{
}
};
cl_program createProgramFromBinary(cl_context context, const char *binary_file_name, const cl_device_id *devices, unsigned num_devices);
std::string getBoardBinaryFile(const char *prefix, cl_device_id device);
bool setCwd(const char* path);
bool setCwdToExeDir();