sc/qa/unit/data/ods/opencl/compiler/nested.ods |binary sc/source/core/opencl/formulagroupcl.cxx | 57 ++++++++++++++---------- sc/source/core/opencl/formulagroupcl_public.hxx | 1 sc/source/core/opencl/opbase.cxx | 6 ++ sc/source/core/opencl/opbase.hxx | 1 5 files changed, 42 insertions(+), 23 deletions(-)
New commits: commit 6769a8a4c0ffb3dfaa236988cf9915805b4abeac Author: Wei Wei <wei...@multicorewareinc.com> Date: Fri Nov 22 17:18:21 2013 -0600 GPU Calc: Testcase for Sums of Product that have out-of-bound window AMLOEXT-244 BUG Change-Id: Iefce62484b2189b37b747bfd4b739115dafbc40d diff --git a/sc/qa/unit/data/ods/opencl/compiler/nested.ods b/sc/qa/unit/data/ods/opencl/compiler/nested.ods index 5957844..83310fa5 100644 Binary files a/sc/qa/unit/data/ods/opencl/compiler/nested.ods and b/sc/qa/unit/data/ods/opencl/compiler/nested.ods differ commit 521acd05aba7fb35a244a6302584a950d4904fbe Author: Wei Wei <wei...@multicorewareinc.com> Date: Fri Nov 22 17:16:49 2013 -0600 GPU Calc: Sum of product doesn't check out-of-bound accesses AMLOEXT-244 FIX Change-Id: I5f49f7acccaabd2a97d8ac4bfba4b973889278f1 diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index 2c795cc..ad6ccc1 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -444,13 +444,26 @@ public: } virtual void GenSlidingWindowFunction(std::stringstream &) {} - virtual std::string GenSlidingWindowDeclRef(bool=false) const + virtual std::string GenSlidingWindowDeclRef(bool nested=false) const { + size_t nArrayLength = mpDVR->GetArrayLength(); std::stringstream ss; if (!bIsStartFixed && !bIsEndFixed) + { + if (nested) + ss << "((i+gid0) <" << nArrayLength <<"?"; ss << Base::GetName() << "[i + gid0]"; + if (nested) + ss << ":NAN)"; + } else + { + if (nested) + ss << "(i <" << nArrayLength <<"?"; ss << Base::GetName() << "[i]"; + if (nested) + ss << ":NAN)"; + } return ss.str(); } /// Controls how the elements in the DoubleVectorRef are traversed @@ -533,9 +546,9 @@ return nCurWindowSize; if(count==0){ temp1 << "if(i + gid0 < " <<mpDVR->GetArrayLength(); temp1 << "){\n\t\t"; - temp1 << "tmp = "; + temp1 << "tmp = legalize("; temp1 << mpCodeGen->Gen2(GenSlidingWindowDeclRef(), "tmp"); - temp1 << ";\n\t\t\t"; + temp1 << ", tmp);\n\t\t\t"; temp1 << "}\n\t"; } ss << temp1.str(); @@ -548,9 +561,9 @@ return nCurWindowSize; if(count==nCurWindowSize/outLoopSize*outLoopSize){ temp2 << "if(i + gid0 < " << mpDVR->GetArrayLength(); temp2 << "){\n\t\t"; - temp2 << "tmp = "; + temp2 << "tmp = legalize("; temp2 << mpCodeGen->Gen2(GenSlidingWindowDeclRef(), "tmp"); - temp2 << ";\n\t\t\t"; + temp2 << ", tmp);\n\t\t\t"; temp2 << "}\n\t"; } ss << temp2.str(); @@ -571,9 +584,9 @@ return nCurWindowSize; for(int count=0; count < outLoopSize; count++){ ss << "i = outLoop*"<<outLoopSize<<"+"<<count<<";\n\t"; if(count==0){ - temp1 << "tmp = "; + temp1 << "tmp = legalize("; temp1 << mpCodeGen->Gen2(GenSlidingWindowDeclRef(), "tmp"); - temp1 << ";\n\t\t\t"; + temp1 << ", tmp);\n\t\t\t"; } ss << temp1.str(); } @@ -583,9 +596,9 @@ return nCurWindowSize; for(unsigned int count=nCurWindowSize/outLoopSize*outLoopSize; count < nCurWindowSize; count++){ ss << "i = "<<count<<";\n\t"; if(count==nCurWindowSize/outLoopSize*outLoopSize){ - temp2 << "tmp = "; + temp2 << "tmp = legalize("; temp2 << mpCodeGen->Gen2(GenSlidingWindowDeclRef(), "tmp"); - temp2 << ";\n\t\t\t"; + temp2 << ", tmp);\n\t\t\t"; } ss << temp2.str(); } @@ -673,13 +686,13 @@ public: ss << " tmp = "<< mpCodeGen->GetBottom() << ";\n"; ss << " int loopOffset = l*512;\n"; ss << " if((loopOffset + lidx + offset + 256) < end) {\n"; - ss << " tmp = " << mpCodeGen->Gen2( - "A[loopOffset + lidx + offset]", "tmp") <<";\n"; - ss << " tmp = " << mpCodeGen->Gen2( - "A[loopOffset + lidx + offset + 256]", "tmp") << ";\n"; + ss << " tmp = legalize(" << mpCodeGen->Gen2( + "A[loopOffset + lidx + offset]", "tmp") <<", tmp);\n"; + ss << " tmp = legalize(" << mpCodeGen->Gen2( + "A[loopOffset + lidx + offset + 256]", "tmp") <<", tmp);\n"; ss << " } else if ((loopOffset + lidx + offset) < end)\n"; - ss << " tmp = " << mpCodeGen->Gen2( - "A[loopOffset + lidx + offset]", "tmp") <<";\n"; + ss << " tmp = legalize(" << mpCodeGen->Gen2( + "A[loopOffset + lidx + offset]", "tmp") <<", tmp);\n"; ss << " shm_buf[lidx] = tmp;\n"; ss << " barrier(CLK_LOCAL_MEM_FENCE);\n"; ss << " for (int i = 128; i >0; i/=2) {\n"; @@ -1040,7 +1053,7 @@ public: } } } - ss << " tmp += "; + ss << " tmp += fsum("; for (unsigned i = 0; i < vSubArguments.size(); i++) { if (i) @@ -1080,7 +1093,7 @@ public: ss << vSubArguments[i]->GenSlidingWindowDeclRef(true); #endif } - ss << ";\n\t}\n\t"; + ss << ", 0.0);\n\t}\n\t"; ss << "return tmp;\n"; ss << "}"; #endif @@ -1098,7 +1111,7 @@ public: if(count==0){ temp3 << "currentCount0 = i+gid0+1;\n\t"; temp3 << "currentCount1 = i+1;\n\t"; - temp3 << "tmp += "; + temp3 << "tmp = fsum("; for (unsigned i = 0; i < vSubArguments.size(); i++){ if (i) temp3 << "*"; @@ -1130,7 +1143,7 @@ public: else temp3 << vSubArguments[i]->GenSlidingWindowDeclRef(true); } - temp3 << ";\n\t"; + temp3 << ", tmp);\n\t"; } ss << temp3.str(); } @@ -1144,7 +1157,7 @@ public: if(count==nCurWindowSize/outLoopSize*outLoopSize){ temp4 << "currentCount0 = i+gid0+1;\n\t"; temp4 << "currentCount1 = i+1;\n\t"; - temp4 << "tmp += "; + temp4 << "tmp = fsum("; for (unsigned i = 0; i < vSubArguments.size(); i++) { if (i) @@ -1183,7 +1196,7 @@ public: ->GenSlidingWindowDeclRef(true); } } - temp4 << ";\n\t"; + temp4 << ", tmp);\n\t"; } ss << temp4.str(); } @@ -1261,7 +1274,7 @@ public: virtual std::string Gen2(const std::string &lhs, const std::string &rhs) const { std::stringstream ss; - ss << "fsum(" << lhs <<","<< rhs<<")"; + ss << "((" << lhs <<")+("<< rhs<<"))"; return ss.str(); } virtual std::string BinFuncName(void) const { return "fsum"; } diff --git a/sc/source/core/opencl/formulagroupcl_public.hxx b/sc/source/core/opencl/formulagroupcl_public.hxx index eaf4227..49510e8 100644 --- a/sc/source/core/opencl/formulagroupcl_public.hxx +++ b/sc/source/core/opencl/formulagroupcl_public.hxx @@ -18,6 +18,7 @@ const char* publicFunc = " return t?b:a+b;\n" "}\n" "double fsum(double a, double b) { return isNan(a)?b:a+b; }\n" + "double legalize(double a, double b) { return isNan(a)?b:a;}\n" "double fsub(double a, double b) { return a-b; }\n" "double fdiv(double a, double b) { return a/b; }\n" "double strequal(unsigned a, unsigned b) { return (a==b)?1.0:0; }\n" diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx index 6bb866c..b7b77ac 100644 --- a/sc/source/core/opencl/opbase.cxx +++ b/sc/source/core/opencl/opbase.cxx @@ -66,7 +66,13 @@ void VectorRef::GenSlidingWindowDecl(std::stringstream &ss) const std::string VectorRef::GenSlidingWindowDeclRef(bool) const { std::stringstream ss; + formula::SingleVectorRefToken *pSVR = + dynamic_cast<formula::SingleVectorRefToken*>(DynamicKernelArgument::GetFormulaToken()); + if (pSVR) + ss << "(gid0 < " << pSVR->GetArrayLength() << "?"; ss << mSymName << "[gid0]"; + if (pSVR) + ss << ":NAN)"; return ss.str(); } diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx index d921119..135ec4d 100644 --- a/sc/source/core/opencl/opbase.hxx +++ b/sc/source/core/opencl/opbase.hxx @@ -133,7 +133,6 @@ public: virtual void GenSlidingWindowFunction(std::stringstream &) {} const std::string &GetSymName(void) const { return mSymName; } - formula::FormulaToken *GetFormulaToken(void) const; virtual size_t GetWindowSize(void) const; virtual std::string DumpOpName(void) const { return std::string(""); } virtual void DumpInlineFun(std::set<std::string>& , _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits