Correct validation during creating command queue
check if device is associated with context Related-To: NEO-3691 Change-Id: I7dfe12376bb2bb2c764b471315072a29068a0cb7 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
parent
70d50616d0
commit
a651625473
|
@ -527,6 +527,10 @@ cl_command_queue CL_API_CALL clCreateCommandQueue(cl_context context,
|
|||
if (retVal != CL_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
if (!pContext->isDeviceAssociated(*pDevice)) {
|
||||
retVal = CL_INVALID_DEVICE;
|
||||
break;
|
||||
}
|
||||
|
||||
cl_queue_properties props[] = {
|
||||
CL_QUEUE_PROPERTIES, properties,
|
||||
|
@ -4719,6 +4723,12 @@ cl_command_queue CL_API_CALL clCreateCommandQueueWithProperties(cl_context conte
|
|||
return commandQueue;
|
||||
}
|
||||
|
||||
if (!pContext->isDeviceAssociated(*pDevice)) {
|
||||
err.set(CL_INVALID_DEVICE);
|
||||
TRACING_EXIT(clCreateCommandQueueWithProperties, &commandQueue);
|
||||
return commandQueue;
|
||||
}
|
||||
|
||||
auto minimumCreateDeviceQueueFlags = static_cast<cl_command_queue_properties>(CL_QUEUE_ON_DEVICE |
|
||||
CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE);
|
||||
auto tokenValue = properties ? *properties : 0;
|
||||
|
|
|
@ -376,4 +376,13 @@ SchedulerKernel &Context::getSchedulerKernel() {
|
|||
return *static_cast<SchedulerKernel *>(schedulerBuiltIn->pKernel);
|
||||
}
|
||||
|
||||
bool Context::isDeviceAssociated(const ClDevice &clDevice) const {
|
||||
for (const auto &device : devices) {
|
||||
if (device == &clDevice) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
|
|
@ -141,6 +141,8 @@ class Context : public BaseObject<_cl_context> {
|
|||
|
||||
SchedulerKernel &getSchedulerKernel();
|
||||
|
||||
bool isDeviceAssociated(const ClDevice &clDevice) const;
|
||||
|
||||
protected:
|
||||
Context(void(CL_CALLBACK *pfnNotify)(const char *, const void *, size_t, void *) = nullptr,
|
||||
void *userData = nullptr);
|
||||
|
|
|
@ -36,12 +36,18 @@ TEST_F(clCreateCommandQueueTest, GivenCorrectParametersWhenCreatingCommandQueueT
|
|||
|
||||
TEST_F(clCreateCommandQueueTest, GivenNullContextWhenCreatingCommandQueueThenInvalidContextErrorIsReturned) {
|
||||
clCreateCommandQueue(nullptr, devices[testedRootDeviceIndex], 0, &retVal);
|
||||
ASSERT_EQ(CL_INVALID_CONTEXT, retVal);
|
||||
EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
|
||||
}
|
||||
|
||||
TEST_F(clCreateCommandQueueTest, GivenNullDeviceWhenCreatingCommandQueueThenInvalidDeviceErrorIsReturned) {
|
||||
clCreateCommandQueue(pContext, nullptr, 0, &retVal);
|
||||
ASSERT_EQ(CL_INVALID_DEVICE, retVal);
|
||||
EXPECT_EQ(CL_INVALID_DEVICE, retVal);
|
||||
}
|
||||
|
||||
TEST_F(clCreateCommandQueueTest, GivenDeviceNotAssociatedWithContextWhenCreatingCommandQueueThenInvalidDeviceErrorIsReturned) {
|
||||
EXPECT_NE(devices[0], devices[testedRootDeviceIndex]);
|
||||
clCreateCommandQueue(pContext, devices[0], 0, &retVal);
|
||||
EXPECT_EQ(CL_INVALID_DEVICE, retVal);
|
||||
}
|
||||
|
||||
TEST_F(clCreateCommandQueueTest, GivenInvalidPropertiesWhenCreatingCommandQueueThenInvalidValueErrorIsReturned) {
|
||||
|
|
|
@ -239,6 +239,14 @@ TEST_F(clCreateCommandQueueWithPropertiesApi, GivenNullDeviceWhenCreatingCommand
|
|||
EXPECT_EQ(retVal, CL_INVALID_DEVICE);
|
||||
}
|
||||
|
||||
TEST_F(clCreateCommandQueueWithPropertiesApi, GivenDeviceNotAssociatedWithContextWhenCreatingCommandQueueWithPropertiesThenInvalidDeviceErrorIsReturned) {
|
||||
cl_int retVal = CL_OUT_OF_HOST_MEMORY;
|
||||
EXPECT_NE(devices[0], devices[testedRootDeviceIndex]);
|
||||
auto cmdq = clCreateCommandQueueWithProperties(pContext, devices[0], nullptr, &retVal);
|
||||
EXPECT_EQ(nullptr, cmdq);
|
||||
EXPECT_EQ(retVal, CL_INVALID_DEVICE);
|
||||
}
|
||||
|
||||
TEST_F(clCreateCommandQueueWithPropertiesApi, GivenSizeWhichExceedsMaxDeviceQueueSizeWhenCreatingCommandQueueWithPropertiesThenInvalidQueuePropertiesErrorIsReturned) {
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
cl_queue_properties ooq[] = {CL_QUEUE_PROPERTIES, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT, CL_QUEUE_SIZE, (cl_uint)0xffffffff, 0, 0};
|
||||
|
|
|
@ -411,3 +411,15 @@ TEST(Context, givenContextWhenCheckIfAllocationsAreMultiStorageThenReturnProperV
|
|||
context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE;
|
||||
EXPECT_TRUE(context.areMultiStorageAllocationsPreferred());
|
||||
}
|
||||
|
||||
TEST(Context, givenContextWhenIsDeviceAssociatedIsCalledWithItsDeviceThenTrueIsReturned) {
|
||||
MockContext context;
|
||||
EXPECT_TRUE(context.isDeviceAssociated(*context.getDevice(0)));
|
||||
}
|
||||
|
||||
TEST(Context, givenContextWhenIsDeviceAssociatedIsCalledWithNotAssociatedDeviceThenFalseIsReturned) {
|
||||
MockContext context0;
|
||||
MockContext context1;
|
||||
EXPECT_FALSE(context0.isDeviceAssociated(*context1.getDevice(0)));
|
||||
EXPECT_FALSE(context1.isDeviceAssociated(*context0.getDevice(0)));
|
||||
}
|
|
@ -111,7 +111,7 @@ TEST_P(PerformanceHintCommandQueueTest, GivenProfilingFlagAndPreemptionFlagWhenC
|
|||
if (profilingEnabled) {
|
||||
properties = CL_QUEUE_PROFILING_ENABLE;
|
||||
}
|
||||
cmdQ = clCreateCommandQueue(context, clDevice, properties, &retVal);
|
||||
cmdQ = clCreateCommandQueue(context, context->getDevice(0), properties, &retVal);
|
||||
|
||||
ASSERT_NE(nullptr, cmdQ);
|
||||
ASSERT_EQ(CL_SUCCESS, retVal);
|
||||
|
@ -123,7 +123,7 @@ TEST_P(PerformanceHintCommandQueueTest, GivenProfilingFlagAndPreemptionFlagWhenC
|
|||
EXPECT_EQ(profilingEnabled, containsHint(expectedHint, userData));
|
||||
|
||||
snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[PROFILING_ENABLED_WITH_DISABLED_PREEMPTION], 0);
|
||||
if (device->getHardwareInfo().platform.eProductFamily < IGFX_SKYLAKE && preemptionSupported && profilingEnabled) {
|
||||
if (context->getDevice(0)->getHardwareInfo().platform.eProductFamily < IGFX_SKYLAKE && preemptionSupported && profilingEnabled) {
|
||||
EXPECT_TRUE(containsHint(expectedHint, userData));
|
||||
} else {
|
||||
EXPECT_FALSE(containsHint(expectedHint, userData));
|
||||
|
@ -136,7 +136,7 @@ TEST_P(PerformanceHintCommandQueueTest, GivenEnabledProfilingFlagAndSupportedPre
|
|||
properties[0] = CL_QUEUE_PROPERTIES;
|
||||
properties[1] = CL_QUEUE_PROFILING_ENABLE;
|
||||
}
|
||||
cmdQ = clCreateCommandQueueWithProperties(context, clDevice, properties, &retVal);
|
||||
cmdQ = clCreateCommandQueueWithProperties(context, context->getDevice(0), properties, &retVal);
|
||||
|
||||
ASSERT_NE(nullptr, cmdQ);
|
||||
ASSERT_EQ(CL_SUCCESS, retVal);
|
||||
|
@ -148,7 +148,7 @@ TEST_P(PerformanceHintCommandQueueTest, GivenEnabledProfilingFlagAndSupportedPre
|
|||
EXPECT_EQ(profilingEnabled, containsHint(expectedHint, userData));
|
||||
|
||||
snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[PROFILING_ENABLED_WITH_DISABLED_PREEMPTION], 0);
|
||||
if (device->getHardwareInfo().platform.eProductFamily < IGFX_SKYLAKE && preemptionSupported && profilingEnabled) {
|
||||
if (context->getDevice(0)->getHardwareInfo().platform.eProductFamily < IGFX_SKYLAKE && preemptionSupported && profilingEnabled) {
|
||||
EXPECT_TRUE(containsHint(expectedHint, userData));
|
||||
} else {
|
||||
EXPECT_FALSE(containsHint(expectedHint, userData));
|
||||
|
|
|
@ -110,18 +110,13 @@ struct PerformanceHintCommandQueueTest : public PerformanceHintTest,
|
|||
void SetUp() override {
|
||||
PerformanceHintTest::SetUp();
|
||||
std::tie(profilingEnabled, preemptionSupported) = GetParam();
|
||||
device = new MockDevice;
|
||||
clDevice = new MockClDevice{device};
|
||||
clDevice->deviceInfo.preemptionSupported = preemptionSupported;
|
||||
static_cast<MockClDevice *>(context->getDevice(0))->deviceInfo.preemptionSupported = preemptionSupported;
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
clReleaseCommandQueue(cmdQ);
|
||||
delete clDevice;
|
||||
PerformanceHintTest::TearDown();
|
||||
}
|
||||
MockDevice *device = nullptr;
|
||||
MockClDevice *clDevice = nullptr;
|
||||
cl_command_queue cmdQ = nullptr;
|
||||
bool profilingEnabled = false;
|
||||
bool preemptionSupported = false;
|
||||
|
|
Loading…
Reference in New Issue