Skip to content

Commit

Permalink
[UR] Extend testing of virtual memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Vesely committed Jul 31, 2023
1 parent 5b4c3d2 commit 0095324
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions test/conformance/enqueue/urEnqueueKernelLaunch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,81 @@ TEST_P(urEnqueueKernelLaunch3DTest, Success) {
ASSERT_SUCCESS(urQueueFinish(queue));
ValidateBuffer(buffer, buffer_size, val);
}

struct urEnqueueKernelLaunchWithVirtualMemory : uur::urKernelExecutionTest {

void SetUp() override {
program_name = "fill_usm";
UUR_RETURN_ON_FATAL_FAILURE(uur::urKernelExecutionTest::SetUp());
ASSERT_SUCCESS(urVirtualMemGranularityGetInfo(
context, device, UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM,
sizeof(granularity), &granularity, nullptr));

alloc_size = 1024;
virtual_page_size =
uur::RoundUpToNearestFactor(alloc_size, granularity);

ASSERT_SUCCESS(urPhysicalMemCreate(context, device, virtual_page_size,
nullptr, &physical_mem));

ASSERT_SUCCESS(urVirtualMemReserve(context, nullptr, virtual_page_size,
&virtual_ptr));

ASSERT_SUCCESS(urVirtualMemMap(context, virtual_ptr, virtual_page_size,
physical_mem, 0,
UR_VIRTUAL_MEM_ACCESS_FLAG_READ_WRITE));

int pattern = 0;
ASSERT_SUCCESS(urEnqueueUSMFill(queue, virtual_ptr, sizeof(pattern),
&pattern, virtual_page_size, 0, nullptr,
nullptr));
ASSERT_SUCCESS(urQueueFinish(queue));
}

void TearDown() override {

if (virtual_ptr) {
EXPECT_SUCCESS(
urVirtualMemUnmap(context, virtual_ptr, virtual_page_size));
EXPECT_SUCCESS(
urVirtualMemFree(context, virtual_ptr, virtual_page_size));
}

if (physical_mem) {
EXPECT_SUCCESS(urPhysicalMemRelease(physical_mem));
}

UUR_RETURN_ON_FATAL_FAILURE(uur::urKernelExecutionTest::TearDown());
}

size_t granularity = 0;
size_t alloc_size = 0;
size_t virtual_page_size = 0;
ur_physical_mem_handle_t physical_mem = nullptr;
void *virtual_ptr = nullptr;
};
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urEnqueueKernelLaunchWithVirtualMemory);

TEST_P(urEnqueueKernelLaunchWithVirtualMemory, Success) {
size_t work_dim = 1;
size_t global_offset = 0;
size_t global_size = alloc_size / sizeof(uint32_t);

ASSERT_SUCCESS(urKernelSetArgPointer(kernel, 0, nullptr, virtual_ptr));

ur_event_handle_t kernel_evt;
ASSERT_SUCCESS(urEnqueueKernelLaunch(queue, kernel, work_dim,
&global_offset, &global_size, nullptr,
0, nullptr, &kernel_evt));

std::vector<uint32_t> data(global_size);
ASSERT_SUCCESS(urEnqueueUSMMemcpy(queue, true, data.data(), virtual_ptr,
alloc_size, 1, &kernel_evt, nullptr));

ASSERT_SUCCESS(urQueueFinish(queue));

// verify fill worked
for (size_t i = 0; i < data.size(); i++) {
ASSERT_EQ(i, data.at(i));
}
}

0 comments on commit 0095324

Please sign in to comment.