2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-24 17:59:56 +08:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/api/cl_api_tests.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
typedef api_tests clCreateContextTests;
|
|
|
|
|
2018-08-09 16:57:53 +08:00
|
|
|
namespace ClCreateContextTests {
|
2017-12-21 07:45:38 +08:00
|
|
|
static int cbInvoked = 0;
|
|
|
|
void CL_CALLBACK eventCallBack(const char *, const void *,
|
|
|
|
size_t, void *) {
|
|
|
|
cbInvoked++;
|
|
|
|
}
|
|
|
|
|
2020-11-05 17:36:44 +08:00
|
|
|
TEST_F(clCreateContextTests, GivenValidParamsWhenCreatingContextThenContextIsCreated) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto context =
|
2020-02-12 18:27:28 +08:00
|
|
|
clCreateContext(nullptr, 1u, &testedClDevice, nullptr, nullptr, &retVal);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
|
|
|
ASSERT_NE(nullptr, context);
|
|
|
|
EXPECT_NE(nullptr, context->dispatch.icdDispatch);
|
|
|
|
EXPECT_NE(nullptr, context->dispatch.crtDispatch);
|
|
|
|
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
2020-11-05 17:36:44 +08:00
|
|
|
TEST_F(clCreateContextTests, GivenNullptrRetValWhenCreatingContextThenContextIsCreated) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto context =
|
2020-02-12 18:27:28 +08:00
|
|
|
clCreateContext(nullptr, 1u, &testedClDevice, nullptr, nullptr, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
ASSERT_NE(nullptr, context);
|
|
|
|
EXPECT_NE(nullptr, context->dispatch.icdDispatch);
|
|
|
|
EXPECT_NE(nullptr, context->dispatch.crtDispatch);
|
|
|
|
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
2020-11-05 17:36:44 +08:00
|
|
|
TEST_F(clCreateContextTests, GivenZeroDevicesWhenCreatingContextThenInvalidValueErrorIsReturned) {
|
|
|
|
auto context = clCreateContext(nullptr, 0, &testedClDevice, nullptr, nullptr, &retVal);
|
2017-12-21 07:45:38 +08:00
|
|
|
ASSERT_EQ(nullptr, context);
|
|
|
|
ASSERT_EQ(CL_INVALID_VALUE, retVal);
|
2020-11-05 17:36:44 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-11-05 17:36:44 +08:00
|
|
|
TEST_F(clCreateContextTests, GivenInvalidUserDataWhenCreatingContextThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_int someData = 25;
|
2020-11-05 17:36:44 +08:00
|
|
|
auto context = clCreateContext(nullptr, 1u, &testedClDevice, nullptr, &someData, &retVal);
|
2017-12-21 07:45:38 +08:00
|
|
|
ASSERT_EQ(nullptr, context);
|
|
|
|
ASSERT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
}
|
|
|
|
|
2020-11-05 17:36:44 +08:00
|
|
|
TEST_F(clCreateContextTests, GivenInvalidDeviceListWhenCreatingContextThenInvalidDeviceErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_device_id devList[2];
|
2020-04-24 18:58:39 +08:00
|
|
|
devList[0] = testedClDevice;
|
2017-12-21 07:45:38 +08:00
|
|
|
devList[1] = (cl_device_id)ptrGarbage;
|
|
|
|
|
|
|
|
auto context = clCreateContext(nullptr, 2, devList, nullptr, nullptr, &retVal);
|
|
|
|
ASSERT_EQ(nullptr, context);
|
|
|
|
ASSERT_EQ(CL_INVALID_DEVICE, retVal);
|
|
|
|
}
|
|
|
|
|
2020-11-05 17:36:44 +08:00
|
|
|
TEST_F(clCreateContextTests, GivenNullDeviceListWhenCreatingContextThenInvalidValueErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto context = clCreateContext(nullptr, 2, nullptr, nullptr, nullptr, &retVal);
|
|
|
|
ASSERT_EQ(nullptr, context);
|
|
|
|
ASSERT_EQ(CL_INVALID_VALUE, retVal);
|
|
|
|
}
|
|
|
|
|
2020-11-05 17:36:44 +08:00
|
|
|
TEST_F(clCreateContextTests, GivenNullUserDataWhenCreatingContextThenContextIsCreated) {
|
2020-02-12 18:27:28 +08:00
|
|
|
auto context = clCreateContext(nullptr, 1u, &testedClDevice, eventCallBack, nullptr, &retVal);
|
2017-12-21 07:45:38 +08:00
|
|
|
ASSERT_NE(nullptr, context);
|
|
|
|
|
|
|
|
retVal = clReleaseContext(context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
2018-01-03 17:54:31 +08:00
|
|
|
|
2020-04-10 21:45:44 +08:00
|
|
|
TEST_F(clCreateContextTests, givenMultipleRootDevicesWhenCreateContextThenOutOrHostMemoryErrorIsReturned) {
|
2020-04-24 18:58:39 +08:00
|
|
|
UltClDeviceFactory deviceFactory{2, 0};
|
|
|
|
cl_device_id devices[] = {deviceFactory.rootDevices[0], deviceFactory.rootDevices[1]};
|
|
|
|
auto context = clCreateContext(nullptr, 2u, devices, eventCallBack, nullptr, &retVal);
|
2020-04-10 21:45:44 +08:00
|
|
|
EXPECT_EQ(nullptr, context);
|
|
|
|
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
|
|
|
|
}
|
2020-10-29 17:21:29 +08:00
|
|
|
|
2020-04-27 22:12:40 +08:00
|
|
|
TEST_F(clCreateContextTests, givenEnabledMultipleRootDeviceSupportWhenCreateContextWithMultipleRootDevicesThenContextIsCreated) {
|
|
|
|
UltClDeviceFactory deviceFactory{2, 0};
|
|
|
|
DebugManager.flags.EnableMultiRootDeviceContexts.set(true);
|
|
|
|
cl_device_id devices[] = {deviceFactory.rootDevices[0], deviceFactory.rootDevices[1]};
|
|
|
|
auto context = clCreateContext(nullptr, 2u, devices, eventCallBack, nullptr, &retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
clReleaseContext(context);
|
|
|
|
}
|
2020-04-10 21:45:44 +08:00
|
|
|
|
2020-09-08 17:19:57 +08:00
|
|
|
TEST_F(clCreateContextTests, givenMultipleRootDevicesWhenCreateContextThenRootDeviceIndicesSetIsFilled) {
|
|
|
|
UltClDeviceFactory deviceFactory{3, 2};
|
|
|
|
DebugManager.flags.EnableMultiRootDeviceContexts.set(true);
|
|
|
|
cl_device_id devices[] = {deviceFactory.rootDevices[0], deviceFactory.rootDevices[1], deviceFactory.rootDevices[2]};
|
|
|
|
auto context = clCreateContext(nullptr, 3u, devices, eventCallBack, nullptr, &retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
auto pContext = castToObject<Context>(context);
|
|
|
|
auto rootDeviceIndices = pContext->getRootDeviceIndices();
|
|
|
|
|
|
|
|
for (auto numDevice = 0u; numDevice < pContext->getNumDevices(); numDevice++) {
|
|
|
|
auto rootDeviceIndex = rootDeviceIndices.find(pContext->getDevice(numDevice)->getRootDeviceIndex());
|
|
|
|
EXPECT_EQ(*rootDeviceIndex, pContext->getDevice(numDevice)->getRootDeviceIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
clReleaseContext(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(clCreateContextTests, givenMultipleRootDevicesWhenCreateContextThenMaxRootDeviceIndexIsProperlyFilled) {
|
|
|
|
UltClDeviceFactory deviceFactory{3, 0};
|
|
|
|
DebugManager.flags.EnableMultiRootDeviceContexts.set(true);
|
|
|
|
cl_device_id devices[] = {deviceFactory.rootDevices[0], deviceFactory.rootDevices[2]};
|
|
|
|
auto context = clCreateContext(nullptr, 2u, devices, eventCallBack, nullptr, &retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
auto pContext = castToObject<Context>(context);
|
|
|
|
EXPECT_EQ(2u, pContext->getMaxRootDeviceIndex());
|
|
|
|
|
|
|
|
clReleaseContext(context);
|
|
|
|
}
|
|
|
|
|
2020-10-29 17:21:29 +08:00
|
|
|
TEST_F(clCreateContextTests, givenMultipleRootDevicesWhenCreateContextThenSpecialQueueIsProperlyFilled) {
|
|
|
|
UltClDeviceFactory deviceFactory{3, 0};
|
|
|
|
DebugManager.flags.EnableMultiRootDeviceContexts.set(true);
|
|
|
|
cl_device_id devices[] = {deviceFactory.rootDevices[0], deviceFactory.rootDevices[2]};
|
|
|
|
auto context = clCreateContext(nullptr, 2u, devices, eventCallBack, nullptr, &retVal);
|
|
|
|
EXPECT_NE(nullptr, context);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
auto pContext = castToObject<Context>(context);
|
|
|
|
auto rootDeviceIndices = pContext->getRootDeviceIndices();
|
|
|
|
|
|
|
|
EXPECT_EQ(2u, pContext->getMaxRootDeviceIndex());
|
|
|
|
StackVec<CommandQueue *, 1> specialQueues;
|
|
|
|
specialQueues.resize(pContext->getMaxRootDeviceIndex());
|
|
|
|
|
|
|
|
for (auto numDevice = 0u; numDevice < pContext->getNumDevices(); numDevice++) {
|
|
|
|
auto rootDeviceIndex = rootDeviceIndices.find(pContext->getDevice(numDevice)->getRootDeviceIndex());
|
|
|
|
EXPECT_EQ(*rootDeviceIndex, pContext->getDevice(numDevice)->getRootDeviceIndex());
|
|
|
|
EXPECT_EQ(*rootDeviceIndex, pContext->getSpecialQueue(*rootDeviceIndex)->getDevice().getRootDeviceIndex());
|
|
|
|
specialQueues[numDevice] = pContext->getSpecialQueue(*rootDeviceIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_EQ(2u, specialQueues.size());
|
|
|
|
|
|
|
|
clReleaseContext(context);
|
|
|
|
}
|
|
|
|
|
2018-01-03 17:54:31 +08:00
|
|
|
TEST_F(clCreateContextTests, givenInvalidContextCreationPropertiesThenContextCreationFails) {
|
|
|
|
cl_context_properties invalidProperties[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties) nullptr, 0};
|
2020-02-12 18:27:28 +08:00
|
|
|
auto context = clCreateContext(invalidProperties, 1u, &testedClDevice, nullptr, nullptr, &retVal);
|
2018-01-03 17:54:31 +08:00
|
|
|
EXPECT_EQ(CL_INVALID_PLATFORM, retVal);
|
|
|
|
EXPECT_EQ(nullptr, context);
|
|
|
|
}
|
|
|
|
|
2020-01-24 17:59:56 +08:00
|
|
|
TEST_F(clCreateContextTests, GivenNonDefaultPlatformInContextCreationPropertiesWhenCreatingContextThenSuccessIsReturned) {
|
2020-02-07 19:15:46 +08:00
|
|
|
auto nonDefaultPlatform = std::make_unique<MockPlatform>();
|
2020-02-15 00:36:30 +08:00
|
|
|
nonDefaultPlatform->initializeWithNewDevices();
|
2020-01-24 17:59:56 +08:00
|
|
|
cl_platform_id nonDefaultPlatformCl = nonDefaultPlatform.get();
|
|
|
|
cl_device_id clDevice = nonDefaultPlatform->getClDevice(0);
|
|
|
|
cl_context_properties properties[3] = {CL_CONTEXT_PLATFORM, reinterpret_cast<cl_context_properties>(nonDefaultPlatformCl), 0};
|
|
|
|
auto clContext = clCreateContext(properties, 1, &clDevice, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, clContext);
|
|
|
|
clReleaseContext(clContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(clCreateContextFromTypeTests, GivenNonDefaultPlatformWithInvalidIcdDispatchInContextCreationPropertiesWhenCreatingContextThenInvalidPlatformErrorIsReturned) {
|
2020-02-07 19:15:46 +08:00
|
|
|
auto nonDefaultPlatform = std::make_unique<MockPlatform>();
|
2020-02-15 00:36:30 +08:00
|
|
|
nonDefaultPlatform->initializeWithNewDevices();
|
2020-01-24 17:59:56 +08:00
|
|
|
cl_platform_id nonDefaultPlatformCl = nonDefaultPlatform.get();
|
|
|
|
nonDefaultPlatformCl->dispatch.icdDispatch = reinterpret_cast<SDispatchTable *>(nonDefaultPlatform.get());
|
|
|
|
cl_device_id clDevice = nonDefaultPlatform->getClDevice(0);
|
|
|
|
cl_context_properties properties[3] = {CL_CONTEXT_PLATFORM, reinterpret_cast<cl_context_properties>(nonDefaultPlatformCl), 0};
|
|
|
|
auto clContext = clCreateContext(properties, 1, &clDevice, nullptr, nullptr, &retVal);
|
|
|
|
EXPECT_EQ(CL_INVALID_PLATFORM, retVal);
|
|
|
|
EXPECT_EQ(nullptr, clContext);
|
|
|
|
}
|
|
|
|
|
2018-08-09 16:57:53 +08:00
|
|
|
} // namespace ClCreateContextTests
|