8
8
9
9
#pragma once
10
10
11
- #include < CL/sycl/context.hpp>
12
11
#include < CL/sycl/detail/defines_elementary.hpp> // for __SYCL_INLINE_NAMESPACE
12
+ #include < CL/sycl/detail/export.hpp> // for __SYCL_EXPORT
13
13
#include < CL/sycl/device.hpp>
14
14
15
- #include < memory >
15
+ #include < string >
16
16
#include < vector>
17
17
18
18
__SYCL_INLINE_NAMESPACE (cl) {
@@ -59,7 +59,9 @@ class device_arch {
59
59
60
60
// / Represents an error happend during online compilation.
61
61
class online_compile_error : public sycl ::exception {
62
- // TBD
62
+ public:
63
+ online_compile_error () = default ;
64
+ online_compile_error (const string_class &Msg) : sycl::exception(Msg) {}
63
65
};
64
66
65
67
// / Designates a source language for the online compiler.
@@ -70,25 +72,32 @@ enum class source_language { opencl_c, cm };
70
72
template <source_language Lang> class online_compiler {
71
73
public:
72
74
// / Constructs online compiler which can target any device and produces
73
- // / given compiled code format. Produces device code is 64-bit.
75
+ // / given compiled code format. Produces 64-bit device code .
74
76
// / The created compiler is "optimistic" - it assumes all applicable SYCL
75
77
// / device capabilities are supported by the target device(s).
76
78
online_compiler (compiled_code_format fmt = compiled_code_format::spir_v)
77
79
: OutputFormat(fmt), OutputFormatVersion({0 , 0 }),
78
- DeviceArch (device_arch::any), Is64Bit(true ), DeviceStepping(" " ) {}
80
+ DeviceType (sycl::info::device_type::all), DeviceArch(device_arch::any),
81
+ Is64Bit (true ), DeviceStepping(" " ) {}
79
82
80
83
// / Constructs online compiler which targets given architecture and produces
81
- // / given compiled code format. Produces device code is 64-bit.
84
+ // / given compiled code format. Produces 64-bit device code .
82
85
// / Throws online_compile_error if values of constructor arguments are
83
86
// / contradictory or not supported - e.g. if the source language is not
84
87
// / supported for given device type.
85
88
online_compiler (sycl::info::device_type dev_type, device_arch arch,
86
89
compiled_code_format fmt = compiled_code_format::spir_v)
87
- : OutputFormat(fmt), OutputFormatVersion({0 , 0 }), DeviceArch(arch ),
88
- Is64Bit (true ), DeviceStepping(" " ) {}
90
+ : OutputFormat(fmt), OutputFormatVersion({0 , 0 }), DeviceType(dev_type ),
91
+ DeviceArch (arch), Is64Bit(true ), DeviceStepping(" " ) {}
89
92
90
93
// / Constructs online compiler for the target specified by given SYCL device.
91
- online_compiler (const sycl::device &dev);
94
+ // TODO: the initial version generates the generic code (SKL now), need
95
+ // to do additional device::info calls to determine the device by it's
96
+ // features.
97
+ online_compiler (const sycl::device &dev)
98
+ : OutputFormat(compiled_code_format::spir_v), OutputFormatVersion({0 , 0 }),
99
+ DeviceType (sycl::info::device_type::all), DeviceArch(device_arch::any),
100
+ Is64Bit (true ), DeviceStepping(" " ) {}
92
101
93
102
// / Compiles given in-memory \c Lang source to a binary blob. Blob format,
94
103
// / other parameters are set in the constructor by the compilation target
@@ -100,31 +109,50 @@ template <source_language Lang> class online_compiler {
100
109
std::vector<byte> compile (const std::string &src, const Tys &... args);
101
110
102
111
// / Sets the compiled code format of the compilation target and returns *this.
103
- online_compiler<Lang> &setOutputFormat (compiled_code_format fmt);
112
+ online_compiler<Lang> &setOutputFormat (compiled_code_format fmt) {
113
+ OutputFormat = fmt;
114
+ return *this ;
115
+ }
104
116
105
117
// / Sets the compiled code format version of the compilation target and
106
118
// / returns *this.
107
- online_compiler<Lang> &setOutputFormatVersion (int major, int minor);
119
+ online_compiler<Lang> &setOutputFormatVersion (int major, int minor) {
120
+ OutputFormatVersion = {major, minor};
121
+ return *this ;
122
+ }
108
123
109
124
// / Sets the device type of the compilation target and returns *this.
110
- online_compiler<Lang> &setTargetDeviceType (sycl::info::device_type type);
125
+ online_compiler<Lang> &setTargetDeviceType (sycl::info::device_type type) {
126
+ DeviceType = type;
127
+ return *this ;
128
+ }
111
129
112
130
// / Sets the device architecture of the compilation target and returns *this.
113
- online_compiler<Lang> &setTargetDeviceArch (device_arch arch);
131
+ online_compiler<Lang> &setTargetDeviceArch (device_arch arch) {
132
+ DeviceArch = arch;
133
+ return *this ;
134
+ }
114
135
115
136
// / Makes the compilation target 32-bit and returns *this.
116
- online_compiler<Lang> &set32bitTarget ();
137
+ online_compiler<Lang> &set32bitTarget () {
138
+ Is64Bit = false ;
139
+ return *this ;
140
+ };
117
141
118
142
// / Makes the compilation target 64-bit and returns *this.
119
- online_compiler<Lang> &set64bitTarget ();
143
+ online_compiler<Lang> &set64bitTarget () {
144
+ Is64Bit = true ;
145
+ return *this ;
146
+ };
120
147
121
148
// / Sets implementation-defined target device stepping of the compilation
122
149
// / target and returns *this.
123
- online_compiler<Lang> &setTargetDeviceStepping (const std::string &id);
150
+ online_compiler<Lang> &setTargetDeviceStepping (const std::string &id) {
151
+ DeviceStepping = id;
152
+ return *this ;
153
+ }
124
154
125
155
private:
126
- // Compilation target specification fields: {
127
-
128
156
// / Compiled code format.
129
157
compiled_code_format OutputFormat;
130
158
@@ -142,51 +170,48 @@ template <source_language Lang> class online_compiler {
142
170
143
171
// / Target device stepping (implementation defined)
144
172
std::string DeviceStepping;
145
- // }
173
+
174
+ // / Handles to helper functions used by the implementation.
175
+ void *CompileToSPIRVHandle = nullptr ;
176
+ void *FreeSPIRVOutputsHandle = nullptr ;
146
177
};
147
178
148
179
// Specializations of the online_compiler class and 'compile' function for
149
180
// particular languages and parameter types.
150
181
151
- // / Compiles given OpenCL source. May throw \c online_compile_error.
152
- // / @param src - contents of the source
182
+ // / Compiles the given OpenCL source. May throw \c online_compile_error.
183
+ // / @param src - contents of the source.
184
+ // / @param options - compilation options (implementation defined); standard
185
+ // / OpenCL JIT compiler options must be supported.
186
+ template <>
187
+ template <>
188
+ __SYCL_EXPORT std::vector<byte>
189
+ online_compiler<source_language::opencl_c>::compile(
190
+ const std::string &src, const std::vector<std::string> &options);
191
+
192
+ // / Compiles the given OpenCL source. May throw \c online_compile_error.
193
+ // / @param src - contents of the source.
153
194
template <>
154
195
template <>
155
196
std::vector<byte>
156
197
online_compiler<source_language::opencl_c>::compile(const std::string &src) {
157
- // real implementation will call some non-templated impl function here
158
- return std::vector<byte>{};
198
+ return compile (src, std::vector<std::string>{});
159
199
}
160
200
161
- // / Compiles given OpenCL source. May throw \c online_compile_error.
162
- // / @param src - contents of the source
163
- // / @param options - compilation options (implementation defined); standard
164
- // / OpenCL JIT compiler options must be supported
201
+ // / Compiles the given CM source \p src.
202
+ // / @param src - contents of the source.
203
+ // / @param options - compilation options (implementation defined).
165
204
template <>
166
205
template <>
167
- std::vector<byte> online_compiler<source_language::opencl_c>::compile(
168
- const std::string &src, const std::vector<std::string> &options) {
169
- // real implementation will call some non-templated impl function here
170
- return std::vector<byte>{};
171
- }
206
+ __SYCL_EXPORT std::vector<byte> online_compiler<source_language::cm>::compile(
207
+ const std::string &src, const std::vector<std::string> &options);
172
208
173
- // / Compiles given CM source.
209
+ // / Compiles the given CM source \p src .
174
210
template <>
175
211
template <>
176
212
std::vector<byte>
177
213
online_compiler<source_language::cm>::compile(const std::string &src) {
178
- // real implementation will call some non-templated impl function here
179
- return std::vector<byte>{};
180
- }
181
-
182
- // / Compiles given CM source.
183
- // / @param options - compilation options (implementation defined)
184
- template <>
185
- template <>
186
- std::vector<byte> online_compiler<source_language::cm>::compile(
187
- const std::string &src, const std::vector<std::string> &options) {
188
- // real implementation will call some non-templated impl function here
189
- return std::vector<byte>{};
214
+ return compile (src, std::vector<std::string>{});
190
215
}
191
216
192
217
} // namespace INTEL
0 commit comments