Skip to content

Commit

Permalink
tests/api/images: force unmap/release to be perform after check (#697)
Browse files Browse the repository at this point in the history
* tests/api/images: force unmap/release to be perform after check

Depending on values in device_properties, some platform can perform
the unmap when the function is called, not when the app calls
clFinish.
Force this behavior by adding a userevent to control when the unmap
can be performed.

It might also fix flakyness in github CI. Not too sure.

* add comments

* Update tests/api/images.cpp

* Update tests/api/images.cpp

---------

Co-authored-by: Kévin Petit <[email protected]>
  • Loading branch information
rjodinchr and kpet authored Aug 13, 2024
1 parent 7afd8df commit de1dda0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tests/api/images.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,12 @@ TEST_F(WithCommandQueue, 1DBufferImageUnmapAfterRelease) {
buffer, // buffer
};

// clvk controller can decide to submit command directly after being
// enqueued. As we need to make sure that the unmap command will not be
// executed before we call Finish, we add this event to guarantee this
// property.
auto event = CreateUserEvent();

auto image = CreateImage(CL_MEM_READ_WRITE, &format, &desc);

std::atomic<bool> destructor_called = false;
Expand All @@ -742,9 +748,11 @@ TEST_F(WithCommandQueue, 1DBufferImageUnmapAfterRelease) {
clReleaseMemObject(released_image);
EXPECT_FALSE(destructor_called);

EnqueueUnmapMemObject(released_image, map_ptr);
EnqueueUnmapMemObject(released_image, map_ptr, 1, (const cl_event*)&event,
nullptr);
EXPECT_FALSE(destructor_called);

SetUserEventStatus(event, CL_COMPLETE);
Finish();
EXPECT_TRUE(destructor_called);
}
Expand All @@ -768,6 +776,12 @@ TEST_F(WithCommandQueue, 1DBufferImageReleaseAfterUnmap) {
buffer, // buffer
};

// clvk controller can decide to submit command directly after being
// enqueued. As we need to make sure that the unmap command will not be
// executed before we call Finish, we add this event to guarantee this
// property.
auto event = CreateUserEvent();

auto image = CreateImage(CL_MEM_READ_WRITE, &format, &desc);

std::atomic<bool> destructor_called = false;
Expand All @@ -779,13 +793,14 @@ TEST_F(WithCommandQueue, 1DBufferImageReleaseAfterUnmap) {
auto map_ptr = EnqueueMapImage<cl_uchar>(image, CL_TRUE, 0, origin, region,
nullptr, nullptr);

EnqueueUnmapMemObject(image, map_ptr);
EnqueueUnmapMemObject(image, map_ptr, 1, (const cl_event*)&event, nullptr);
EXPECT_FALSE(destructor_called);

cl_mem released_image = image.release();
clReleaseMemObject(released_image);
EXPECT_FALSE(destructor_called);

SetUserEventStatus(event, CL_COMPLETE);
Finish();
EXPECT_TRUE(destructor_called);
}

0 comments on commit de1dda0

Please sign in to comment.