2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 2017-2018 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
|
|
|
|
#include "runtime/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
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
constexpr size_t bigAllocation = 1 * MB;
|
|
|
|
constexpr uintptr_t dummyAddress = 0xFFFFF000u;
|
|
|
|
class MemoryAllocation : public GraphicsAllocation {
|
|
|
|
public:
|
|
|
|
unsigned long long id;
|
|
|
|
size_t sizeToFree = 0;
|
2018-01-05 00:48:46 +08:00
|
|
|
bool uncacheable = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
void setSharedHandle(osHandle handle) { this->sharedHandle = handle; }
|
|
|
|
|
2018-11-07 20:04:10 +08:00
|
|
|
MemoryAllocation(void *driverAllocatedCpuPointer, void *pMem, uint64_t gpuAddress, size_t memSize, uint64_t count, MemoryPool::Type pool, uint32_t osContextCount, bool isShareable) : GraphicsAllocation(pMem, gpuAddress, 0u, memSize, osContextCount, isShareable),
|
|
|
|
id(count) {
|
2018-10-30 21:44:41 +08:00
|
|
|
this->driverAllocatedCpuPointer = driverAllocatedCpuPointer;
|
2018-09-26 04:03:50 +08:00
|
|
|
overrideMemoryPool(pool);
|
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
|
|
|
};
|
|
|
|
|
2018-03-01 17:08:20 +08:00
|
|
|
typedef std::map<void *, MemoryAllocation *> PointerMap;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class OsAgnosticMemoryManager : public MemoryManager {
|
|
|
|
public:
|
|
|
|
using MemoryManager::allocateGraphicsMemory;
|
|
|
|
using MemoryManager::createGraphicsAllocationFromSharedHandle;
|
|
|
|
|
2018-10-01 22:10:54 +08:00
|
|
|
OsAgnosticMemoryManager(bool enable64kbPages, bool enableLocalMemory, ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, false, executionEnvironment){};
|
2018-09-26 23:45:35 +08:00
|
|
|
|
2018-10-01 22:10:54 +08:00
|
|
|
OsAgnosticMemoryManager(bool enable64kbPages, bool enableLocalMemory, bool aubUsage, ExecutionEnvironment &executionEnvironment) : MemoryManager(enable64kbPages, enableLocalMemory, executionEnvironment) {
|
2018-09-26 23:45:35 +08:00
|
|
|
allocator32Bit = std::unique_ptr<Allocator32bit>(create32BitAllocator(aubUsage));
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2018-09-26 23:45:35 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
~OsAgnosticMemoryManager() override;
|
2018-01-05 00:48:46 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override;
|
2018-07-23 01:27:33 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) override;
|
2018-08-24 21:23:45 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) override;
|
2018-07-09 20:12:32 +08:00
|
|
|
GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) override;
|
2018-08-29 20:50:36 +08:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { return nullptr; }
|
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override;
|
2018-07-18 15:48:21 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
|
|
|
|
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;
|
|
|
|
void *lockResource(GraphicsAllocation *graphicsAllocation) override { return nullptr; };
|
|
|
|
void unlockResource(GraphicsAllocation *graphicsAllocation) override{};
|
|
|
|
|
2018-02-28 19:09:48 +08:00
|
|
|
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
void cleanOsHandles(OsHandleStorage &handleStorage) override;
|
|
|
|
|
|
|
|
uint64_t getSystemSharedMemory() override;
|
|
|
|
uint64_t getMaxApplicationAddress() override;
|
2018-03-12 22:24:46 +08:00
|
|
|
uint64_t getInternalHeapBaseAddress() override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) override;
|
|
|
|
|
|
|
|
void turnOnFakingBigAllocations();
|
|
|
|
|
2018-09-26 23:45:35 +08:00
|
|
|
Allocator32bit *create32BitAllocator(bool enableLocalMemory);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
private:
|
|
|
|
unsigned long long counter = 0;
|
|
|
|
bool fakeBigAllocations = false;
|
|
|
|
};
|
|
|
|
} // namespace OCLRT
|