2023-12-22 22:26:30 +08:00
|
|
|
/*
|
2024-01-03 21:15:24 +08:00
|
|
|
* Copyright (C) 2023-2024 Intel Corporation
|
2023-12-22 22:26:30 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "shared/source/helpers/constants.h"
|
|
|
|
#include "shared/source/memory_manager/unified_memory_manager.h"
|
|
|
|
#include "shared/source/utilities/heap_allocator.h"
|
|
|
|
#include "shared/source/utilities/sorted_vector.h"
|
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
class UsmMemAllocPool {
|
2024-01-03 21:15:24 +08:00
|
|
|
public:
|
2023-12-22 22:26:30 +08:00
|
|
|
using UnifiedMemoryProperties = SVMAllocsManager::UnifiedMemoryProperties;
|
|
|
|
struct AllocationInfo {
|
2024-03-14 23:10:57 +08:00
|
|
|
uint64_t address;
|
2023-12-22 22:26:30 +08:00
|
|
|
size_t size;
|
2024-01-03 21:15:24 +08:00
|
|
|
size_t requestedSize;
|
2023-12-22 22:26:30 +08:00
|
|
|
};
|
2024-01-03 21:15:24 +08:00
|
|
|
using AllocationsInfoStorage = BaseSortedPointerWithValueVector<AllocationInfo>;
|
2023-12-22 22:26:30 +08:00
|
|
|
|
|
|
|
UsmMemAllocPool() = default;
|
|
|
|
bool initialize(SVMAllocsManager *svmMemoryManager, const UnifiedMemoryProperties &memoryProperties, size_t poolSize);
|
|
|
|
bool isInitialized();
|
|
|
|
void cleanup();
|
2024-01-03 21:15:24 +08:00
|
|
|
bool alignmentIsAllowed(size_t alignment);
|
2023-12-22 22:26:30 +08:00
|
|
|
bool canBePooled(size_t size, const UnifiedMemoryProperties &memoryProperties);
|
|
|
|
void *createUnifiedMemoryAllocation(size_t size, const UnifiedMemoryProperties &memoryProperties);
|
|
|
|
bool isInPool(const void *ptr);
|
2024-05-15 21:30:37 +08:00
|
|
|
bool freeSVMAlloc(const void *ptr, bool blocking);
|
2024-01-03 21:15:24 +08:00
|
|
|
size_t getPooledAllocationSize(const void *ptr);
|
|
|
|
void *getPooledAllocationBasePtr(const void *ptr);
|
2024-05-15 21:30:37 +08:00
|
|
|
size_t getOffsetInPool(const void *ptr);
|
2023-12-22 22:26:30 +08:00
|
|
|
|
2024-08-06 19:38:23 +08:00
|
|
|
static constexpr auto allocationThreshold = 1 * MemoryConstants::megaByte;
|
2024-04-08 21:46:31 +08:00
|
|
|
static constexpr auto chunkAlignment = 512u;
|
2024-08-06 19:38:23 +08:00
|
|
|
static constexpr auto startingOffset = 2 * allocationThreshold;
|
2023-12-22 22:26:30 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
size_t poolSize{};
|
|
|
|
std::unique_ptr<HeapAllocator> chunkAllocator;
|
|
|
|
void *pool{};
|
|
|
|
void *poolEnd{};
|
|
|
|
SVMAllocsManager *svmMemoryManager{};
|
|
|
|
AllocationsInfoStorage allocations;
|
|
|
|
std::mutex mtx;
|
|
|
|
InternalMemoryType poolMemoryType;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace NEO
|