diff --git a/runtime/api/api.cpp b/runtime/api/api.cpp index 795c66d3ee..4d9acb3cb9 100644 --- a/runtime/api/api.cpp +++ b/runtime/api/api.cpp @@ -6,6 +6,7 @@ */ #include "config.h" +#include #include "api.h" #include "CL/cl.h" #include "runtime/accelerators/intel_motion_estimation.h" @@ -199,6 +200,10 @@ cl_int CL_API_CALL clGetDeviceIDs(cl_platform_id platform, } } + if (DebugManager.flags.LimitAmountOfReturnedDevices.get()) { + retNum = std::min(static_cast(DebugManager.flags.LimitAmountOfReturnedDevices.get()), retNum); + } + if (numDevices) { *numDevices = retNum; } diff --git a/runtime/os_interface/DebugVariables_base.inl b/runtime/os_interface/DebugVariables_base.inl index e0a9f59e1f..eb0ded4e52 100644 --- a/runtime/os_interface/DebugVariables_base.inl +++ b/runtime/os_interface/DebugVariables_base.inl @@ -85,6 +85,7 @@ DECLARE_DEBUG_VARIABLE(bool, AddClGlSharing, false, "Add cl-gl extension") DECLARE_DEBUG_VARIABLE(bool, EnablePassInlineData, false, "Enable passing of inline data") DECLARE_DEBUG_VARIABLE(int32_t, EnableStatelessToStatefulBufferOffsetOpt, -1, "-1: dont override, 0: disable, 1: enable, Enables buffer-offset improvement of the stateless to stateful optimization") DECLARE_DEBUG_VARIABLE(int32_t, CreateMultipleDevices, 0, "0: default - disable, 1+: Driver will create multiple (N) devices during initialization.") +DECLARE_DEBUG_VARIABLE(int32_t, LimitAmountOfReturnedDevices, 0, "0: default - disable, 1+: Driver will limit the number of devices returned from clGetDeviceIds to N.") DECLARE_DEBUG_VARIABLE(int32_t, Enable64kbpages, -1, "-1: default behaviour, 0 Disables, 1 Enables support for 64KB pages for driver allocated fine grain svm buffers") DECLARE_DEBUG_VARIABLE(int32_t, OverrideEnableKmdNotify, -1, "-1: dont override, 0: disable, 1: enable") DECLARE_DEBUG_VARIABLE(int32_t, OverrideKmdNotifyDelayMicroseconds, -1, "-1: dont override, 0: infinite timeout, >0: timeout in microseconds") diff --git a/unit_tests/api/cl_get_device_ids_tests.inl b/unit_tests/api/cl_get_device_ids_tests.inl index 41f80dc0a5..ebad3d523a 100644 --- a/unit_tests/api/cl_get_device_ids_tests.inl +++ b/unit_tests/api/cl_get_device_ids_tests.inl @@ -7,6 +7,8 @@ #include "cl_api_tests.h" #include "runtime/platform/platform.h" +#include "unit_tests/helpers/debug_manager_state_restore.h" +#include "unit_tests/helpers/variable_backup.h" using namespace OCLRT; @@ -92,4 +94,24 @@ TEST_F(clGetDeviceIDsTests, cpuDevices) { EXPECT_EQ(CL_DEVICE_NOT_FOUND, retVal); EXPECT_EQ(numDevices, (cl_uint)0); } + } // namespace ULT +namespace OCLRT { +extern bool overrideDeviceWithDefaultHardwareInfo; +extern bool overrideCommandStreamReceiverCreation; + +TEST(MultiDeviceTests, givenCreateMultipleDevicesAndLimitAmountOfReturnedDevicesFlagWhenClGetDeviceIdsIsCalledThenLowerValueIsReturned) { + platformImpl.reset(nullptr); + overrideCommandStreamReceiverCreation = true; + VariableBackup overrideHelper(&overrideDeviceWithDefaultHardwareInfo, false); + DeviceFactoryCleaner cleaner; + DebugManagerStateRestore stateRestore; + DebugManager.flags.CreateMultipleDevices.set(2); + DebugManager.flags.LimitAmountOfReturnedDevices.set(1); + cl_uint numDevices = 0; + + auto retVal = clGetDeviceIDs(nullptr, CL_DEVICE_TYPE_GPU, 0, nullptr, &numDevices); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(1u, numDevices); +} +} // namespace OCLRT diff --git a/unit_tests/test_files/igdrcl.config b/unit_tests/test_files/igdrcl.config index 4c24a7b0ab..ac657aeaa2 100644 --- a/unit_tests/test_files/igdrcl.config +++ b/unit_tests/test_files/igdrcl.config @@ -86,4 +86,5 @@ EnableTimestampPacket = false ReturnRawGpuTimestamps = 0 DoNotRegisterTrimCallback = false AddClGlSharing = 0 -EnablePassInlineData = false \ No newline at end of file +EnablePassInlineData = false +LimitAmountOfReturnedDevices = 0 \ No newline at end of file