Skip to content

Commit 3bcc073

Browse files
Respect EnableMultiRootDeviceContexts when creating context from type
Related-To: NEO-3691 Change-Id: Ib61ddfe1e5df5ed7611ed785fadd305a49ef204a Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 2eea76e commit 3bcc073

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

opencl/source/api/api.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,14 @@ cl_context CL_API_CALL clCreateContextFromType(const cl_context_properties *prop
427427
retVal = clGetDeviceIDs(nullptr, deviceType, numDevices, supportedDevs.begin(), nullptr);
428428
DEBUG_BREAK_IF(retVal != CL_SUCCESS);
429429

430-
ClDeviceVector allDevs(supportedDevs.begin(), std::min(numDevices, 1u));
431-
pContext = Context::create<Context>(properties, allDevs, funcNotify, userData, retVal);
430+
if (!DebugManager.flags.EnableMultiRootDeviceContexts.get()) {
431+
numDevices = 1u;
432+
}
433+
434+
ClDeviceVector deviceVector(supportedDevs.begin(), numDevices);
435+
pContext = Context::create<Context>(properties, deviceVector, funcNotify, userData, retVal);
432436
if (pContext != nullptr) {
433-
gtpinNotifyContextCreate((cl_context)pContext);
437+
gtpinNotifyContextCreate(pContext);
434438
}
435439
} while (false);
436440

opencl/test/unit_test/api/cl_create_context_from_type_tests.inl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,51 @@ TEST_F(clCreateContextFromTypeTests, GivenNonDefaultPlatformWithInvalidIcdDispat
100100
EXPECT_EQ(nullptr, clContext);
101101
}
102102

103+
TEST(clCreateContextFromTypeTest, GivenPlatformWithMultipleDevicesAndMultiRootDeviceContextsAreEnabledWhenCreatingContextFromTypeThenContextContainsAllDevices) {
104+
DebugManagerStateRestore restorer;
105+
DebugManager.flags.CreateMultipleRootDevices.set(2);
106+
DebugManager.flags.EnableMultiRootDeviceContexts.set(true);
107+
108+
initPlatform();
109+
110+
cl_int retVal = CL_INVALID_CONTEXT;
111+
112+
auto context =
113+
clCreateContextFromType(nullptr, CL_DEVICE_TYPE_GPU, nullptr, nullptr, &retVal);
114+
115+
ASSERT_EQ(CL_SUCCESS, retVal);
116+
ASSERT_NE(nullptr, context);
117+
118+
auto pContext = castToObject<Context>(context);
119+
EXPECT_EQ(2u, pContext->getNumDevices());
120+
EXPECT_EQ(platform()->getClDevice(0), pContext->getDevice(0));
121+
EXPECT_EQ(platform()->getClDevice(1), pContext->getDevice(1));
122+
123+
retVal = clReleaseContext(context);
124+
ASSERT_EQ(CL_SUCCESS, retVal);
125+
}
126+
127+
TEST(clCreateContextFromTypeTest, GivenPlatformWithMultipleDevicesAndMultiRootDeviceContextsAreDisabledWhenCreatingContextFromTypeThenContextContainsOnlyOneDevice) {
128+
DebugManagerStateRestore restorer;
129+
DebugManager.flags.CreateMultipleRootDevices.set(2);
130+
DebugManager.flags.EnableMultiRootDeviceContexts.set(false);
131+
132+
initPlatform();
133+
134+
cl_int retVal = CL_INVALID_CONTEXT;
135+
136+
auto context =
137+
clCreateContextFromType(nullptr, CL_DEVICE_TYPE_GPU, nullptr, nullptr, &retVal);
138+
139+
ASSERT_EQ(CL_SUCCESS, retVal);
140+
ASSERT_NE(nullptr, context);
141+
142+
auto pContext = castToObject<Context>(context);
143+
EXPECT_EQ(1u, pContext->getNumDevices());
144+
EXPECT_EQ(platform()->getClDevice(0), pContext->getDevice(0));
145+
146+
retVal = clReleaseContext(context);
147+
ASSERT_EQ(CL_SUCCESS, retVal);
148+
}
149+
103150
} // namespace ULT

0 commit comments

Comments
 (0)