Skip to content

Commit

Permalink
Merge pull request #867 from HPS-1/peisenhu/fix_spec_constants_tests_…
Browse files Browse the repository at this point in the history
…for_AOT_mode

Fix errors for some spec_constants tests when running in AOT mode
  • Loading branch information
bader authored Feb 22, 2024
2 parents b94c346 + 5006313 commit 6114e29
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 30 deletions.
11 changes: 8 additions & 3 deletions tests/spec_constants/spec_constants_defined_various_ways.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void perform_test(util::logger &log, const std::string &type_name,
auto queue = util::get_cts_object::queue();
const sycl::context ctx = queue.get_context();
const sycl::device dev = queue.get_device();
bool has_target_kernel = true;

if constexpr (via_kb::value) {
if (!dev.has(sycl::aspect::online_compiler)) {
Expand All @@ -50,6 +51,7 @@ void perform_test(util::logger &log, const std::string &type_name,
sycl::get_kernel_bundle<sycl::bundle_state::input>(ctx, {dev},
{kernelId});
if (!k_bundle.has_kernel(kernelId)) {
has_target_kernel = false;
log.note("kernel_bundle doesn't contain target kernel in case (" +
case_hint + ") for " + type_name_string<T>::get(type_name) +
" (skipped)");
Expand All @@ -72,9 +74,12 @@ void perform_test(util::logger &log, const std::string &type_name,
}
});
}
if (!check_equal_values(ref, result))
FAIL(log,
"case (" + case_hint + ") for " + type_name_string<T>::get(type_name));
if (has_target_kernel) {
// Check results only if target kernel is available
if (!check_equal_values(ref, result))
FAIL(log, "case (" + case_hint + ") for " +
type_name_string<T>::get(type_name));
}
}

template <typename T, typename via_kb>
Expand Down
27 changes: 16 additions & 11 deletions tests/spec_constants/spec_constants_multiple.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class check_specialization_constants_multiple_for_type {
auto queue = util::get_cts_object::queue();
const sycl::context ctx = queue.get_context();
const sycl::device dev = queue.get_device();
bool has_target_kernel = true;

if constexpr (via_kb::value) {
if (!dev.has(sycl::aspect::online_compiler)) {
Expand Down Expand Up @@ -77,6 +78,7 @@ class check_specialization_constants_multiple_for_type {
sycl::get_kernel_bundle<sycl::bundle_state::input>(ctx, {dev},
{kernelId});
if (!k_bundle.has_kernel(kernelId)) {
has_target_kernel = false;
log.note(
"kernel_bundle doesn't contain target kernel;"
"multiple spec const for " +
Expand Down Expand Up @@ -111,17 +113,20 @@ class check_specialization_constants_multiple_for_type {
}
});
}
if (!check_equal_values(ref1, result_vec[0].value) ||
!check_equal_values(ref2, result_vec[1].value) ||
!check_equal_values(ref3, result_vec[2].value) ||
!check_equal_values(user_def_types::get_init_value<T>(def_values[3]),
result_vec[3].value) ||
!check_equal_values(user_def_types::get_init_value<T>(def_values[4]),
result_vec[4].value) ||
!check_equal_values(user_def_types::get_init_value<T>(def_values[5]),
result_vec[5].value))
FAIL(log,
"multiple spec const for " + type_name_string<T>::get(type_name));
if (has_target_kernel) {
// Check results only if target kernel is available
if (!check_equal_values(ref1, result_vec[0].value) ||
!check_equal_values(ref2, result_vec[1].value) ||
!check_equal_values(ref3, result_vec[2].value) ||
!check_equal_values(user_def_types::get_init_value<T>(def_values[3]),
result_vec[3].value) ||
!check_equal_values(user_def_types::get_init_value<T>(def_values[4]),
result_vec[4].value) ||
!check_equal_values(user_def_types::get_init_value<T>(def_values[5]),
result_vec[5].value))
FAIL(log,
"multiple spec const for " + type_name_string<T>::get(type_name));
}
}
};

Expand Down
21 changes: 13 additions & 8 deletions tests/spec_constants/spec_constants_same_name_inter_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class check_specialization_constants_same_name_inter_link_for_type {
auto queue = util::get_cts_object::queue();
const sycl::context ctx = queue.get_context();
const sycl::device dev = queue.get_device();
bool has_target_kernel = true;

if constexpr (via_kb::value) {
if (!dev.has(sycl::aspect::online_compiler)) {
Expand Down Expand Up @@ -67,6 +68,7 @@ class check_specialization_constants_same_name_inter_link_for_type {
sycl::get_kernel_bundle<sycl::bundle_state::input>(ctx, {dev},
{kernelId});
if (!k_bundle.has_kernel(kernelId)) {
has_target_kernel = false;
log.note("kernel_bundle doesn't contain target kernel for " +
type_name_string<T>::get(type_name) + " (skipped)");
return;
Expand All @@ -93,14 +95,17 @@ class check_specialization_constants_same_name_inter_link_for_type {
}
});
}
if (!check_equal_values(ref_def_value, def_value))
FAIL(log, "Wrong linked spec const; (translation unit " +
std::to_string(TestConfig::tu) + ") for " +
type_name_string<T>::get(type_name));
if (!check_equal_values(ref, result))
FAIL(log, "Wrong returned value; (translation unit " +
std::to_string(TestConfig::tu) + ") for " +
type_name_string<T>::get(type_name));
if (has_target_kernel) {
// Check results only if target kernel is available
if (!check_equal_values(ref_def_value, def_value))
FAIL(log, "Wrong linked spec const; (translation unit " +
std::to_string(TestConfig::tu) + ") for " +
type_name_string<T>::get(type_name));
if (!check_equal_values(ref, result))
FAIL(log, "Wrong returned value; (translation unit " +
std::to_string(TestConfig::tu) + ") for " +
type_name_string<T>::get(type_name));
}
}
} catch (...) {
std::string message{"translation unit " + std::to_string(TestConfig::tu) +
Expand Down
21 changes: 13 additions & 8 deletions tests/spec_constants/spec_constants_same_name_stress.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class check_specialization_constants_same_name_stress_for_type {
auto queue = util::get_cts_object::queue();
const sycl::context ctx = queue.get_context();
const sycl::device dev = queue.get_device();
bool has_target_kernel = true;

if constexpr (via_kb::value) {
if (!dev.has(sycl::aspect::online_compiler)) {
Expand Down Expand Up @@ -149,6 +150,7 @@ class check_specialization_constants_same_name_stress_for_type {
auto k_bundle = sycl::get_kernel_bundle<sycl::bundle_state::input>(
ctx, {dev}, {kernelId});
if (!k_bundle.has_kernel(kernelId)) {
has_target_kernel = false;
log.note("kernel_bundle doesn't contain target kernel for " +
type_name_string<T>::get(type_name) + " (skipped)");
return;
Expand All @@ -160,14 +162,17 @@ class check_specialization_constants_same_name_stress_for_type {
}
});
}
for (int i = 0; i < size; ++i) {
if (!check_equal_values(def_values_arr[i], ref_def_values_arr[i])) {
FAIL(log, "Wrong default value for spec const defined in " +
get_hint(i) + " for type " + type_name);
}
if (!check_equal_values(result_arr[i], ref_arr[i])) {
FAIL(log, "Wrong result value for spec const defined in " +
get_hint(i) + "for type " + type_name);
if (has_target_kernel) {
// Check results only if target kernel is available
for (int i = 0; i < size; ++i) {
if (!check_equal_values(def_values_arr[i], ref_def_values_arr[i])) {
FAIL(log, "Wrong default value for spec const defined in " +
get_hint(i) + " for type " + type_name);
}
if (!check_equal_values(result_arr[i], ref_arr[i])) {
FAIL(log, "Wrong result value for spec const defined in " +
get_hint(i) + "for type " + type_name);
}
}
}
} catch (...) {
Expand Down

0 comments on commit 6114e29

Please sign in to comment.