Skip to content

Commit 112c8b7

Browse files
authored
[UR][Test] Improve error message when kernel source is not found (#18440)
Add a note to suggest checking if UR_CONFORMANCE_TARGET_TRIPLES includes the requested target. Depends on: #18279
1 parent ea2dad3 commit 112c8b7

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

unified-runtime/test/conformance/source/environment.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <cstring>
99
#include <fstream>
1010
#include <sstream>
11+
#include <string>
1112

1213
#include "ur_api.h"
1314
#include "ur_filesystem_resolved.hpp"
@@ -190,23 +191,20 @@ KernelsEnvironment::parseKernelOptions(int argc, char **argv,
190191
return options;
191192
}
192193

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) {
196196
if (instance->GetDevices().size() == 0) {
197197
error = "no devices available on the platform";
198198
return {};
199199
}
200200

201-
// special case for AMD as it doesn't support IL.
202201
ur_platform_backend_t backend;
203202
if (urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND, sizeof(backend),
204203
&backend, nullptr)) {
205204
error = "failed to get backend from platform.";
206205
return {};
207206
}
208207

209-
std::string target = "";
210208
switch (backend) {
211209
case UR_PLATFORM_BACKEND_OPENCL:
212210
case UR_PLATFORM_BACKEND_LEVEL_ZERO:
@@ -226,17 +224,10 @@ std::string KernelsEnvironment::getTargetName(ur_platform_handle_t platform) {
226224

227225
std::string
228226
KernelsEnvironment::getKernelSourcePath(const std::string &kernel_name,
229-
ur_platform_handle_t platform) {
227+
const std::string &target_name) {
230228
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";
240231
return path.str();
241232
}
242233

@@ -246,13 +237,20 @@ void KernelsEnvironment::LoadSource(
246237
// We don't have a way to build device code for native cpu yet.
247238
UUR_KNOWN_FAILURE_ON_PARAM(platform, uur::NativeCPU{});
248239

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()) {
253242
FAIL() << error;
254243
}
255244

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+
256254
if (cached_kernels.find(source_path) != cached_kernels.end()) {
257255
binary_out = cached_kernels[source_path];
258256
return;
@@ -263,7 +261,10 @@ void KernelsEnvironment::LoadSource(
263261
std::ios::binary | std::ios::in | std::ios::ate);
264262

265263
if (!source_file.is_open()) {
266-
FAIL() << "failed opening kernel path: " + source_path;
264+
FAIL() << "failed opening kernel path: " + source_path
265+
<< "\nNote: make sure that UR_CONFORMANCE_TARGET_TRIPLES includes "
266+
<< '\'' << target_name << '\''
267+
<< " and that device binaries have been built.";
267268
}
268269

269270
size_t source_size = static_cast<size_t>(source_file.tellg());

unified-runtime/test/conformance/testing/include/uur/environment.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ struct KernelsEnvironment : DevicesEnvironment {
7171
void LoadSource(const std::string &kernel_name, ur_platform_handle_t platform,
7272
std::shared_ptr<std::vector<char>> &binary_out);
7373

74+
void LoadSource(const std::string &kernel_name,
75+
const std::string &target_name,
76+
std::shared_ptr<std::vector<char>> &binary_out);
77+
7478
void CreateProgram(ur_platform_handle_t hPlatform,
7579
ur_context_handle_t hContext, ur_device_handle_t hDevice,
7680
const std::vector<char> &binary,
@@ -85,8 +89,8 @@ struct KernelsEnvironment : DevicesEnvironment {
8589
KernelOptions parseKernelOptions(int argc, char **argv,
8690
const std::string &kernels_default_dir);
8791
std::string getKernelSourcePath(const std::string &kernel_name,
88-
ur_platform_handle_t platform);
89-
std::string getTargetName(ur_platform_handle_t platform);
92+
const std::string &target_name);
93+
std::string getDefaultTargetName(ur_platform_handle_t platform);
9094

9195
KernelOptions kernel_options;
9296
// mapping between kernels (full_path + kernel_name) and their saved source.

0 commit comments

Comments
 (0)