diff --git a/runtime/indirect_heap/indirect_heap.cpp b/runtime/indirect_heap/indirect_heap.cpp index 5aa79876a7..cc5f1251a2 100644 --- a/runtime/indirect_heap/indirect_heap.cpp +++ b/runtime/indirect_heap/indirect_heap.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -27,6 +27,9 @@ namespace OCLRT { IndirectHeap::IndirectHeap(GraphicsAllocation *gfxAllocation) : BaseClass(gfxAllocation) { } +IndirectHeap::IndirectHeap(GraphicsAllocation *gfxAllocation, bool canBeUtilizedAs4GbHeap) : BaseClass(gfxAllocation), canBeUtilizedAs4GbHeap(canBeUtilizedAs4GbHeap) { +} + IndirectHeap::IndirectHeap(void *buffer, size_t bufferSize) : BaseClass(buffer, bufferSize) { } } diff --git a/runtime/indirect_heap/indirect_heap.h b/runtime/indirect_heap/indirect_heap.h index 8ac104aa35..2fe2265c29 100644 --- a/runtime/indirect_heap/indirect_heap.h +++ b/runtime/indirect_heap/indirect_heap.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -46,16 +46,28 @@ class IndirectHeap : public LinearStream { IndirectHeap(void *buffer, size_t bufferSize); IndirectHeap(GraphicsAllocation *buffer); + IndirectHeap(GraphicsAllocation *buffer, bool canBeUtilizedAs4GbHeap); // Disallow copy'ing IndirectHeap(const IndirectHeap &) = delete; IndirectHeap &operator=(const IndirectHeap &) = delete; void align(size_t alignment); + uint64_t getHeapGpuStartOffset(); + + protected: + bool canBeUtilizedAs4GbHeap = false; }; inline void IndirectHeap::align(size_t alignment) { auto address = alignUp(ptrOffset(buffer, sizeUsed), alignment); sizeUsed = ptrDiff(address, buffer); } +inline uint64_t IndirectHeap::getHeapGpuStartOffset() { + if (this->canBeUtilizedAs4GbHeap) { + return this->graphicsAllocation->getGpuAddressToPatch(); + } else { + return 0llu; + } +} } diff --git a/unit_tests/command_queue/command_queue_tests.cpp b/unit_tests/command_queue/command_queue_tests.cpp index ed549daa61..8b776c01ac 100644 --- a/unit_tests/command_queue/command_queue_tests.cpp +++ b/unit_tests/command_queue/command_queue_tests.cpp @@ -637,7 +637,7 @@ TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWhenGetHeapMemoryIsCalledW const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0}; CommandQueue cmdQ(context.get(), pDevice, props); - IndirectHeap heap(nullptr, 100); + IndirectHeap heap(nullptr, size_t{100}); IndirectHeap *indirectHeap = &heap; cmdQ.allocateHeapMemory(this->GetParam(), 100, indirectHeap); diff --git a/unit_tests/indirect_heap/indirect_heap_tests.cpp b/unit_tests/indirect_heap/indirect_heap_tests.cpp index 47e2e038b7..5c8bad5bb1 100644 --- a/unit_tests/indirect_heap/indirect_heap_tests.cpp +++ b/unit_tests/indirect_heap/indirect_heap_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -27,8 +27,6 @@ using namespace OCLRT; struct IndirectHeapTest : public ::testing::Test { - IndirectHeapTest() { - } uint8_t buffer[256]; MockGraphicsAllocation gfxAllocation = {(void *)buffer, sizeof(buffer)}; IndirectHeap indirectHeap = {&gfxAllocation}; @@ -102,3 +100,21 @@ TEST_F(IndirectHeapTest, givenIndirectHeapWhenGetCpuBaseIsCalledThenCpuAddressIs auto base = indirectHeap.getCpuBase(); EXPECT_EQ(base, buffer); } + +TEST(IndirectHeapWith4GbAllocatorTest, givenIndirectHeapNotSupporting4GbModeWhenAskedForHeapGpuStartOffsetThenZeroIsReturned) { + auto cpuBaseAddress = reinterpret_cast(0x3000); + GraphicsAllocation graphicsAllocation(cpuBaseAddress, 4096u); + graphicsAllocation.gpuBaseAddress = 4096u; + IndirectHeap indirectHeap(&graphicsAllocation, false); + + EXPECT_EQ(0u, indirectHeap.getHeapGpuStartOffset()); +} + +TEST(IndirectHeapWith4GbAllocatorTest, givenIndirectHeapSupporting4GbModeWhenAskedForHeapGpuStartOffsetThenZeroIsReturned) { + auto cpuBaseAddress = reinterpret_cast(0x3000); + GraphicsAllocation graphicsAllocation(cpuBaseAddress, 4096u); + graphicsAllocation.gpuBaseAddress = 4096u; + IndirectHeap indirectHeap(&graphicsAllocation, true); + + EXPECT_EQ(8192u, indirectHeap.getHeapGpuStartOffset()); +}