Skip to content

Commit

Permalink
Allow fixtures derived from KernelTest to defer compilation.
Browse files Browse the repository at this point in the history
Separating the device code compilation from the rest of the setup lets
a test query device or platform properties to decide whether it should
skip without potentially hitting a compilation error because the kernel
being built as part of the setup uses an unsupported feature.
  • Loading branch information
aarongreig committed Dec 4, 2023
1 parent fe5bc76 commit 512b158
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 20 deletions.
12 changes: 11 additions & 1 deletion test/conformance/kernel/kernel_adapter_level_zero.match
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@ urKernelSetArgPointerTest.SuccessDevice/Intel_R__oneAPI_Unified_Runtime_over_Lev
urKernelSetArgPointerTest.SuccessShared/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urKernelSetArgPointerNegativeTest.InvalidNullHandleKernel/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urKernelSetArgPointerNegativeTest.InvalidKernelArgumentIndex/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
Segmentation fault
urKernelSetArgSamplerTest.InvalidKernelArgumentIndex/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urKernelSetArgValueTest.InvalidKernelArgumentIndex/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urKernelSetArgValueTest.InvalidKernelArgumentSize/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urKernelSetExecInfoTest.SuccessIndirectAccess/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urKernelSetExecInfoUSMPointersTest.SuccessHost/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urKernelSetExecInfoUSMPointersTest.SuccessDevice/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urKernelSetExecInfoUSMPointersTest.SuccessShared/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urKernelSetSpecializationConstantsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urKernelSetSpecializationConstantsTest.InvalidNullHandleKernel/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urKernelSetSpecializationConstantsTest.InvalidNullPointerSpecConstants/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
urKernelSetSpecializationConstantsTest.InvalidSizeCount/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_
4 changes: 0 additions & 4 deletions test/conformance/kernel/kernel_adapter_opencl.match
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
urKernelSetArgSamplerTest.Success/Intel_R__OpenCL___{{.*}}_
urKernelSetArgSamplerTest.InvalidNullHandleKernel/Intel_R__OpenCL___{{.*}}_
urKernelSetArgSamplerTest.InvalidNullHandleArgValue/Intel_R__OpenCL___{{.*}}_
urKernelSetArgSamplerTest.InvalidKernelArgumentIndex/Intel_R__OpenCL___{{.*}}_
urKernelSetArgValueTest.InvalidKernelArgumentSize/Intel_R__OpenCL___{{.*}}_
urKernelSetSpecializationConstantsTest.Success/Intel_R__OpenCL___{{.*}}_
urKernelSetSpecializationConstantsTest.InvalidNullHandleKernel/Intel_R__OpenCL___{{.*}}_
Expand Down
2 changes: 1 addition & 1 deletion test/conformance/kernel/urKernelSetArgPointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct urKernelSetArgPointerTest : uur::urKernelExecutionTest {
if (allocation) {
ASSERT_SUCCESS(urUSMFree(context, allocation));
}
UUR_RETURN_ON_FATAL_FAILURE(urKernelTest::TearDown());
UUR_RETURN_ON_FATAL_FAILURE(urKernelExecutionTest::TearDown());
}

void ValidateAllocation(void *pointer) {
Expand Down
10 changes: 5 additions & 5 deletions test/conformance/kernel/urKernelSetArgSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

#include <uur/fixtures.h>

struct urKernelSetArgSamplerTest : uur::urKernelTest {
struct urKernelSetArgSamplerTest : uur::urBaseKernelTest {
void SetUp() {
program_name = "image_copy";
UUR_RETURN_ON_FATAL_FAILURE(urBaseKernelTest::SetUp());
// Images and samplers are not available on AMD
ur_platform_backend_t backend;
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
sizeof(backend), &backend, nullptr));
if (backend == UR_PLATFORM_BACKEND_HIP) {
GTEST_SKIP() << "Sampler are not supported on hip.";
}

program_name = "image_copy";
UUR_RETURN_ON_FATAL_FAILURE(urKernelTest::SetUp());
Build();
ur_sampler_desc_t sampler_desc = {
UR_STRUCTURE_TYPE_SAMPLER_DESC, /* sType */
nullptr, /* pNext */
Expand All @@ -31,7 +31,7 @@ struct urKernelSetArgSamplerTest : uur::urKernelTest {
if (sampler) {
ASSERT_SUCCESS(urSamplerRelease(sampler));
}
UUR_RETURN_ON_FATAL_FAILURE(urKernelTest::TearDown());
UUR_RETURN_ON_FATAL_FAILURE(urBaseKernelTest::TearDown());
}

ur_sampler_handle_t sampler = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

#include <uur/fixtures.h>

struct urKernelSetSpecializationConstantsTest : uur::urKernelExecutionTest {
struct urKernelSetSpecializationConstantsTest : uur::urBaseKernelExecutionTest {
void SetUp() override {
program_name = "spec_constant";
UUR_RETURN_ON_FATAL_FAILURE(urKernelExecutionTest::SetUp());
UUR_RETURN_ON_FATAL_FAILURE(urBaseKernelExecutionTest::SetUp());
bool supports_kernel_spec_constant = false;
ASSERT_SUCCESS(urDeviceGetInfo(
device, UR_DEVICE_INFO_KERNEL_SET_SPECIALIZATION_CONSTANTS,
Expand All @@ -18,6 +18,7 @@ struct urKernelSetSpecializationConstantsTest : uur::urKernelExecutionTest {
GTEST_SKIP()
<< "Device does not support setting kernel spec constants.";
}
Build();
}

uint32_t spec_value = 42;
Expand Down
42 changes: 35 additions & 7 deletions test/conformance/testing/include/uur/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -1089,14 +1089,17 @@ template <class T> struct urProgramTestWithParam : urContextTestWithParam<T> {
ur_program_handle_t program = nullptr;
};

struct urKernelTest : urProgramTest {
struct urBaseKernelTest : urProgramTest {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urProgramTest::SetUp());
ASSERT_SUCCESS(urProgramBuild(context, program, nullptr));
auto kernel_names =
uur::KernelsEnvironment::instance->GetEntryPointNames(program_name);
kernel_name = kernel_names[0];
ASSERT_FALSE(kernel_name.empty());
}

void Build() {
ASSERT_SUCCESS(urProgramBuild(context, program, nullptr));
ASSERT_SUCCESS(urKernelCreate(program, kernel_name.data(), &kernel));
}

Expand All @@ -1111,15 +1114,26 @@ struct urKernelTest : urProgramTest {
ur_kernel_handle_t kernel = nullptr;
};

template <class T> struct urKernelTestWithParam : urProgramTestWithParam<T> {
struct urKernelTest : urBaseKernelTest {
void SetUp() override {
urBaseKernelTest::SetUp();
Build();
}
};

template <class T>
struct urBaseKernelTestWithParam : urProgramTestWithParam<T> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urProgramTestWithParam<T>::SetUp());
ASSERT_SUCCESS(urProgramBuild(this->context, this->program, nullptr));
auto kernel_names =
uur::KernelsEnvironment::instance->GetEntryPointNames(
this->program_name);
kernel_name = kernel_names[0];
ASSERT_FALSE(kernel_name.empty());
}

void Build() {
ASSERT_SUCCESS(urProgramBuild(this->context, this->program, nullptr));
ASSERT_SUCCESS(
urKernelCreate(this->program, kernel_name.data(), &kernel));
}
Expand All @@ -1135,16 +1149,23 @@ template <class T> struct urKernelTestWithParam : urProgramTestWithParam<T> {
ur_kernel_handle_t kernel = nullptr;
};

struct urKernelExecutionTest : urKernelTest {
template <class T> struct urKernelTestWithParam : urBaseKernelTestWithParam<T> {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urBaseKernelTestWithParam<T>::SetUp());
urBaseKernelTestWithParam<T>::Build();
}
};

struct urBaseKernelExecutionTest : urBaseKernelTest {
void SetUp() override {
UUR_RETURN_ON_FATAL_FAILURE(urKernelTest::SetUp());
UUR_RETURN_ON_FATAL_FAILURE(urBaseKernelTest::SetUp());
}

void TearDown() override {
for (auto &buffer : buffer_args) {
ASSERT_SUCCESS(urMemRelease(buffer));
}
UUR_RETURN_ON_FATAL_FAILURE(urKernelTest::TearDown());
UUR_RETURN_ON_FATAL_FAILURE(urBaseKernelTest::TearDown());
}

// Adds a kernel arg representing a sycl buffer constructed with a 1D range.
Expand Down Expand Up @@ -1233,6 +1254,13 @@ struct urKernelExecutionTest : urKernelTest {
uint32_t current_arg_index = 0;
};

struct urKernelExecutionTest : urBaseKernelExecutionTest {
void SetUp() {
UUR_RETURN_ON_FATAL_FAILURE(urBaseKernelExecutionTest::SetUp());
Build();
}
};

template <class T> struct GlobalVar {
std::string name;
T value;
Expand Down

0 comments on commit 512b158

Please sign in to comment.