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