Skip to content

Commit fee5135

Browse files
kgibalaCompute-Runtime-Automation
authored andcommitted
Add function to get maxRootDeviceIndex & set of rootDeviceIndices
Add to context: - getRootDeviceIndices - getMaxRootDeviceIndex Related-To: NEO-4589 Change-Id: I68a2162eea3d566c2ee99714d45253dfa35ec0cd Signed-off-by: Krzysztof Gibala <[email protected]>
1 parent 6472d7b commit fee5135

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

opencl/source/context/context.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ cl_int Context::setDestructorCallback(void(CL_CALLBACK *funcNotify)(cl_context,
8484
return CL_SUCCESS;
8585
}
8686

87+
const std::set<uint32_t> &Context::getRootDeviceIndices() const {
88+
return rootDeviceIndices;
89+
}
90+
91+
uint32_t Context::getMaxRootDeviceIndex() const {
92+
return maxRootDeviceIndex;
93+
}
94+
8795
DeviceQueue *Context::getDefaultDeviceQueue() {
8896
return defaultDeviceQueue;
8997
}
@@ -178,22 +186,21 @@ bool Context::createImpl(const cl_context_properties *properties,
178186
return false;
179187
}
180188

189+
for (const auto &device : inputDevices) {
190+
rootDeviceIndices.insert(device->getRootDeviceIndex());
191+
}
192+
181193
this->driverDiagnostics = driverDiagnostics.release();
182-
if (inputDevices.size() > 1) {
183-
if (!DebugManager.flags.EnableMultiRootDeviceContexts.get()) {
184-
auto rootDeviceIndex = inputDevices[0]->getRootDeviceIndex();
185-
for (const auto &device : inputDevices) {
186-
if (device->getRootDeviceIndex() != rootDeviceIndex) {
187-
DEBUG_BREAK_IF("No support for context with multiple root devices");
188-
errcodeRet = CL_OUT_OF_HOST_MEMORY;
189-
return false;
190-
}
191-
}
192-
}
194+
if (rootDeviceIndices.size() > 1 && !DebugManager.flags.EnableMultiRootDeviceContexts.get()) {
195+
DEBUG_BREAK_IF("No support for context with multiple root devices");
196+
errcodeRet = CL_OUT_OF_HOST_MEMORY;
197+
return false;
193198
}
199+
194200
this->devices = inputDevices;
195201

196202
if (devices.size() > 0) {
203+
maxRootDeviceIndex = *std::max_element(rootDeviceIndices.begin(), rootDeviceIndices.end(), std::less<uint32_t const>());
197204
auto device = this->getDevice(0);
198205
this->memoryManager = device->getMemoryManager();
199206
if (memoryManager->isAsyncDeleterEnabled()) {

opencl/source/context/context.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "opencl/source/helpers/destructor_callback.h"
1818

1919
#include <list>
20+
#include <set>
2021

2122
namespace NEO {
2223

@@ -88,6 +89,10 @@ class Context : public BaseObject<_cl_context> {
8889
return svmAllocsManager;
8990
}
9091

92+
const std::set<uint32_t> &getRootDeviceIndices() const;
93+
94+
uint32_t getMaxRootDeviceIndex() const;
95+
9196
DeviceQueue *getDefaultDeviceQueue();
9297
void setDefaultDeviceQueue(DeviceQueue *queue);
9398

@@ -155,6 +160,9 @@ class Context : public BaseObject<_cl_context> {
155160
cl_int processExtraProperties(cl_context_properties propertyType, cl_context_properties propertyValue);
156161
void setupContextType();
157162

163+
std::set<uint32_t> rootDeviceIndices = {};
164+
uint32_t maxRootDeviceIndex = std::numeric_limits<uint32_t>::max();
165+
158166
const cl_context_properties *properties = nullptr;
159167
size_t numProperties = 0u;
160168
void(CL_CALLBACK *contextCallback)(const char *, const void *, size_t, void *) = nullptr;

opencl/test/unit_test/api/cl_create_context_tests.inl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,39 @@ TEST_F(clCreateContextTests, givenEnabledMultipleRootDeviceSupportWhenCreateCont
9999
clReleaseContext(context);
100100
}
101101

102+
TEST_F(clCreateContextTests, givenMultipleRootDevicesWhenCreateContextThenRootDeviceIndicesSetIsFilled) {
103+
UltClDeviceFactory deviceFactory{3, 2};
104+
DebugManager.flags.EnableMultiRootDeviceContexts.set(true);
105+
cl_device_id devices[] = {deviceFactory.rootDevices[0], deviceFactory.rootDevices[1], deviceFactory.rootDevices[2]};
106+
auto context = clCreateContext(nullptr, 3u, devices, eventCallBack, nullptr, &retVal);
107+
EXPECT_NE(nullptr, context);
108+
EXPECT_EQ(CL_SUCCESS, retVal);
109+
110+
auto pContext = castToObject<Context>(context);
111+
auto rootDeviceIndices = pContext->getRootDeviceIndices();
112+
113+
for (auto numDevice = 0u; numDevice < pContext->getNumDevices(); numDevice++) {
114+
auto rootDeviceIndex = rootDeviceIndices.find(pContext->getDevice(numDevice)->getRootDeviceIndex());
115+
EXPECT_EQ(*rootDeviceIndex, pContext->getDevice(numDevice)->getRootDeviceIndex());
116+
}
117+
118+
clReleaseContext(context);
119+
}
120+
121+
TEST_F(clCreateContextTests, givenMultipleRootDevicesWhenCreateContextThenMaxRootDeviceIndexIsProperlyFilled) {
122+
UltClDeviceFactory deviceFactory{3, 0};
123+
DebugManager.flags.EnableMultiRootDeviceContexts.set(true);
124+
cl_device_id devices[] = {deviceFactory.rootDevices[0], deviceFactory.rootDevices[2]};
125+
auto context = clCreateContext(nullptr, 2u, devices, eventCallBack, nullptr, &retVal);
126+
EXPECT_NE(nullptr, context);
127+
EXPECT_EQ(CL_SUCCESS, retVal);
128+
129+
auto pContext = castToObject<Context>(context);
130+
EXPECT_EQ(2u, pContext->getMaxRootDeviceIndex());
131+
132+
clReleaseContext(context);
133+
}
134+
102135
TEST_F(clCreateContextTests, givenInvalidContextCreationPropertiesThenContextCreationFails) {
103136
cl_context_properties invalidProperties[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties) nullptr, 0};
104137
auto context = clCreateContext(invalidProperties, 1u, &testedClDevice, nullptr, nullptr, &retVal);

0 commit comments

Comments
 (0)