|
5 | 5 | * |
6 | 6 | */ |
7 | 7 |
|
| 8 | +#include "core/memory_manager/allocations_list.h" |
8 | 9 | #include "core/unit_tests/helpers/debug_manager_state_restore.h" |
9 | 10 | #include "core/unit_tests/page_fault_manager/mock_cpu_page_fault_manager.h" |
| 11 | +#include "runtime/api/api.h" |
10 | 12 | #include "runtime/command_stream/command_stream_receiver.h" |
11 | 13 | #include "runtime/mem_obj/mem_obj_helper.h" |
12 | 14 | #include "test.h" |
13 | 15 | #include "unit_tests/mocks/mock_command_queue.h" |
| 16 | +#include "unit_tests/mocks/mock_context.h" |
14 | 17 | #include "unit_tests/mocks/mock_execution_environment.h" |
15 | 18 | #include "unit_tests/mocks/mock_memory_manager.h" |
16 | 19 | #include "unit_tests/mocks/mock_svm_manager.h" |
@@ -576,3 +579,115 @@ TEST_F(ShareableUnifiedMemoryManagerPropertiesTest, givenShareableUnifiedPropert |
576 | 579 | EXPECT_TRUE(memoryManager->shareablePassed); |
577 | 580 | svmManager->freeSVMAlloc(ptr); |
578 | 581 | } |
| 582 | + |
| 583 | +TEST(UnfiedSharedMemoryTransferCalls, givenHostUSMllocationWhenPointerIsUsedAsWriteBufferSourceThenUSMAllocationIsReused) { |
| 584 | + MockContext mockContext; |
| 585 | + cl_context clContext = &mockContext; |
| 586 | + |
| 587 | + auto status = CL_SUCCESS; |
| 588 | + |
| 589 | + auto hostMemory = clHostMemAllocINTEL(clContext, nullptr, 4096u, 0u, &status); |
| 590 | + auto svmAllocation = mockContext.getSVMAllocsManager()->getSVMAlloc(hostMemory); |
| 591 | + |
| 592 | + ASSERT_EQ(CL_SUCCESS, status); |
| 593 | + auto buffer = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4096u, nullptr, &status); |
| 594 | + ASSERT_EQ(CL_SUCCESS, status); |
| 595 | + |
| 596 | + cl_device_id clDevice = mockContext.getDevice(0u); |
| 597 | + |
| 598 | + auto commandQueue = clCreateCommandQueue(clContext, clDevice, 0u, &status); |
| 599 | + ASSERT_EQ(CL_SUCCESS, status); |
| 600 | + |
| 601 | + status = clEnqueueWriteBuffer(commandQueue, buffer, false, 0u, 4096u, hostMemory, 0u, nullptr, nullptr); |
| 602 | + ASSERT_EQ(CL_SUCCESS, status); |
| 603 | + |
| 604 | + auto neoQueue = castToObject<CommandQueue>(commandQueue); |
| 605 | + auto &temporaryAllocations = neoQueue->getGpgpuCommandStreamReceiver().getTemporaryAllocations(); |
| 606 | + EXPECT_TRUE(temporaryAllocations.peekIsEmpty()); |
| 607 | + auto osContextId = neoQueue->getGpgpuCommandStreamReceiver().getOsContext().getContextId(); |
| 608 | + |
| 609 | + EXPECT_EQ(1u, svmAllocation->gpuAllocation->getTaskCount(osContextId)); |
| 610 | + |
| 611 | + status = clReleaseMemObject(buffer); |
| 612 | + ASSERT_EQ(CL_SUCCESS, status); |
| 613 | + status = clMemFreeINTEL(clContext, hostMemory); |
| 614 | + ASSERT_EQ(CL_SUCCESS, status); |
| 615 | + clReleaseCommandQueue(commandQueue); |
| 616 | +} |
| 617 | + |
| 618 | +TEST(UnfiedSharedMemoryTransferCalls, givenSharedUSMllocationWithoutLocalMemoryWhenPointerIsUsedAsWriteBufferSourceThenUSMAllocationIsReused) { |
| 619 | + DebugManagerStateRestore restore; |
| 620 | + DebugManager.flags.EnableLocalMemory.set(0); |
| 621 | + |
| 622 | + MockContext mockContext; |
| 623 | + cl_context clContext = &mockContext; |
| 624 | + cl_device_id clDevice = mockContext.getDevice(0u); |
| 625 | + |
| 626 | + auto status = CL_SUCCESS; |
| 627 | + |
| 628 | + auto sharedMemory = clSharedMemAllocINTEL(clContext, clDevice, nullptr, 4096u, 0u, &status); |
| 629 | + auto svmAllocation = mockContext.getSVMAllocsManager()->getSVMAlloc(sharedMemory); |
| 630 | + |
| 631 | + ASSERT_EQ(CL_SUCCESS, status); |
| 632 | + auto buffer = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4096u, nullptr, &status); |
| 633 | + ASSERT_EQ(CL_SUCCESS, status); |
| 634 | + |
| 635 | + auto commandQueue = clCreateCommandQueue(clContext, clDevice, 0u, &status); |
| 636 | + ASSERT_EQ(CL_SUCCESS, status); |
| 637 | + |
| 638 | + status = clEnqueueWriteBuffer(commandQueue, buffer, false, 0u, 4096u, sharedMemory, 0u, nullptr, nullptr); |
| 639 | + ASSERT_EQ(CL_SUCCESS, status); |
| 640 | + |
| 641 | + auto neoQueue = castToObject<CommandQueue>(commandQueue); |
| 642 | + auto &temporaryAllocations = neoQueue->getGpgpuCommandStreamReceiver().getTemporaryAllocations(); |
| 643 | + EXPECT_TRUE(temporaryAllocations.peekIsEmpty()); |
| 644 | + auto osContextId = neoQueue->getGpgpuCommandStreamReceiver().getOsContext().getContextId(); |
| 645 | + |
| 646 | + EXPECT_EQ(1u, svmAllocation->gpuAllocation->getTaskCount(osContextId)); |
| 647 | + |
| 648 | + status = clReleaseMemObject(buffer); |
| 649 | + ASSERT_EQ(CL_SUCCESS, status); |
| 650 | + status = clMemFreeINTEL(clContext, sharedMemory); |
| 651 | + ASSERT_EQ(CL_SUCCESS, status); |
| 652 | + clReleaseCommandQueue(commandQueue); |
| 653 | +} |
| 654 | + |
| 655 | +TEST(UnfiedSharedMemoryTransferCalls, givenSharedUSMllocationWithLocalMemoryWhenPointerIsUsedAsWriteBufferSourceThenUSMAllocationIsReused) { |
| 656 | + DebugManagerStateRestore restore; |
| 657 | + DebugManager.flags.EnableLocalMemory.set(1); |
| 658 | + |
| 659 | + MockContext mockContext; |
| 660 | + cl_context clContext = &mockContext; |
| 661 | + cl_device_id clDevice = mockContext.getDevice(0u); |
| 662 | + |
| 663 | + auto status = CL_SUCCESS; |
| 664 | + |
| 665 | + auto sharedMemory = clSharedMemAllocINTEL(clContext, clDevice, nullptr, 4096u, 0u, &status); |
| 666 | + auto svmAllocation = mockContext.getSVMAllocsManager()->getSVMAlloc(sharedMemory); |
| 667 | + |
| 668 | + ASSERT_EQ(CL_SUCCESS, status); |
| 669 | + auto buffer = clCreateBuffer(clContext, CL_MEM_READ_WRITE, 4096u, nullptr, &status); |
| 670 | + ASSERT_EQ(CL_SUCCESS, status); |
| 671 | + |
| 672 | + auto commandQueue = clCreateCommandQueue(clContext, clDevice, 0u, &status); |
| 673 | + ASSERT_EQ(CL_SUCCESS, status); |
| 674 | + |
| 675 | + auto neoQueue = castToObject<CommandQueue>(commandQueue); |
| 676 | + auto osContextId = neoQueue->getGpgpuCommandStreamReceiver().getOsContext().getContextId(); |
| 677 | + |
| 678 | + EXPECT_EQ(1u, svmAllocation->cpuAllocation->getTaskCount(osContextId)); |
| 679 | + |
| 680 | + status = clEnqueueWriteBuffer(commandQueue, buffer, false, 0u, 4096u, sharedMemory, 0u, nullptr, nullptr); |
| 681 | + ASSERT_EQ(CL_SUCCESS, status); |
| 682 | + |
| 683 | + auto &temporaryAllocations = neoQueue->getGpgpuCommandStreamReceiver().getTemporaryAllocations(); |
| 684 | + EXPECT_TRUE(temporaryAllocations.peekIsEmpty()); |
| 685 | + |
| 686 | + EXPECT_EQ(2u, svmAllocation->cpuAllocation->getTaskCount(osContextId)); |
| 687 | + |
| 688 | + status = clReleaseMemObject(buffer); |
| 689 | + ASSERT_EQ(CL_SUCCESS, status); |
| 690 | + status = clMemFreeINTEL(clContext, sharedMemory); |
| 691 | + ASSERT_EQ(CL_SUCCESS, status); |
| 692 | + clReleaseCommandQueue(commandQueue); |
| 693 | +} |
0 commit comments