Do not copy std::vector of OS handles when it is not needed
This change replaces unneeded copying of std::vectors with usage of const references. Furthermore, it adds reserve() call before filling the container via push_back(). Signed-off-by: Patryk Wrobel <patryk.wrobel@intel.com>
This commit is contained in:
parent
40ddeeb3ba
commit
9b26e96b11
|
@ -508,6 +508,8 @@ ze_result_t ContextImp::openIpcMemHandles(ze_device_handle_t hDevice,
|
||||||
ze_ipc_memory_flags_t flags,
|
ze_ipc_memory_flags_t flags,
|
||||||
void **pptr) {
|
void **pptr) {
|
||||||
std::vector<NEO::osHandle> handles;
|
std::vector<NEO::osHandle> handles;
|
||||||
|
handles.reserve(numIpcHandles);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < numIpcHandles; i++) {
|
for (uint32_t i = 0; i < numIpcHandles; i++) {
|
||||||
uint64_t handle = 0;
|
uint64_t handle = 0;
|
||||||
memcpy_s(&handle,
|
memcpy_s(&handle,
|
||||||
|
|
|
@ -513,7 +513,7 @@ void *DriverHandleImp::importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flag
|
||||||
return reinterpret_cast<void *>(alloc->getGpuAddress());
|
return reinterpret_cast<void *>(alloc->getGpuAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
void *DriverHandleImp::importFdHandles(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, std::vector<NEO::osHandle> handles, NEO::GraphicsAllocation **pAlloc) {
|
void *DriverHandleImp::importFdHandles(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, const std::vector<NEO::osHandle> &handles, NEO::GraphicsAllocation **pAlloc) {
|
||||||
NEO::AllocationProperties unifiedMemoryProperties{neoDevice->getRootDeviceIndex(),
|
NEO::AllocationProperties unifiedMemoryProperties{neoDevice->getRootDeviceIndex(),
|
||||||
MemoryConstants::pageSize,
|
MemoryConstants::pageSize,
|
||||||
NEO::AllocationType::BUFFER,
|
NEO::AllocationType::BUFFER,
|
||||||
|
|
|
@ -40,7 +40,7 @@ struct DriverHandleImp : public DriverHandle {
|
||||||
NEO::MemoryManager *getMemoryManager() override;
|
NEO::MemoryManager *getMemoryManager() override;
|
||||||
void setMemoryManager(NEO::MemoryManager *memoryManager) override;
|
void setMemoryManager(NEO::MemoryManager *memoryManager) override;
|
||||||
MOCKABLE_VIRTUAL void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAlloc);
|
MOCKABLE_VIRTUAL void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::GraphicsAllocation **pAlloc);
|
||||||
MOCKABLE_VIRTUAL void *importFdHandles(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, std::vector<NEO::osHandle> handles, NEO::GraphicsAllocation **pAlloc);
|
MOCKABLE_VIRTUAL void *importFdHandles(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, const std::vector<NEO::osHandle> &handles, NEO::GraphicsAllocation **pAlloc);
|
||||||
MOCKABLE_VIRTUAL void *importNTHandle(ze_device_handle_t hDevice, void *handle);
|
MOCKABLE_VIRTUAL void *importNTHandle(ze_device_handle_t hDevice, void *handle);
|
||||||
ze_result_t checkMemoryAccessFromDevice(Device *device, const void *ptr) override;
|
ze_result_t checkMemoryAccessFromDevice(Device *device, const void *ptr) override;
|
||||||
NEO::SVMAllocsManager *getSvmAllocsManager() override;
|
NEO::SVMAllocsManager *getSvmAllocsManager() override;
|
||||||
|
|
|
@ -387,7 +387,7 @@ struct ContextGetIpcHandleMock : public L0::ContextImp {
|
||||||
class MemoryManagerIpcMock : public NEO::MemoryManager {
|
class MemoryManagerIpcMock : public NEO::MemoryManager {
|
||||||
public:
|
public:
|
||||||
MemoryManagerIpcMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MemoryManager(executionEnvironment) {}
|
MemoryManagerIpcMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MemoryManager(executionEnvironment) {}
|
||||||
NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; }
|
NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; }
|
||||||
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; }
|
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; }
|
||||||
void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{};
|
void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{};
|
||||||
void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{};
|
void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{};
|
||||||
|
@ -490,7 +490,7 @@ class MemoryManagerOpenIpcMock : public MemoryManagerIpcMock {
|
||||||
alloc->setGpuBaseAddress(0xabcd);
|
alloc->setGpuBaseAddress(0xabcd);
|
||||||
return alloc;
|
return alloc;
|
||||||
}
|
}
|
||||||
NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
|
NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
|
||||||
if (failOnCreateGraphicsAllocationFromSharedHandle) {
|
if (failOnCreateGraphicsAllocationFromSharedHandle) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -656,7 +656,7 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager {
|
||||||
return alloc;
|
return alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
|
NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
|
||||||
if (failOnCreateGraphicsAllocationFromSharedHandle) {
|
if (failOnCreateGraphicsAllocationFromSharedHandle) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ class MemoryManagerEventPoolFailMock : public NEO::MemoryManager {
|
||||||
void *createMultiGraphicsAllocationInSystemMemoryPool(RootDeviceIndicesContainer &rootDeviceIndices, AllocationProperties &properties, NEO::MultiGraphicsAllocation &multiGraphicsAllocation) override {
|
void *createMultiGraphicsAllocationInSystemMemoryPool(RootDeviceIndicesContainer &rootDeviceIndices, AllocationProperties &properties, NEO::MultiGraphicsAllocation &multiGraphicsAllocation) override {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; }
|
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; }
|
||||||
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; }
|
NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; }
|
||||||
void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{};
|
void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{};
|
||||||
void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{};
|
void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{};
|
||||||
|
|
|
@ -91,7 +91,7 @@ class MemoryManager {
|
||||||
|
|
||||||
virtual bool verifyHandle(osHandle handle, uint32_t rootDeviceIndex, bool) { return true; }
|
virtual bool verifyHandle(osHandle handle, uint32_t rootDeviceIndex, bool) { return true; }
|
||||||
virtual bool isNTHandle(osHandle handle, uint32_t rootDeviceIndex) { return false; }
|
virtual bool isNTHandle(osHandle handle, uint32_t rootDeviceIndex) { return false; }
|
||||||
virtual GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) = 0;
|
virtual GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) = 0;
|
||||||
virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) = 0;
|
virtual GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) = 0;
|
||||||
virtual void closeSharedHandle(GraphicsAllocation *graphicsAllocation){};
|
virtual void closeSharedHandle(GraphicsAllocation *graphicsAllocation){};
|
||||||
virtual GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) = 0;
|
virtual GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) = 0;
|
||||||
|
|
|
@ -235,7 +235,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(con
|
||||||
return memoryAllocation;
|
return memoryAllocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) {
|
GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ class OsAgnosticMemoryManager : public MemoryManager {
|
||||||
OsAgnosticMemoryManager(bool aubUsage, ExecutionEnvironment &executionEnvironment);
|
OsAgnosticMemoryManager(bool aubUsage, ExecutionEnvironment &executionEnvironment);
|
||||||
void initialize(bool aubUsage);
|
void initialize(bool aubUsage);
|
||||||
~OsAgnosticMemoryManager() override;
|
~OsAgnosticMemoryManager() override;
|
||||||
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
||||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
||||||
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; }
|
||||||
|
|
||||||
|
|
|
@ -680,7 +680,7 @@ BufferObject *DrmMemoryManager::findAndReferenceSharedBufferObject(int boHandle,
|
||||||
return bo;
|
return bo;
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) {
|
GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) {
|
||||||
BufferObjects bos;
|
BufferObjects bos;
|
||||||
std::vector<size_t> sizes;
|
std::vector<size_t> sizes;
|
||||||
size_t totalSize = 0;
|
size_t totalSize = 0;
|
||||||
|
|
|
@ -36,7 +36,7 @@ class DrmMemoryManager : public MemoryManager {
|
||||||
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override;
|
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override;
|
||||||
void handleFenceCompletion(GraphicsAllocation *allocation) override;
|
void handleFenceCompletion(GraphicsAllocation *allocation) override;
|
||||||
GraphicsAllocation *createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) override;
|
GraphicsAllocation *createGraphicsAllocationFromExistingStorage(AllocationProperties &properties, void *ptr, MultiGraphicsAllocation &multiGraphicsAllocation) override;
|
||||||
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
||||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
||||||
void closeSharedHandle(GraphicsAllocation *gfxAllocation) override;
|
void closeSharedHandle(GraphicsAllocation *gfxAllocation) override;
|
||||||
|
|
||||||
|
|
|
@ -467,7 +467,7 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handl
|
||||||
return allocation.release();
|
return allocation.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) {
|
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ class WddmMemoryManager : public MemoryManager {
|
||||||
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override;
|
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override;
|
||||||
void handleFenceCompletion(GraphicsAllocation *allocation) override;
|
void handleFenceCompletion(GraphicsAllocation *allocation) override;
|
||||||
|
|
||||||
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
||||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
||||||
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override;
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override;
|
||||||
|
|
||||||
|
|
|
@ -306,7 +306,7 @@ class FailMemoryManager : public MockMemoryManager {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
|
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -340,7 +340,7 @@ TEST_F(DeviceGetCapsTest, givenFlagEnabled64kbPagesWhenCallConstructorMemoryMana
|
||||||
MockMemoryManager(ExecutionEnvironment &executionEnvironment) : MemoryManager(executionEnvironment) {}
|
MockMemoryManager(ExecutionEnvironment &executionEnvironment) : MemoryManager(executionEnvironment) {}
|
||||||
void addAllocationToHostPtrManager(GraphicsAllocation *memory) override{};
|
void addAllocationToHostPtrManager(GraphicsAllocation *memory) override{};
|
||||||
void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) override{};
|
void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) override{};
|
||||||
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(std::vector<osHandle> handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; }
|
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; }
|
||||||
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; };
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override { return nullptr; };
|
||||||
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; };
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { return nullptr; };
|
||||||
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; };
|
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { return AllocationStatus::Success; };
|
||||||
|
|
Loading…
Reference in New Issue