simple_pool_manager.cc revision 11308
14661Sksewell@umich.edu/* 24661Sksewell@umich.edu * Copyright (c) 2015 Advanced Micro Devices, Inc. 34661Sksewell@umich.edu * All rights reserved. 44661Sksewell@umich.edu * 54661Sksewell@umich.edu * For use for simulation and test purposes only 64661Sksewell@umich.edu * 74661Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 84661Sksewell@umich.edu * modification, are permitted provided that the following conditions are met: 94661Sksewell@umich.edu * 104661Sksewell@umich.edu * 1. Redistributions of source code must retain the above copyright notice, 114661Sksewell@umich.edu * this list of conditions and the following disclaimer. 124661Sksewell@umich.edu * 134661Sksewell@umich.edu * 2. Redistributions in binary form must reproduce the above copyright notice, 144661Sksewell@umich.edu * this list of conditions and the following disclaimer in the documentation 154661Sksewell@umich.edu * and/or other materials provided with the distribution. 164661Sksewell@umich.edu * 174661Sksewell@umich.edu * 3. Neither the name of the copyright holder nor the names of its contributors 184661Sksewell@umich.edu * may be used to endorse or promote products derived from this software 194661Sksewell@umich.edu * without specific prior written permission. 204661Sksewell@umich.edu * 214661Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 224661Sksewell@umich.edu * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 234661Sksewell@umich.edu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 244661Sksewell@umich.edu * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 254661Sksewell@umich.edu * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 264661Sksewell@umich.edu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 274661Sksewell@umich.edu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 284661Sksewell@umich.edu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 294661Sksewell@umich.edu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 304661Sksewell@umich.edu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 314661Sksewell@umich.edu * POSSIBILITY OF SUCH DAMAGE. 324661Sksewell@umich.edu * 334661Sksewell@umich.edu * Author: John Kalamatianos 344661Sksewell@umich.edu */ 354661Sksewell@umich.edu 364661Sksewell@umich.edu#include "gpu-compute/simple_pool_manager.hh" 374661Sksewell@umich.edu 384661Sksewell@umich.edu#include "base/misc.hh" 394661Sksewell@umich.edu 404661Sksewell@umich.edu// return the min number of elements that the manager can reserve given 414661Sksewell@umich.edu// a request for "size" elements 424661Sksewell@umich.eduuint32_t 434661Sksewell@umich.eduSimplePoolManager::minAllocatedElements(uint32_t size) 444661Sksewell@umich.edu{ 454661Sksewell@umich.edu fatal_if(size <= 0 || size > poolSize(), "Illegal VGPR region size=%d\n", 464661Sksewell@umich.edu size); 474661Sksewell@umich.edu 484661Sksewell@umich.edu return size % minAllocation() > 0 ? 494661Sksewell@umich.edu (minAllocation() - (size % minAllocation())) + size : size; 504661Sksewell@umich.edu} 514661Sksewell@umich.edu 524661Sksewell@umich.edustd::string 534661Sksewell@umich.eduSimplePoolManager::printRegion() 544661Sksewell@umich.edu{ 554661Sksewell@umich.edu std::string _cout; 564661Sksewell@umich.edu if (_reservedGroups == 0) 574661Sksewell@umich.edu _cout = "VRF is empty\n"; 584661Sksewell@umich.edu else if (_reservedGroups > 0) { 594661Sksewell@umich.edu uint32_t reservedEntries = _reservedGroups * _regionSize; 604661Sksewell@umich.edu _cout = "VRF reserves " + std::to_string(reservedEntries) + " VGPRs\n"; 614661Sksewell@umich.edu } 624661Sksewell@umich.edu 634661Sksewell@umich.edu return _cout; 644661Sksewell@umich.edu} 654661Sksewell@umich.edu 664661Sksewell@umich.edubool 674661Sksewell@umich.eduSimplePoolManager::canAllocate(uint32_t numRegions, uint32_t size) 684661Sksewell@umich.edu{ 694661Sksewell@umich.edu assert(numRegions * minAllocatedElements(size) <= poolSize()); 704661Sksewell@umich.edu 714661Sksewell@umich.edu return _reservedGroups == 0; 724661Sksewell@umich.edu} 734661Sksewell@umich.edu 744661Sksewell@umich.eduvoid 754661Sksewell@umich.eduSimplePoolManager::freeRegion(uint32_t firstIdx, uint32_t lastIdx) 764661Sksewell@umich.edu{ 774661Sksewell@umich.edu assert(_reservedGroups > 0); 784661Sksewell@umich.edu --_reservedGroups; 794661Sksewell@umich.edu 804661Sksewell@umich.edu if (!_reservedGroups) 814661Sksewell@umich.edu _nxtFreeIdx = 0; 824661Sksewell@umich.edu} 834661Sksewell@umich.edu 844661Sksewell@umich.eduuint32_t 854661Sksewell@umich.eduSimplePoolManager::allocateRegion(const uint32_t size, 864661Sksewell@umich.edu uint32_t *reservedPoolSize) 874661Sksewell@umich.edu{ 884661Sksewell@umich.edu uint32_t actualSize = minAllocatedElements(size); 894661Sksewell@umich.edu uint32_t startIdx = _nxtFreeIdx; 904661Sksewell@umich.edu _nxtFreeIdx += actualSize; 914661Sksewell@umich.edu _regionSize = actualSize; 924661Sksewell@umich.edu assert(_nxtFreeIdx < poolSize()); 934661Sksewell@umich.edu *reservedPoolSize = actualSize; 944661Sksewell@umich.edu ++_reservedGroups; 954661Sksewell@umich.edu 964661Sksewell@umich.edu return startIdx; 974661Sksewell@umich.edu} 984661Sksewell@umich.edu 994661Sksewell@umich.eduuint32_t 1004661Sksewell@umich.eduSimplePoolManager::regionSize(std::pair<uint32_t, uint32_t> ®ion) 1014661Sksewell@umich.edu{ 1024661Sksewell@umich.edu bool wrapAround = (region.first > region.second); 1034661Sksewell@umich.edu if (!wrapAround) { 1044661Sksewell@umich.edu return region.second - region.first + 1; 1054661Sksewell@umich.edu } else { 1064661Sksewell@umich.edu return region.second + poolSize() - region.first + 1; 1074661Sksewell@umich.edu } 1084661Sksewell@umich.edu} 1094661Sksewell@umich.edu