diff --git a/runtime/os_interface/linux/drm_buffer_object.cpp b/runtime/os_interface/linux/drm_buffer_object.cpp index b34db9a2748a0..bd819594ed05c 100644 --- a/runtime/os_interface/linux/drm_buffer_object.cpp +++ b/runtime/os_interface/linux/drm_buffer_object.cpp @@ -30,30 +30,17 @@ namespace OCLRT { BufferObject::BufferObject(Drm *drm, int handle, bool isAllocated) : drm(drm), refCount(1), handle(handle), isReused(false), isAllocated(isAllocated) { - this->isSoftpin = false; - this->tiling_mode = I915_TILING_NONE; this->stride = 0; - execObjectsStorage = nullptr; - this->size = 0; - this->address = nullptr; this->lockedAddress = nullptr; - this->offset64 = 0; } uint32_t BufferObject::getRefCount() const { return this->refCount.load(); } -bool BufferObject::softPin(uint64_t offset) { - this->isSoftpin = true; - this->offset64 = offset; - - return true; -}; - bool BufferObject::close() { drm_gem_close close = {}; close.handle = this->handle; @@ -111,11 +98,11 @@ void BufferObject::fillExecObject(drm_i915_gem_exec_object2 &execObject, uint32_ execObject.relocation_count = 0; //No relocations, we are SoftPinning execObject.relocs_ptr = 0ul; execObject.alignment = 0; - execObject.offset = this->isSoftpin ? this->offset64 : 0; - execObject.flags = this->isSoftpin ? EXEC_OBJECT_PINNED : 0; + execObject.offset = this->gpuAddress; + execObject.flags = EXEC_OBJECT_PINNED; #ifdef __x86_64__ // set EXEC_OBJECT_SUPPORTS_48B_ADDRESS flag if whole object resides in 32BIT address space boundary - execObject.flags |= (reinterpret_cast(this->address) + this->size) & MemoryConstants::zoneHigh ? EXEC_OBJECT_SUPPORTS_48B_ADDRESS : 0; + execObject.flags |= (this->gpuAddress + this->size) & MemoryConstants::zoneHigh ? EXEC_OBJECT_SUPPORTS_48B_ADDRESS : 0; #endif execObject.rsvd1 = drmContextId; execObject.rsvd2 = 0; @@ -157,8 +144,8 @@ int BufferObject::pin(BufferObject *boToPin[], size_t numberOfBos, uint32_t drmC drm_i915_gem_execbuffer2 execbuf = {}; StackVec execObject; - reinterpret_cast(this->address)[0] = 0x05000000; - reinterpret_cast(this->address)[1] = 0x00000000; + reinterpret_cast(this->gpuAddress)[0] = 0x05000000; + reinterpret_cast(this->gpuAddress)[1] = 0x00000000; execObject.resize(numberOfBos + 1); diff --git a/runtime/os_interface/linux/drm_buffer_object.h b/runtime/os_interface/linux/drm_buffer_object.h index 7555ae28e4c1f..2240e25285d22 100644 --- a/runtime/os_interface/linux/drm_buffer_object.h +++ b/runtime/os_interface/linux/drm_buffer_object.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -40,8 +40,6 @@ class BufferObject { public: MOCKABLE_VIRTUAL ~BufferObject(){}; - bool softPin(uint64_t offset); - bool setTiling(uint32_t mode, uint32_t stride); MOCKABLE_VIRTUAL int pin(BufferObject *boToPin[], size_t numberOfBos, uint32_t drmContextId); @@ -59,8 +57,8 @@ class BufferObject { bool peekIsAllocated() const { return isAllocated; } size_t peekSize() const { return size; } int peekHandle() const { return handle; } - void *peekAddress() const { return address; } - void setAddress(void *address) { this->address = address; } + uint64_t peekAddress() const { return gpuAddress; } + void setAddress(uint64_t address) { this->gpuAddress = address; } void *peekLockedAddress() const { return lockedAddress; } void setLockedAddress(void *cpuAddress) { this->lockedAddress = cpuAddress; } void setUnmapSize(uint64_t unmapSize) { this->unmapSize = unmapSize; } @@ -87,7 +85,6 @@ class BufferObject { drm_i915_gem_exec_object2 *execObjectsStorage; int handle; // i915 gem object handle - bool isSoftpin; bool isReused; //Tiling @@ -97,9 +94,9 @@ class BufferObject { MOCKABLE_VIRTUAL void fillExecObject(drm_i915_gem_exec_object2 &execObject, uint32_t drmContextId); void processRelocs(int &idx, uint32_t drmContextId); - uint64_t offset64; // last-seen GPU offset - size_t size; - void *address; // GPU side virtual address + uint64_t gpuAddress = 0llu; + + uint64_t size; void *lockedAddress; // CPU side virtual address bool isAllocated = false; diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index 4a4be4dfc76b1..4c9540bb146b1 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -128,7 +128,7 @@ uint32_t DrmMemoryManager::unreference(OCLRT::BufferObject *bo, bool synchronous if (r == 1) { auto unmapSize = bo->peekUnmapSize(); - auto address = bo->isAllocated || unmapSize > 0 ? bo->address : nullptr; + auto address = bo->isAllocated || unmapSize > 0 ? reinterpret_cast(bo->gpuAddress) : nullptr; auto allocatorType = bo->peekAllocationType(); if (bo->isReused) { @@ -206,8 +206,7 @@ OCLRT::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t si return nullptr; } res->size = size; - res->address = reinterpret_cast(address); - res->softPin(address); + res->gpuAddress = address; return res; } @@ -279,8 +278,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(size_t s bo->isAllocated = false; bo->setUnmapSize(alignedSize); - bo->address = reinterpret_cast(gpuVirtualAddress); - bo->softPin((uint64_t)bo->address); + bo->gpuAddress = gpuVirtualAddress; bo->setAllocationType(allocType); auto allocation = new DrmAllocation(bo, alignedPtr, gpuVirtualAddress, size, MemoryPool::System4KBPages, false); @@ -319,8 +317,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A return nullptr; } bo->size = allocationData.imgInfo->size; - bo->address = reinterpret_cast(gpuRange); - bo->softPin(gpuRange); + bo->gpuAddress = gpuRange; auto ret2 = bo->setTiling(I915_TILING_Y, static_cast(allocationData.imgInfo->rowPitch)); DEBUG_BREAK_IF(ret2 != true); @@ -358,9 +355,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio bo->isAllocated = false; bo->setUnmapSize(realAllocationSize); - bo->address = reinterpret_cast(gpuVirtualAddress); - uintptr_t offset = (uintptr_t)bo->address; - bo->softPin((uint64_t)offset); + bo->gpuAddress = gpuVirtualAddress; bo->setAllocationType(allocatorType); auto drmAllocation = new DrmAllocation(bo, const_cast(allocationData.hostPtr), static_cast(ptrOffset(gpuVirtualAddress, inputPointerOffset)), allocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing, false); @@ -409,8 +404,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio DrmAllocation *drmAllocation = nullptr; if (limitedRangeAllocation) { // softpin to the GPU address, res if it uses limitedRangeAllocation - bo->address = reinterpret_cast(res); - bo->softPin(res); + bo->gpuAddress = res; drmAllocation = new DrmAllocation(bo, ptrAlloc, res, alignedAllocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing, false); } else { @@ -451,8 +445,7 @@ BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t si } bo->size = size; - bo->address = reinterpret_cast(gpuRange); - bo->softPin(gpuRange); + bo->gpuAddress = gpuRange; bo->setUnmapSize(size); bo->setAllocationType(storageType); return bo; @@ -490,7 +483,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o lock.unlock(); - auto drmAllocation = new DrmAllocation(bo, bo->address, bo->size, handle, MemoryPool::SystemCpuInaccessible, false); + auto drmAllocation = new DrmAllocation(bo, reinterpret_cast(bo->gpuAddress), bo->size, handle, MemoryPool::SystemCpuInaccessible, false); if (requireSpecificBitness && this->force32bitAllocations) { drmAllocation->is32BitAllocation = true; @@ -517,8 +510,7 @@ GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation if (!bo) { return nullptr; } - bo->setAddress(reinterpret_cast(gpuRange)); - bo->softPin(gpuRange); + bo->gpuAddress = gpuRange; bo->setUnmapSize(sizeWithPadding); bo->setAllocationType(storageType); return new DrmAllocation(bo, (void *)srcPtr, (uint64_t)ptrOffset(gpuRange, offset), sizeWithPadding, diff --git a/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp b/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp index de1a3dae55caf..2ad9416225740 100644 --- a/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp +++ b/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp @@ -102,7 +102,7 @@ TEST_F(DrmBufferObjectTest, givenAddressThatWhenSizeIsAddedCrosses32BitBoundaryW drm_i915_gem_exec_object2 execObject; memset(&execObject, 0, sizeof(execObject)); - bo->setAddress((void *)(((uint64_t)1u << 32) - 0x1000u)); + bo->setAddress(((uint64_t)1u << 32) - 0x1000u); bo->setSize(0x1000); bo->fillExecObject(execObject, 1); //base address + size > size of 32bit address space @@ -113,7 +113,7 @@ TEST_F(DrmBufferObjectTest, givenAddressThatWhenSizeIsAddedWithin32BitBoundaryWh drm_i915_gem_exec_object2 execObject; memset(&execObject, 0, sizeof(execObject)); - bo->setAddress((void *)(((uint64_t)1u << 32) - 0x1000u)); + bo->setAddress(((uint64_t)1u << 32) - 0x1000u); bo->setSize(0xFFF); bo->fillExecObject(execObject, 1); //base address + size < size of 32bit address space @@ -130,7 +130,7 @@ TEST_F(DrmBufferObjectTest, onPinIoctlFailed) { std::unique_ptr boToPin(new TestedBufferObject(this->mock)); ASSERT_NE(nullptr, boToPin.get()); - bo->setAddress(buff.get()); + bo->setAddress(reinterpret_cast(buff.get())); BufferObject *boArray[1] = {boToPin.get()}; auto ret = bo->pin(boArray, 1, 1); EXPECT_EQ(EINVAL, ret); @@ -151,7 +151,7 @@ TEST(DrmBufferObjectSimpleTest, givenInvalidBoWhenPinIsCalledThenErrorIsReturned std::unique_ptr boToPin(new TestedBufferObject(mock.get())); ASSERT_NE(nullptr, boToPin.get()); - bo->setAddress(buff.get()); + bo->setAddress(reinterpret_cast(buff.get())); mock->errnoValue = EFAULT; BufferObject *boArray[1] = {boToPin.get()}; @@ -179,7 +179,7 @@ TEST(DrmBufferObjectSimpleTest, givenArrayOfBosWhenPinnedThenAllBosArePinned) { BufferObject *array[3] = {boToPin.get(), boToPin2.get(), boToPin3.get()}; - bo->setAddress(buff.get()); + bo->setAddress(reinterpret_cast(buff.get())); auto ret = bo->pin(array, 3, 1); EXPECT_EQ(mock->ioctl_res, ret); uint32_t bb_end = 0x05000000; @@ -191,5 +191,5 @@ TEST(DrmBufferObjectSimpleTest, givenArrayOfBosWhenPinnedThenAllBosArePinned) { EXPECT_NE(nullptr, boToPin2->execObjectPointerFilled); EXPECT_NE(nullptr, boToPin3->execObjectPointerFilled); - bo->setAddress(nullptr); + bo->setAddress(0llu); } diff --git a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp index 4be473005bb79..05efbbf4966b2 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -604,7 +604,6 @@ class DrmCommandStreamEnhancedFixture protected: MockBufferObject(Drm *drm, size_t size) : BufferObject(drm, 1, false) { - this->isSoftpin = true; this->size = alignUp(size, 4096); } }; diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index b9b81042b7eb0..c4b8c265b21b6 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -468,7 +468,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr) { auto bo = alloc->getBO(); ASSERT_NE(nullptr, bo); EXPECT_FALSE(bo->peekIsAllocated()); - EXPECT_EQ(ptr, bo->peekAddress()); + EXPECT_EQ(ptr, reinterpret_cast(bo->peekAddress())); EXPECT_EQ(Sharing::nonSharedResource, alloc->peekSharedHandle()); memoryManager->freeGraphicsMemory(alloc); ::alignedFree(ptr); @@ -490,7 +490,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr_Nullptr) { auto bo = alloc->getBO(); ASSERT_NE(nullptr, bo); EXPECT_FALSE(bo->peekIsAllocated()); - EXPECT_EQ(ptr, bo->peekAddress()); + EXPECT_EQ(ptr, reinterpret_cast(bo->peekAddress())); memoryManager->freeGraphicsMemory(alloc); ::alignedFree(ptr); @@ -514,7 +514,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr_MisAligned) { auto bo = alloc->getBO(); ASSERT_NE(nullptr, bo); EXPECT_FALSE(bo->peekIsAllocated()); - EXPECT_EQ(ptrT, bo->peekAddress()); + EXPECT_EQ(ptrT, reinterpret_cast(bo->peekAddress())); memoryManager->freeGraphicsMemory(alloc); ::alignedFree(ptrT); @@ -747,7 +747,7 @@ TEST_F(DrmMemoryManagerTest, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAsked for (int i = 0; i < maxFragmentsCount; i++) { ASSERT_NE(nullptr, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo); EXPECT_EQ(reqs.AllocationFragments[i].allocationSize, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekSize()); - EXPECT_EQ(reqs.AllocationFragments[i].allocationPtr, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekAddress()); + EXPECT_EQ(reqs.AllocationFragments[i].allocationPtr, reinterpret_cast(graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekAddress())); EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekIsAllocated()); } memoryManager->freeGraphicsMemory(graphicsAllocation); @@ -1561,7 +1561,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledT auto bo = drmAllocation->getBO(); EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle); EXPECT_EQ(bo->peekUnmapSize(), size); - EXPECT_NE(nullptr, bo->peekAddress()); + EXPECT_NE(0llu, bo->peekAddress()); EXPECT_TRUE(bo->peekIsAllocated()); EXPECT_EQ(1u, bo->getRefCount()); EXPECT_EQ(size, bo->peekSize()); @@ -1625,7 +1625,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndThreeOsHandlesWhenReuseCrea bo = drmAllocation->getBO(); EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle); EXPECT_EQ(bo->peekUnmapSize(), size); - EXPECT_NE(nullptr, bo->peekAddress()); + EXPECT_NE(0llu, bo->peekAddress()); EXPECT_TRUE(bo->peekIsAllocated()); EXPECT_EQ(expectedRefCount, bo->getRefCount()); EXPECT_EQ(size, bo->peekSize()); @@ -2041,7 +2041,7 @@ TEST_F(DrmMemoryManagerTest, givenSharedAllocationWithSmallerThenRealSizeWhenCre auto bo = drmAllocation->getBO(); EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle); EXPECT_EQ(bo->peekUnmapSize(), realSize); - EXPECT_NE(nullptr, bo->peekAddress()); + EXPECT_NE(0llu, bo->peekAddress()); EXPECT_TRUE(bo->peekIsAllocated()); EXPECT_EQ(1u, bo->getRefCount()); EXPECT_EQ(realSize, bo->peekSize());