mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-07 21:27:04 +08:00
Add fence ULTs (2)
Signed-off-by: Aravind Gopalakrishnan <aravind.gopalakrishnan@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
1a35b0a8c9
commit
9b2399019c
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "shared/source/command_stream/command_stream_receiver.h"
|
||||
#include "shared/source/helpers/constants.h"
|
||||
#include "shared/source/helpers/string.h"
|
||||
#include "shared/source/memory_manager/memory_manager.h"
|
||||
#include "shared/source/utilities/wait_util.h"
|
||||
|
||||
@@ -36,8 +37,10 @@ ze_result_t FenceImp::queryStatus() {
|
||||
csr->downloadAllocations();
|
||||
}
|
||||
|
||||
auto hostAddr = static_cast<uint64_t *>(allocation->getUnderlyingBuffer());
|
||||
return *hostAddr == Fence::STATE_CLEARED ? ZE_RESULT_NOT_READY : ZE_RESULT_SUCCESS;
|
||||
uint64_t *hostAddr = static_cast<uint64_t *>(allocation->getUnderlyingBuffer());
|
||||
uint32_t queryVal = Fence::STATE_CLEARED;
|
||||
memcpy_s(static_cast<void *>(&queryVal), sizeof(uint32_t), static_cast<void *>(hostAddr), sizeof(uint32_t));
|
||||
return queryVal == Fence::STATE_CLEARED ? ZE_RESULT_NOT_READY : ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
void FenceImp::initialize() {
|
||||
|
||||
@@ -7,10 +7,12 @@
|
||||
|
||||
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_csr.h"
|
||||
#include "test.h"
|
||||
|
||||
#include "level_zero/core/source/fence/fence.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h"
|
||||
#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h"
|
||||
|
||||
namespace L0 {
|
||||
@@ -63,5 +65,89 @@ TEST_F(FenceTest, whenQueryingStatusAndStateSignaledThenReturnSuccess) {
|
||||
fence->destroy();
|
||||
}
|
||||
|
||||
using FenceSynchronizeTest = Test<DeviceFixture>;
|
||||
|
||||
TEST_F(FenceSynchronizeTest, givenCallToFenceHostSynchronizeWithTimeoutZeroAndStateInitialHostSynchronizeReturnsNotReady) {
|
||||
std::unique_ptr<MockCommandStreamReceiver> csr = nullptr;
|
||||
csr = std::make_unique<MockCommandStreamReceiver>(*neoDevice->getExecutionEnvironment(), 0, neoDevice->getDeviceBitfield());
|
||||
|
||||
Mock<CommandQueue> cmdQueue(device, csr.get());
|
||||
std::unique_ptr<L0::Fence> fence;
|
||||
fence = std::unique_ptr<L0::Fence>(L0::Fence::create(&cmdQueue, nullptr));
|
||||
EXPECT_NE(nullptr, fence);
|
||||
|
||||
ze_result_t result = fence->hostSynchronize(0);
|
||||
EXPECT_EQ(ZE_RESULT_NOT_READY, result);
|
||||
}
|
||||
|
||||
TEST_F(FenceSynchronizeTest, givenCallToFenceHostSynchronizeWithNonZeroTimeoutAndStateInitialHostSynchronizeReturnsNotReady) {
|
||||
std::unique_ptr<MockCommandStreamReceiver> csr = nullptr;
|
||||
csr = std::make_unique<MockCommandStreamReceiver>(*neoDevice->getExecutionEnvironment(), 0, neoDevice->getDeviceBitfield());
|
||||
|
||||
Mock<CommandQueue> cmdQueue(device, csr.get());
|
||||
std::unique_ptr<L0::Fence> fence;
|
||||
fence = std::unique_ptr<L0::Fence>(L0::Fence::create(&cmdQueue, nullptr));
|
||||
EXPECT_NE(nullptr, fence);
|
||||
ze_result_t result = fence->hostSynchronize(10);
|
||||
EXPECT_EQ(ZE_RESULT_NOT_READY, result);
|
||||
}
|
||||
|
||||
TEST_F(FenceSynchronizeTest, givenCallToFenceHostSynchronizeWithTimeoutZeroAndStateSignaledHostSynchronizeReturnsSuccess) {
|
||||
std::unique_ptr<MockCommandStreamReceiver> csr = nullptr;
|
||||
csr = std::make_unique<MockCommandStreamReceiver>(*neoDevice->getExecutionEnvironment(), 0, neoDevice->getDeviceBitfield());
|
||||
|
||||
Mock<CommandQueue> cmdQueue(device, csr.get());
|
||||
std::unique_ptr<L0::Fence> fence;
|
||||
fence = std::unique_ptr<L0::Fence>(L0::Fence::create(&cmdQueue, nullptr));
|
||||
EXPECT_NE(nullptr, fence);
|
||||
auto alloc = &(fence->getAllocation());
|
||||
auto hostAddr = static_cast<uint64_t *>(alloc->getUnderlyingBuffer());
|
||||
*hostAddr = Fence::STATE_SIGNALED;
|
||||
ze_result_t result = fence->hostSynchronize(0);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(FenceSynchronizeTest, givenCallToFenceHostSynchronizeWithTimeoutNonZeroAndStateSignaledHostSynchronizeReturnsSuccess) {
|
||||
std::unique_ptr<MockCommandStreamReceiver> csr = nullptr;
|
||||
csr = std::make_unique<MockCommandStreamReceiver>(*neoDevice->getExecutionEnvironment(), 0, neoDevice->getDeviceBitfield());
|
||||
|
||||
Mock<CommandQueue> cmdQueue(device, csr.get());
|
||||
std::unique_ptr<L0::Fence> fence;
|
||||
fence = std::unique_ptr<L0::Fence>(L0::Fence::create(&cmdQueue, nullptr));
|
||||
EXPECT_NE(nullptr, fence);
|
||||
auto alloc = &(fence->getAllocation());
|
||||
auto hostAddr = static_cast<uint64_t *>(alloc->getUnderlyingBuffer());
|
||||
*hostAddr = Fence::STATE_SIGNALED;
|
||||
ze_result_t result = fence->hostSynchronize(10);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
using FenceAubCsrTest = Test<DeviceFixture>;
|
||||
|
||||
HWTEST_F(FenceAubCsrTest, givenCallToFenceHostSynchronizeWithAubModeCsrReturnsSuccess) {
|
||||
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
|
||||
NEO::MockDevice *neoDevice = nullptr;
|
||||
L0::Device *device = nullptr;
|
||||
|
||||
neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(NEO::defaultHwInfo.get());
|
||||
auto mockBuiltIns = new MockBuiltins();
|
||||
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns);
|
||||
NEO::DeviceVector devices;
|
||||
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
|
||||
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
|
||||
driverHandle->initialize(std::move(devices));
|
||||
device = driverHandle->devices[0];
|
||||
int32_t tag;
|
||||
auto aubCsr = new MockCsrAub<FamilyType>(tag, *neoDevice->executionEnvironment, neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield());
|
||||
neoDevice->resetCommandStreamReceiver(aubCsr);
|
||||
|
||||
Mock<CommandQueue> cmdQueue(device, aubCsr);
|
||||
auto fence = Fence::create(&cmdQueue, nullptr);
|
||||
|
||||
ze_result_t result = fence->hostSynchronize(10);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
fence->destroy();
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
Reference in New Issue
Block a user