Kaydet (Commit) 0beb28ce authored tarafından I-Jui (Ray) Sung's avatar I-Jui (Ray) Sung

GPU Calc: refactor op_financial.cxx to fix warning and bad indentation

Change-Id: I93db1e5d2b03904a3d7787cc16f642ebf4752d85
üst 3e040287
...@@ -2155,241 +2155,239 @@ void OpPrice::GenSlidingWindowFunction(std::stringstream &ss, ...@@ -2155,241 +2155,239 @@ void OpPrice::GenSlidingWindowFunction(std::stringstream &ss,
ss<<"double tmp3=0;\n "; ss<<"double tmp3=0;\n ";
ss<<"double tmp4=0,tmp5=0;\n "; ss<<"double tmp4=0,tmp5=0;\n ";
ss<<"double tmp6=0;\n "; ss<<"double tmp6=0;\n ";
unsigned i = vSubArguments.size();
size_t nItems = 0; size_t nItems = 0;
ss <<"\n "; ss <<"\n ";
//while (i-- > 1) for (size_t i = 0; i < vSubArguments.size(); i++)
for (size_t i = 0; i < vSubArguments.size(); i++) {
{ FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
FormulaToken *pCur = vSubArguments[i]->GetFormulaToken(); assert(pCur);
assert(pCur); if (pCur->GetType() == formula::svDoubleVectorRef)
if (pCur->GetType() == formula::svDoubleVectorRef) {
{ const formula::DoubleVectorRefToken* pDVR =
const formula::DoubleVectorRefToken* pDVR = dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
dynamic_cast<const formula::DoubleVectorRefToken *>(pCur); size_t nCurWindowSize = pDVR->GetRefRowSize();
size_t nCurWindowSize = pDVR->GetRefRowSize(); ss << "for (int i = ";
ss << "for (int i = "; if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
#ifdef ISNAN #ifdef ISNAN
ss << "gid0; i < " << pDVR->GetArrayLength(); ss << "gid0; i < " << pDVR->GetArrayLength();
ss << " && i < " << nCurWindowSize << "; i++){\n "; ss << " && i < " << nCurWindowSize << "; i++){\n ";
#else #else
ss << "gid0; i < "<< nCurWindowSize << "; i++)\n "; ss << "gid0; i < "<< nCurWindowSize << "; i++)\n ";
#endif #endif
} else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) { } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
#ifdef ISNAN #ifdef ISNAN
ss << "0; i < " << pDVR->GetArrayLength(); ss << "0; i < " << pDVR->GetArrayLength();
ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n "; ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n ";
#else #else
ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n "; ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n ";
#endif #endif
} else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){ } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
#ifdef ISNAN #ifdef ISNAN
ss << "0; i + gid0 < " << pDVR->GetArrayLength(); ss << "0; i + gid0 < " << pDVR->GetArrayLength();
ss << " && i < "<< nCurWindowSize << "; i++){\n "; ss << " && i < "<< nCurWindowSize << "; i++){\n ";
#else #else
ss << "0; i < "<< nCurWindowSize << "; i++)\n "; ss << "0; i < "<< nCurWindowSize << "; i++)\n ";
#endif #endif
} }
else { else {
#ifdef ISNAN #ifdef ISNAN
ss << "0; i < "<< nCurWindowSize << "; i++){\n "; ss << "0; i < "<< nCurWindowSize << "; i++){\n ";
#else #else
ss << "0; i < "<< nCurWindowSize << "; i++)\n "; ss << "0; i < "<< nCurWindowSize << "; i++)\n ";
#endif #endif
} }
nItems += nCurWindowSize; nItems += nCurWindowSize;
} }
else if (pCur->GetType() == formula::svSingleVectorRef) else if (pCur->GetType() == formula::svSingleVectorRef)
{ {
#ifdef ISNAN #ifdef ISNAN
const formula::SingleVectorRefToken* pSVR = const formula::SingleVectorRefToken* pSVR =
dynamic_cast< const formula::SingleVectorRefToken* >(pCur); dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n "; ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n ";
#else #else
nItems += 1; nItems += 1;
#endif #endif
} }
else if (pCur->GetType() == formula::svDouble) else if (pCur->GetType() == formula::svDouble)
{ {
#ifdef ISNAN #ifdef ISNAN
ss << "{\n "; ss << "{\n ";
#endif #endif
nItems += 1; nItems += 1;
} }
else else
{ {
#ifdef ISNAN #ifdef ISNAN
#endif #endif
nItems += 1; nItems += 1;
} }
#ifdef ISNAN #ifdef ISNAN
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode()) if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{ {
ss << "if (isNan("; ss << "if (isNan(";
ss << vSubArguments[i]->GenSlidingWindowDeclRef(); ss << vSubArguments[i]->GenSlidingWindowDeclRef();
ss << "))\n "; ss << "))\n ";
ss << "tmp"<<i<<"= 0;\n "; ss << "tmp"<<i<<"= 0;\n ";
ss << "else\n "; ss << "else\n ";
ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(); ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
ss << ";\n }\n "; ss << ";\n }\n ";
} }
else else
{ {
ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(); ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
ss <<";\n "; ss <<";\n ";
} }
#else #else
ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(); ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
ss <<";\n "; ss <<";\n ";
#endif #endif
} }
ss << "tmp = getPrice_(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n\t"; ss << "tmp = getPrice_(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n\t";
ss << "return tmp;\n"; ss << "return tmp;\n";
ss << "}"; ss << "}";
} }
void OpPPMT::BinInlineFun(std::set<std::string>& decls, void OpPPMT::BinInlineFun(std::set<std::string>& decls,
std::set<std::string>& funs) std::set<std::string>& funs)
{ {
decls.insert(GetZwDecl); decls.insert(GetZwDecl);
funs.insert(GetZw); funs.insert(GetZw);
} }
void OpPPMT::GenSlidingWindowFunction(std::stringstream &ss, void OpPPMT::GenSlidingWindowFunction(std::stringstream &ss,
const std::string sSymName, SubArguments &vSubArguments) const std::string sSymName, SubArguments &vSubArguments)
{ {
ArgVector argVector; ArgVector argVector;
ss << "\ndouble " << sSymName; ss << "\ndouble " << sSymName;
ss << "_"<< BinFuncName() <<"("; ss << "_"<< BinFuncName() <<"(";
for (unsigned i = 0; i < vSubArguments.size(); i++) for (unsigned i = 0; i < vSubArguments.size(); i++)
{ {
if (i) if (i)
ss << ", "; ss << ", ";
vSubArguments[i]->GenSlidingWindowDecl(ss); vSubArguments[i]->GenSlidingWindowDecl(ss);
} }
ss << ") {\n "; ss << ") {\n ";
ss << "double tmp = 0;\n "; ss << "double tmp = 0;\n ";
ss << "int gid0 = get_global_id(0);\n "; ss << "int gid0 = get_global_id(0);\n ";
ss<<"double tmp0=0;\n "; ss<<"double tmp0=0;\n ";
ss<<"double tmp1=0;\n "; ss<<"double tmp1=0;\n ";
ss<<"double tmp2=0;\n "; ss<<"double tmp2=0;\n ";
ss<<"double tmp3=0;\n "; ss<<"double tmp3=0;\n ";
ss<<"double tmp4=0,tmp5=0;\n "; ss<<"double tmp4=0,tmp5=0;\n ";
size_t nItems = 0; size_t nItems = 0;
ss <<"\n "; ss <<"\n ";
//while (i-- > 1) //while (i-- > 1)
for (size_t i = 0; i < vSubArguments.size(); i++) for (size_t i = 0; i < vSubArguments.size(); i++)
{ {
FormulaToken *pCur = vSubArguments[i]->GetFormulaToken(); FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
assert(pCur); assert(pCur);
if (pCur->GetType() == formula::svDoubleVectorRef) if (pCur->GetType() == formula::svDoubleVectorRef)
{ {
const formula::DoubleVectorRefToken* pDVR = const formula::DoubleVectorRefToken* pDVR =
dynamic_cast<const formula::DoubleVectorRefToken *>(pCur); dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
size_t nCurWindowSize = pDVR->GetRefRowSize(); size_t nCurWindowSize = pDVR->GetRefRowSize();
ss << "for (int i = "; ss << "for (int i = ";
if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) { if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
#ifdef ISNAN #ifdef ISNAN
ss << "gid0; i < " << pDVR->GetArrayLength(); ss << "gid0; i < " << pDVR->GetArrayLength();
ss << " && i < " << nCurWindowSize << "; i++){\n "; ss << " && i < " << nCurWindowSize << "; i++){\n ";
#else #else
ss << "gid0; i < "<< nCurWindowSize << "; i++)\n "; ss << "gid0; i < "<< nCurWindowSize << "; i++)\n ";
#endif #endif
} else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) { } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
#ifdef ISNAN #ifdef ISNAN
ss << "0; i < " << pDVR->GetArrayLength(); ss << "0; i < " << pDVR->GetArrayLength();
ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n "; ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n ";
#else #else
ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n "; ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n ";
#endif #endif
} else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){ } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
#ifdef ISNAN #ifdef ISNAN
ss << "0; i + gid0 < " << pDVR->GetArrayLength(); ss << "0; i + gid0 < " << pDVR->GetArrayLength();
ss << " && i < "<< nCurWindowSize << "; i++){\n "; ss << " && i < "<< nCurWindowSize << "; i++){\n ";
#else #else
ss << "0; i < "<< nCurWindowSize << "; i++)\n "; ss << "0; i < "<< nCurWindowSize << "; i++)\n ";
#endif #endif
} }
else { else {
#ifdef ISNAN #ifdef ISNAN
ss << "0; i < "<< nCurWindowSize << "; i++){\n "; ss << "0; i < "<< nCurWindowSize << "; i++){\n ";
#else #else
ss << "0; i < "<< nCurWindowSize << "; i++)\n "; ss << "0; i < "<< nCurWindowSize << "; i++)\n ";
#endif #endif
} }
nItems += nCurWindowSize; nItems += nCurWindowSize;
} }
else if (pCur->GetType() == formula::svSingleVectorRef) else if (pCur->GetType() == formula::svSingleVectorRef)
{ {
#ifdef ISNAN #ifdef ISNAN
const formula::SingleVectorRefToken* pSVR = const formula::SingleVectorRefToken* pSVR =
dynamic_cast< const formula::SingleVectorRefToken* >(pCur); dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n "; ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n ";
#else #else
nItems += 1; nItems += 1;
#endif #endif
} }
else if (pCur->GetType() == formula::svDouble) else if (pCur->GetType() == formula::svDouble)
{ {
#ifdef ISNAN #ifdef ISNAN
ss << "{\n "; ss << "{\n ";
#endif #endif
nItems += 1; nItems += 1;
} }
else else
{ {
#ifdef ISNAN #ifdef ISNAN
#endif #endif
nItems += 1; nItems += 1;
} }
#ifdef ISNAN #ifdef ISNAN
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode()) if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{ {
ss << "if (isNan("; ss << "if (isNan(";
ss << vSubArguments[i]->GenSlidingWindowDeclRef(); ss << vSubArguments[i]->GenSlidingWindowDeclRef();
ss << "))\n "; ss << "))\n ";
ss << "tmp"<<i<<"= 0;\n "; ss << "tmp"<<i<<"= 0;\n ";
ss << "else\n "; ss << "else\n ";
ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(); ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
ss << ";\n }\n "; ss << ";\n }\n ";
} }
else else
{ {
ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(); ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
ss <<";\n "; ss <<";\n ";
} }
#else #else
ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(); ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
ss <<";\n "; ss <<";\n ";
#endif #endif
} }
ss <<"double pmt ;\n "; ss <<"double pmt ;\n ";
ss<<"if(tmp0==0.0)\n "; ss<<"if(tmp0==0.0)\n ";
ss<<" return -(tmp3+tmp4)/"; ss<<" return -(tmp3+tmp4)/";
ss<<"tmp2;\n double temp1=0;\n "; ss<<"tmp2;\n double temp1=0;\n ";
ss <<"double abl = pow(1.0+tmp0,tmp2);\n "; ss <<"double abl = pow(1.0+tmp0,tmp2);\n ";
ss <<"temp1-=tmp4"; ss <<"temp1-=tmp4";
ss<<";\n "; ss<<";\n ";
ss<<"temp1-=tmp3*abl;\n "; ss<<"temp1-=tmp3*abl;\n ";
ss <<"pmt = temp1/(1.0+tmp0*tmp5"; ss <<"pmt = temp1/(1.0+tmp0*tmp5";
ss<<") / ( (abl-1.0)/tmp0);\n "; ss<<") / ( (abl-1.0)/tmp0);\n ";
ss <<"double temp = pow( 1+tmp0,tmp1-2);\n "; ss <<"double temp = pow( 1+tmp0,tmp1-2);\n ";
ss <<"double re;\n "; ss <<"double re;\n ";
ss <<"if(tmp1==1.0)\n {\n "; ss <<"if(tmp1==1.0)\n {\n ";
ss <<"if(tmp5>0.0)\n "; ss <<"if(tmp5>0.0)\n ";
ss <<" re=0.0;\n "; ss <<" re=0.0;\n ";
ss << "else\n re=-tmp3;\n }\n "; ss << "else\n re=-tmp3;\n }\n ";
ss <<"else\n {\n "; ss <<"else\n {\n ";
ss <<"if(tmp5>0.0)\n "; ss <<"if(tmp5>0.0)\n ";
ss <<" re=GetZw(tmp0, tmp1-2.0, pmt, tmp3, 1.0) - pmt;\n "; ss <<" re=GetZw(tmp0, tmp1-2.0, pmt, tmp3, 1.0) - pmt;\n ";
ss <<"else\n "; ss <<"else\n ";
ss <<" re=GetZw(tmp0, tmp1-1.0, pmt, tmp3, 0.0);\n "; ss <<" re=GetZw(tmp0, tmp1-1.0, pmt, tmp3, 0.0);\n ";
ss <<"}\n "; ss <<"}\n ";
ss <<"re = re * tmp0;\n "; ss <<"re = re * tmp0;\n ";
ss <<"tmp = pmt - re;\n "; ss <<"tmp = pmt - re;\n ";
ss << "return tmp;\n"; ss << "return tmp;\n";
ss << "}"; ss << "}";
} }
void OpCoupdaybs::BinInlineFun(std::set<std::string>& decls, void OpCoupdaybs::BinInlineFun(std::set<std::string>& decls,
std::set<std::string>& funs) std::set<std::string>& funs)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment