main.cc revision 11534
111308Santhony.gutierrez@amd.com/* 211308Santhony.gutierrez@amd.com * Copyright (c) 2012-2015 Advanced Micro Devices, Inc. 311308Santhony.gutierrez@amd.com * All rights reserved. 411308Santhony.gutierrez@amd.com * 511308Santhony.gutierrez@amd.com * For use for simulation and test purposes only 611308Santhony.gutierrez@amd.com * 711308Santhony.gutierrez@amd.com * Redistribution and use in source and binary forms, with or without 811308Santhony.gutierrez@amd.com * modification, are permitted provided that the following conditions are met: 911308Santhony.gutierrez@amd.com * 1011308Santhony.gutierrez@amd.com * 1. Redistributions of source code must retain the above copyright notice, 1111308Santhony.gutierrez@amd.com * this list of conditions and the following disclaimer. 1211308Santhony.gutierrez@amd.com * 1311308Santhony.gutierrez@amd.com * 2. Redistributions in binary form must reproduce the above copyright notice, 1411308Santhony.gutierrez@amd.com * this list of conditions and the following disclaimer in the documentation 1511308Santhony.gutierrez@amd.com * and/or other materials provided with the distribution. 1611308Santhony.gutierrez@amd.com * 1711308Santhony.gutierrez@amd.com * 3. Neither the name of the copyright holder nor the names of its contributors 1811308Santhony.gutierrez@amd.com * may be used to endorse or promote products derived from this software 1911308Santhony.gutierrez@amd.com * without specific prior written permission. 2011308Santhony.gutierrez@amd.com * 2111308Santhony.gutierrez@amd.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2211308Santhony.gutierrez@amd.com * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2311308Santhony.gutierrez@amd.com * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2411308Santhony.gutierrez@amd.com * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 2511308Santhony.gutierrez@amd.com * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2611308Santhony.gutierrez@amd.com * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2711308Santhony.gutierrez@amd.com * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2811308Santhony.gutierrez@amd.com * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2911308Santhony.gutierrez@amd.com * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3011308Santhony.gutierrez@amd.com * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3111308Santhony.gutierrez@amd.com * POSSIBILITY OF SUCH DAMAGE. 3211308Santhony.gutierrez@amd.com * 3311308Santhony.gutierrez@amd.com * Author: Steve Reinhardt 3411308Santhony.gutierrez@amd.com */ 3511308Santhony.gutierrez@amd.com 3611308Santhony.gutierrez@amd.com#include "arch/hsail/insts/decl.hh" 3711308Santhony.gutierrez@amd.com#include "debug/GPUExec.hh" 3811308Santhony.gutierrez@amd.com#include "gpu-compute/dispatcher.hh" 3911308Santhony.gutierrez@amd.com#include "gpu-compute/simple_pool_manager.hh" 4011308Santhony.gutierrez@amd.com 4111308Santhony.gutierrez@amd.comnamespace HsailISA 4211308Santhony.gutierrez@amd.com{ 4311308Santhony.gutierrez@amd.com template<> const char *B1::label = "b1"; 4411308Santhony.gutierrez@amd.com template<> const char *B8::label = "b8"; 4511308Santhony.gutierrez@amd.com template<> const char *B16::label = "b16"; 4611308Santhony.gutierrez@amd.com template<> const char *B32::label = "b32"; 4711308Santhony.gutierrez@amd.com template<> const char *B64::label = "b64"; 4811308Santhony.gutierrez@amd.com 4911308Santhony.gutierrez@amd.com template<> const char *S8::label = "s8"; 5011308Santhony.gutierrez@amd.com template<> const char *S16::label = "s16"; 5111308Santhony.gutierrez@amd.com template<> const char *S32::label = "s32"; 5211308Santhony.gutierrez@amd.com template<> const char *S64::label = "s64"; 5311308Santhony.gutierrez@amd.com 5411308Santhony.gutierrez@amd.com template<> const char *U8::label = "u8"; 5511308Santhony.gutierrez@amd.com template<> const char *U16::label = "u16"; 5611308Santhony.gutierrez@amd.com template<> const char *U32::label = "u32"; 5711308Santhony.gutierrez@amd.com template<> const char *U64::label = "u64"; 5811308Santhony.gutierrez@amd.com 5911308Santhony.gutierrez@amd.com template<> const char *F32::label = "f32"; 6011308Santhony.gutierrez@amd.com template<> const char *F64::label = "f64"; 6111308Santhony.gutierrez@amd.com 6211308Santhony.gutierrez@amd.com const char* 6311308Santhony.gutierrez@amd.com cmpOpToString(Brig::BrigCompareOperation cmpOp) 6411308Santhony.gutierrez@amd.com { 6511308Santhony.gutierrez@amd.com using namespace Brig; 6611308Santhony.gutierrez@amd.com 6711308Santhony.gutierrez@amd.com switch (cmpOp) { 6811308Santhony.gutierrez@amd.com case BRIG_COMPARE_EQ: 6911308Santhony.gutierrez@amd.com return "eq"; 7011308Santhony.gutierrez@amd.com case BRIG_COMPARE_NE: 7111308Santhony.gutierrez@amd.com return "ne"; 7211308Santhony.gutierrez@amd.com case BRIG_COMPARE_LT: 7311308Santhony.gutierrez@amd.com return "lt"; 7411308Santhony.gutierrez@amd.com case BRIG_COMPARE_LE: 7511308Santhony.gutierrez@amd.com return "le"; 7611308Santhony.gutierrez@amd.com case BRIG_COMPARE_GT: 7711308Santhony.gutierrez@amd.com return "gt"; 7811308Santhony.gutierrez@amd.com case BRIG_COMPARE_GE: 7911308Santhony.gutierrez@amd.com return "ge"; 8011308Santhony.gutierrez@amd.com case BRIG_COMPARE_EQU: 8111308Santhony.gutierrez@amd.com return "equ"; 8211308Santhony.gutierrez@amd.com case BRIG_COMPARE_NEU: 8311308Santhony.gutierrez@amd.com return "neu"; 8411308Santhony.gutierrez@amd.com case BRIG_COMPARE_LTU: 8511308Santhony.gutierrez@amd.com return "ltu"; 8611308Santhony.gutierrez@amd.com case BRIG_COMPARE_LEU: 8711308Santhony.gutierrez@amd.com return "leu"; 8811308Santhony.gutierrez@amd.com case BRIG_COMPARE_GTU: 8911308Santhony.gutierrez@amd.com return "gtu"; 9011308Santhony.gutierrez@amd.com case BRIG_COMPARE_GEU: 9111308Santhony.gutierrez@amd.com return "geu"; 9211308Santhony.gutierrez@amd.com case BRIG_COMPARE_NUM: 9311308Santhony.gutierrez@amd.com return "num"; 9411308Santhony.gutierrez@amd.com case BRIG_COMPARE_NAN: 9511308Santhony.gutierrez@amd.com return "nan"; 9611308Santhony.gutierrez@amd.com case BRIG_COMPARE_SEQ: 9711308Santhony.gutierrez@amd.com return "seq"; 9811308Santhony.gutierrez@amd.com case BRIG_COMPARE_SNE: 9911308Santhony.gutierrez@amd.com return "sne"; 10011308Santhony.gutierrez@amd.com case BRIG_COMPARE_SLT: 10111308Santhony.gutierrez@amd.com return "slt"; 10211308Santhony.gutierrez@amd.com case BRIG_COMPARE_SLE: 10311308Santhony.gutierrez@amd.com return "sle"; 10411308Santhony.gutierrez@amd.com case BRIG_COMPARE_SGT: 10511308Santhony.gutierrez@amd.com return "sgt"; 10611308Santhony.gutierrez@amd.com case BRIG_COMPARE_SGE: 10711308Santhony.gutierrez@amd.com return "sge"; 10811308Santhony.gutierrez@amd.com case BRIG_COMPARE_SGEU: 10911308Santhony.gutierrez@amd.com return "sgeu"; 11011308Santhony.gutierrez@amd.com case BRIG_COMPARE_SEQU: 11111308Santhony.gutierrez@amd.com return "sequ"; 11211308Santhony.gutierrez@amd.com case BRIG_COMPARE_SNEU: 11311308Santhony.gutierrez@amd.com return "sneu"; 11411308Santhony.gutierrez@amd.com case BRIG_COMPARE_SLTU: 11511308Santhony.gutierrez@amd.com return "sltu"; 11611308Santhony.gutierrez@amd.com case BRIG_COMPARE_SLEU: 11711308Santhony.gutierrez@amd.com return "sleu"; 11811308Santhony.gutierrez@amd.com case BRIG_COMPARE_SNUM: 11911308Santhony.gutierrez@amd.com return "snum"; 12011308Santhony.gutierrez@amd.com case BRIG_COMPARE_SNAN: 12111308Santhony.gutierrez@amd.com return "snan"; 12211308Santhony.gutierrez@amd.com case BRIG_COMPARE_SGTU: 12311308Santhony.gutierrez@amd.com return "sgtu"; 12411308Santhony.gutierrez@amd.com default: 12511308Santhony.gutierrez@amd.com return "unknown"; 12611308Santhony.gutierrez@amd.com } 12711308Santhony.gutierrez@amd.com } 12811308Santhony.gutierrez@amd.com 12911308Santhony.gutierrez@amd.com void 13011308Santhony.gutierrez@amd.com Ret::execute(GPUDynInstPtr gpuDynInst) 13111308Santhony.gutierrez@amd.com { 13211308Santhony.gutierrez@amd.com Wavefront *w = gpuDynInst->wavefront(); 13311308Santhony.gutierrez@amd.com 13411308Santhony.gutierrez@amd.com const VectorMask &mask = w->get_pred(); 13511308Santhony.gutierrez@amd.com 13611308Santhony.gutierrez@amd.com // mask off completed work-items 13711534Sjohn.kalamatianos@amd.com for (int lane = 0; lane < w->computeUnit->wfSize(); ++lane) { 13811308Santhony.gutierrez@amd.com if (mask[lane]) { 13911308Santhony.gutierrez@amd.com w->init_mask[lane] = 0; 14011308Santhony.gutierrez@amd.com } 14111308Santhony.gutierrez@amd.com 14211308Santhony.gutierrez@amd.com } 14311308Santhony.gutierrez@amd.com 14411308Santhony.gutierrez@amd.com // delete extra instructions fetched for completed work-items 14511308Santhony.gutierrez@amd.com w->instructionBuffer.erase(w->instructionBuffer.begin() + 1, 14611308Santhony.gutierrez@amd.com w->instructionBuffer.end()); 14711308Santhony.gutierrez@amd.com if (w->pendingFetch) { 14811308Santhony.gutierrez@amd.com w->dropFetch = true; 14911308Santhony.gutierrez@amd.com } 15011308Santhony.gutierrez@amd.com 15111308Santhony.gutierrez@amd.com // if all work-items have completed, then wave-front is done 15211308Santhony.gutierrez@amd.com if (w->init_mask.none()) { 15311308Santhony.gutierrez@amd.com w->status = Wavefront::S_STOPPED; 15411308Santhony.gutierrez@amd.com 15511308Santhony.gutierrez@amd.com int32_t refCount = w->computeUnit->getLds(). 15611308Santhony.gutierrez@amd.com decreaseRefCounter(w->dispatchid, w->wg_id); 15711308Santhony.gutierrez@amd.com 15811308Santhony.gutierrez@amd.com DPRINTF(GPUExec, "CU%d: decrease ref ctr WG[%d] to [%d]\n", 15911308Santhony.gutierrez@amd.com w->computeUnit->cu_id, w->wg_id, refCount); 16011308Santhony.gutierrez@amd.com 16111308Santhony.gutierrez@amd.com // free the vector registers of the completed wavefront 16211308Santhony.gutierrez@amd.com w->computeUnit->vectorRegsReserved[w->simdId] -= 16311308Santhony.gutierrez@amd.com w->reservedVectorRegs; 16411308Santhony.gutierrez@amd.com 16511308Santhony.gutierrez@amd.com assert(w->computeUnit->vectorRegsReserved[w->simdId] >= 0); 16611308Santhony.gutierrez@amd.com 16711308Santhony.gutierrez@amd.com uint32_t endIndex = (w->startVgprIndex + 16811308Santhony.gutierrez@amd.com w->reservedVectorRegs - 1) % 16911308Santhony.gutierrez@amd.com w->computeUnit->vrf[w->simdId]->numRegs(); 17011308Santhony.gutierrez@amd.com 17111308Santhony.gutierrez@amd.com w->computeUnit->vrf[w->simdId]->manager-> 17211308Santhony.gutierrez@amd.com freeRegion(w->startVgprIndex, endIndex); 17311308Santhony.gutierrez@amd.com 17411308Santhony.gutierrez@amd.com w->reservedVectorRegs = 0; 17511308Santhony.gutierrez@amd.com w->startVgprIndex = 0; 17611308Santhony.gutierrez@amd.com w->computeUnit->completedWfs++; 17711308Santhony.gutierrez@amd.com 17811308Santhony.gutierrez@amd.com DPRINTF(GPUExec, "Doing return for CU%d: WF[%d][%d][%d]\n", 17911308Santhony.gutierrez@amd.com w->computeUnit->cu_id, w->simdId, w->wfSlotId, w->wfDynId); 18011308Santhony.gutierrez@amd.com 18111308Santhony.gutierrez@amd.com if (!refCount) { 18211308Santhony.gutierrez@amd.com // Notify Memory System of Kernel Completion 18311308Santhony.gutierrez@amd.com // Kernel End = isKernel + isRelease 18411308Santhony.gutierrez@amd.com w->status = Wavefront::S_RETURNING; 18511308Santhony.gutierrez@amd.com GPUDynInstPtr local_mempacket = gpuDynInst; 18611308Santhony.gutierrez@amd.com local_mempacket->memoryOrder = Enums::MEMORY_ORDER_SC_RELEASE; 18711308Santhony.gutierrez@amd.com local_mempacket->scope = Enums::MEMORY_SCOPE_SYSTEM; 18811308Santhony.gutierrez@amd.com local_mempacket->useContinuation = false; 18911308Santhony.gutierrez@amd.com local_mempacket->simdId = w->simdId; 19011308Santhony.gutierrez@amd.com local_mempacket->wfSlotId = w->wfSlotId; 19111308Santhony.gutierrez@amd.com local_mempacket->wfDynId = w->wfDynId; 19211308Santhony.gutierrez@amd.com w->computeUnit->injectGlobalMemFence(local_mempacket, true); 19311308Santhony.gutierrez@amd.com } else { 19411308Santhony.gutierrez@amd.com w->computeUnit->shader->dispatcher->scheduleDispatch(); 19511308Santhony.gutierrez@amd.com } 19611308Santhony.gutierrez@amd.com } 19711308Santhony.gutierrez@amd.com } 19811308Santhony.gutierrez@amd.com 19911308Santhony.gutierrez@amd.com void 20011308Santhony.gutierrez@amd.com Barrier::execute(GPUDynInstPtr gpuDynInst) 20111308Santhony.gutierrez@amd.com { 20211308Santhony.gutierrez@amd.com Wavefront *w = gpuDynInst->wavefront(); 20311308Santhony.gutierrez@amd.com 20411308Santhony.gutierrez@amd.com assert(w->barrier_cnt == w->old_barrier_cnt); 20511308Santhony.gutierrez@amd.com w->barrier_cnt = w->old_barrier_cnt + 1; 20611308Santhony.gutierrez@amd.com w->stalledAtBarrier = true; 20711308Santhony.gutierrez@amd.com } 20811308Santhony.gutierrez@amd.com} // namespace HsailISA 209