From: Junyan He Date: Wed, 7 May 2014 10:02:50 +0000 (+0800) Subject: Add Gen75Context and Gen75Encoder class for hsw X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8de42dcefb7b78d340ba1cc18df3b2bde4fc9669;p=contrib%2Fbeignet.git Add Gen75Context and Gen75Encoder class for hsw We will create the Gen75Context and Gen75Encoder dynamically based on the vendor ID, which is same with the PCI ID. Signed-off-by: Junyan He Reviewed-by: Yang Rong --- diff --git a/backend/src/CMakeLists.txt b/backend/src/CMakeLists.txt index 3bb31e5..1dfbcf6 100644 --- a/backend/src/CMakeLists.txt +++ b/backend/src/CMakeLists.txt @@ -158,14 +158,19 @@ else (GBE_USE_BLOB) backend/gen_reg_allocation.cpp backend/gen_reg_allocation.hpp backend/gen_context.cpp - backend/gen_context.hpp + backend/gen_context.cpp + backend/gen75_context.hpp + backend/gen75_context.cpp backend/gen_program.cpp backend/gen_program.hpp backend/gen_program.h backend/gen_defs.hpp backend/gen_insn_compact.cpp backend/gen_encoder.hpp - backend/gen_encoder.cpp) + backend/gen_encoder.cpp + backend/gen75_encoder.hpp + backend/gen75_encoder.cpp + ) endif (GBE_USE_BLOB) diff --git a/backend/src/backend/gen75_context.cpp b/backend/src/backend/gen75_context.cpp new file mode 100644 index 0000000..2e35324 --- /dev/null +++ b/backend/src/backend/gen75_context.cpp @@ -0,0 +1,29 @@ +/* + * Copyright © 2012 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + */ + +/** + * \file gen75_context.cpp + */ + +#include "backend/gen75_context.hpp" +#include "backend/gen75_encoder.hpp" + +namespace gbe +{ + +} diff --git a/backend/src/backend/gen75_context.hpp b/backend/src/backend/gen75_context.hpp new file mode 100644 index 0000000..2bb6e17 --- /dev/null +++ b/backend/src/backend/gen75_context.hpp @@ -0,0 +1,46 @@ +/* + * Copyright © 2012 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + */ + +/** + * \file gen75_context.hpp + */ +#ifndef __GBE_GEN75_CONTEXT_HPP__ +#define __GBE_GEN75_CONTEXT_HPP__ + +#include "backend/gen_context.hpp" +#include "backend/gen75_encoder.hpp" + +namespace gbe +{ + /* This class is used to implement the HSW + specific logic for context. */ + class Gen75Context : public GenContext + { + public: + Gen75Context(const ir::Unit &unit, const std::string &name, uint32_t deviceID, bool relaxMath = false) + : GenContext(unit, name, deviceID, relaxMath) { + }; + + protected: + virtual GenEncoder* generateEncoder(void) { + return GBE_NEW(Gen75Encoder, this->simdWidth, 75, deviceID); + } + + }; +} +#endif /* __GBE_GEN75_CONTEXT_HPP__ */ diff --git a/backend/src/backend/gen75_encoder.cpp b/backend/src/backend/gen75_encoder.cpp new file mode 100644 index 0000000..909b301 --- /dev/null +++ b/backend/src/backend/gen75_encoder.cpp @@ -0,0 +1,33 @@ +/* + Copyright (C) Intel Corp. 2006. All Rights Reserved. + Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to + develop this 3D driver. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice (including the + next paragraph) shall be included in all copies or substantial + portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + **********************************************************************/ + +#include "backend/gen75_encoder.hpp" + +namespace gbe +{ + +} /* End of the name space. */ diff --git a/backend/src/backend/gen75_encoder.hpp b/backend/src/backend/gen75_encoder.hpp new file mode 100644 index 0000000..9541c26 --- /dev/null +++ b/backend/src/backend/gen75_encoder.hpp @@ -0,0 +1,38 @@ +/* + * Copyright © 2012 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + */ + +/** + * \file gen75_context.hpp + */ +#ifndef __GBE_GEN75_ENCODER_HPP__ +#define __GBE_GEN75_ENCODER_HPP__ + +#include "backend/gen_encoder.hpp" + +namespace gbe +{ + /* This class is used to implement the HSW + specific logic for encoder. */ + class Gen75Encoder : public GenEncoder + { + public: + Gen75Encoder(uint32_t simdWidth, uint32_t gen, uint32_t deviceID) + : GenEncoder(simdWidth, gen, deviceID, 8) { }; + }; +} +#endif /* __GBE_GEN75_ENCODER_HPP__ */ diff --git a/backend/src/backend/gen_context.cpp b/backend/src/backend/gen_context.cpp index a6a6503..41f2db1 100644 --- a/backend/src/backend/gen_context.cpp +++ b/backend/src/backend/gen_context.cpp @@ -43,10 +43,8 @@ namespace gbe /////////////////////////////////////////////////////////////////////////// // GenContext implementation /////////////////////////////////////////////////////////////////////////// - GenContext::GenContext(const ir::Unit &unit, - const std::string &name, - uint32_t deviceID, - bool relaxMath) : + GenContext::GenContext(const ir::Unit &unit, const std::string &name, uint32_t deviceID, + bool relaxMath) : Context(unit, name), deviceID(deviceID), relaxMath(relaxMath) { this->p = NULL; @@ -68,7 +66,7 @@ namespace gbe GBE_SAFE_DELETE(ra); GBE_SAFE_DELETE(sel); GBE_SAFE_DELETE(p); - this->p = GBE_NEW(GenEncoder, this->simdWidth, 7, deviceID); // XXX handle more than Gen7 + this->p = generateEncoder(); this->sel = GBE_NEW(Selection, *this); this->ra = GBE_NEW(GenRegAllocator, *this); this->branchPos2.clear(); diff --git a/backend/src/backend/gen_context.hpp b/backend/src/backend/gen_context.hpp index 3eda148..21ee28d 100644 --- a/backend/src/backend/gen_context.hpp +++ b/backend/src/backend/gen_context.hpp @@ -26,6 +26,7 @@ #define __GBE_GEN_CONTEXT_HPP__ #include "backend/context.hpp" +#include "backend/gen_encoder.hpp" #include "backend/program.h" #include "backend/gen_register.hpp" #include "ir/function.hpp" @@ -59,7 +60,8 @@ namespace gbe /*! Create a new context. name is the name of the function we want to * compile */ - GenContext(const ir::Unit &unit, const std::string &name, uint32_t deviceID, bool relaxMath = false); + GenContext(const ir::Unit &unit, const std::string &name, uint32_t deviceID, + bool relaxMath = false); /*! Release everything needed */ ~GenContext(void); /*! Start new code generation with specific parameters */ @@ -187,6 +189,12 @@ namespace gbe const bool getIFENDIFFix(void) const { return ifEndifFix; } void setIFENDIFFix(bool fix) { ifEndifFix = fix; } const CompileErrorCode getErrCode() { return errCode; } + + protected: + virtual GenEncoder* generateEncoder(void) { + return GBE_NEW(GenEncoder, this->simdWidth, 7, deviceID); + } + private: CompileErrorCode errCode; bool ifEndifFix; diff --git a/backend/src/backend/gen_encoder.cpp b/backend/src/backend/gen_encoder.cpp index e850eeb..1f8ecc6 100644 --- a/backend/src/backend/gen_encoder.cpp +++ b/backend/src/backend/gen_encoder.cpp @@ -223,8 +223,8 @@ namespace gbe ////////////////////////////////////////////////////////////////////////// // Gen Emitter encoding class ////////////////////////////////////////////////////////////////////////// - GenEncoder::GenEncoder(uint32_t simdWidth, uint32_t gen, uint32_t deviceID) : - stateNum(0), gen(gen), deviceID(deviceID) + GenEncoder::GenEncoder(uint32_t simdWidth, uint32_t gen, uint32_t deviceID, int jump_width) : + stateNum(0), gen(gen), deviceID(deviceID), jump_width(jump_width) { this->curr.execWidth = simdWidth; this->curr.quarterControl = GEN_COMPRESSION_Q1; diff --git a/backend/src/backend/gen_encoder.hpp b/backend/src/backend/gen_encoder.hpp index 8d5ef37..024d9c6 100644 --- a/backend/src/backend/gen_encoder.hpp +++ b/backend/src/backend/gen_encoder.hpp @@ -65,7 +65,7 @@ namespace gbe { public: /*! simdWidth is the default width for the instructions */ - GenEncoder(uint32_t simdWidth, uint32_t gen, uint32_t deviceID); + GenEncoder(uint32_t simdWidth, uint32_t gen, uint32_t deviceID, int jump_width = 1); /*! Size of the stack (should be large enough) */ enum { MAX_STATE_NUM = 16 }; /*! Push the current instruction state */ @@ -84,7 +84,8 @@ namespace gbe uint32_t gen; /*! Device ID */ uint32_t deviceID; - + /*! The constant for jump. */ + const int jump_width; //////////////////////////////////////////////////////////////////////// // Encoding functions //////////////////////////////////////////////////////////////////////// diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp index dd03153..52db904 100644 --- a/backend/src/backend/gen_program.cpp +++ b/backend/src/backend/gen_program.cpp @@ -26,6 +26,7 @@ #include "backend/gen_program.h" #include "backend/gen_program.hpp" #include "backend/gen_context.hpp" +#include "backend/gen75_context.hpp" #include "backend/gen_defs.hpp" #include "backend/gen/gen_mesa_disasm.h" #include "backend/gen_reg_allocation.hpp" @@ -94,6 +95,7 @@ namespace gbe { const ir::Function *fn = unit.getFunction(name); uint32_t codeGenNum = sizeof(codeGenStrategy) / sizeof(codeGenStrategy[0]); uint32_t codeGen = 0; + GenContext *ctx = NULL; if (fn->getSimdWidth() == 8) { codeGen = 2; } else if (fn->getSimdWidth() == 16) { @@ -105,7 +107,13 @@ namespace gbe { Kernel *kernel = NULL; // Stop when compilation is successful - GenContext *ctx = GBE_NEW(GenContext, unit, name, deviceID, relaxMath); + if (IS_IVYBRIDGE(deviceID)) { + ctx = GBE_NEW(GenContext, unit, name, deviceID, relaxMath); + } else if (IS_HASWELL(deviceID)) { + ctx = GBE_NEW(Gen75Context, unit, name, deviceID, relaxMath); + } + GBE_ASSERTM(ctx != NULL, "Fail to create the gen context\n"); + for (; codeGen < codeGenNum; ++codeGen) { const uint32_t simdWidth = codeGenStrategy[codeGen].simdWidth; const bool limitRegisterPressure = codeGenStrategy[codeGen].limitRegisterPressure; diff --git a/backend/src/gbe_bin_generater.cpp b/backend/src/gbe_bin_generater.cpp index 1d97f01..15bdbd1 100644 --- a/backend/src/gbe_bin_generater.cpp +++ b/backend/src/gbe_bin_generater.cpp @@ -194,7 +194,7 @@ void program_build_instance::build_program(void) throw(int) { // FIXME, we need to find a graceful way to generate internal binaries for difference // devices. - gbe_program opaque = gbe_program_new_from_source(0, code, 0, build_opt.c_str(), NULL, NULL); + gbe_program opaque = gbe_program_new_from_source(0x0152, code, 0, build_opt.c_str(), NULL, NULL); if (!opaque) throw FILE_BUILD_FAILED;