|
1 | 1 | /*
|
2 |
| - * Copyright (C) 2024 Intel Corporation |
| 2 | + * Copyright (C) 2024-2025 Intel Corporation |
3 | 3 | *
|
4 | 4 | * SPDX-License-Identifier: MIT
|
5 | 5 | *
|
6 | 6 | */
|
7 | 7 |
|
8 | 8 | #include "shared/source/os_interface/product_helper.h"
|
| 9 | +#include "shared/source/unified_memory/usm_memory_support.h" |
9 | 10 | #include "shared/test/common/cmd_parse/gen_cmd_parse.h"
|
10 | 11 | #include "shared/test/common/helpers/debug_manager_state_restore.h"
|
| 12 | +#include "shared/test/common/memory_manager/mock_prefetch_manager.h" |
11 | 13 | #include "shared/test/common/test_macros/hw_test.h"
|
12 | 14 |
|
13 | 15 | #include "level_zero/core/source/event/event.h"
|
@@ -456,5 +458,160 @@ HWTEST2_F(CmdListLargeGrfTestXe2Hpg,
|
456 | 458 | testBody<FamilyType>();
|
457 | 459 | }
|
458 | 460 |
|
| 461 | +using CommandListStatePrefetchXe2HpgCore = Test<ModuleFixture>; |
| 462 | + |
| 463 | +HWTEST2_F(CommandListStatePrefetchXe2HpgCore, givenUnifiedSharedMemoryWhenPrefetchApiIsCalledThenRequestMemoryPrefetchByDefault, IsXe2HpgCore) { |
| 464 | + auto memoryManager = static_cast<MockMemoryManager *>(device->getDriverHandle()->getMemoryManager()); |
| 465 | + memoryManager->prefetchManager.reset(new MockPrefetchManager()); |
| 466 | + auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>(); |
| 467 | + auto result = pCommandList->initialize(device, NEO::EngineGroupType::compute, 0u); |
| 468 | + ASSERT_EQ(ZE_RESULT_SUCCESS, result); |
| 469 | + |
| 470 | + DebugManagerStateRestore restore; |
| 471 | + debugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.set(true); |
| 472 | + |
| 473 | + size_t size = 10; |
| 474 | + size_t alignment = 1u; |
| 475 | + void *ptr = nullptr; |
| 476 | + |
| 477 | + ze_device_mem_alloc_desc_t deviceDesc = {}; |
| 478 | + ze_host_mem_alloc_desc_t hostDesc = {}; |
| 479 | + result = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, size, alignment, &ptr); |
| 480 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 481 | + EXPECT_NE(nullptr, ptr); |
| 482 | + |
| 483 | + result = pCommandList->appendMemoryPrefetch(ptr, size); |
| 484 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 485 | + |
| 486 | + EXPECT_TRUE(pCommandList->isMemoryPrefetchRequested()); |
| 487 | + |
| 488 | + context->freeMem(ptr); |
| 489 | +} |
| 490 | + |
| 491 | +HWTEST2_F(CommandListStatePrefetchXe2HpgCore, givenUnifiedSharedMemoryWhenPrefetchApiIsCalledThenRequestMemoryPrefetchByDefaultWithNoPrefetchManager, IsXe2HpgCore) { |
| 492 | + auto memoryManager = static_cast<MockMemoryManager *>(device->getDriverHandle()->getMemoryManager()); |
| 493 | + memoryManager->prefetchManager.reset(new MockPrefetchManager()); |
| 494 | + auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>(); |
| 495 | + auto result = pCommandList->initialize(device, NEO::EngineGroupType::compute, 0u); |
| 496 | + ASSERT_EQ(ZE_RESULT_SUCCESS, result); |
| 497 | + |
| 498 | + DebugManagerStateRestore restore; |
| 499 | + debugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.set(true); |
| 500 | + |
| 501 | + size_t size = 10; |
| 502 | + size_t alignment = 1u; |
| 503 | + void *ptr = nullptr; |
| 504 | + |
| 505 | + ze_device_mem_alloc_desc_t deviceDesc = {}; |
| 506 | + ze_host_mem_alloc_desc_t hostDesc = {}; |
| 507 | + result = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, size, alignment, &ptr); |
| 508 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 509 | + EXPECT_NE(nullptr, ptr); |
| 510 | + |
| 511 | + result = pCommandList->appendMemoryPrefetch(ptr, size); |
| 512 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 513 | + |
| 514 | + EXPECT_TRUE(pCommandList->isMemoryPrefetchRequested()); |
| 515 | + |
| 516 | + context->freeMem(ptr); |
| 517 | +} |
| 518 | + |
| 519 | +HWTEST2_F(CommandListStatePrefetchXe2HpgCore, givenUnifiedSharedMemoryWhenPrefetchApiCalledAndDebugFlagFalseThenRequestMemoryPrefetchNotCalled, IsXe2HpgCore) { |
| 520 | + auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>(); |
| 521 | + auto result = pCommandList->initialize(device, NEO::EngineGroupType::compute, 0u); |
| 522 | + ASSERT_EQ(ZE_RESULT_SUCCESS, result); |
| 523 | + |
| 524 | + DebugManagerStateRestore restore; |
| 525 | + debugManager.flags.AppendMemoryPrefetchForKmdMigratedSharedAllocations.set(false); |
| 526 | + |
| 527 | + size_t size = 10; |
| 528 | + size_t alignment = 1u; |
| 529 | + void *ptr = nullptr; |
| 530 | + |
| 531 | + ze_device_mem_alloc_desc_t deviceDesc = {}; |
| 532 | + ze_host_mem_alloc_desc_t hostDesc = {}; |
| 533 | + result = context->allocSharedMem(device->toHandle(), &deviceDesc, &hostDesc, size, alignment, &ptr); |
| 534 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 535 | + EXPECT_NE(nullptr, ptr); |
| 536 | + |
| 537 | + result = pCommandList->appendMemoryPrefetch(ptr, size); |
| 538 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 539 | + |
| 540 | + EXPECT_FALSE(pCommandList->isMemoryPrefetchRequested()); |
| 541 | + |
| 542 | + context->freeMem(ptr); |
| 543 | +} |
| 544 | + |
| 545 | +HWTEST2_F(CommandListStatePrefetchXe2HpgCore, givenSharedSystemAllocationOnSupportedDeviceWhenPrefetchApiIsCalledThenRequestMemoryPrefetchCalled, IsXe2HpgCore) { |
| 546 | + auto memoryManager = static_cast<MockMemoryManager *>(device->getDriverHandle()->getMemoryManager()); |
| 547 | + memoryManager->prefetchManager.reset(new MockPrefetchManager()); |
| 548 | + auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>(); |
| 549 | + auto result = pCommandList->initialize(device, NEO::EngineGroupType::compute, 0u); |
| 550 | + ASSERT_EQ(ZE_RESULT_SUCCESS, result); |
| 551 | + |
| 552 | + auto &hwInfo = *device->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo(); |
| 553 | + |
| 554 | + VariableBackup<uint64_t> sharedSystemMemCapabilities{&hwInfo.capabilityTable.sharedSystemMemCapabilities}; |
| 555 | + sharedSystemMemCapabilities = UnifiedSharedMemoryFlags::access | UnifiedSharedMemoryFlags::sharedSystemPageFaultEnabled; |
| 556 | + |
| 557 | + size_t size = 10; |
| 558 | + void *ptr = malloc(size); |
| 559 | + |
| 560 | + EXPECT_NE(nullptr, ptr); |
| 561 | + |
| 562 | + result = pCommandList->appendMemoryPrefetch(ptr, size); |
| 563 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 564 | + |
| 565 | + EXPECT_TRUE(pCommandList->isMemoryPrefetchRequested()); |
| 566 | + |
| 567 | + free(ptr); |
| 568 | +} |
| 569 | + |
| 570 | +HWTEST2_F(CommandListStatePrefetchXe2HpgCore, givenSharedSystemAllocationOnSupportedDeviceWhenPrefetchApiIsCalledThenRequestMemoryPrefetchCalledWithNoPrefetchManager, IsXe2HpgCore) { |
| 571 | + auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>(); |
| 572 | + auto result = pCommandList->initialize(device, NEO::EngineGroupType::compute, 0u); |
| 573 | + ASSERT_EQ(ZE_RESULT_SUCCESS, result); |
| 574 | + |
| 575 | + auto &hwInfo = *device->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo(); |
| 576 | + |
| 577 | + VariableBackup<uint64_t> sharedSystemMemCapabilities{&hwInfo.capabilityTable.sharedSystemMemCapabilities}; |
| 578 | + sharedSystemMemCapabilities = UnifiedSharedMemoryFlags::access | UnifiedSharedMemoryFlags::sharedSystemPageFaultEnabled; |
| 579 | + |
| 580 | + size_t size = 10; |
| 581 | + void *ptr = malloc(size); |
| 582 | + |
| 583 | + EXPECT_NE(nullptr, ptr); |
| 584 | + |
| 585 | + result = pCommandList->appendMemoryPrefetch(ptr, size); |
| 586 | + EXPECT_EQ(ZE_RESULT_SUCCESS, result); |
| 587 | + |
| 588 | + EXPECT_TRUE(pCommandList->isMemoryPrefetchRequested()); |
| 589 | + |
| 590 | + free(ptr); |
| 591 | +} |
| 592 | + |
| 593 | +HWTEST2_F(CommandListStatePrefetchXe2HpgCore, givenSharedSystemAllocationOnUnSupportedDeviceWhenPrefetchApiIsCalledThenRequestMemoryPrefetchNotCalled, IsXe2HpgCore) { |
| 594 | + auto memoryManager = static_cast<MockMemoryManager *>(device->getDriverHandle()->getMemoryManager()); |
| 595 | + memoryManager->prefetchManager.reset(new MockPrefetchManager()); |
| 596 | + auto pCommandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>(); |
| 597 | + auto result = pCommandList->initialize(device, NEO::EngineGroupType::compute, 0u); |
| 598 | + ASSERT_EQ(ZE_RESULT_SUCCESS, result); |
| 599 | + |
| 600 | + DebugManagerStateRestore restore; |
| 601 | + debugManager.flags.EnableSharedSystemUsmSupport.set(0); |
| 602 | + |
| 603 | + size_t size = 10; |
| 604 | + void *ptr = malloc(size); |
| 605 | + |
| 606 | + EXPECT_NE(nullptr, ptr); |
| 607 | + |
| 608 | + result = pCommandList->appendMemoryPrefetch(ptr, size); |
| 609 | + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result); |
| 610 | + |
| 611 | + EXPECT_FALSE(pCommandList->isMemoryPrefetchRequested()); |
| 612 | + |
| 613 | + free(ptr); |
| 614 | +} |
| 615 | + |
459 | 616 | } // namespace ult
|
460 | 617 | } // namespace L0
|
0 commit comments