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:
Patryk Wrobel
2022-10-20 22:18:08 +00:00
committed by Compute-Runtime-Automation
parent 40ddeeb3ba
commit 9b26e96b11
14 changed files with 17 additions and 15 deletions

View File

@@ -508,6 +508,8 @@ ze_result_t ContextImp::openIpcMemHandles(ze_device_handle_t hDevice,
ze_ipc_memory_flags_t flags,
void **pptr) {
std::vector<NEO::osHandle> handles;
handles.reserve(numIpcHandles);
for (uint32_t i = 0; i < numIpcHandles; i++) {
uint64_t handle = 0;
memcpy_s(&handle,

View File

@@ -513,7 +513,7 @@ void *DriverHandleImp::importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flag
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(),
MemoryConstants::pageSize,
NEO::AllocationType::BUFFER,

View File

@@ -40,7 +40,7 @@ struct DriverHandleImp : public DriverHandle {
NEO::MemoryManager *getMemoryManager() 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 *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);
ze_result_t checkMemoryAccessFromDevice(Device *device, const void *ptr) override;
NEO::SVMAllocsManager *getSvmAllocsManager() override;

View File

@@ -387,7 +387,7 @@ struct ContextGetIpcHandleMock : public L0::ContextImp {
class MemoryManagerIpcMock : public NEO::MemoryManager {
public:
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; }
void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{};
void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{};
@@ -490,7 +490,7 @@ class MemoryManagerOpenIpcMock : public MemoryManagerIpcMock {
alloc->setGpuBaseAddress(0xabcd);
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) {
return nullptr;
}
@@ -656,7 +656,7 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager {
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) {
return nullptr;
}

View File

@@ -50,7 +50,7 @@ class MemoryManagerEventPoolFailMock : public NEO::MemoryManager {
void *createMultiGraphicsAllocationInSystemMemoryPool(RootDeviceIndicesContainer &rootDeviceIndices, AllocationProperties &properties, NEO::MultiGraphicsAllocation &multiGraphicsAllocation) override {
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; }
void addAllocationToHostPtrManager(NEO::GraphicsAllocation *memory) override{};
void removeAllocationFromHostPtrManager(NEO::GraphicsAllocation *memory) override{};