From 42810f4690ee6d239fb0bc9d5d5423dd3dabb773 Mon Sep 17 00:00:00 2001 From: Andrzej Swierczynski Date: Fri, 10 Apr 2020 14:45:04 +0200 Subject: [PATCH] Return 0 when Program Scope Global Variables are not supported clGetDeviceInfo and clGetProgramBuildInfo may return 0 when Program Scope Global Variables are not supported Related-To: NEO-4368 Change-Id: I2c319c53ffa2e02eeb370775023f5d73219cb39e Signed-off-by: Andrzej Swierczynski --- opencl/source/cl_device/cl_device_caps.cpp | 4 +-- .../source/program/process_device_binary.cpp | 7 ++-- .../device/get_device_info_tests.cpp | 32 +++++++++++++++++++ opencl/test/unit_test/mocks/mock_program.h | 1 - .../test/unit_test/program/program_tests.cpp | 14 ++++++-- 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/opencl/source/cl_device/cl_device_caps.cpp b/opencl/source/cl_device/cl_device_caps.cpp index dc3c087fd4..79ce47005b 100644 --- a/opencl/source/cl_device/cl_device_caps.cpp +++ b/opencl/source/cl_device/cl_device_caps.cpp @@ -303,8 +303,8 @@ void ClDevice::initializeCaps() { } deviceInfo.preemptionSupported = false; - deviceInfo.maxGlobalVariableSize = 64 * KB; - deviceInfo.globalVariablePreferredTotalSize = static_cast(sharedDeviceInfo.maxMemAllocSize); + deviceInfo.maxGlobalVariableSize = enabledClVersion >= 20 ? 64 * KB : 0; + deviceInfo.globalVariablePreferredTotalSize = enabledClVersion >= 20 ? static_cast(sharedDeviceInfo.maxMemAllocSize) : 0; deviceInfo.planarYuvMaxWidth = 16384; deviceInfo.planarYuvMaxHeight = 16352; diff --git a/opencl/source/program/process_device_binary.cpp b/opencl/source/program/process_device_binary.cpp index 24f4dcaee7..cf138d4c28 100644 --- a/opencl/source/program/process_device_binary.cpp +++ b/opencl/source/program/process_device_binary.cpp @@ -180,13 +180,16 @@ cl_int Program::processProgramInfo(ProgramInfo &src) { this->constantSurface = allocateGlobalsSurface(svmAllocsManager, *pDevice, src.globalConstants.size, true, linkerInput.get(), src.globalConstants.initData); } + this->globalVarTotalSize = src.globalVariables.size; + if (src.globalVariables.size != 0) { UNRECOVERABLE_IF(nullptr == pDevice); this->globalSurface = allocateGlobalsSurface(svmAllocsManager, *pDevice, src.globalVariables.size, false, linkerInput.get(), src.globalVariables.initData); + if (pDevice->getSpecializedDevice()->getEnabledClVersion() < 20) { + this->globalVarTotalSize = 0u; + } } - this->globalVarTotalSize = src.globalVariables.size; - for (auto &kernelInfo : this->kernelInfoArray) { cl_int retVal = CL_SUCCESS; if (kernelInfo->heapInfo.pKernelHeader->KernelHeapSize && this->pDevice) { diff --git a/opencl/test/unit_test/device/get_device_info_tests.cpp b/opencl/test/unit_test/device/get_device_info_tests.cpp index f097adff5b..93af74f7a9 100644 --- a/opencl/test/unit_test/device/get_device_info_tests.cpp +++ b/opencl/test/unit_test/device/get_device_info_tests.cpp @@ -478,6 +478,38 @@ TEST(GetDeviceInfo, GivenSimultaneousInteropsWhenGettingDeviceInfoThenCorrectVal EXPECT_TRUE(memcmp(value, &device->simultaneousInterops[0], 4u * sizeof(cl_uint)) == 0); } +TEST(GetDeviceInfo, GivenMaxGlobalVariableSizeWhenGettingDeviceInfoThenCorrectValueIsReturned) { + auto device = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr)); + + size_t value = 0; + size_t size = 0; + + auto retVal = device->getDeviceInfo(CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE, sizeof(size_t), &value, &size); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(sizeof(size_t), size); + if (device->getEnabledClVersion() >= 20) { + EXPECT_EQ(value, 65536u); + } else { + EXPECT_EQ(value, 0u); + } +} + +TEST(GetDeviceInfo, GivenGlobalVariablePreferredTotalSizeWhenGettingDeviceInfoThenCorrectValueIsReturned) { + auto device = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr)); + + size_t value = 0; + size_t size = 0; + + auto retVal = device->getDeviceInfo(CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE, sizeof(size_t), &value, &size); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(sizeof(size_t), size); + if (device->getEnabledClVersion() >= 20) { + EXPECT_EQ(value, static_cast(device->getSharedDeviceInfo().maxMemAllocSize)); + } else { + EXPECT_EQ(value, 0u); + } +} + TEST(GetDeviceInfo, GivenPreferredInteropsWhenGettingDeviceInfoThenCorrectValueIsReturned) { auto device = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr)); diff --git a/opencl/test/unit_test/mocks/mock_program.h b/opencl/test/unit_test/mocks/mock_program.h index cade1945ff..7abc30ea2f 100644 --- a/opencl/test/unit_test/mocks/mock_program.h +++ b/opencl/test/unit_test/mocks/mock_program.h @@ -108,7 +108,6 @@ class MockProgram : public Program { void ClearOptions() { options = ""; } void SetCreatedFromBinary(bool createdFromBin) { isCreatedFromBinary = createdFromBin; } void ClearLog() { buildLog.clear(); } - void SetGlobalVariableTotalSize(size_t globalVarSize) { globalVarTotalSize = globalVarSize; } void SetDevice(Device *pDev) { pDevice = pDev; } void SetIrBinary(char *ptr, bool isSpirv) { diff --git a/opencl/test/unit_test/program/program_tests.cpp b/opencl/test/unit_test/program/program_tests.cpp index 8d1d9a1156..fd42b9ec1f 100644 --- a/opencl/test/unit_test/program/program_tests.cpp +++ b/opencl/test/unit_test/program/program_tests.cpp @@ -550,6 +550,7 @@ TEST_P(ProgramFromBinaryTest, GivenGlobalVariableTotalSizeSetWhenGettingBuildGlo paramValueSize, paramValue, ¶mValueSizeRet); + EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_EQ(paramValueSizeRet, sizeof(globalVarSize)); EXPECT_EQ(globalVarSize, 0u); @@ -557,7 +558,12 @@ TEST_P(ProgramFromBinaryTest, GivenGlobalVariableTotalSizeSetWhenGettingBuildGlo // Set GlobalVariableTotalSize as 1024 CreateProgramFromBinary(pContext, &device, BinaryFileName); MockProgram *p = pProgram; - p->SetGlobalVariableTotalSize(1024u); + ProgramInfo programInfo; + + char constantData[1024] = {}; + programInfo.globalVariables.initData = constantData; + programInfo.globalVariables.size = sizeof(constantData); + p->processProgramInfo(programInfo); // get build info once again retVal = pProgram->getBuildInfo( @@ -568,7 +574,11 @@ TEST_P(ProgramFromBinaryTest, GivenGlobalVariableTotalSizeSetWhenGettingBuildGlo ¶mValueSizeRet); EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_EQ(paramValueSizeRet, sizeof(globalVarSize)); - EXPECT_EQ(globalVarSize, 1024u); + if (castToObject(pClDevice)->getEnabledClVersion() >= 20) { + EXPECT_EQ(globalVarSize, 1024u); + } else { + EXPECT_EQ(globalVarSize, 0u); + } } TEST_P(ProgramFromBinaryTest, givenProgramWhenItIsBeingBuildThenItContainsGraphicsAllocationInKernelInfo) {