2019-03-01 23:14:28 +08:00
|
|
|
/*
|
2020-01-08 19:36:09 +08:00
|
|
|
* Copyright (C) 2019-2020 Intel Corporation
|
2019-03-01 23:14:28 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-04-02 17:28:38 +08:00
|
|
|
#include "shared/source/helpers/constants.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/os_memory.h"
|
|
|
|
#include "shared/source/utilities/heap_allocator.h"
|
2019-03-01 23:14:28 +08:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2019-03-01 23:14:28 +08:00
|
|
|
|
|
|
|
enum class HeapIndex : uint32_t {
|
|
|
|
HEAP_INTERNAL_DEVICE_MEMORY = 0u,
|
|
|
|
HEAP_INTERNAL = 1u,
|
|
|
|
HEAP_EXTERNAL_DEVICE_MEMORY = 2u,
|
|
|
|
HEAP_EXTERNAL = 3u,
|
|
|
|
HEAP_STANDARD,
|
|
|
|
HEAP_STANDARD64KB,
|
|
|
|
HEAP_SVM,
|
2020-01-08 19:36:09 +08:00
|
|
|
HEAP_EXTENDED,
|
2019-03-01 23:14:28 +08:00
|
|
|
|
|
|
|
// Please put new heap indexes above this line
|
|
|
|
TOTAL_HEAPS
|
|
|
|
};
|
|
|
|
|
|
|
|
class GfxPartition {
|
|
|
|
public:
|
2020-08-12 18:18:34 +08:00
|
|
|
GfxPartition(OSMemory::ReservedCpuAddressRange &sharedReservedCpuAddressRange);
|
2019-07-29 23:50:46 +08:00
|
|
|
MOCKABLE_VIRTUAL ~GfxPartition();
|
2019-03-01 23:14:28 +08:00
|
|
|
|
2020-01-30 00:48:36 +08:00
|
|
|
void init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices);
|
2019-03-01 23:14:28 +08:00
|
|
|
|
|
|
|
void heapInit(HeapIndex heapIndex, uint64_t base, uint64_t size) {
|
|
|
|
getHeap(heapIndex).init(base, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t heapAllocate(HeapIndex heapIndex, size_t &size) {
|
|
|
|
return getHeap(heapIndex).allocate(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void heapFree(HeapIndex heapIndex, uint64_t ptr, size_t size) {
|
|
|
|
getHeap(heapIndex).free(ptr, size);
|
|
|
|
}
|
|
|
|
|
2019-07-29 23:50:46 +08:00
|
|
|
MOCKABLE_VIRTUAL void freeGpuAddressRange(uint64_t ptr, size_t size);
|
2019-04-18 21:30:47 +08:00
|
|
|
|
2019-03-01 23:14:28 +08:00
|
|
|
uint64_t getHeapBase(HeapIndex heapIndex) {
|
|
|
|
return getHeap(heapIndex).getBase();
|
|
|
|
}
|
2019-04-04 20:22:13 +08:00
|
|
|
|
2019-03-18 17:06:01 +08:00
|
|
|
uint64_t getHeapLimit(HeapIndex heapIndex) {
|
2019-04-18 21:30:47 +08:00
|
|
|
return getHeap(heapIndex).getLimit();
|
2019-03-18 17:06:01 +08:00
|
|
|
}
|
2019-03-01 23:14:28 +08:00
|
|
|
|
2019-04-15 21:20:51 +08:00
|
|
|
uint64_t getHeapMinimalAddress(HeapIndex heapIndex) {
|
|
|
|
return getHeapBase(heapIndex) + heapGranularity;
|
|
|
|
}
|
|
|
|
|
2019-04-18 21:30:47 +08:00
|
|
|
bool isLimitedRange() { return getHeap(HeapIndex::HEAP_SVM).getSize() == 0ull; }
|
|
|
|
|
2019-04-04 20:22:13 +08:00
|
|
|
static const uint64_t heapGranularity = MemoryConstants::pageSize64k;
|
|
|
|
|
2019-03-01 23:14:28 +08:00
|
|
|
static const std::array<HeapIndex, 4> heap32Names;
|
2020-01-08 19:36:09 +08:00
|
|
|
static const std::array<HeapIndex, 7> heapNonSvmNames;
|
2019-03-01 23:14:28 +08:00
|
|
|
|
|
|
|
protected:
|
2020-01-30 00:48:36 +08:00
|
|
|
void initAdditionalRange(uint64_t gpuAddressSpace, uint64_t &gfxBase, uint64_t &gfxTop, uint32_t rootDeviceIndex, size_t numRootDevices);
|
2019-09-10 20:59:45 +08:00
|
|
|
|
2019-03-01 23:14:28 +08:00
|
|
|
class Heap {
|
|
|
|
public:
|
|
|
|
Heap() = default;
|
2019-04-18 21:30:47 +08:00
|
|
|
void init(uint64_t base, uint64_t size);
|
2019-03-01 23:14:28 +08:00
|
|
|
uint64_t getBase() const { return base; }
|
|
|
|
uint64_t getSize() const { return size; }
|
2020-01-08 19:36:09 +08:00
|
|
|
uint64_t getLimit() const { return size ? base + size - 1 : 0; }
|
2019-03-01 23:14:28 +08:00
|
|
|
uint64_t allocate(size_t &size) { return alloc->allocate(size); }
|
|
|
|
void free(uint64_t ptr, size_t size) { alloc->free(ptr, size); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint64_t base = 0, size = 0;
|
|
|
|
std::unique_ptr<HeapAllocator> alloc;
|
|
|
|
};
|
|
|
|
|
|
|
|
Heap &getHeap(HeapIndex heapIndex) {
|
2019-04-18 21:30:47 +08:00
|
|
|
return heaps[static_cast<uint32_t>(heapIndex)];
|
2019-03-01 23:14:28 +08:00
|
|
|
}
|
|
|
|
|
2019-04-18 21:30:47 +08:00
|
|
|
std::array<Heap, static_cast<uint32_t>(HeapIndex::TOTAL_HEAPS)> heaps;
|
|
|
|
|
2020-08-12 18:18:34 +08:00
|
|
|
OSMemory::ReservedCpuAddressRange &reservedCpuAddressRange;
|
2019-07-30 22:46:58 +08:00
|
|
|
std::unique_ptr<OSMemory> osMemory;
|
2019-03-01 23:14:28 +08:00
|
|
|
};
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|