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 <filip.hazubski@intel.com>
This commit is contained in:
Filip Hazubski
2020-05-28 15:11:50 +02:00
committed by sys_ocldev
parent cc5fd45b47
commit ca459b8d59
3 changed files with 63 additions and 8 deletions

View File

@@ -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<uint64_t>(this->clDevices[0]->getPlatformHostTimerResolution());
case CL_PLATFORM_HOST_TIMER_RESOLUTION: {
auto pVal = static_cast<uint64_t>(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<std::unique_ptr<Device>> 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;
}
}

View File

@@ -6,13 +6,18 @@
*/
#pragma once
#include "CL/cl.h"
#include <string>
#include <vector>
struct PlatformInfo {
std::vector<cl_name_version> 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;
};

View File

@@ -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<cl_name_version[]>(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<uint32_t /*cl_platform_info*/> {
using PlatformFixture::SetUp;