mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 14:09:03 +00:00
* Fix enqueue_flags test to use correct barrier type. Currently, enqueue_flags test uses CLK_LOCAL_MEM_FENCE. Use CLK_GLOBAL_MEM_FENCE instead as all threads across work-groups need to wait here. * Add check for support for Read-Wrie images Read-Write images have required OpenCL 2.x. Read-Write image tests are already being skipped for 1.x devices. With OpenCL 3.0, read-write images being optional, the tests should be run or skipped depending on the implementation support. Add a check to decide if Read-Write images are supported or required to be supported depending on OpenCL version and decide if the tests should be run on skipped. Fixes issue #894 * Fix formatting in case of Read-Write image checks. Fix formatting in case of Read-write image checks. Also, combine two ifs into one in case of kerne_read_write tests * Fix some more formatting for RW-image checks Remove unnecessary spaces at various places. Also, fix lengthy lines. * Fix malloc-size calculation in test imagedim unsigned char size is silently assumed to be 1 in imagedim test of test_basic. Pass sizeof(type) in malloc size calculation. Also, change loop variable from signed to unsigned. Add checks for null pointer for malloced memory. * Initial CTS for external sharing extensions Initial set of tests for below extensions with Vulkan as producer 1. cl_khr_external_memory 2. cl_khr_external_memory_win32 3. cl_khr_external_memory_opaque_fd 4. cl_khr_external_semaphore 5. cl_khr_external_semaphore_win32 6. cl_khr_external_semaphore_opaque_fd * Updates to external sharing CTS Updates to external sharing CTS 1. Fix some build issues to remove unnecessary, non-existent files 2. Add new tests for platform and device queries. 3. Some added checks for VK Support. * Update CTS build script for Vulkan Headers Update CTS build to clone Vulkan Headers repo and pass it to CTS build in preparation for external memory and semaphore tests * Fix Vulkan header path Fix Vulkan header include path. * Add Vulkan loader dependency Vulkan loader is required to build test_vulkan of OpenCL-CTS. Clone and build Vulkan loader as prerequisite to OpenCL-CTS. * Fix Vulkan loader path in test_vulkan Remove arch/os suffix in Vulkan loader path to match vulkan loader repo build. * Fix warnings around getHandle API. Return type of getHandle is defined differently based on win or linux builds. Use appropriate guards when using API at other places. While at it remove duplicate definition of ARRAY_SIZE. * Use ARRAY_SIZE in harness. Use already defined ARRAY_SIZE macro from test_harness. * Fix build issues for test_vulkan Fix build issues for test_vulkan 1. Add cl_ext.h in common files 2. Replace cl_mem_properties_khr with cl_mem_properties 3. Replace cl_external_mem_handle_type_khr with cl_external_memory_handle_type_khr 4. Type-cast malloc as required. * Fix code formatting. Fix code formatting to get CTS CI builds clean. * Fix formatting fixes part-2 Another set of formatting fixes. * Fix code formatting part-3 Some more code formatting fixes. * Fix code formatting issues part-4 More code formatting fixes. * Formatting fixes part-5 Some more formatting fixes * Fix formatting part-6 More formatting fixes continued. * Code formatting fixes part-7 Code formatting fixes for image * Code formatting fixes part-8 Fixes for platform and device query tests. * Code formatting fixes part-9 More formatting fixes for vulkan_wrapper * Code formatting fixes part-10 More fixes to wrapper header * Code formatting fixes part-11 Formatting fixes for api_list * Code formatting fixes part-12 Formatting fixes for api_list_map. * Code formatting changes part-13 Code formatting changes for utility. * Code formatting fixes part-15 Formatting fixes for wrapper. * Misc Code formatting fixes Some more misc code formatting fixes. * Fix build breaks due to code formatting Fix build issues arised with recent code formatting issues. * Fix presubmit script after merge Fix presubmit script after merge conflicts. * Fix Vulkan loader build in presubmit script. Use cmake ninja and appropriate toolchain for Vulkan loader dependency to fix linking issue on arm/aarch64. * Use static array sizes Use static array sizes to fix windows builds. * Some left-out formatting fixes. Fix remaining formatting issues. * Fix harness header path Fix harness header path While at it, remove Misc and test pragma. * Add/Fix license information Add Khronos License info for test_vulkan. Replace Apple license with Khronos as applicable. * Fix headers for Mac OSX builds. Use appropriate headers for Mac OSX builds * Fix Mac OSX builds. Use appropriate headers for Mac OSX builds. Also, fix some build issues due to type-casting. * Fix new code formatting issues Fix new code formatting issues with recent MacOS fixes. * Add back missing case statement Add back missing case statement that was accidentally removed. * Disable USE_GAS for Vulkan Loader build. Disable USE_GAS for Vulkan Loader build to fix aarch64 build. * Fixes to OpenCL external sharing tests Fix clReleaseSemaphore() API. Fix copyright year. Some other minor fixes. * Improvements to OpenCL external sharing CTS Use SPIR-V shaders instead of NV extension path from GLSL to Vulkan shaders. Fixes for lower end GPUs to use limited memory. Update copy-right year at some more places. * Fix new code formatting issues. Fix code formatting issues with recent changes for external sharing tests. * More formatting fixes. More formatting fixes for recent updates to external sharing tests. * Final code formatting fixes. Minor formatting fixes to get format checks clean.
569 lines
22 KiB
C++
569 lines
22 KiB
C++
//
|
|
// Copyright (c) 2022 The Khronos Group Inc.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
#include <vulkan_interop_common.hpp>
|
|
#include <opencl_vulkan_wrapper.hpp>
|
|
#include <vulkan_wrapper.hpp>
|
|
#if !defined(__APPLE__)
|
|
#include <CL/cl.h>
|
|
#include <CL/cl_ext.h>
|
|
#else
|
|
#include <OpenCL/cl.h>
|
|
#include <OpenCL/cl_ext.h>
|
|
#endif
|
|
|
|
#include <assert.h>
|
|
#include <vector>
|
|
#include <iostream>
|
|
#include <string.h>
|
|
#include "harness/testHarness.h"
|
|
#include "harness/typeWrappers.h"
|
|
#include "harness/deviceInfo.h"
|
|
|
|
int test_consistency_external_buffer(cl_device_id deviceID, cl_context _context,
|
|
cl_command_queue _queue, int num_elements)
|
|
{
|
|
cl_int errNum;
|
|
VulkanDevice vkDevice;
|
|
// Context and command queue creation
|
|
cl_platform_id platform = NULL;
|
|
cl_context context = NULL;
|
|
cl_command_queue cmd_queue = NULL;
|
|
|
|
cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, 0, 0 };
|
|
errNum = clGetPlatformIDs(1, &platform, NULL);
|
|
test_error(errNum, "Failed to get platform Id");
|
|
|
|
contextProperties[1] = (cl_context_properties)platform;
|
|
|
|
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
|
|
NULL, NULL, &errNum);
|
|
test_error(errNum, "Unable to create context with properties");
|
|
|
|
cmd_queue = clCreateCommandQueue(context, deviceID, 0, &errNum);
|
|
test_error(errNum, "Unable to create command queue");
|
|
|
|
uint32_t bufferSize = 32;
|
|
cl_device_id devList[] = { deviceID, NULL };
|
|
|
|
#ifdef _WIN32
|
|
if (!is_extension_available(devList[0], "cl_khr_external_memory_win32"))
|
|
{
|
|
throw std::runtime_error("Device does not support "
|
|
"cl_khr_external_memory_win32 extension \n");
|
|
}
|
|
#else
|
|
if (!is_extension_available(devList[0], "cl_khr_external_memory_opaque_fd"))
|
|
{
|
|
throw std::runtime_error(
|
|
"Device does not support "
|
|
"cl_khr_external_memory_opaque_fd extension \n");
|
|
}
|
|
#endif
|
|
|
|
VulkanExternalMemoryHandleType vkExternalMemoryHandleType =
|
|
getSupportedVulkanExternalMemoryHandleTypeList()[0];
|
|
|
|
VulkanBuffer vkDummyBuffer(vkDevice, 4 * 1024, vkExternalMemoryHandleType);
|
|
const VulkanMemoryTypeList& memoryTypeList =
|
|
vkDummyBuffer.getMemoryTypeList();
|
|
|
|
VulkanDeviceMemory* vkDeviceMem = new VulkanDeviceMemory(
|
|
vkDevice, bufferSize, memoryTypeList[0], vkExternalMemoryHandleType);
|
|
VulkanBufferList vkBufferList(1, vkDevice, bufferSize,
|
|
vkExternalMemoryHandleType);
|
|
|
|
vkDeviceMem->bindBuffer(vkBufferList[0], 0);
|
|
|
|
void* handle = NULL;
|
|
int fd;
|
|
|
|
std::vector<cl_mem_properties> extMemProperties{
|
|
(cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR,
|
|
(cl_mem_properties)devList[0],
|
|
(cl_mem_properties)CL_DEVICE_HANDLE_LIST_END_KHR,
|
|
};
|
|
cl_external_memory_handle_type_khr type;
|
|
switch (vkExternalMemoryHandleType)
|
|
{
|
|
#ifdef _WIN32
|
|
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT:
|
|
handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType);
|
|
type = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR;
|
|
errNum = check_external_memory_handle_type(devList[0], type);
|
|
extMemProperties.push_back((cl_mem_properties)type);
|
|
extMemProperties.push_back((cl_mem_properties)handle);
|
|
break;
|
|
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
|
|
handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType);
|
|
type = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR;
|
|
errNum = check_external_memory_handle_type(devList[0], type);
|
|
extMemProperties.push_back((cl_mem_properties)type);
|
|
extMemProperties.push_back((cl_mem_properties)handle);
|
|
break;
|
|
#else
|
|
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD:
|
|
fd = (int)vkDeviceMem->getHandle(vkExternalMemoryHandleType);
|
|
type = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR;
|
|
errNum = check_external_memory_handle_type(devList[0], type);
|
|
extMemProperties.push_back((cl_mem_properties)type);
|
|
extMemProperties.push_back((cl_mem_properties)fd);
|
|
break;
|
|
#endif
|
|
default:
|
|
errNum = TEST_FAIL;
|
|
log_error("Unsupported external memory handle type \n");
|
|
break;
|
|
}
|
|
if (errNum != CL_SUCCESS)
|
|
{
|
|
log_error("Checks failed for "
|
|
"CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR\n");
|
|
return TEST_FAIL;
|
|
}
|
|
extMemProperties.push_back(0);
|
|
|
|
clMemWrapper buffer;
|
|
|
|
// Passing NULL properties and a valid extMem_desc size
|
|
buffer = clCreateBufferWithProperties(context, NULL, 1, bufferSize, NULL,
|
|
&errNum);
|
|
test_error(errNum, "Unable to create buffer with NULL properties");
|
|
|
|
buffer.reset();
|
|
|
|
// Passing valid extMemProperties and buffersize
|
|
buffer = clCreateBufferWithProperties(context, extMemProperties.data(), 1,
|
|
bufferSize, NULL, &errNum);
|
|
test_error(errNum, "Unable to create buffer with Properties");
|
|
|
|
buffer.reset();
|
|
|
|
// Not passing external memory handle
|
|
std::vector<cl_mem_properties> extMemProperties2{
|
|
#ifdef _WIN32
|
|
(cl_mem_properties)type,
|
|
NULL, // Passing NULL handle
|
|
#else
|
|
(cl_mem_properties)type,
|
|
(cl_mem_properties)-64, // Passing random invalid fd
|
|
#endif
|
|
(cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR,
|
|
(cl_mem_properties)devList[0],
|
|
(cl_mem_properties)CL_DEVICE_HANDLE_LIST_END_KHR,
|
|
0
|
|
};
|
|
buffer = clCreateBufferWithProperties(context, extMemProperties2.data(), 1,
|
|
bufferSize, NULL, &errNum);
|
|
test_failure_error(errNum, CL_INVALID_VALUE,
|
|
"Should return CL_INVALID_VALUE ");
|
|
|
|
buffer.reset();
|
|
|
|
// Passing extMem_desc size = 0 but valid memProperties, CL_INVALID_SIZE
|
|
// should be returned.
|
|
buffer = clCreateBufferWithProperties(context, extMemProperties.data(), 1,
|
|
0, NULL, &errNum);
|
|
test_failure_error(errNum, CL_INVALID_BUFFER_SIZE,
|
|
"Should return CL_INVALID_BUFFER_SIZE");
|
|
|
|
return TEST_PASS;
|
|
}
|
|
|
|
int test_consistency_external_image(cl_device_id deviceID, cl_context _context,
|
|
cl_command_queue _queue, int num_elements)
|
|
{
|
|
cl_int errNum;
|
|
VulkanDevice vkDevice;
|
|
|
|
// Context and command queue creation
|
|
cl_platform_id platform = NULL;
|
|
cl_context context = NULL;
|
|
cl_command_queue cmd_queue = NULL;
|
|
|
|
cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, 0, 0 };
|
|
errNum = clGetPlatformIDs(1, &platform, NULL);
|
|
test_error(errNum, "Failed to get platform id");
|
|
|
|
contextProperties[1] = (cl_context_properties)platform;
|
|
|
|
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
|
|
NULL, NULL, &errNum);
|
|
test_error(errNum, "Unable to create context with properties");
|
|
|
|
cmd_queue = clCreateCommandQueue(context, deviceID, 0, &errNum);
|
|
test_error(errNum, "Unable to create command queue");
|
|
|
|
cl_device_id devList[] = { deviceID, NULL };
|
|
|
|
#ifdef _WIN32
|
|
if (!is_extension_available(devList[0], "cl_khr_external_memory_win32"))
|
|
{
|
|
throw std::runtime_error("Device does not support"
|
|
"cl_khr_external_memory_win32 extension \n");
|
|
}
|
|
#else
|
|
if (!is_extension_available(devList[0], "cl_khr_external_memory_opaque_fd"))
|
|
{
|
|
throw std::runtime_error(
|
|
"Device does not support cl_khr_external_memory_opaque_fd "
|
|
"extension \n");
|
|
}
|
|
#endif
|
|
uint32_t width = 256;
|
|
uint32_t height = 16;
|
|
cl_image_desc image_desc;
|
|
memset(&image_desc, 0x0, sizeof(cl_image_desc));
|
|
cl_image_format img_format = { 0 };
|
|
|
|
VulkanExternalMemoryHandleType vkExternalMemoryHandleType =
|
|
getSupportedVulkanExternalMemoryHandleTypeList()[0];
|
|
VulkanImage2D* vkImage2D =
|
|
new VulkanImage2D(vkDevice, VULKAN_FORMAT_R8G8B8A8_UNORM, width, height,
|
|
1, vkExternalMemoryHandleType);
|
|
|
|
const VulkanMemoryTypeList& memoryTypeList = vkImage2D->getMemoryTypeList();
|
|
uint64_t totalImageMemSize = vkImage2D->getSize();
|
|
|
|
log_info("Memory type index: %lu\n", (uint32_t)memoryTypeList[0]);
|
|
log_info("Memory type property: %d\n",
|
|
memoryTypeList[0].getMemoryTypeProperty());
|
|
log_info("Image size : %d\n", totalImageMemSize);
|
|
|
|
VulkanDeviceMemory* vkDeviceMem =
|
|
new VulkanDeviceMemory(vkDevice, totalImageMemSize, memoryTypeList[0],
|
|
vkExternalMemoryHandleType);
|
|
vkDeviceMem->bindImage(*vkImage2D, 0);
|
|
|
|
void* handle = NULL;
|
|
int fd;
|
|
std::vector<cl_mem_properties> extMemProperties{
|
|
(cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR,
|
|
(cl_mem_properties)devList[0],
|
|
(cl_mem_properties)CL_DEVICE_HANDLE_LIST_END_KHR,
|
|
};
|
|
switch (vkExternalMemoryHandleType)
|
|
{
|
|
#ifdef _WIN32
|
|
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT:
|
|
handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType);
|
|
errNum = check_external_memory_handle_type(
|
|
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
|
|
extMemProperties.push_back(
|
|
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
|
|
extMemProperties.push_back((cl_mem_properties)handle);
|
|
break;
|
|
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
|
|
handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType);
|
|
errNum = check_external_memory_handle_type(
|
|
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
|
|
extMemProperties.push_back(
|
|
(cl_mem_properties)
|
|
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
|
|
extMemProperties.push_back((cl_mem_properties)handle);
|
|
break;
|
|
#else
|
|
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD:
|
|
fd = (int)vkDeviceMem->getHandle(vkExternalMemoryHandleType);
|
|
errNum = check_external_memory_handle_type(
|
|
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
|
|
extMemProperties.push_back(
|
|
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
|
|
extMemProperties.push_back((cl_mem_properties)fd);
|
|
break;
|
|
#endif
|
|
default:
|
|
errNum = TEST_FAIL;
|
|
log_error("Unsupported external memory handle type \n");
|
|
break;
|
|
}
|
|
if (errNum != CL_SUCCESS)
|
|
{
|
|
log_error("Checks failed for "
|
|
"CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR\n");
|
|
return TEST_FAIL;
|
|
}
|
|
extMemProperties.push_back(0);
|
|
|
|
const VkImageCreateInfo VulkanImageCreateInfo =
|
|
vkImage2D->getVkImageCreateInfo();
|
|
|
|
errNum = getCLImageInfoFromVkImageInfo(
|
|
&VulkanImageCreateInfo, totalImageMemSize, &img_format, &image_desc);
|
|
if (errNum != CL_SUCCESS)
|
|
{
|
|
log_error("getCLImageInfoFromVkImageInfo failed!!!");
|
|
return TEST_FAIL;
|
|
}
|
|
|
|
clMemWrapper image;
|
|
|
|
// Pass valid properties, image_desc and image_format
|
|
image = clCreateImageWithProperties(
|
|
context, extMemProperties.data(), CL_MEM_READ_WRITE, &img_format,
|
|
&image_desc, NULL /* host_ptr */, &errNum);
|
|
test_error(errNum, "Unable to create Image with Properties");
|
|
image.reset();
|
|
|
|
// Passing properties, image_desc and image_format all as NULL
|
|
image = clCreateImageWithProperties(context, NULL, CL_MEM_READ_WRITE, NULL,
|
|
NULL, NULL, &errNum);
|
|
test_failure_error(
|
|
errNum, CL_INVALID_IMAGE_DESCRIPTOR,
|
|
"Image creation must fail with CL_INVALID_IMAGE_DESCRIPTOR "
|
|
"when all are passed as NULL");
|
|
|
|
image.reset();
|
|
|
|
// Passing NULL properties and a valid image_format and image_desc
|
|
image =
|
|
clCreateImageWithProperties(context, NULL, CL_MEM_READ_WRITE,
|
|
&img_format, &image_desc, NULL, &errNum);
|
|
test_error(errNum,
|
|
"Unable to create image with NULL properties "
|
|
"with valid image format and image desc");
|
|
|
|
image.reset();
|
|
|
|
// Passing image_format as NULL
|
|
image = clCreateImageWithProperties(context, extMemProperties.data(),
|
|
CL_MEM_READ_WRITE, NULL, &image_desc,
|
|
NULL, &errNum);
|
|
test_failure_error(errNum, CL_INVALID_IMAGE_FORMAT_DESCRIPTOR,
|
|
"Image creation must fail with "
|
|
"CL_INVALID_IMAGE_FORMAT_DESCRIPTOR"
|
|
"when image desc passed as NULL");
|
|
|
|
image.reset();
|
|
|
|
// Passing image_desc as NULL
|
|
image = clCreateImageWithProperties(context, extMemProperties.data(),
|
|
CL_MEM_READ_WRITE, &img_format, NULL,
|
|
NULL, &errNum);
|
|
test_failure_error(errNum, CL_INVALID_IMAGE_DESCRIPTOR,
|
|
"Image creation must fail with "
|
|
"CL_INVALID_IMAGE_DESCRIPTOR "
|
|
"when image desc passed as NULL");
|
|
image.reset();
|
|
|
|
return TEST_PASS;
|
|
}
|
|
|
|
int test_consistency_external_semaphore(cl_device_id deviceID,
|
|
cl_context _context,
|
|
cl_command_queue _queue,
|
|
int num_elements)
|
|
{
|
|
cl_int errNum;
|
|
VulkanDevice vkDevice;
|
|
// Context and command queue creation
|
|
cl_platform_id platform = NULL;
|
|
cl_context context = NULL;
|
|
cl_command_queue cmd_queue = NULL;
|
|
|
|
errNum = clGetPlatformIDs(1, &platform, NULL);
|
|
test_error(errNum, "Failed to get platform Id");
|
|
|
|
cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, 0, 0 };
|
|
|
|
contextProperties[1] = (cl_context_properties)platform;
|
|
|
|
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
|
|
NULL, NULL, &errNum);
|
|
test_error(errNum, "Unable to create context with properties");
|
|
|
|
cmd_queue = clCreateCommandQueue(context, deviceID, 0, &errNum);
|
|
test_error(errNum, "Unable to create command queue");
|
|
|
|
cl_device_id devList[] = { deviceID, NULL };
|
|
|
|
#ifdef _WIN32
|
|
if (!is_extension_available(devList[0], "cl_khr_external_semaphore_win32"))
|
|
{
|
|
throw std::runtime_error(
|
|
"Device does not support cl_khr_external_semaphore_win32 "
|
|
"extension \n");
|
|
}
|
|
#else
|
|
if (!is_extension_available(devList[0],
|
|
"cl_khr_external_semaphore_opaque_fd"))
|
|
{
|
|
throw std::runtime_error(
|
|
"Device does not support "
|
|
"cl_khr_external_semaphore_opaque_fd extension \n");
|
|
}
|
|
#endif
|
|
VulkanExternalSemaphoreHandleType vkExternalSemaphoreHandleType =
|
|
getSupportedVulkanExternalSemaphoreHandleTypeList()[0];
|
|
VulkanSemaphore vkVk2Clsemaphore(vkDevice, vkExternalSemaphoreHandleType);
|
|
VulkanSemaphore vkCl2Vksemaphore(vkDevice, vkExternalSemaphoreHandleType);
|
|
cl_semaphore_khr clCl2Vksemaphore;
|
|
cl_semaphore_khr clVk2Clsemaphore;
|
|
|
|
void* handle1 = NULL;
|
|
void* handle2 = NULL;
|
|
int fd1, fd2;
|
|
std::vector<cl_semaphore_properties_khr> sema_props1{
|
|
(cl_semaphore_properties_khr)CL_SEMAPHORE_TYPE_KHR,
|
|
(cl_semaphore_properties_khr)CL_SEMAPHORE_TYPE_BINARY_KHR,
|
|
};
|
|
std::vector<cl_semaphore_properties_khr> sema_props2{
|
|
(cl_semaphore_properties_khr)CL_SEMAPHORE_TYPE_KHR,
|
|
(cl_semaphore_properties_khr)CL_SEMAPHORE_TYPE_BINARY_KHR,
|
|
};
|
|
switch (vkExternalSemaphoreHandleType)
|
|
{
|
|
#ifdef _WIN32
|
|
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT:
|
|
log_info(" Opaque NT handles are only supported on Windows\n");
|
|
handle1 = vkVk2Clsemaphore.getHandle(vkExternalSemaphoreHandleType);
|
|
handle2 = vkCl2Vksemaphore.getHandle(vkExternalSemaphoreHandleType);
|
|
errNum = check_external_semaphore_handle_type(
|
|
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR);
|
|
sema_props1.push_back((cl_semaphore_properties_khr)
|
|
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR);
|
|
sema_props1.push_back((cl_semaphore_properties_khr)handle1);
|
|
sema_props2.push_back((cl_semaphore_properties_khr)
|
|
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR);
|
|
sema_props2.push_back((cl_semaphore_properties_khr)handle2);
|
|
break;
|
|
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT:
|
|
log_info(" Opaque D3DKMT handles are only supported on Windows\n");
|
|
handle1 = vkVk2Clsemaphore.getHandle(vkExternalSemaphoreHandleType);
|
|
handle2 = vkCl2Vksemaphore.getHandle(vkExternalSemaphoreHandleType);
|
|
errNum = check_external_semaphore_handle_type(
|
|
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR);
|
|
sema_props1.push_back((cl_semaphore_properties_khr)
|
|
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR);
|
|
sema_props1.push_back((cl_semaphore_properties_khr)handle1);
|
|
sema_props2.push_back((cl_semaphore_properties_khr)
|
|
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR);
|
|
sema_props2.push_back((cl_semaphore_properties_khr)handle2);
|
|
break;
|
|
#else
|
|
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD:
|
|
log_info(" Opaque file descriptors are not supported on Windows\n");
|
|
fd1 =
|
|
(int)vkVk2Clsemaphore.getHandle(vkExternalSemaphoreHandleType);
|
|
fd2 =
|
|
(int)vkCl2Vksemaphore.getHandle(vkExternalSemaphoreHandleType);
|
|
errNum = check_external_semaphore_handle_type(
|
|
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR);
|
|
sema_props1.push_back(
|
|
(cl_semaphore_properties_khr)CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR);
|
|
sema_props1.push_back((cl_semaphore_properties_khr)fd1);
|
|
sema_props2.push_back(
|
|
(cl_semaphore_properties_khr)CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR);
|
|
sema_props2.push_back((cl_semaphore_properties_khr)fd2);
|
|
break;
|
|
#endif
|
|
default: log_error("Unsupported external memory handle type\n"); break;
|
|
}
|
|
if (CL_SUCCESS != errNum)
|
|
{
|
|
throw std::runtime_error(
|
|
"Unsupported external sempahore handle type\n ");
|
|
}
|
|
sema_props1.push_back(
|
|
(cl_semaphore_properties_khr)CL_DEVICE_HANDLE_LIST_KHR);
|
|
sema_props1.push_back((cl_semaphore_properties_khr)devList[0]);
|
|
sema_props1.push_back(
|
|
(cl_semaphore_properties_khr)CL_DEVICE_HANDLE_LIST_END_KHR);
|
|
sema_props2.push_back(
|
|
(cl_semaphore_properties_khr)CL_DEVICE_HANDLE_LIST_KHR);
|
|
sema_props2.push_back((cl_semaphore_properties_khr)devList[0]);
|
|
sema_props2.push_back(
|
|
(cl_semaphore_properties_khr)CL_DEVICE_HANDLE_LIST_END_KHR);
|
|
sema_props1.push_back(0);
|
|
sema_props2.push_back(0);
|
|
|
|
// Pass NULL properties
|
|
cl_semaphore_khr cl_ext_semaphore =
|
|
clCreateSemaphoreWithPropertiesKHRptr(context, NULL, &errNum);
|
|
test_failure_error(errNum, CL_INVALID_VALUE,
|
|
"Semaphore creation must fail with CL_INVALID_VALUE "
|
|
" when properties are passed as NULL");
|
|
|
|
|
|
// Pass invalid semaphore object to wait
|
|
errNum =
|
|
clEnqueueWaitSemaphoresKHRptr(cmd_queue, 1, NULL, NULL, 0, NULL, NULL);
|
|
test_failure_error(errNum, CL_INVALID_VALUE,
|
|
"clEnqueueWaitSemaphoresKHR fails with CL_INVALID_VALUE "
|
|
"when invalid semaphore object is passed");
|
|
|
|
|
|
// Pass invalid semaphore object to signal
|
|
errNum = clEnqueueSignalSemaphoresKHRptr(cmd_queue, 1, NULL, NULL, 0, NULL,
|
|
NULL);
|
|
test_failure_error(
|
|
errNum, CL_INVALID_VALUE,
|
|
"clEnqueueSignalSemaphoresKHR fails with CL_INVALID_VALUE"
|
|
"when invalid semaphore object is passed");
|
|
|
|
|
|
// Create two semaphore objects
|
|
clVk2Clsemaphore = clCreateSemaphoreWithPropertiesKHRptr(
|
|
context, sema_props1.data(), &errNum);
|
|
test_error(errNum,
|
|
"Unable to create semaphore with valid semaphore properties");
|
|
|
|
clCl2Vksemaphore = clCreateSemaphoreWithPropertiesKHRptr(
|
|
context, sema_props2.data(), &errNum);
|
|
test_error(errNum,
|
|
"Unable to create semaphore with valid semaphore properties");
|
|
|
|
|
|
// Call Signal twice consecutively
|
|
errNum = clEnqueueSignalSemaphoresKHRptr(cmd_queue, 1, &clVk2Clsemaphore,
|
|
NULL, 0, NULL, NULL);
|
|
test_error(errNum, "clEnqueueSignalSemaphoresKHRptr failed");
|
|
|
|
errNum = clEnqueueSignalSemaphoresKHRptr(cmd_queue, 1, &clCl2Vksemaphore,
|
|
NULL, 0, NULL, NULL);
|
|
test_error(errNum,
|
|
"clEnqueueSignalSemaphoresKHRptr failed for two "
|
|
"consecutive wait events");
|
|
|
|
|
|
// Call Wait twice consecutively
|
|
errNum = clEnqueueWaitSemaphoresKHRptr(cmd_queue, 1, &clVk2Clsemaphore,
|
|
NULL, 0, NULL, NULL);
|
|
test_error(errNum, "clEnqueueWaitSemaphoresKHRptr failed");
|
|
|
|
errNum = clEnqueueWaitSemaphoresKHRptr(cmd_queue, 1, &clCl2Vksemaphore,
|
|
NULL, 0, NULL, NULL);
|
|
test_error(errNum,
|
|
"clEnqueueWaitSemaphoresKHRptr failed for two "
|
|
" consecutive wait events");
|
|
|
|
|
|
// Pass invalid object to release call
|
|
errNum = clReleaseSemaphoreKHRptr(NULL);
|
|
test_failure_error(errNum, CL_INVALID_VALUE,
|
|
"clReleaseSemaphoreKHRptr fails with "
|
|
"CL_INVALID_VALUE when NULL semaphore object is passed");
|
|
|
|
// Release both semaphore objects
|
|
errNum = clReleaseSemaphoreKHRptr(clVk2Clsemaphore);
|
|
test_error(errNum, "clReleaseSemaphoreKHRptr failed");
|
|
|
|
errNum = clReleaseSemaphoreKHRptr(clCl2Vksemaphore);
|
|
test_error(errNum, "clReleaseSemaphoreKHRptr failed");
|
|
|
|
return TEST_PASS;
|
|
}
|