Add external semaphore tests. (#1645)

* Add external semaphore tests.

Added basic test to check the functionality of cl_ext_external_semaphore_test extension.
Tests rely on Vulkan API as the producer of the external semaphore functionality. The
Vulkan wrapper has been copied from the Vulkan CTS tests and minor changes have been
introduced. A separate copy of the Vulkan wrapper is for breaking any dependencies
between different CTS modules and thus make the build system simpler.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Fix clang-format

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Move vulkan wrapper to a separate library.

Vulkan wrapper is extracted as a separate module and can be used in different
CTS tests as a shared library.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Add cl_ext_external_samaphore tests based on cl_khr_semaphore tests.

Added cl_khr_semaphore adjusted to creating semaphores in Vulkan context
and importing them through export semaphore functionality in OpenCL
(cl_ext_external_samaphore).

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Cleanup.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Fix build issues.

* Add missing directories for build cl_ext_external_semaphore.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Set Vulkan lib directory.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Change extension directory name.

Changed extensions directory name from cl_ext_external_semaphore to cl_khr_external_semaphore.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

* Remove unneeded compile options.

Removed VK_USE_PLATFORM_WIN32_KHR option from cl_khr_external_semaphore
compilation arguments.

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>

---------

Signed-off-by: Paweł Jastrzębski <p.k.jastrzebski@gmail.com>
This commit is contained in:
Paweł Jastrzębski
2023-03-21 17:06:15 +01:00
committed by GitHub
parent b7f2dd58e9
commit 63b0f441f1
20 changed files with 2056 additions and 475 deletions

View File

@@ -53,6 +53,7 @@ add_subdirectory( device_timer )
add_subdirectory( spirv_new )
add_subdirectory( spir )
if(VULKAN_IS_SUPPORTED)
add_subdirectory( common/vulkan_wrapper )
add_subdirectory( vulkan )
endif()

View File

@@ -0,0 +1,69 @@
set(VULKAN_WRAPPER_SOURCES
vulkan_wrapper.cpp
opencl_vulkan_wrapper.cpp
vulkan_utility.cpp
vulkan_list_map.cpp
)
# needed by Vulkan wrapper to compile
add_cxx_flag_if_supported(-Wmisleading-indentation)
add_cxx_flag_if_supported(-Wno-narrowing)
add_cxx_flag_if_supported(-Wno-format)
add_cxx_flag_if_supported(-Wno-error)
add_cxx_flag_if_supported(-Wno-error=cpp) # Allow #warning directive
add_cxx_flag_if_supported(-Wno-error=unknown-pragmas) # Issue #785
add_cxx_flag_if_supported(-Wno-error=asm-operand-widths) # Issue #784
add_cxx_flag_if_supported(-Wno-unused-variable)
add_cxx_flag_if_supported(-Wno-error=terminate)
add_cxx_flag_if_supported(-Wno-error=unused-function)
add_cxx_flag_if_supported(-Wno-error=return-type)
link_directories(${CLConform_VULKAN_LIBRARIES_DIR})
list(APPEND CLConform_INCLUDE_DIR ${VULKAN_INCLUDE_DIR})
add_library(vulkan_wrapper STATIC ${VULKAN_WRAPPER_SOURCES})
if(ANDROID)
target_compile_definitions(vulkan_wrapper PUBLIC VK_USE_PLATFORM_ANDROID_KHR)
elseif(WIN32)
target_compile_definitions(vulkan_wrapper PUBLIC VK_USE_PLATFORM_WIN32_KHR)
elseif(APPLE)
target_compile_definitions(vulkan_wrapper PUBLIC VK_USE_PLATFORM_METAL_EXT)
elseif(UNIX)
# Variable taken from Vulkan samples, commented out due to lack of WSI
# Choose WSI based on VKB_WSI_SELECTION
#if (VKB_WSI_SELECTION STREQUAL XCB OR VKB_WSI_SELECTION STREQUAL XLIB OR VKB_WSI_SELECTION STREQUAL WAYLAND)
# find_package(PkgConfig REQUIRED)
#endif()
#if (VKB_WSI_SELECTION STREQUAL XCB)
# pkg_check_modules(XCB xcb REQUIRED)
# if (XCB_FOUND)
# target_compile_definitions(vulkan_wrapper PUBLIC VK_USE_PLATFORM_XCB_KHR)
# endif()
#elseif (VKB_WSI_SELECTION STREQUAL XLIB)
# pkg_check_modules(X11 x11 REQUIRED)
# if (X11_FOUND)
# target_compile_definitions(vulkan_wrapper PUBLIC VK_USE_PLATFORM_XLIB_KHR)
# endif()
#elseif (VKB_WSI_SELECTION STREQUAL WAYLAND)
# pkg_check_modules(WAYLAND wayland-client REQUIRED)
# if (WAYLAND_FOUND)
# target_compile_definitions(vulkan_wrapper PUBLIC VK_USE_PLATFORM_WAYLAND_KHR)
# endif()
#elseif (VKB_WSI_SELECTION STREQUAL D2D)
# set(DIRECT_TO_DISPLAY TRUE)
# set(DIRECT_TO_DISPLAY TRUE PARENT_SCOPE)
# target_compile_definitions(vulkan_wrapper PUBLIC VK_USE_PLATFORM_DISPLAY_KHR)
#else()
# message(FATAL_ERROR "Unknown WSI")
#endif()
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories (${CLConform_INCLUDE_DIR})
if (NOT WIN32)
target_link_libraries(vulkan_wrapper dl)
endif()

View File

@@ -831,7 +831,7 @@ clExternalSemaphore::clExternalSemaphore(
}
}
clExternalSemaphore::~clExternalSemaphore()
clExternalSemaphore::~clExternalSemaphore() noexcept(false)
{
cl_int err = clReleaseSemaphoreKHRptr(m_externalSemaphore);
if (err != CL_SUCCESS)
@@ -851,3 +851,8 @@ void clExternalSemaphore::wait(cl_command_queue cmd_queue)
clEnqueueWaitSemaphoresKHRptr(cmd_queue, 1, &m_externalSemaphore, NULL, 0,
NULL, NULL);
}
cl_semaphore_khr &clExternalSemaphore::getCLSemaphore()
{
return m_externalSemaphore;
}

View File

@@ -120,9 +120,10 @@ public:
const VulkanSemaphore &deviceSemaphore, cl_context context,
VulkanExternalSemaphoreHandleType externalSemaphoreHandleType,
cl_device_id deviceId);
virtual ~clExternalSemaphore();
virtual ~clExternalSemaphore() noexcept(false);
void signal(cl_command_queue command_queue);
void wait(cl_command_queue command_queue);
cl_semaphore_khr &getCLSemaphore();
// operator openclExternalSemaphore_t() const;
};

View File

@@ -161,7 +161,7 @@
#define vkCreateImage _vkCreateImage
#define vkGetImageMemoryRequirements _vkGetImageMemoryRequirements
#define vkDestroyImage _vkDestroyImage
#define vkDestroyBuffe _vkDestroyBuffer
#define vkDestroyBuffer _vkDestroyBuffer
#define vkDestroyPipeline _vkDestroyPipeline
#define vkDestroyShaderModule _vkDestroyShaderModule
#define vkGetPhysicalDeviceMemoryProperties _vkGetPhysicalDeviceMemoryProperties

View File

@@ -2,3 +2,6 @@ add_subdirectory( cl_ext_cxx_for_opencl )
add_subdirectory( cl_khr_command_buffer )
add_subdirectory( cl_khr_dx9_media_sharing )
add_subdirectory( cl_khr_semaphore )
if(VULKAN_IS_SUPPORTED)
add_subdirectory( cl_khr_external_semaphore )
endif()

View File

@@ -0,0 +1,28 @@
set(MODULE_NAME CL_KHR_EXTERNAL_SEMAPHORE)
set(${MODULE_NAME}_SOURCES
main.cpp
test_external_semaphore.cpp
)
set (CLConform_VULKAN_LIBRARIES_DIR "${VULKAN_LIB_DIR}")
link_directories(${CLConform_VULKAN_LIBRARIES_DIR})
list(APPEND CLConform_INCLUDE_DIR ${VULKAN_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories (${CLConform_INCLUDE_DIR})
# needed by Vulkan wrapper to link
if(WIN32)
list(APPEND CLConform_LIBRARIES vulkan-1 vulkan_wrapper)
else(WIN32)
list(APPEND CLConform_LIBRARIES vulkan dl vulkan_wrapper)
endif(WIN32)
set(CMAKE_CXX_FLAGS "-fpermissive")
include_directories("../../common/vulkan_wrapper")
include(../../CMakeCommon.txt)

View File

@@ -0,0 +1,46 @@
// 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 "procs.h"
#include "harness/testHarness.h"
test_definition test_list[] = {
ADD_TEST(external_semaphores_queries),
ADD_TEST(external_semaphores_multi_context),
ADD_TEST(external_semaphores_simple_1),
// ADD_TEST(external_semaphores_simple_2),
ADD_TEST(external_semaphores_reuse),
ADD_TEST(external_semaphores_cross_queues_ooo),
ADD_TEST(external_semaphores_cross_queues_io),
ADD_TEST(external_semaphores_cross_queues_io2),
ADD_TEST(external_semaphores_multi_signal),
ADD_TEST(external_semaphores_multi_wait),
// ADD_TEST(external_semaphores_order_1),
// ADD_TEST(external_semaphores_order_2),
// ADD_TEST(external_semaphores_order_3),
// ADD_TEST(external_semaphores_invalid_command)
};
int main(int argc, const char *argv[])
{
// A device may report the required properties of a queue that
// is compatible with command-buffers via the query
// CL_DEVICE_COMMAND_BUFFER_REQUIRED_QUEUE_PROPERTIES_KHR. We account
// for this in the tests themselves, rather than here, where we have a
// device to query.
const cl_command_queue_properties queue_properties = 0;
return runTestHarnessWithCheck(argc, argv, ARRAY_SIZE(test_list), test_list,
false, queue_properties, nullptr);
}

View File

@@ -0,0 +1,82 @@
//
// 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.
//
#ifndef _CL_KHR_EXTERNAL_SEMAPHORE_PROCS_H
#define _CL_KHR_EXTERNAL_SEMAPHORE_PROCS_H
#include <CL/cl.h>
// Basic command-buffer tests
extern int test_external_semaphores_queries(cl_device_id deviceID,
cl_context context,
cl_command_queue defaultQueue,
int num_elements);
extern int test_external_semaphores_multi_context(cl_device_id deviceID,
cl_context context,
cl_command_queue defaultQueue,
int num_elements);
extern int test_external_semaphores_simple_1(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_external_semaphores_simple_2(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_external_semaphores_reuse(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_external_semaphores_cross_queues_ooo(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_external_semaphores_cross_queues_io(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_external_semaphores_cross_queues_io2(
cl_device_id deviceID, cl_context context, cl_command_queue defaultQueue,
int num_elements);
extern int test_external_semaphores_multi_signal(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_external_semaphores_multi_wait(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_external_semaphores_order_1(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_external_semaphores_order_2(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_external_semaphores_order_3(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_external_semaphores_import_export_fd(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_external_semaphores_invalid_command(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
#endif /* CL_KHR_EXTERNAL_SEMAPHORE */

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,9 @@
set (MODULE_NAME VULKAN)
if(WIN32)
list(APPEND CLConform_LIBRARIES vulkan-1)
list(APPEND CLConform_LIBRARIES vulkan-1 vulkan_wrapper)
else(WIN32)
list(APPEND CLConform_LIBRARIES vulkan dl)
list(APPEND CLConform_LIBRARIES vulkan dl vulkan_wrapper)
endif(WIN32)
set(CMAKE_CXX_FLAGS "-fpermissive")
if(WIN32)
@@ -26,11 +26,7 @@ set (${MODULE_NAME}_SOURCES
test_vulkan_interop_image.cpp
test_vulkan_api_consistency.cpp
test_vulkan_platform_device_info.cpp
vulkan_interop_common/vulkan_wrapper.cpp
vulkan_interop_common/vulkan_interop_common.cpp
vulkan_interop_common/opencl_vulkan_wrapper.cpp
vulkan_interop_common/vulkan_utility.cpp
vulkan_interop_common/vulkan_list_map.cpp
vulkan_interop_common.cpp
../../test_common/harness/genericThread.cpp
../../test_common/harness/errorHelpers.cpp
../../test_common/harness/testHarness.cpp
@@ -45,6 +41,6 @@ set (${MODULE_NAME}_SOURCES
set_source_files_properties(
${${MODULE_NAME}_SOURCES}
PROPERTIES LANGUAGE CXX)
include_directories("./vulkan_interop_common/")
include_directories("../common/vulkan_wrapper")
include(../CMakeCommon.txt)