Skip to content

Commit

Permalink
Add acquire/release (#1899)
Browse files Browse the repository at this point in the history
Add acquire/release commands where appropriate. This is related to 1886.
  • Loading branch information
joshqti authored May 21, 2024
1 parent fb39357 commit 4fceb78
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 7 deletions.
20 changes: 20 additions & 0 deletions test_conformance/common/vulkan_wrapper/opencl_vulkan_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ void init_cl_vk_ext(cl_platform_id opencl_platform, cl_uint num_devices,
"clReImportSemaphoreSyncFdKHR!");
}
}

clEnqueueAcquireExternalMemObjectsKHRptr =
(pfnclEnqueueAcquireExternalMemObjectsKHR)
clGetExtensionFunctionAddressForPlatform(
opencl_platform, "clEnqueueAcquireExternalMemObjectsKHR");
if (nullptr == clEnqueueAcquireExternalMemObjectsKHRptr)
{
throw std::runtime_error("Failed to get the function pointer of "
"clEnqueueAcquireExternalMemObjectsKHR!");
}

clEnqueueReleaseExternalMemObjectsKHRptr =
(pfnclEnqueueReleaseExternalMemObjectsKHR)
clGetExtensionFunctionAddressForPlatform(
opencl_platform, "clEnqueueReleaseExternalMemObjectsKHR");
if (nullptr == clEnqueueReleaseExternalMemObjectsKHRptr)
{
throw std::runtime_error("Failed to get the function pointer of "
"clEnqueueReleaseExternalMemObjectsKHR!");
}
}

cl_int setMaxImageDimensions(cl_device_id deviceID, size_t &max_width,
Expand Down
90 changes: 85 additions & 5 deletions test_conformance/vulkan/test_vulkan_interop_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,16 @@ int run_test_with_two_queue(

cl_event first_launch;

cl_event acquire_event = nullptr;
err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue1, vkBufferList.size(), buffers, 0, nullptr,
&acquire_event);
test_error_and_cleanup(err, CLEANUP,
"Failed to acquire buffers");

err = clEnqueueNDRangeKernel(cmd_queue1, update_buffer_kernel,
1, NULL, global_work_size, NULL, 0,
NULL, &first_launch);
1, NULL, global_work_size, NULL, 1,
&acquire_event, &first_launch);
test_error_and_cleanup(
err, CLEANUP,
"Error: Failed to launch update_buffer_kernel,"
Expand All @@ -297,6 +304,12 @@ int run_test_with_two_queue(
"Error: Failed to launch update_buffer_kernel,"
"error\n");

err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue2, vkBufferList.size(), buffers, 0, nullptr,
nullptr);
test_error_and_cleanup(err, CLEANUP,
"Failed to release buffers");

if (use_fence)
{
clFlush(cmd_queue1);
Expand All @@ -310,6 +323,9 @@ int run_test_with_two_queue(
test_error_and_cleanup(err, CLEANUP,
"Failed to signal CL semaphore\n");
}
err = clReleaseEvent(acquire_event);
test_error_and_cleanup(err, CLEANUP,
"Failed to release acquire event\n");
}
error_2 = (uint8_t *)malloc(sizeof(uint8_t));
if (NULL == error_2)
Expand Down Expand Up @@ -585,6 +601,12 @@ int run_test_with_one_queue(
err, CLEANUP,
"Error: Failed to set arg values for kernel\n");

err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue1, vkBufferList.size(), buffers, 0, nullptr,
nullptr);
test_error_and_cleanup(err, CLEANUP,
"Failed to acquire buffers");

err = clEnqueueNDRangeKernel(cmd_queue1, update_buffer_kernel,
1, NULL, global_work_size, NULL, 0,
NULL, NULL);
Expand All @@ -593,6 +615,12 @@ int run_test_with_one_queue(
"Error: Failed to launch update_buffer_kernel,"
" error\n");

err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue1, vkBufferList.size(), buffers, 0, nullptr,
nullptr);
test_error_and_cleanup(err, CLEANUP,
"Failed to release buffers");

if (use_fence)
{
clFlush(cmd_queue1);
Expand Down Expand Up @@ -883,6 +911,11 @@ int run_test_with_multi_import_same_ctx(
err |= clSetKernelArg(
update_buffer_kernel, i + 1, sizeof(cl_mem),
(void *)&(buffers[i][launchIter]));
err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue1, 1, &buffers[i][launchIter], 0,
nullptr, nullptr);
test_error_and_cleanup(err, CLEANUP,
"Failed to acquire buffers");
}
test_error_and_cleanup(
err, CLEANUP,
Expand All @@ -896,6 +929,15 @@ int run_test_with_multi_import_same_ctx(
err, CLEANUP,
"Error: Failed to launch "
"update_buffer_kernel, error\n ");

for (int i = 0; i < numBuffers; i++)
{
err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue1, 1, &buffers[i][launchIter], 0,
nullptr, nullptr);
test_error_and_cleanup(err, CLEANUP,
"Failed to release buffers");
}
}
if (use_fence)
{
Expand Down Expand Up @@ -1229,11 +1271,22 @@ int run_test_with_multi_import_diff_ctx(
err =
clSetKernelArg(update_buffer_kernel1[launchIter], 0,
sizeof(uint32_t), (void *)&pBufferSize);
test_error_and_cleanup(err, CLEANUP,
"Failed to set kernel arg");

for (int i = 0; i < numBuffers; i++)
{
err |= clSetKernelArg(
err = clSetKernelArg(
update_buffer_kernel1[launchIter], i + 1,
sizeof(cl_mem), (void *)&(buffers1[i][launchIter]));
test_error_and_cleanup(err, CLEANUP,
"Failed to set kernel arg");

err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue1, 1, &buffers1[i][launchIter], 0, nullptr,
nullptr);
test_error_and_cleanup(err, CLEANUP,
"Failed to acquire buffers");
}
test_error_and_cleanup(
err, CLEANUP,
Expand All @@ -1246,6 +1299,14 @@ int run_test_with_multi_import_diff_ctx(
test_error_and_cleanup(err, CLEANUP,
"Error: Failed to launch "
"update_buffer_kernel, error\n");
for (int i = 0; i < numBuffers; i++)
{
err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue1, 1, &buffers1[i][launchIter], 0, nullptr,
nullptr);
test_error_and_cleanup(err, CLEANUP,
"Failed to release buffers");
}
}
if (use_fence)
{
Expand Down Expand Up @@ -1298,12 +1359,23 @@ int run_test_with_multi_import_diff_ctx(
err = clSetKernelArg(update_buffer_kernel2[launchIter],
0, sizeof(uint32_t),
(void *)&bufferSize);
test_error_and_cleanup(err, CLEANUP,
"Failed to set kernel arg");

for (int i = 0; i < numBuffers; i++)
{
err |= clSetKernelArg(
err = clSetKernelArg(
update_buffer_kernel2[launchIter], i + 1,
sizeof(cl_mem),
(void *)&(buffers2[i][launchIter]));
test_error_and_cleanup(err, CLEANUP,
"Failed to set kernel arg");

err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue1, 1, &buffers2[i][launchIter], 0,
nullptr, nullptr);
test_error_and_cleanup(err, CLEANUP,
"Failed to acquire buffers");
}
test_error_and_cleanup(
err, CLEANUP,
Expand All @@ -1317,6 +1389,14 @@ int run_test_with_multi_import_diff_ctx(
err, CLEANUP,
"Error: Failed to launch "
"update_buffer_kernel, error\n ");
for (int i = 0; i < numBuffers; i++)
{
err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue1, 1, &buffers2[i][launchIter], 0,
nullptr, nullptr);
test_error_and_cleanup(err, CLEANUP,
"Failed to release buffers");
}
}
if (use_fence)
{
Expand Down Expand Up @@ -1757,4 +1837,4 @@ int test_buffer_common(cl_device_id device_, cl_context context_,
if (extensions) free(extensions);

return errNum;
}
}
75 changes: 73 additions & 2 deletions test_conformance/vulkan/test_vulkan_interop_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,18 @@ int run_test_with_two_queue(
err, CLEANUP,
"Error: Failed to set arg values \n");

// clVk2CLExternalSemaphore->wait(cmd_queue1);
err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue1, num2DImages,
external_mem_image1, 0, nullptr, nullptr);
test_error_and_cleanup(
err, CLEANUP, "Failed to acquire images");

err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue1, num2DImages,
external_mem_image2, 0, nullptr, nullptr);
test_error_and_cleanup(
err, CLEANUP, "Failed to acquire images");

size_t global_work_size[3] = { width, height,
1 };
cl_event first_launch;
Expand All @@ -656,6 +667,30 @@ int run_test_with_two_queue(
err, CLEANUP,
"Failed to enqueue updateKernelCQ1\n");

err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue1, num2DImages,
external_mem_image1, 0, nullptr, nullptr);
test_error_and_cleanup(
err, CLEANUP, "Failed to release images");

err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue1, num2DImages,
external_mem_image2, 0, nullptr, nullptr);
test_error_and_cleanup(
err, CLEANUP, "Failed to release images");

err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue2, num2DImages,
external_mem_image1, 0, nullptr, nullptr);
test_error_and_cleanup(
err, CLEANUP, "Failed to acquire images");

err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue2, num2DImages,
external_mem_image2, 0, nullptr, nullptr);
test_error_and_cleanup(
err, CLEANUP, "Failed to acquire images");

err = clEnqueueNDRangeKernel(
cmd_queue2, updateKernelCQ2, 2, NULL,
global_work_size, NULL, 1, &first_launch,
Expand All @@ -664,6 +699,18 @@ int run_test_with_two_queue(
err, CLEANUP,
"Failed to enqueue updateKernelCQ2\n");

err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue2, num2DImages,
external_mem_image1, 0, nullptr, nullptr);
test_error_and_cleanup(
err, CLEANUP, "Failed to release images");

err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue2, num2DImages,
external_mem_image2, 0, nullptr, nullptr);
test_error_and_cleanup(
err, CLEANUP, "Failed to release images");

clFinish(cmd_queue2);
err = clCl2VkExternalSemaphore->signal(
cmd_queue2);
Expand Down Expand Up @@ -1182,6 +1229,18 @@ int run_test_with_one_queue(
"Error: Failed to set arg "
"values for kernel-1\n");

err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue1, num2DImages,
external_mem_image1, 0, nullptr, nullptr);
test_error_and_cleanup(
err, CLEANUP, "Failed to acquire images");

err = clEnqueueAcquireExternalMemObjectsKHRptr(
cmd_queue1, num2DImages,
external_mem_image2, 0, nullptr, nullptr);
test_error_and_cleanup(
err, CLEANUP, "Failed to acquire images");

size_t global_work_size[3] = { width, height,
1 };
err = clEnqueueNDRangeKernel(
Expand All @@ -1191,6 +1250,18 @@ int run_test_with_one_queue(
err, CLEANUP,
"Failed to enqueue updateKernelCQ1\n");

err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue1, num2DImages,
external_mem_image1, 0, nullptr, nullptr);
test_error_and_cleanup(
err, CLEANUP, "Failed to release images");

err = clEnqueueReleaseExternalMemObjectsKHRptr(
cmd_queue1, num2DImages,
external_mem_image2, 0, nullptr, nullptr);
test_error_and_cleanup(
err, CLEANUP, "Failed to release images");

err = clCl2VkExternalSemaphore->signal(
cmd_queue1);
test_error_and_cleanup(
Expand Down Expand Up @@ -1538,4 +1609,4 @@ int test_image_common(cl_device_id device_, cl_context context_,
if (devices) free(devices);

return err;
}
}

0 comments on commit 4fceb78

Please sign in to comment.