From ca459b8d596ad5330e7ae2bf8e78c37180ab0109 Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Thu, 28 May 2020 15:11:50 +0200 Subject: [PATCH] Add new clGetPlatformInfo queries Add support for following queries: - CL_PLATFORM_NUMERIC_VERSION - CL_PLATFORM_EXTENSIONS_WITH_VERSION Related-To: NEO-4368 Change-Id: I88a1878b786d424a718f1b3351a8af26cf69479f Signed-off-by: Filip Hazubski --- opencl/source/platform/platform.cpp | 22 ++++++++-- opencl/source/platform/platform_info.h | 5 +++ .../api/cl_get_platform_info_tests.inl | 44 ++++++++++++++++--- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/opencl/source/platform/platform.cpp b/opencl/source/platform/platform.cpp index 4bdb26546f..96fb2a0496 100644 --- a/opencl/source/platform/platform.cpp +++ b/opencl/source/platform/platform.cpp @@ -60,15 +60,27 @@ cl_int Platform::getInfo(cl_platform_info paramName, auto retVal = CL_INVALID_VALUE; const std::string *param = nullptr; size_t paramSize = GetInfo::invalidSourceSize; - uint64_t pVal = 0; auto getInfoStatus = GetInfoStatus::INVALID_VALUE; switch (paramName) { - case CL_PLATFORM_HOST_TIMER_RESOLUTION: - pVal = static_cast(this->clDevices[0]->getPlatformHostTimerResolution()); + case CL_PLATFORM_HOST_TIMER_RESOLUTION: { + auto pVal = static_cast(this->clDevices[0]->getPlatformHostTimerResolution()); paramSize = sizeof(uint64_t); getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, &pVal, paramSize); break; + } + case CL_PLATFORM_NUMERIC_VERSION: { + auto pVal = platformInfo->numericVersion; + paramSize = sizeof(pVal); + getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, &pVal, paramSize); + break; + } + case CL_PLATFORM_EXTENSIONS_WITH_VERSION: { + auto pVal = platformInfo->extensionsWithVersion.data(); + paramSize = platformInfo->extensionsWithVersion.size() * sizeof(cl_name_version); + getInfoStatus = GetInfo::getInfo(paramValue, paramValueSize, pVal, paramSize); + break; + } case CL_PLATFORM_PROFILE: param = &platformInfo->profile; break; @@ -126,16 +138,20 @@ bool Platform::initialize(std::vector> devices) { this->clDevices.push_back(pClDevice); this->platformInfo->extensions = pClDevice->getDeviceInfo().deviceExtensions; + this->platformInfo->extensionsWithVersion = pClDevice->getDeviceInfo().extensionsWithVersion; switch (pClDevice->getEnabledClVersion()) { case 30: this->platformInfo->version = "OpenCL 3.0 "; + this->platformInfo->numericVersion = CL_MAKE_VERSION(3, 0, 0); break; case 21: this->platformInfo->version = "OpenCL 2.1 "; + this->platformInfo->numericVersion = CL_MAKE_VERSION(2, 1, 0); break; default: this->platformInfo->version = "OpenCL 1.2 "; + this->platformInfo->numericVersion = CL_MAKE_VERSION(1, 2, 0); break; } } diff --git a/opencl/source/platform/platform_info.h b/opencl/source/platform/platform_info.h index b5f9f1ae0d..6ca53c2f3b 100644 --- a/opencl/source/platform/platform_info.h +++ b/opencl/source/platform/platform_info.h @@ -6,13 +6,18 @@ */ #pragma once +#include "CL/cl.h" + #include +#include struct PlatformInfo { + std::vector extensionsWithVersion; std::string profile = "FULL_PROFILE"; std::string version = ""; std::string name = "Intel(R) OpenCL HD Graphics"; std::string vendor = "Intel(R) Corporation"; std::string extensions; std::string icdSuffixKhr = "INTEL"; + cl_version numericVersion = 0; }; diff --git a/opencl/test/unit_test/api/cl_get_platform_info_tests.inl b/opencl/test/unit_test/api/cl_get_platform_info_tests.inl index c576670b57..46c274abc5 100644 --- a/opencl/test/unit_test/api/cl_get_platform_info_tests.inl +++ b/opencl/test/unit_test/api/cl_get_platform_info_tests.inl @@ -61,20 +61,33 @@ class clGetPlatformInfoParameterizedTests : public clGetPlatformInfoTests, TEST_P(clGetPlatformInfoParameterizedTests, GivenClPlatformVersionWhenGettingPlatformInfoStringThenCorrectOpenClVersionIsReturned) { paramValue = getPlatformInfoString(pPlatform, CL_PLATFORM_VERSION); - std::string deviceVer; + + cl_version platformNumericVersion = 0; + auto retVal = clGetPlatformInfo(pPlatform, CL_PLATFORM_NUMERIC_VERSION, + sizeof(platformNumericVersion), &platformNumericVersion, &retSize); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(sizeof(cl_version), retSize); + + std::string expectedPlatformVersion; + cl_version expectedNumericPlatformVersion; switch (GetParam()) { case 30: - deviceVer = "OpenCL 3.0 "; + expectedPlatformVersion = "OpenCL 3.0 "; + expectedNumericPlatformVersion = CL_MAKE_VERSION(3, 0, 0); break; case 21: - deviceVer = "OpenCL 2.1 "; + expectedPlatformVersion = "OpenCL 2.1 "; + expectedNumericPlatformVersion = CL_MAKE_VERSION(2, 1, 0); break; case 12: default: - deviceVer = "OpenCL 1.2 "; + expectedPlatformVersion = "OpenCL 1.2 "; + expectedNumericPlatformVersion = CL_MAKE_VERSION(1, 2, 0); break; } - EXPECT_STREQ(paramValue, deviceVer.c_str()); + + EXPECT_STREQ(expectedPlatformVersion.c_str(), paramValue); + EXPECT_EQ(expectedNumericPlatformVersion, platformNumericVersion); } INSTANTIATE_TEST_CASE_P(OCLVersions, @@ -176,6 +189,27 @@ TEST_F(clGetPlatformInfoTests, GivenDeviceWhenGettingIcdDispatchTableThenDeviceA } } +TEST_F(clGetPlatformInfoTests, WhenCheckingPlatformExtensionsWithVersionThenTheyMatchPlatformExtensions) { + + auto retVal = clGetPlatformInfo(pPlatform, CL_PLATFORM_EXTENSIONS_WITH_VERSION, 0, nullptr, &retSize); + EXPECT_EQ(CL_SUCCESS, retVal); + + size_t extensionsCount = retSize / sizeof(cl_name_version); + auto platformExtensionsWithVersion = std::make_unique(extensionsCount); + retVal = clGetPlatformInfo(pPlatform, CL_PLATFORM_EXTENSIONS_WITH_VERSION, + retSize, platformExtensionsWithVersion.get(), nullptr); + EXPECT_EQ(CL_SUCCESS, retVal); + + std::string allExtensions; + for (size_t i = 0; i < extensionsCount; i++) { + EXPECT_EQ(CL_MAKE_VERSION(1u, 0u, 0u), platformExtensionsWithVersion[i].version); + allExtensions += platformExtensionsWithVersion[i].name; + allExtensions += " "; + } + + EXPECT_STREQ(pPlatform->getPlatformInfo().extensions.c_str(), allExtensions.c_str()); +} + class GetPlatformInfoTests : public PlatformFixture, public testing::TestWithParam { using PlatformFixture::SetUp;