1 /* 2 * Copyright (C) 2021 Intel Corporation 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 */ 7 8 #pragma once 9 10 #include "shared/source/memory_manager/gfx_partition.h" 11 12 #include <vector> 13 14 namespace NEO { 15 16 class AlignmentSelector { 17 public: 18 constexpr static inline float anyWastage = 1.f; 19 constexpr static inline float noWastage = 0.f; 20 21 struct CandidateAlignment { 22 size_t alignment; // selected alignment for the allocation 23 bool applyForSmallerSize; // if enabled, this alignment can be used even when size < alignment 24 float maxMemoryWastage; // maximum percent of wasted memory after alignUp(size, alignment) 25 HeapIndex heap; // GPUVA heap, which allocation should go to 26 }; 27 28 AlignmentSelector() = default; 29 30 void addCandidateAlignment(size_t alignment, bool applyForSmallerSize, float maxMemoryWastage); 31 void addCandidateAlignment(size_t alignment, bool applyForSmallerSize, float maxMemoryWastage, HeapIndex heap); 32 33 CandidateAlignment selectAlignment(size_t size) const; peekCandidateAlignments()34 auto &peekCandidateAlignments() const { return candidateAlignments; } 35 36 private: 37 std::vector<CandidateAlignment> candidateAlignments; // sorted by alignment size 38 }; 39 40 bool operator==(const AlignmentSelector::CandidateAlignment &left, const AlignmentSelector::CandidateAlignment &right); 41 42 } // namespace NEO 43