summaryrefslogtreecommitdiff
path: root/sc/source/core
diff options
context:
space:
mode:
authorWei Wei <weiwei@multicorewareinc.com>2013-11-22 17:16:49 -0600
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-11-22 19:55:50 -0600
commit2947549f2361a5462346f4f88fc207213c180bd8 (patch)
tree2addf7cb2b7e11584fbca6bfbb52e52a24a20cd2 /sc/source/core
parent3621f1952d129892d14ab57a123c6c3e181cae49 (diff)
GPU Calc: Sum of product doesn't check out-of-bound accesses
AMLOEXT-244 FIX Change-Id: I5f49f7acccaabd2a97d8ac4bfba4b973889278f1
Diffstat (limited to 'sc/source/core')
-rw-r--r--sc/source/core/opencl/formulagroupcl.cxx57
-rw-r--r--sc/source/core/opencl/formulagroupcl_public.hxx1
-rw-r--r--sc/source/core/opencl/opbase.cxx6
-rw-r--r--sc/source/core/opencl/opbase.hxx1
4 files changed, 42 insertions, 23 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index b0bb011464c1..340545977b95 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";
@@ -1036,7 +1049,7 @@ public:
}
}
}
- ss << " tmp += ";
+ ss << " tmp += fsum(";
for (unsigned i = 0; i < vSubArguments.size(); i++)
{
if (i)
@@ -1076,7 +1089,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
@@ -1094,7 +1107,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 << "*";
@@ -1126,7 +1139,7 @@ public:
else
temp3 << vSubArguments[i]->GenSlidingWindowDeclRef(true);
}
- temp3 << ";\n\t";
+ temp3 << ", tmp);\n\t";
}
ss << temp3.str();
}
@@ -1140,7 +1153,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)
@@ -1179,7 +1192,7 @@ public:
->GenSlidingWindowDeclRef(true);
}
}
- temp4 << ";\n\t";
+ temp4 << ", tmp);\n\t";
}
ss << temp4.str();
}
@@ -1257,7 +1270,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 d001a0675184..ac02e3352ff9 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 95657df491a3..7589de9a813e 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 d921119aede1..135ec4ddb4e3 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>& ,