mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-24 21:18:24 +08:00
Initial commit
Change-Id: I4bf1707bd3dfeadf2c17b0a7daff372b1925ebbd
This commit is contained in:
94
runtime/os_interface/linux/drm_memory_manager.h
Normal file
94
runtime/os_interface/linux/drm_memory_manager.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "drm_gem_close_worker.h"
|
||||
#include "runtime/memory_manager/memory_manager.h"
|
||||
#include "runtime/os_interface/linux/drm_allocation.h"
|
||||
#include "runtime/os_interface/linux/drm_neo.h"
|
||||
#include <map>
|
||||
#include <sys/mman.h>
|
||||
|
||||
namespace OCLRT {
|
||||
class BufferObject;
|
||||
class Drm;
|
||||
|
||||
class DrmMemoryManager : public MemoryManager {
|
||||
public:
|
||||
using MemoryManager::createGraphicsAllocationFromSharedHandle;
|
||||
|
||||
DrmMemoryManager(Drm *drm, gemCloseWorkerMode mode, bool forcePinAllowed);
|
||||
~DrmMemoryManager() override;
|
||||
|
||||
BufferObject *getPinBB() const;
|
||||
|
||||
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override;
|
||||
DrmAllocation *allocateGraphicsMemory(size_t size, size_t alignment) override {
|
||||
return allocateGraphicsMemory(size, alignment, false);
|
||||
}
|
||||
DrmAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin) override;
|
||||
DrmAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin) override;
|
||||
DrmAllocation *allocateGraphicsMemory(size_t size, const void *ptr) override {
|
||||
return allocateGraphicsMemory(size, ptr, false);
|
||||
}
|
||||
DrmAllocation *allocateGraphicsMemory(size_t size, const void *ptr, bool forcePin) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override;
|
||||
DrmAllocation *allocate32BitGraphicsMemory(size_t size, void *ptr) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness, bool reuseBO) override;
|
||||
GraphicsAllocation *createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) override;
|
||||
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { return nullptr; }
|
||||
void *lockResource(GraphicsAllocation *graphicsAllocation) override { return nullptr; };
|
||||
void unlockResource(GraphicsAllocation *graphicsAllocation) override{};
|
||||
|
||||
uint64_t getSystemSharedMemory() override;
|
||||
uint64_t getMaxApplicationAddress() override;
|
||||
|
||||
bool populateOsHandles(OsHandleStorage &handleStorage) override;
|
||||
void cleanOsHandles(OsHandleStorage &handleStorage) override;
|
||||
|
||||
// drm/i915 ioctl wrappers
|
||||
uint32_t unreference(BufferObject *bo, bool synchronousDestroy = false);
|
||||
|
||||
// CloseWorker delegate
|
||||
void push(DrmAllocation *alloc);
|
||||
|
||||
DrmAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) override;
|
||||
|
||||
protected:
|
||||
BufferObject *findAndReferenceSharedBufferObject(int boHandle);
|
||||
BufferObject *createSharedBufferObject(int boHandle, size_t size, bool requireSpecificBitness);
|
||||
void eraseSharedBufferObject(BufferObject *bo);
|
||||
void pushSharedBufferObject(BufferObject *bo);
|
||||
BufferObject *allocUserptr(uintptr_t address, size_t size, uint64_t flags, bool softpin);
|
||||
|
||||
Drm *drm;
|
||||
BufferObject *pinBB;
|
||||
size_t pinThreshold = 8 * 1024 * 1024;
|
||||
std::unique_ptr<DrmGemCloseWorker> gemCloseWorker;
|
||||
decltype(&lseek) lseekFunction = lseek;
|
||||
decltype(&mmap) mmapFunction = mmap;
|
||||
decltype(&munmap) munmapFunction = munmap;
|
||||
decltype(&close) closeFunction = close;
|
||||
std::vector<BufferObject *> sharingBufferObjects;
|
||||
std::recursive_mutex mtx;
|
||||
};
|
||||
} // namespace OCLRT
|
||||
Reference in New Issue
Block a user