2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-01-07 16:29:49 +08:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2019-05-13 18:53:40 +08:00
|
|
|
#include "core/helpers/basic_math.h"
|
2018-07-23 01:27:33 +08:00
|
|
|
#include "runtime/memory_manager/memory_manager.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
constexpr size_t bigAllocation = 1 * MB;
|
|
|
|
constexpr uintptr_t dummyAddress = 0xFFFFF000u;
|
|
|
|
class MemoryAllocation : public GraphicsAllocation {
|
|
|
|
public:
|
2019-04-03 17:22:04 +08:00
|
|
|
const unsigned long long id;
|
2017-12-21 07:45:38 +08:00
|
|
|
size_t sizeToFree = 0;
|
2019-04-03 17:22:04 +08:00
|
|
|
const bool uncacheable;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-02-27 21:59:46 +08:00
|
|
|
void setSharedHandle(osHandle handle) { sharingInfo.sharedHandle = handle; }
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-11-04 23:03:30 +08:00
|
|
|
MemoryAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, size_t sizeIn,
|
|
|
|
MemoryPool::Type pool)
|
|
|
|
: GraphicsAllocation(rootDeviceIndex, allocationType, cpuPtrIn, gpuAddress, baseAddress, sizeIn, pool),
|
2019-04-18 21:30:47 +08:00
|
|
|
id(0), uncacheable(false) {}
|
|
|
|
|
2019-11-04 23:03:30 +08:00
|
|
|
MemoryAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, MemoryPool::Type pool)
|
|
|
|
: GraphicsAllocation(rootDeviceIndex, allocationType, cpuPtrIn, sizeIn, sharedHandleIn, pool),
|
2019-04-18 21:30:47 +08:00
|
|
|
id(0), uncacheable(false) {}
|
|
|
|
|
2019-11-04 23:03:30 +08:00
|
|
|
MemoryAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *driverAllocatedCpuPointer, void *pMem, uint64_t gpuAddress, size_t memSize,
|
|
|
|
uint64_t count, MemoryPool::Type pool, bool uncacheable, bool flushL3Required)
|
|
|
|
: GraphicsAllocation(rootDeviceIndex, allocationType, pMem, gpuAddress, 0u, memSize, pool),
|
2019-04-03 17:22:04 +08:00
|
|
|
id(count), uncacheable(uncacheable) {
|
2019-02-11 17:02:27 +08:00
|
|
|
|
2018-10-30 21:44:41 +08:00
|
|
|
this->driverAllocatedCpuPointer = driverAllocatedCpuPointer;
|
2018-09-26 04:03:50 +08:00
|
|
|
overrideMemoryPool(pool);
|
2019-04-03 17:22:04 +08:00
|
|
|
allocationInfo.flags.flushL3Required = flushL3Required;
|
2018-07-14 00:50:55 +08:00
|
|
|
}
|
|
|
|
|
2018-09-26 04:03:50 +08:00
|
|
|
void overrideMemoryPool(MemoryPool::Type pool);
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class OsAgnosticMemoryManager : public MemoryManager {
|
|
|
|
public:
|
|
|
|
using MemoryManager::allocateGraphicsMemory;
|
|
|
|
|
2019-03-15 17:22:35 +08:00
|
|
|
OsAgnosticMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, executionEnvironment) {}
|
2019-04-18 21:30:47 +08:00
|
|
|
OsAgnosticMemoryManager(bool aubUsage, ExecutionEnvironment &executionEnvironment);
|
2017-12-21 07:45:38 +08:00
|
|
|
~OsAgnosticMemoryManager() override;
|
2019-04-01 20:04:50 +08:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override;
|
2019-10-22 16:26:23 +08:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) override { return nullptr; }
|
2018-07-18 15:48:21 +08:00
|
|
|
|
2018-05-08 16:00:23 +08:00
|
|
|
void addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) override;
|
|
|
|
void removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override;
|
|
|
|
|
2018-02-28 19:09:48 +08:00
|
|
|
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override;
|
2019-11-15 16:59:48 +08:00
|
|
|
void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
uint64_t getSystemSharedMemory() override;
|
2019-07-26 05:25:10 +08:00
|
|
|
uint64_t getLocalMemorySize() override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
void turnOnFakingBigAllocations();
|
|
|
|
|
2019-03-13 22:31:46 +08:00
|
|
|
void *reserveCpuAddressRange(size_t size) override;
|
|
|
|
void releaseReservedCpuAddressRange(void *reserved, size_t size) override;
|
|
|
|
|
2018-11-30 18:01:33 +08:00
|
|
|
protected:
|
2019-02-25 21:11:34 +08:00
|
|
|
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override;
|
2019-03-12 19:00:41 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override;
|
2018-11-30 18:01:33 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
|
2019-02-28 21:12:13 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override;
|
2019-01-22 19:40:17 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override;
|
2018-11-30 18:01:33 +08:00
|
|
|
|
2019-08-15 07:23:57 +08:00
|
|
|
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override { return graphicsAllocation.getUnderlyingBuffer(); }
|
2019-02-20 18:18:24 +08:00
|
|
|
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override {}
|
2018-12-21 17:16:27 +08:00
|
|
|
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
|
|
|
|
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
2019-04-18 21:30:47 +08:00
|
|
|
MemoryAllocation *createMemoryAllocation(GraphicsAllocation::AllocationType allocationType, void *driverAllocatedCpuPointer, void *pMem, uint64_t gpuAddress, size_t memSize,
|
2019-10-22 16:26:23 +08:00
|
|
|
uint64_t count, MemoryPool::Type pool, uint32_t rootDeviceIndex, bool uncacheable, bool flushL3Required, bool requireSpecificBitness);
|
2019-01-24 18:51:33 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
private:
|
|
|
|
unsigned long long counter = 0;
|
|
|
|
bool fakeBigAllocations = false;
|
|
|
|
};
|
2019-06-28 03:33:05 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|