[Beignet] [PATCH 13/18] GBE: pass the OCL_STRICT_CONFORMANCE env to the backend.

Zhigang Gong zhigang.gong at intel.com
Fri Mar 28 00:10:51 PDT 2014


Enable the mad pattern matching if the strict conformance
is false.

Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
 backend/src/backend/gen_context.cpp        | 5 +++--
 backend/src/backend/gen_context.hpp        | 3 ++-
 backend/src/backend/gen_insn_selection.cpp | 3 ++-
 backend/src/backend/gen_program.cpp        | 4 ++--
 backend/src/backend/gen_program.hpp        | 2 +-
 backend/src/backend/program.cpp            | 5 +++--
 backend/src/backend/program.hpp            | 2 +-
 7 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/backend/src/backend/gen_context.cpp b/backend/src/backend/gen_context.cpp
index 2225ff9..6cfeca4 100644
--- a/backend/src/backend/gen_context.cpp
+++ b/backend/src/backend/gen_context.cpp
@@ -44,8 +44,9 @@ namespace gbe
   ///////////////////////////////////////////////////////////////////////////
   GenContext::GenContext(const ir::Unit &unit,
                          const std::string &name,
-                         bool limitRegisterPressure) :
-    Context(unit, name), limitRegisterPressure(limitRegisterPressure)
+                         bool limitRegisterPressure,
+                         bool relaxMath) :
+    Context(unit, name), limitRegisterPressure(limitRegisterPressure), relaxMath(relaxMath)
   {
     this->p = GBE_NEW(GenEncoder, simdWidth, 7); // XXX handle more than Gen7
     this->sel = GBE_NEW(Selection, *this);
diff --git a/backend/src/backend/gen_context.hpp b/backend/src/backend/gen_context.hpp
index bd01c49..d24d05b 100644
--- a/backend/src/backend/gen_context.hpp
+++ b/backend/src/backend/gen_context.hpp
@@ -52,7 +52,7 @@ 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, bool limitRegisterPressure = false);
+    GenContext(const ir::Unit &unit, const std::string &name, bool limitRegisterPressure = false, bool relaxMath = false);
     /*! Release everything needed */
     ~GenContext(void);
     /*! Implements base class */
@@ -174,6 +174,7 @@ namespace gbe
      * regenerating the code
      */
     bool limitRegisterPressure;
+    bool relaxMath;
   private:
     /*! Build the curbe patch list for the given kernel */
     void buildPatchList(void);
diff --git a/backend/src/backend/gen_insn_selection.cpp b/backend/src/backend/gen_insn_selection.cpp
index 6f38ff2..afe6392 100644
--- a/backend/src/backend/gen_insn_selection.cpp
+++ b/backend/src/backend/gen_insn_selection.cpp
@@ -2024,7 +2024,8 @@ namespace gbe
 
       // XXX TODO: we need a clean support of FP_CONTRACT to remove below line 'return false'
       // if 'pragma FP_CONTRACT OFF' is used in cl kernel, we should not do mad optimization.
-      return false;
+      if (!sel.ctx.relaxMath)
+        return false;
       // MAD tend to increase liveness of the sources (since there are three of
       // them). TODO refine this strategy. Well, we should be able at least to
       // evaluate per basic block register pressure and selectively enable
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
index 22f4aa1..1f157e0 100644
--- a/backend/src/backend/gen_program.cpp
+++ b/backend/src/backend/gen_program.cpp
@@ -85,7 +85,7 @@ namespace gbe {
     {8,true},
   };
 
-  Kernel *GenProgram::compileKernel(const ir::Unit &unit, const std::string &name) {
+  Kernel *GenProgram::compileKernel(const ir::Unit &unit, const std::string &name, bool relaxMath) {
 
     // Be careful when the simdWidth is forced by the programmer. We can see it
     // when the function already provides the simd width we need to use (i.e.
@@ -102,7 +102,7 @@ namespace gbe {
 
       // Force the SIMD width now and try to compile
       unit.getFunction(name)->setSimdWidth(simdWidth);
-      Context *ctx = GBE_NEW(GenContext, unit, name, limitRegisterPressure);
+      Context *ctx = GBE_NEW(GenContext, unit, name, limitRegisterPressure, relaxMath);
       kernel = ctx->compileKernel();
       if (kernel != NULL) {
         break;
diff --git a/backend/src/backend/gen_program.hpp b/backend/src/backend/gen_program.hpp
index f78e324..189c262 100644
--- a/backend/src/backend/gen_program.hpp
+++ b/backend/src/backend/gen_program.hpp
@@ -62,7 +62,7 @@ namespace gbe
     /*! Destroy the program */
     virtual ~GenProgram(void);
     /*! Implements base class */
-    virtual Kernel *compileKernel(const ir::Unit &unit, const std::string &name);
+    virtual Kernel *compileKernel(const ir::Unit &unit, const std::string &name, bool relaxMath);
     /*! Allocate an empty kernel. */
     virtual Kernel *allocateKernel(const std::string &name) {
       return GBE_NEW(GenKernel, name);
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 5fddd64..91abbae 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -121,6 +121,8 @@ namespace gbe {
     return true;
   }
 
+  BVAR(OCL_STRICT_CONFORMANCE, true);
+
   bool Program::buildFromUnit(const ir::Unit &unit, std::string &error) {
     constantSet = new ir::ConstantSet(unit.getConstantSet());
     const auto &set = unit.getFunctionSet();
@@ -129,7 +131,7 @@ namespace gbe {
     if (kernelNum == 0) return true;
     for (const auto &pair : set) {
       const std::string &name = pair.first;
-      Kernel *kernel = this->compileKernel(unit, name);
+      Kernel *kernel = this->compileKernel(unit, name, !OCL_STRICT_CONFORMANCE);
       kernel->setSamplerSet(pair.second->getSamplerSet());
       kernel->setImageSet(pair.second->getImageSet());
       kernel->setCompileWorkGroupSize(pair.second->getCompileWorkGroupSize());
@@ -506,7 +508,6 @@ namespace gbe {
   }
 
   BVAR(OCL_OUTPUT_BUILD_LOG, false);
-  BVAR(OCL_STRICT_CONFORMANCE, true);
   SVAR(OCL_PCH_PATH, PCH_OBJECT_DIR);
   SVAR(OCL_PCM_PATH, PCM_OBJECT_DIR);
 
diff --git a/backend/src/backend/program.hpp b/backend/src/backend/program.hpp
index 83fb0b4..0e01256 100644
--- a/backend/src/backend/program.hpp
+++ b/backend/src/backend/program.hpp
@@ -262,7 +262,7 @@ namespace gbe {
 
   protected:
     /*! Compile a kernel */
-    virtual Kernel *compileKernel(const ir::Unit &unit, const std::string &name) = 0;
+    virtual Kernel *compileKernel(const ir::Unit &unit, const std::string &name, bool relaxMath) = 0;
     /*! Allocate an empty kernel. */
     virtual Kernel *allocateKernel(const std::string &name) = 0;
     /*! Kernels sorted by their name */
-- 
1.8.3.2



More information about the Beignet mailing list