From 6ab39150e0f52a9d9a4dbe75cd65ffa9764c82f4 Mon Sep 17 00:00:00 2001 From: "Dunajski, Bartosz" Date: Mon, 29 Jan 2018 12:25:49 +0100 Subject: [PATCH] clGetDeviceIDsFromVA_APIMediaAdapterINTEL support Change-Id: I3d43f00795c36562585bee7b4ee96123389586c7 --- Jenkinsfile | 2 +- runtime/api/dispatch.h | 12 +++++++- runtime/sharings/va/cl_va_api.cpp | 19 ++++++++++++ runtime/sharings/va/enable_va.cpp | 4 ++- unit_tests/helpers/base_object_tests.cpp | 2 -- ...l_get_extension_function_address_tests.cpp | 5 ++++ .../sharings/va/va_base_object_tests.cpp | 3 ++ .../sharings/va/va_sharing_enable_tests.cpp | 2 ++ unit_tests/sharings/va/va_sharing_tests.cpp | 29 ++++++++++++++++++- 9 files changed, 72 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0d77450150..8681640dfd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,4 +2,4 @@ neoDependenciesRev='730226-753' strategy='EQUAL' allowedF=49 -allowedCD=366 +allowedCD=365 diff --git a/runtime/api/dispatch.h b/runtime/api/dispatch.h index d81a4022e2..8350a3c97e 100644 --- a/runtime/api/dispatch.h +++ b/runtime/api/dispatch.h @@ -1045,6 +1045,15 @@ typedef CL_API_ENTRY cl_mem(CL_API_CALL *INTELpfn_clCreateFromVA_APIMediaSurface cl_uint plane, cl_int *errcodeRet) CL_API_SUFFIX__VERSION_1_2; +typedef CL_API_ENTRY cl_int(CL_API_CALL *INTELpfn_clGetDeviceIDsFromVA_APIMediaAdapterINTEL)( + cl_platform_id platform, + cl_va_api_device_source_intel mediaAdapterType, + void *mediaAdapter, + cl_va_api_device_set_intel mediaAdapterSet, + cl_uint numEntries, + cl_device_id *devices, + cl_uint *numDevices) CL_API_SUFFIX__VERSION_1_2; + typedef CL_API_ENTRY cl_int(CL_API_CALL *INTELpfn_clEnqueueAcquireVA_APIMediaSurfacesINTEL)( cl_command_queue commandQueue, cl_uint numObjects, @@ -1062,6 +1071,7 @@ typedef CL_API_ENTRY cl_int(CL_API_CALL *INTELpfn_clEnqueueReleaseVA_APIMediaSur cl_event *event) CL_API_SUFFIX__VERSION_1_2; #else typedef void (*INTELpfn_clCreateFromVA_APIMediaSurfaceINTEL)(); +typedef void (*INTELpfn_clGetDeviceIDsFromVA_APIMediaAdapterINTEL)(); typedef void (*INTELpfn_clEnqueueAcquireVA_APIMediaSurfacesINTEL)(); typedef void (*INTELpfn_clEnqueueReleaseVA_APIMediaSurfacesINTEL)(); #endif @@ -1270,7 +1280,7 @@ struct SCRTDispatchTable { // VAMedia sharing extension #ifdef LIBVA INTELpfn_clCreateFromVA_APIMediaSurfaceINTEL clCreateFromVA_APIMediaSurfaceINTEL; - void *placeholder15; // clGetDeviceIDsFromVA_APIMediaAdapterINTEL handled by CRT + INTELpfn_clGetDeviceIDsFromVA_APIMediaAdapterINTEL clGetDeviceIDsFromVA_APIMediaAdapterINTEL; INTELpfn_clEnqueueReleaseVA_APIMediaSurfacesINTEL clEnqueueReleaseVA_APIMediaSurfacesINTEL; INTELpfn_clEnqueueAcquireVA_APIMediaSurfacesINTEL clEnqueueAcquireVA_APIMediaSurfacesINTEL; #else diff --git a/runtime/sharings/va/cl_va_api.cpp b/runtime/sharings/va/cl_va_api.cpp index 40df52b74a..1fba18eb4e 100644 --- a/runtime/sharings/va/cl_va_api.cpp +++ b/runtime/sharings/va/cl_va_api.cpp @@ -26,6 +26,8 @@ #include "runtime/command_queue/command_queue.h" #include "runtime/context/context.h" #include "runtime/helpers/get_info.h" +#include "runtime/platform/platform.h" +#include "runtime/device/device.h" #include "runtime/sharings/va/va_sharing.h" #include "runtime/sharings/va/va_surface.h" #include @@ -49,6 +51,23 @@ clCreateFromVA_APIMediaSurfaceINTEL(cl_context context, cl_mem_flags flags, VASu return VASurface::createSharedVaSurface(pContext, pContext->getSharing(), flags, surface, plane, errcodeRet); } +cl_int CL_API_CALL +clGetDeviceIDsFromVA_APIMediaAdapterINTEL(cl_platform_id platform, cl_va_api_device_source_intel mediaAdapterType, + void *mediaAdapter, cl_va_api_device_set_intel mediaAdapterSet, cl_uint numEntries, + cl_device_id *devices, cl_uint *numDevices) { + + Platform *pPlatform = nullptr; + auto status = validateObjects(WithCastToInternal(platform, &pPlatform)); + if (status != CL_SUCCESS) { + return CL_INVALID_PLATFORM; + } + + cl_device_id device = pPlatform->getDevice(0); + GetInfoHelper::set(devices, device); + GetInfoHelper::set(numDevices, 1u); + return CL_SUCCESS; +} + cl_int CL_API_CALL clEnqueueAcquireVA_APIMediaSurfacesINTEL(cl_command_queue commandQueue, cl_uint numObjects, diff --git a/runtime/sharings/va/enable_va.cpp b/runtime/sharings/va/enable_va.cpp index 1f09f492d3..d9349d2457 100644 --- a/runtime/sharings/va/enable_va.cpp +++ b/runtime/sharings/va/enable_va.cpp @@ -76,6 +76,7 @@ std::string VaSharingBuilderFactory::getExtensions() { void VaSharingBuilderFactory::fillGlobalDispatchTable() { crtGlobalDispatchTable.clCreateFromVA_APIMediaSurfaceINTEL = clCreateFromVA_APIMediaSurfaceINTEL; + crtGlobalDispatchTable.clGetDeviceIDsFromVA_APIMediaAdapterINTEL = clGetDeviceIDsFromVA_APIMediaAdapterINTEL; crtGlobalDispatchTable.clEnqueueReleaseVA_APIMediaSurfacesINTEL = clEnqueueReleaseVA_APIMediaSurfacesINTEL; crtGlobalDispatchTable.clEnqueueAcquireVA_APIMediaSurfacesINTEL = clEnqueueAcquireVA_APIMediaSurfacesINTEL; } @@ -88,6 +89,7 @@ void VaSharingBuilderFactory::fillGlobalDispatchTable() { } void *VaSharingBuilderFactory::getExtensionFunctionAddress(const std::string &functionName) { RETURN_FUNC_PTR_IF_EXIST(clCreateFromVA_APIMediaSurfaceINTEL); + RETURN_FUNC_PTR_IF_EXIST(clGetDeviceIDsFromVA_APIMediaAdapterINTEL); RETURN_FUNC_PTR_IF_EXIST(clEnqueueAcquireVA_APIMediaSurfacesINTEL); RETURN_FUNC_PTR_IF_EXIST(clEnqueueReleaseVA_APIMediaSurfacesINTEL); @@ -95,5 +97,5 @@ void *VaSharingBuilderFactory::getExtensionFunctionAddress(const std::string &fu } static SharingFactory::RegisterSharing vaSharing; -} +} // namespace OCLRT #endif diff --git a/unit_tests/helpers/base_object_tests.cpp b/unit_tests/helpers/base_object_tests.cpp index fe59f5d661..be09102abd 100644 --- a/unit_tests/helpers/base_object_tests.cpp +++ b/unit_tests/helpers/base_object_tests.cpp @@ -226,8 +226,6 @@ TYPED_TEST(BaseObjectTests, commonRuntimeExpectsDispatchTableAtFirstPointerInObj EXPECT_EQ(nullptr, genericObject->dispatch.crtDispatch->placeholder12); EXPECT_EQ(nullptr, genericObject->dispatch.crtDispatch->placeholder13); - EXPECT_EQ(nullptr, genericObject->dispatch.crtDispatch->placeholder15); - EXPECT_EQ(nullptr, genericObject->dispatch.crtDispatch->placeholder18); EXPECT_EQ(nullptr, genericObject->dispatch.crtDispatch->placeholder19); EXPECT_EQ(nullptr, genericObject->dispatch.crtDispatch->placeholder20); diff --git a/unit_tests/sharings/va/cl_get_extension_function_address_tests.cpp b/unit_tests/sharings/va/cl_get_extension_function_address_tests.cpp index b23abd1cd3..7333a2f481 100644 --- a/unit_tests/sharings/va/cl_get_extension_function_address_tests.cpp +++ b/unit_tests/sharings/va/cl_get_extension_function_address_tests.cpp @@ -42,4 +42,9 @@ TEST_F(clGetExtensionFunctionAddressTests, clEnqueueReleaseVA_APIMediaSurfacesIN auto retVal = clGetExtensionFunctionAddress("clEnqueueReleaseVA_APIMediaSurfacesINTEL"); EXPECT_EQ(retVal, reinterpret_cast(clEnqueueReleaseVA_APIMediaSurfacesINTEL)); } + +TEST_F(clGetExtensionFunctionAddressTests, clGetDeviceIDsFromVA_APIMediaAdapterINTEL) { + auto retVal = clGetExtensionFunctionAddress("clGetDeviceIDsFromVA_APIMediaAdapterINTEL"); + EXPECT_EQ(retVal, reinterpret_cast(clGetDeviceIDsFromVA_APIMediaAdapterINTEL)); +} } // namespace ULT diff --git a/unit_tests/sharings/va/va_base_object_tests.cpp b/unit_tests/sharings/va/va_base_object_tests.cpp index e5ef9bec87..6e9f5b2f22 100644 --- a/unit_tests/sharings/va/va_base_object_tests.cpp +++ b/unit_tests/sharings/va/va_base_object_tests.cpp @@ -71,5 +71,8 @@ TYPED_TEST(VABaseObjectTests, commonRuntimeExpectsDispatchTableAtFirstPointerInO EXPECT_EQ(reinterpret_cast(clEnqueueReleaseVA_APIMediaSurfacesINTEL), genericObject->dispatch.crtDispatch->clEnqueueReleaseVA_APIMediaSurfacesINTEL); + + EXPECT_EQ(reinterpret_cast(clGetDeviceIDsFromVA_APIMediaAdapterINTEL), + genericObject->dispatch.crtDispatch->clGetDeviceIDsFromVA_APIMediaAdapterINTEL); } } // namespace OCLRT diff --git a/unit_tests/sharings/va/va_sharing_enable_tests.cpp b/unit_tests/sharings/va/va_sharing_enable_tests.cpp index bd22f95c4e..08cc8a73ab 100644 --- a/unit_tests/sharings/va/va_sharing_enable_tests.cpp +++ b/unit_tests/sharings/va/va_sharing_enable_tests.cpp @@ -96,10 +96,12 @@ TEST_F(VaSharingEnablerTests, givenVaFactoryWhenAskedThenGlobalIcdIsConfigured) crtGlobalDispatchTable.clCreateFromVA_APIMediaSurfaceINTEL = nullptr; crtGlobalDispatchTable.clEnqueueReleaseVA_APIMediaSurfacesINTEL = nullptr; crtGlobalDispatchTable.clEnqueueAcquireVA_APIMediaSurfacesINTEL = nullptr; + crtGlobalDispatchTable.clGetDeviceIDsFromVA_APIMediaAdapterINTEL = nullptr; factory->fillGlobalDispatchTable(); EXPECT_NE(nullptr, crtGlobalDispatchTable.clCreateFromVA_APIMediaSurfaceINTEL); EXPECT_NE(nullptr, crtGlobalDispatchTable.clEnqueueAcquireVA_APIMediaSurfacesINTEL); EXPECT_NE(nullptr, crtGlobalDispatchTable.clEnqueueAcquireVA_APIMediaSurfacesINTEL); + EXPECT_NE(nullptr, crtGlobalDispatchTable.clGetDeviceIDsFromVA_APIMediaAdapterINTEL); } TEST_F(VaSharingEnablerTests, givenVaFactoryWhenAskedThenBuilderIsCreated) { diff --git a/unit_tests/sharings/va/va_sharing_tests.cpp b/unit_tests/sharings/va/va_sharing_tests.cpp index 7398dfc592..392606b2cf 100644 --- a/unit_tests/sharings/va/va_sharing_tests.cpp +++ b/unit_tests/sharings/va/va_sharing_tests.cpp @@ -22,18 +22,21 @@ #include "unit_tests/libult/ult_command_stream_receiver.h" #include "runtime/device/device.h" +#include "runtime/platform/platform.h" #include "runtime/sharings/va/va_sharing.h" #include "unit_tests/mocks/mock_context.h" #include "unit_tests/sharings/va/mock_va_sharing.h" +#include "unit_tests/fixtures/platform_fixture.h" #include "runtime/sharings/va/va_surface.h" #include "runtime/api/api.h" #include "gtest/gtest.h" using namespace OCLRT; -class VaSharingTests : public ::testing::Test { +class VaSharingTests : public ::testing::Test, public PlatformFixture { public: void SetUp() override { + PlatformFixture::SetUp(numPlatformDevices, platformDevices); vaSharing = new MockVaSharing; context.setSharingFunctions(&vaSharing->m_sharingFunctions); vaSharing->updateAcquiredHandle(sharingHandle); @@ -47,6 +50,7 @@ class VaSharingTests : public ::testing::Test { } context.releaseSharingFunctions(SharingType::VA_SHARING); delete vaSharing; + PlatformFixture::TearDown(); } void updateAcquiredHandle(unsigned int handle) { @@ -398,3 +402,26 @@ TEST_F(VaSharingTests, givenContextWhenEmptySharingTableEmptyThenReturnsNullptr) VASharingFunctions *sharingF = context.getSharing(); EXPECT_EQ(sharingF, nullptr); } + +TEST_F(VaSharingTests, givenValidPlatformWhenGetDeviceIdsFromVaApiMediaAdapterCalledThenReturnFirstDevice) { + cl_device_id devices = 0; + cl_uint numDevices = 0; + + cl_platform_id platformId = this->pPlatform; + + auto errCode = clGetDeviceIDsFromVA_APIMediaAdapterINTEL(platformId, 0u, nullptr, 0u, 1, &devices, &numDevices); + EXPECT_EQ(CL_SUCCESS, errCode); + EXPECT_EQ(1u, numDevices); + EXPECT_NE(nullptr, platform()->getDevice(0)); + EXPECT_EQ(platform()->getDevice(0), devices); +} + +TEST_F(VaSharingTests, givenInValidPlatformWhenGetDeviceIdsFromVaApiMediaAdapterCalledThenReturnFirstDevice) { + cl_device_id devices = 0; + cl_uint numDevices = 0; + + auto errCode = clGetDeviceIDsFromVA_APIMediaAdapterINTEL(nullptr, 0u, nullptr, 0u, 1, &devices, &numDevices); + EXPECT_EQ(CL_INVALID_PLATFORM, errCode); + EXPECT_EQ(0u, numDevices); + EXPECT_EQ(0u, devices); +}