Skip to content

Commit 6e07281

Browse files
Don't allow for creating context with multiple root devices
Related-To: NEO-3691 Change-Id: Ica7ec1681b948ff8f9f69eeb1e11cdee64f57e50 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent aefd972 commit 6e07281

File tree

6 files changed

+43
-21
lines changed

6 files changed

+43
-21
lines changed

opencl/source/api/api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ cl_context CL_API_CALL clCreateContextFromType(const cl_context_properties *prop
428428
retVal = clGetDeviceIDs(nullptr, deviceType, numDevices, supportedDevs.begin(), nullptr);
429429
DEBUG_BREAK_IF(retVal != CL_SUCCESS);
430430

431-
ClDeviceVector allDevs(supportedDevs.begin(), numDevices);
431+
ClDeviceVector allDevs(supportedDevs.begin(), std::min(numDevices, 1u));
432432
pContext = Context::create<Context>(properties, allDevs, funcNotify, userData, retVal);
433433
if (pContext != nullptr) {
434434
gtpinNotifyContextCreate((cl_context)pContext);

opencl/source/context/context.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,18 @@ bool Context::createImpl(const cl_context_properties *properties,
172172
}
173173

174174
this->driverDiagnostics = driverDiagnostics.release();
175+
if (inputDevices.size() > 1) {
176+
auto rootDeviceIndex = inputDevices[0]->getRootDeviceIndex();
177+
for (const auto &device : inputDevices) {
178+
if (device->getRootDeviceIndex() != rootDeviceIndex) {
179+
DEBUG_BREAK_IF("No support for context with multiple root devices");
180+
errcodeRet = CL_OUT_OF_HOST_MEMORY;
181+
return false;
182+
}
183+
}
184+
}
175185
this->devices = inputDevices;
176186

177-
// We currently assume each device uses the same MemoryManager
178187
if (devices.size() > 0) {
179188
auto device = this->getDevice(0);
180189
this->memoryManager = device->getMemoryManager();

opencl/test/unit_test/api/cl_create_context_from_type_tests.inl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void CL_CALLBACK contextCallBack(const char *, const void *,
2626
size_t, void *) {
2727
}
2828

29-
TEST_F(clCreateContextFromTypeTests, GivenOnlyGpuDeviceTypeAndReturnValueWhenCreatingContextFromTypeThenCallSucceeds) {
29+
TEST_F(clCreateContextFromTypeTests, GivenOnlyGpuDeviceTypeAndReturnValueWhenCreatingContextFromTypeThenContextWithSingleDeviceIsCreated) {
3030
auto context =
3131
clCreateContextFromType(nullptr, CL_DEVICE_TYPE_GPU, nullptr, nullptr, &retVal);
3232

@@ -35,6 +35,9 @@ TEST_F(clCreateContextFromTypeTests, GivenOnlyGpuDeviceTypeAndReturnValueWhenCre
3535
EXPECT_NE(nullptr, context->dispatch.icdDispatch);
3636
EXPECT_NE(nullptr, context->dispatch.crtDispatch);
3737

38+
auto pContext = castToObject<Context>(context);
39+
EXPECT_EQ(1u, pContext->getNumDevices());
40+
3841
retVal = clReleaseContext(context);
3942
ASSERT_EQ(CL_SUCCESS, retVal);
4043
}

opencl/test/unit_test/api/cl_create_context_tests.inl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ TEST_F(clCreateContextTests, nullUserData) {
8282
EXPECT_EQ(CL_SUCCESS, retVal);
8383
}
8484

85+
TEST_F(clCreateContextTests, givenMultipleRootDevicesWhenCreateContextThenOutOrHostMemoryErrorIsReturned) {
86+
auto firstDeviceRootDeviceIndex = castToObject<ClDevice>(devices[testedRootDeviceIndex])->getRootDeviceIndex();
87+
auto secondDeviceRootDeviceIndex = castToObject<ClDevice>(devices[testedRootDeviceIndex + 1])->getRootDeviceIndex();
88+
EXPECT_NE(firstDeviceRootDeviceIndex, secondDeviceRootDeviceIndex);
89+
auto context = clCreateContext(nullptr, 2u, &devices[testedRootDeviceIndex], eventCallBack, nullptr, &retVal);
90+
EXPECT_EQ(nullptr, context);
91+
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
92+
}
93+
8594
TEST_F(clCreateContextTests, givenInvalidContextCreationPropertiesThenContextCreationFails) {
8695
cl_context_properties invalidProperties[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties) nullptr, 0};
8796
auto context = clCreateContext(invalidProperties, 1u, &testedClDevice, nullptr, nullptr, &retVal);

opencl/test/unit_test/api/cl_get_context_info_tests.inl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,18 @@ TEST_F(clGetContextInfoTests, GivenContextWithSingleDeviceAndContextDevicesParam
4444
}
4545

4646
TEST_F(clGetContextInfoTests, GivenContextWithMultipleDevicesAndContextDevicesParamWhenGettingContextInfoThenListOfDevicesContainsAllDevices) {
47-
auto devicesReturned = new cl_device_id[this->num_devices - 1];
48-
cl_uint numDevices = this->num_devices - 1;
47+
cl_uint numDevices = 2u;
48+
auto inputDevices = std::make_unique<cl_device_id[]>(numDevices);
49+
auto outputDevices = std::make_unique<cl_device_id[]>(numDevices);
50+
51+
for (auto i = 0u; i < numDevices; i++) {
52+
inputDevices[i] = testedClDevice;
53+
}
4954

5055
auto context = clCreateContext(
5156
nullptr,
52-
this->num_devices - 1,
53-
this->devices + 1,
57+
numDevices,
58+
inputDevices.get(),
5459
nullptr,
5560
nullptr,
5661
&retVal);
@@ -61,16 +66,15 @@ TEST_F(clGetContextInfoTests, GivenContextWithMultipleDevicesAndContextDevicesPa
6166
context,
6267
CL_CONTEXT_DEVICES,
6368
numDevices * sizeof(cl_device_id),
64-
devicesReturned,
69+
outputDevices.get(),
6570
nullptr);
6671

6772
ASSERT_EQ(CL_SUCCESS, retVal);
68-
for (size_t deviceOrdinal = 0; deviceOrdinal < this->num_devices - 1; ++deviceOrdinal) {
69-
EXPECT_EQ(this->devices[deviceOrdinal + 1], devicesReturned[deviceOrdinal]);
73+
for (size_t deviceOrdinal = 0; deviceOrdinal < numDevices; ++deviceOrdinal) {
74+
EXPECT_EQ(inputDevices[deviceOrdinal], outputDevices[deviceOrdinal]);
7075
}
7176

7277
clReleaseContext(context);
73-
delete[] devicesReturned;
7478
}
7579

7680
TEST(clGetContextInfo, GivenNullContextWhenGettingContextInfoThenInvalidContextErrorIsReturned) {

opencl/test/unit_test/context/context_tests.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,23 +334,20 @@ TEST(Context, whenCreateContextThenSpecialQueueUsesInternalEngine) {
334334

335335
TEST(MultiDeviceContextTest, givenContextWithMultipleDevicesWhenGettingTotalNumberOfDevicesThenNumberOfAllAvailableDevicesIsReturned) {
336336
DebugManagerStateRestore restorer;
337-
const uint32_t numDevices = 2u;
337+
const uint32_t numRootDevices = 1u;
338338
const uint32_t numSubDevices = 3u;
339-
DebugManager.flags.CreateMultipleRootDevices.set(numDevices);
340339
DebugManager.flags.CreateMultipleSubDevices.set(numSubDevices);
341340
initPlatform();
342-
auto device0 = platform()->getClDevice(0);
343-
auto device1 = platform()->getClDevice(1);
344-
cl_device_id clDevices[2]{device0, device1};
341+
auto device = platform()->getClDevice(0);
345342

346-
ClDeviceVector deviceVector(clDevices, 2);
343+
cl_device_id clDevice = device;
344+
ClDeviceVector deviceVector(&clDevice, numRootDevices);
347345
cl_int retVal = CL_OUT_OF_HOST_MEMORY;
348346
auto context = std::unique_ptr<Context>(Context::create<Context>(nullptr, deviceVector, nullptr, nullptr, retVal));
349347
EXPECT_EQ(CL_SUCCESS, retVal);
350-
EXPECT_EQ(numSubDevices, device0->getNumAvailableDevices());
351-
EXPECT_EQ(numSubDevices, device1->getNumAvailableDevices());
352-
EXPECT_EQ(numDevices, context->getNumDevices());
353-
EXPECT_EQ(numDevices * numSubDevices, context->getTotalNumDevices());
348+
EXPECT_EQ(numSubDevices, device->getNumAvailableDevices());
349+
EXPECT_EQ(numRootDevices, context->getNumDevices());
350+
EXPECT_EQ(numRootDevices * numSubDevices, context->getTotalNumDevices());
354351
}
355352

356353
class ContextWithAsyncDeleterTest : public ::testing::WithParamInterface<bool>,

0 commit comments

Comments
 (0)