diff options
author | zhenyu yuan <zhenyuyuan@multicorewareinc.com> | 2013-11-09 19:14:59 +0800 |
---|---|---|
committer | I-Jui (Ray) Sung <ray@multicorewareinc.com> | 2013-11-14 20:30:33 -0600 |
commit | 717a0129b5fa8f5b53343c8843b321b54c1b649d (patch) | |
tree | 4b8b21d94c144c7b11b1e3f0aeb272b38cb6a2b2 | |
parent | 66a36c944021f7bc845d291f931b52bbbf3e1212 (diff) |
GPU Calc: implemented COMBINA
AMLOEXT-174 FIX
Change-Id: I51c746891fe2b7f68ce3d0029ad1e71a21264f76
Signed-off-by: haochen <haochen@multicorewareinc.com>
Signed-off-by: I-Jui (Ray) Sung <ray@multicorewareinc.com>
-rw-r--r-- | sc/source/core/opencl/formulagroupcl.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/opencl/op_math.cxx | 63 | ||||
-rw-r--r-- | sc/source/core/opencl/op_math.hxx | 9 | ||||
-rw-r--r-- | sc/source/core/opencl/opinlinefun_math.hxx | 16 |
4 files changed, 92 insertions, 0 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index 2ec90e17165b..86a073064647 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1281,6 +1281,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],new OpCountIfs)); break; + case ocKombin2: + mvSubArguments.push_back(SoPHelper(ts, + ft->Children[i], new OpCombina)); + break; case ocExternal: if ( !(pChild->GetExternal().compareTo(OUString( "com.sun.star.sheet.addin.Analysis.getEffect")))) diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx index adf5af0bd231..a15962cf54fe 100644 --- a/sc/source/core/opencl/op_math.cxx +++ b/sc/source/core/opencl/op_math.cxx @@ -139,6 +139,69 @@ void OpCoth::GenSlidingWindowFunction(std::stringstream &ss, ss << "}"; } +void OpCombina::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) +{ + decls.insert(bikDecl); + funs.insert(bik); +} + +void OpCombina::GenSlidingWindowFunction(std::stringstream &ss, + const std::string sSymName, SubArguments &vSubArguments) +{ + ss << "\ndouble " << sSymName; + ss << "_"<< BinFuncName() <<"("; + for (unsigned i = 0; i < vSubArguments.size(); i++) + { + if (i) + ss << ","; + vSubArguments[i]->GenSlidingWindowDecl(ss); + } + ss << ")\n{\n"; + ss << " int gid0 = get_global_id(0);\n"; + ss << " double tem;\n"; + ss << " double arg0,arg1;\n"; + for (unsigned int i = 0; i < vSubArguments.size(); i++) + { + FormulaToken *pCur = vSubArguments[i]->GetFormulaToken(); + assert(pCur); + ss << " arg"<<i<<" = "<<vSubArguments[i]->GenSlidingWindowDeclRef(); + ss << ";\n"; + if(pCur->GetType() == formula::svSingleVectorRef) + { +#ifdef ISNAN + const formula::SingleVectorRefToken* pSVR = + dynamic_cast< const formula::SingleVectorRefToken* >(pCur); + ss << " if(isNan(arg" << i <<")||(gid0 >= "; + ss << pSVR->GetArrayLength(); + ss << "))\n"; + ss << " arg" << i << " = 0;\n"; + } + else if (pCur->GetType() == formula::svDouble) + { + ss << " if(isNan(arg" << i <<"))\n"; + ss << " arg" << i << " = 0;\n"; + } +#endif + } + ss << " arg0 = trunc(arg0);\n"; + ss << " arg1 = trunc(arg1);\n"; + ss << " if(arg0 < arg1 || arg0 < 0 || arg1 < 0)\n"; + ss << " tem = -1;\n"; + ss << " else if(arg0 == 0 && arg1 == 0)\n"; + ss << " tem = 0;\n"; + ss << " else if(arg0 > 0 && arg1 == 0)\n"; + ss << " tem = 1;\n"; + ss << " else\n"; + ss << " tem = bik(arg0+arg1-1,arg1);\n"; + ss << " double k = tem - trunc(tem);\n"; + ss << " if(k < 0.5)\n"; + ss << " tem = trunc(tem);\n"; + ss << " else\n"; + ss << " tem = trunc(tem) + 1;"; + ss << " return tem;\n"; + ss << "}"; +} void OpCsc::GenSlidingWindowFunction( std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments) { diff --git a/sc/source/core/opencl/op_math.hxx b/sc/source/core/opencl/op_math.hxx index b7aec25157ab..fef872a35b9d 100644 --- a/sc/source/core/opencl/op_math.hxx +++ b/sc/source/core/opencl/op_math.hxx @@ -239,6 +239,15 @@ public: const std::string sSymName, SubArguments &vSubArguments); virtual std::string BinFuncName(void) const { return "CountIfs"; } }; +class OpCombina: public Normal +{ +public: + virtual void GenSlidingWindowFunction(std::stringstream &ss, + const std::string sSymName, SubArguments &vSubArguments); + + virtual std::string BinFuncName(void) const { return "Combina"; } + virtual void BinInlineFun(std::set<std::string>& ,std::set<std::string>& ); +}; }} #endif diff --git a/sc/source/core/opencl/opinlinefun_math.hxx b/sc/source/core/opencl/opinlinefun_math.hxx index ebc98777a57a..e4927cc9a652 100644 --- a/sc/source/core/opencl/opinlinefun_math.hxx +++ b/sc/source/core/opencl/opinlinefun_math.hxx @@ -21,6 +21,22 @@ std::string Math_Intg_Str= return trunc(n)+1;\n\ }\n"; +std::string bikDecl = "double bik(double n,double k);\n"; +std::string bik = +"double bik(double n,double k)\n" +"{\n" +" double nVal = n/k;\n" +" n = n - 1;\n" +" k = k - 1;\n" +" while (k > 0)\n" +" {\n" +" nVal = nVal * ( n/k );\n" +" k = k - 1;\n" +" n = n - 1;\n" +" }\n" +" return nVal;\n" +"}\n"; + #endif //SC_OPENCL_OPINLINFUN_MATH /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |