8
8
#include < cstring>
9
9
#include < fstream>
10
10
#include < sstream>
11
+ #include < string>
11
12
12
13
#include " ur_api.h"
13
14
#include " ur_filesystem_resolved.hpp"
@@ -190,23 +191,20 @@ KernelsEnvironment::parseKernelOptions(int argc, char **argv,
190
191
return options;
191
192
}
192
193
193
- std::string KernelsEnvironment::getTargetName (ur_platform_handle_t platform) {
194
- std::stringstream IL;
195
-
194
+ std::string
195
+ KernelsEnvironment::getDefaultTargetName (ur_platform_handle_t platform) {
196
196
if (instance->GetDevices ().size () == 0 ) {
197
197
error = " no devices available on the platform" ;
198
198
return {};
199
199
}
200
200
201
- // special case for AMD as it doesn't support IL.
202
201
ur_platform_backend_t backend;
203
202
if (urPlatformGetInfo (platform, UR_PLATFORM_INFO_BACKEND, sizeof (backend),
204
203
&backend, nullptr )) {
205
204
error = " failed to get backend from platform." ;
206
205
return {};
207
206
}
208
207
209
- std::string target = " " ;
210
208
switch (backend) {
211
209
case UR_PLATFORM_BACKEND_OPENCL:
212
210
case UR_PLATFORM_BACKEND_LEVEL_ZERO:
@@ -226,17 +224,10 @@ std::string KernelsEnvironment::getTargetName(ur_platform_handle_t platform) {
226
224
227
225
std::string
228
226
KernelsEnvironment::getKernelSourcePath (const std::string &kernel_name,
229
- ur_platform_handle_t platform ) {
227
+ const std::string &target_name ) {
230
228
std::stringstream path;
231
- path << kernel_options.kernel_directory << " /" << kernel_name;
232
-
233
- std::string target_name = getTargetName (platform);
234
- if (target_name.empty ()) {
235
- return {};
236
- }
237
-
238
- path << " /" << target_name << " .bin.0" ;
239
-
229
+ path << kernel_options.kernel_directory << " /" << kernel_name << " /"
230
+ << target_name << " .bin.0" ;
240
231
return path.str ();
241
232
}
242
233
@@ -246,13 +237,20 @@ void KernelsEnvironment::LoadSource(
246
237
// We don't have a way to build device code for native cpu yet.
247
238
UUR_KNOWN_FAILURE_ON_PARAM (platform, uur::NativeCPU{});
248
239
249
- std::string source_path =
250
- instance->getKernelSourcePath (kernel_name, platform);
251
-
252
- if (source_path.empty ()) {
240
+ std::string target_name = getDefaultTargetName (platform);
241
+ if (target_name.empty ()) {
253
242
FAIL () << error;
254
243
}
255
244
245
+ return LoadSource (kernel_name, target_name, binary_out);
246
+ }
247
+
248
+ void KernelsEnvironment::LoadSource (
249
+ const std::string &kernel_name, const std::string &target_name,
250
+ std::shared_ptr<std::vector<char >> &binary_out) {
251
+ std::string source_path =
252
+ instance->getKernelSourcePath (kernel_name, target_name);
253
+
256
254
if (cached_kernels.find (source_path) != cached_kernels.end ()) {
257
255
binary_out = cached_kernels[source_path];
258
256
return ;
@@ -263,7 +261,10 @@ void KernelsEnvironment::LoadSource(
263
261
std::ios::binary | std::ios::in | std::ios::ate);
264
262
265
263
if (!source_file.is_open ()) {
266
- FAIL () << " failed opening kernel path: " + source_path;
264
+ FAIL () << " failed opening kernel path: " + source_path
265
+ << " \n Note: make sure that UR_CONFORMANCE_TARGET_TRIPLES includes "
266
+ << ' \' ' << target_name << ' \' '
267
+ << " and that device binaries have been built." ;
267
268
}
268
269
269
270
size_t source_size = static_cast <size_t >(source_file.tellg ());
0 commit comments