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:
Mateusz Jablonski
2020-03-24 15:05:12 +01:00
committed by sys_ocldev
parent 70d50616d0
commit a651625473
8 changed files with 54 additions and 12 deletions

View File

@@ -527,6 +527,10 @@ cl_command_queue CL_API_CALL clCreateCommandQueue(cl_context context,
if (retVal != CL_SUCCESS) { if (retVal != CL_SUCCESS) {
break; break;
} }
if (!pContext->isDeviceAssociated(*pDevice)) {
retVal = CL_INVALID_DEVICE;
break;
}
cl_queue_properties props[] = { cl_queue_properties props[] = {
CL_QUEUE_PROPERTIES, properties, CL_QUEUE_PROPERTIES, properties,
@@ -4719,6 +4723,12 @@ cl_command_queue CL_API_CALL clCreateCommandQueueWithProperties(cl_context conte
return commandQueue; 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 | auto minimumCreateDeviceQueueFlags = static_cast<cl_command_queue_properties>(CL_QUEUE_ON_DEVICE |
CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE); CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE);
auto tokenValue = properties ? *properties : 0; auto tokenValue = properties ? *properties : 0;

View File

@@ -376,4 +376,13 @@ SchedulerKernel &Context::getSchedulerKernel() {
return *static_cast<SchedulerKernel *>(schedulerBuiltIn->pKernel); 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 } // namespace NEO

View File

@@ -141,6 +141,8 @@ class Context : public BaseObject<_cl_context> {
SchedulerKernel &getSchedulerKernel(); SchedulerKernel &getSchedulerKernel();
bool isDeviceAssociated(const ClDevice &clDevice) const;
protected: protected:
Context(void(CL_CALLBACK *pfnNotify)(const char *, const void *, size_t, void *) = nullptr, Context(void(CL_CALLBACK *pfnNotify)(const char *, const void *, size_t, void *) = nullptr,
void *userData = nullptr); void *userData = nullptr);

View File

@@ -36,12 +36,18 @@ TEST_F(clCreateCommandQueueTest, GivenCorrectParametersWhenCreatingCommandQueueT
TEST_F(clCreateCommandQueueTest, GivenNullContextWhenCreatingCommandQueueThenInvalidContextErrorIsReturned) { TEST_F(clCreateCommandQueueTest, GivenNullContextWhenCreatingCommandQueueThenInvalidContextErrorIsReturned) {
clCreateCommandQueue(nullptr, devices[testedRootDeviceIndex], 0, &retVal); clCreateCommandQueue(nullptr, devices[testedRootDeviceIndex], 0, &retVal);
ASSERT_EQ(CL_INVALID_CONTEXT, retVal); EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
} }
TEST_F(clCreateCommandQueueTest, GivenNullDeviceWhenCreatingCommandQueueThenInvalidDeviceErrorIsReturned) { TEST_F(clCreateCommandQueueTest, GivenNullDeviceWhenCreatingCommandQueueThenInvalidDeviceErrorIsReturned) {
clCreateCommandQueue(pContext, nullptr, 0, &retVal); 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) { TEST_F(clCreateCommandQueueTest, GivenInvalidPropertiesWhenCreatingCommandQueueThenInvalidValueErrorIsReturned) {

View File

@@ -239,6 +239,14 @@ TEST_F(clCreateCommandQueueWithPropertiesApi, GivenNullDeviceWhenCreatingCommand
EXPECT_EQ(retVal, CL_INVALID_DEVICE); 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) { TEST_F(clCreateCommandQueueWithPropertiesApi, GivenSizeWhichExceedsMaxDeviceQueueSizeWhenCreatingCommandQueueWithPropertiesThenInvalidQueuePropertiesErrorIsReturned) {
cl_int retVal = CL_SUCCESS; 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}; 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};

View File

@@ -411,3 +411,15 @@ TEST(Context, givenContextWhenCheckIfAllocationsAreMultiStorageThenReturnProperV
context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE; context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE;
EXPECT_TRUE(context.areMultiStorageAllocationsPreferred()); 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)));
}

View File

@@ -111,7 +111,7 @@ TEST_P(PerformanceHintCommandQueueTest, GivenProfilingFlagAndPreemptionFlagWhenC
if (profilingEnabled) { if (profilingEnabled) {
properties = CL_QUEUE_PROFILING_ENABLE; properties = CL_QUEUE_PROFILING_ENABLE;
} }
cmdQ = clCreateCommandQueue(context, clDevice, properties, &retVal); cmdQ = clCreateCommandQueue(context, context->getDevice(0), properties, &retVal);
ASSERT_NE(nullptr, cmdQ); ASSERT_NE(nullptr, cmdQ);
ASSERT_EQ(CL_SUCCESS, retVal); ASSERT_EQ(CL_SUCCESS, retVal);
@@ -123,7 +123,7 @@ TEST_P(PerformanceHintCommandQueueTest, GivenProfilingFlagAndPreemptionFlagWhenC
EXPECT_EQ(profilingEnabled, containsHint(expectedHint, userData)); EXPECT_EQ(profilingEnabled, containsHint(expectedHint, userData));
snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[PROFILING_ENABLED_WITH_DISABLED_PREEMPTION], 0); 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)); EXPECT_TRUE(containsHint(expectedHint, userData));
} else { } else {
EXPECT_FALSE(containsHint(expectedHint, userData)); EXPECT_FALSE(containsHint(expectedHint, userData));
@@ -136,7 +136,7 @@ TEST_P(PerformanceHintCommandQueueTest, GivenEnabledProfilingFlagAndSupportedPre
properties[0] = CL_QUEUE_PROPERTIES; properties[0] = CL_QUEUE_PROPERTIES;
properties[1] = CL_QUEUE_PROFILING_ENABLE; 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_NE(nullptr, cmdQ);
ASSERT_EQ(CL_SUCCESS, retVal); ASSERT_EQ(CL_SUCCESS, retVal);
@@ -148,7 +148,7 @@ TEST_P(PerformanceHintCommandQueueTest, GivenEnabledProfilingFlagAndSupportedPre
EXPECT_EQ(profilingEnabled, containsHint(expectedHint, userData)); EXPECT_EQ(profilingEnabled, containsHint(expectedHint, userData));
snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[PROFILING_ENABLED_WITH_DISABLED_PREEMPTION], 0); 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)); EXPECT_TRUE(containsHint(expectedHint, userData));
} else { } else {
EXPECT_FALSE(containsHint(expectedHint, userData)); EXPECT_FALSE(containsHint(expectedHint, userData));

View File

@@ -110,18 +110,13 @@ struct PerformanceHintCommandQueueTest : public PerformanceHintTest,
void SetUp() override { void SetUp() override {
PerformanceHintTest::SetUp(); PerformanceHintTest::SetUp();
std::tie(profilingEnabled, preemptionSupported) = GetParam(); std::tie(profilingEnabled, preemptionSupported) = GetParam();
device = new MockDevice; static_cast<MockClDevice *>(context->getDevice(0))->deviceInfo.preemptionSupported = preemptionSupported;
clDevice = new MockClDevice{device};
clDevice->deviceInfo.preemptionSupported = preemptionSupported;
} }
void TearDown() override { void TearDown() override {
clReleaseCommandQueue(cmdQ); clReleaseCommandQueue(cmdQ);
delete clDevice;
PerformanceHintTest::TearDown(); PerformanceHintTest::TearDown();
} }
MockDevice *device = nullptr;
MockClDevice *clDevice = nullptr;
cl_command_queue cmdQ = nullptr; cl_command_queue cmdQ = nullptr;
bool profilingEnabled = false; bool profilingEnabled = false;
bool preemptionSupported = false; bool preemptionSupported = false;