2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-14 21:32:11 +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-01-28 00:28:10 +08:00
|
|
|
#include "core/helpers/array_count.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "test.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "unit_tests/fixtures/device_fixture.h"
|
|
|
|
|
2020-02-22 16:28:27 +08:00
|
|
|
#include "context/context.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-27 23:55:34 +08:00
|
|
|
TEST(ContextMultiDevice, GivenSingleDeviceWhenCreatingContextThenContextIsCreated) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_device_id devices[] = {
|
2020-01-14 21:32:11 +08:00
|
|
|
new MockClDevice{MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)}};
|
2018-08-13 15:27:49 +08:00
|
|
|
auto numDevices = static_cast<cl_uint>(arrayCount(devices));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
auto retVal = CL_SUCCESS;
|
2020-01-14 21:32:11 +08:00
|
|
|
auto pContext = Context::create<Context>(nullptr, ClDeviceVector(devices, numDevices),
|
2017-12-21 07:45:38 +08:00
|
|
|
nullptr, nullptr, retVal);
|
|
|
|
ASSERT_NE(nullptr, pContext);
|
|
|
|
|
|
|
|
auto numDevicesReturned = pContext->getNumDevices();
|
|
|
|
EXPECT_EQ(numDevices, numDevicesReturned);
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
ClDeviceVector ctxDevices;
|
2017-12-21 07:45:38 +08:00
|
|
|
for (size_t deviceOrdinal = 0; deviceOrdinal < numDevicesReturned; ++deviceOrdinal) {
|
|
|
|
ctxDevices.push_back(pContext->getDevice(deviceOrdinal));
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pContext;
|
|
|
|
|
|
|
|
for (size_t deviceOrdinal = 0; deviceOrdinal < numDevicesReturned; ++deviceOrdinal) {
|
2020-01-14 21:32:11 +08:00
|
|
|
auto pDevice = (ClDevice *)devices[deviceOrdinal];
|
2017-12-21 07:45:38 +08:00
|
|
|
ASSERT_NE(nullptr, pDevice);
|
|
|
|
|
|
|
|
EXPECT_EQ(pDevice, ctxDevices[deviceOrdinal]);
|
|
|
|
delete pDevice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-27 23:55:34 +08:00
|
|
|
TEST(ContextMultiDevice, GivenMultipleDevicesWhenCreatingContextThenContextIsCreatedForEachDevice) {
|
2017-12-21 07:45:38 +08:00
|
|
|
cl_device_id devices[] = {
|
2020-01-14 21:32:11 +08:00
|
|
|
new MockClDevice{MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)},
|
|
|
|
new MockClDevice{MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)},
|
|
|
|
new MockClDevice{MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)},
|
|
|
|
new MockClDevice{MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)},
|
|
|
|
new MockClDevice{MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)},
|
|
|
|
new MockClDevice{MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)},
|
|
|
|
new MockClDevice{MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)},
|
|
|
|
new MockClDevice{MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)}};
|
2018-08-13 15:27:49 +08:00
|
|
|
auto numDevices = static_cast<cl_uint>(arrayCount(devices));
|
2017-12-21 07:45:38 +08:00
|
|
|
ASSERT_EQ(8u, numDevices);
|
|
|
|
|
|
|
|
auto retVal = CL_SUCCESS;
|
2020-01-14 21:32:11 +08:00
|
|
|
auto pContext = Context::create<Context>(nullptr, ClDeviceVector(devices, numDevices),
|
2017-12-21 07:45:38 +08:00
|
|
|
nullptr, nullptr, retVal);
|
|
|
|
ASSERT_NE(nullptr, pContext);
|
|
|
|
|
|
|
|
auto numDevicesReturned = pContext->getNumDevices();
|
|
|
|
EXPECT_EQ(numDevices, numDevicesReturned);
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
ClDeviceVector ctxDevices;
|
2017-12-21 07:45:38 +08:00
|
|
|
for (size_t deviceOrdinal = 0; deviceOrdinal < numDevicesReturned; ++deviceOrdinal) {
|
|
|
|
ctxDevices.push_back(pContext->getDevice(deviceOrdinal));
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pContext;
|
|
|
|
|
|
|
|
for (size_t deviceOrdinal = 0; deviceOrdinal < numDevicesReturned; ++deviceOrdinal) {
|
2020-01-14 21:32:11 +08:00
|
|
|
auto pDevice = (ClDevice *)devices[deviceOrdinal];
|
2017-12-21 07:45:38 +08:00
|
|
|
ASSERT_NE(nullptr, pDevice);
|
|
|
|
|
|
|
|
EXPECT_EQ(pDevice, ctxDevices[deviceOrdinal]);
|
|
|
|
delete pDevice;
|
|
|
|
}
|
|
|
|
}
|