-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIgorCLUtilities.h
93 lines (67 loc) · 2.97 KB
/
IgorCLUtilities.h
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
/*
IgorCL - an XOP to use OpenCL in Igor Pro
Copyright(C) 2013-2017 Peter Dedecker
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/>.
The developer(s) of this software hereby grants permission to link
this program with Igor Pro, developed by WaveMetrics Inc. (www.wavemetrics.com).
*/
#ifndef __IgorCL__IgorCLUtilities__
#define __IgorCL__IgorCLUtilities__
#include "cl.hpp"
#include <string>
#include <vector>
#include <mutex>
#include "XOPStandardHeaders.h"
void StoreStringInTextWave(const std::string str, waveHndl textWave, IndexInt* indices);
std::string GetStdStringFromHandle(const Handle handle);
Handle PutStdStringInHandle(const std::string theString);
size_t WaveDataSizeInBytes(waveHndl wave);
size_t SharedMemorySizeFromWave(waveHndl wave);
int GetFirstDeviceOfType(const int platformIndex, const std::string& deviceTypeStr);
int ConvertIgorCLFlagsToOpenCLFlags(const int igorCLFlags);
class IgorCLContextAndDeviceProvider {
public:
IgorCLContextAndDeviceProvider() {;}
~IgorCLContextAndDeviceProvider() {;}
void getContextForPlatformAndDevice(const int platformIndex, const int deviceIndex, cl::Context& context, cl::Device &device);
private:
std::vector<std::pair<int, int> > availableContextIndices;
std::vector<cl::Context> availableContexts;
std::vector<cl::Device> deviceForContext;
std::mutex contextMutex;
};
extern IgorCLContextAndDeviceProvider contextAndDeviceProvider;
class IgorCLCommandQueueFactory {
public:
IgorCLCommandQueueFactory() {;}
~IgorCLCommandQueueFactory() {;}
cl::CommandQueue getCommandQueue(const int platformIndex, const int deviceIndex);
void returnCommandQueue(const cl::CommandQueue commandQueue, const int platformIndex, const int deviceIndex);
void deleteAllCommandQueues();
private:
std::vector<std::pair<int, int> > _availableQueueIndices;
std::vector<std::vector<cl::CommandQueue> > _availableQueues;
std::mutex _queueMutex;
};
extern IgorCLCommandQueueFactory commandQueueFactory;
class IgorCLCommandQueueProvider {
public:
IgorCLCommandQueueProvider(const int platformIndex, const int deviceIndex);
~IgorCLCommandQueueProvider();
cl::CommandQueue getCommandQueue() const {return _commandQueue;}
private:
int _platformIndex;
int _deviceIndex;
cl::CommandQueue _commandQueue;
};
std::string OpenCLErrorCodeToSymbolicName(int errorCode);
#endif /* defined(__IgorCL__IgorCLUtilities__) */