Debian Codegraph @

src/acl/aclHardware.h

raw
1 /*
2 * Advanced Simulation Library <http://asl.org.il>
3 *
4 * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5 *
6 *
7 * This file is part of Advanced Simulation Library (ASL).
8 *
9 * ASL is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, version 3 of the License.
12 *
13 * ASL is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23
24 #ifndef ACLHARDWARE_H
25 #define ACLHARDWARE_H
26
27
28 //#include <CL/cl.hpp>
29 // Supply "cl.hpp" with ASL, since it is not present in OpenCL 2.0
30 // Remove the file after switching to OpenCL 2.1
31 #include "cl.hpp"
32 #include "aclStdIncludes.h"
33 #include <memory>
34 #include "aclTypes.h"
35
36 namespace acl
37 {
38
39 typedef std::shared_ptr<cl::CommandQueue> CommandQueue;
40
41
42 extern const std::vector<std::string> TYPE;
43 extern const std::vector<unsigned char> TYPE_SIZE;
44 /// contains trasnlation of types necessery for use in the function select
45 /* expression in the condition field should have this type */
46 extern const std::vector<TypeID> TYPE_SELECT;
47
48 /// Returns vendor name.
49 /// \ingroup HardwareInformation
50 std::string getPlatformVendor(const CommandQueue & queue);
51
52 /// Returns device name.
53 /// \ingroup HardwareInformation
54 std::string getDeviceName(const CommandQueue & queue);
55
56 /** Returns the OpenCL version supported by the device */
57 std::string getDeviceVersion(const CommandQueue & queue);
58
59 /** Returns the OpenCL driver version */
60 std::string getDriverVersion(const CommandQueue & queue);
61
62 /// Returns device type.
63 /// \ingroup HardwareInformation
64 cl_device_type getDeviceType(const CommandQueue & queue);
65
66 /// Returns number of computer units on the device.
67 /// \ingroup HardwareInformation
68 cl_uint getNComputeUnits(const CommandQueue & queue);
69
70 cl::Device getDevice(const CommandQueue & queue);
71 cl::Context getContext(const CommandQueue & queue);
72
73 /// Returns the smallest alignment in bytes which can be used for any data type.
74 /// \ingroup HardwareInformation
75 unsigned int getAlignment(const CommandQueue & queue);
76
77
78 /// Returns type of local memory supported.
79 /// CL_LOCAL (implies dedicated local memory storage such as SRAM) or CL_GLOBAL.
80 /// \ingroup HardwareInformation
81 cl_device_local_mem_type getLocalMemoryType(const CommandQueue & queue);
82
83
84 /// Size of local memory arena in bytes. The minimum value is 1 KB.
85 /// \ingroup HardwareInformation
86 cl_ulong getLocalMemorySize(const CommandQueue & queue);
87
88
89 /// Returns the maximum number of work-items that can be specified
90 /// in '0' dimension of the work-group to clEnqueueNDRangeKernel.
91 /// \ingroup HardwareInformation
92 size_t getMaxItemSize(const CommandQueue & queue);
93
94
95 /// Returns the native ISA vector width. The vector width is defined as the
96 /// number of scalar elements that can be stored in the vector.
97 /// If the cl_khr_fp64 extension is not supported,
98 /// CL_DEVICE_NATIVE_DOUBLE must return 0.
99 /// \ingroup HardwareInformation
100 cl_uint getVectorWidth(const CommandQueue & queue, const TypeID typeID);
101
102
103 /// Checks availability of an OpenCL extension
104 /// \ingroup HardwareInformation
105 bool extensionAvailable(const CommandQueue & queue, const Extension extension);
106
107
108 /// Describes double precision floating-point capability of the OpenCL device.
109 /// Returns a non-zero value if double precision FP is supported.
110 /// See CL_DEVICE_DOUBLE_FP_CONFIG for more info.
111 /// \ingroup HardwareInformation
112 cl_device_fp_config doublePrecisionSupport(const CommandQueue & queue);
113
114 class Kernel;
115
116 /**
117 Returns the amount of local memory in bytes being used by a kernel. This
118 includes local memory that may be needed by an implementation to execute
119 the kernel, variables declared inside the kernel with the __local address
120 qualifier and local memory to be allocated for arguments to the kernel
121 declared as pointers with the __local address qualifier and whose size is
122 specified with clSetKernelArg.
123
124 \ingroup HardwareInformation
125 */
126 cl_ulong getKernelLocalMemSize(const Kernel & kernel);
127
128
129 /**
130 Returns the minimum amount of private memory, in bytes, used by each work-item
131 in the kernel. This value may include any private memory needed by
132 an implementation to execute the kernel, including that used by the language
133 built-ins and variable declared inside the kernel with the __private qualifier.
134
135 \ingroup HardwareInformation
136 */
137 cl_ulong getKernelPrivateMemSize(const Kernel & kernel);
138
139
140 /// Provides access to the underlying hardware
141 class Hardware
142 {
143 public:
144 /// OpenCL related initializations are done here.
145 /// Context, Device list, Command Queue are set up.
146 /// Default computation queue is set to the first found device.
147 Hardware();
148 /// Sets default computation queue
149 /// identified by \p platform and \p device.
150 /// Warns if requested combination is not found.
151 void setDefaultQueue(const std::string & platform = "",
152 const std::string & device = "");
153 std::vector<CommandQueue> queues;
154 CommandQueue defaultQueue;
155 std::string getDevicesInfo();
156 std::string getDefaultDeviceInfo();
157 private:
158 std::string devicesInfo;
159 };
160
161
162 // GLOBALS
163 extern Hardware hardware;
164
165 } // namespace acl
166 #endif // ACLHARDWARE_H