diff options
author | minwang <min@multicorewareinc.com> | 2013-12-24 14:35:55 +0800 |
---|---|---|
committer | I-Jui (Ray) Sung <ray@multicorewareinc.com> | 2013-12-30 15:05:28 -0600 |
commit | e600adae34fe99373eb9695864aadabc06682773 (patch) | |
tree | a1840c68345a7964357705c70e92415a0f646f03 /sc | |
parent | 9d5b5dfeb2d4d913900de86a97387e6d997c5e38 (diff) |
GPU Calc: Optimized AMORLINC
AMLOEXT-228
Change-Id: Ie48898fd7b783bb94e3dcf0121ae40d9aa32916e
Signed-off-by: haochen <haochen@multicorewareinc.com>
Signed-off-by: Wei Wei <weiwei@multicorewareinc.com>
Signed-off-by: I-Jui (Ray) Sung <ray@multicorewareinc.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/opencl/op_financial.cxx | 115 |
1 files changed, 54 insertions, 61 deletions
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx index f7b7ed04b92e..17f37bf6a0f2 100644 --- a/sc/source/core/opencl/op_financial.cxx +++ b/sc/source/core/opencl/op_financial.cxx @@ -4189,11 +4189,11 @@ void OpAmorlinc::BinInlineFun(std::set<std::string>& decls, decls.insert(nKorrValDecl); decls.insert(RoundDecl); decls.insert(IsLeapYearDecl);decls.insert(DaysInMonthDecl); decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl); - decls.insert(GetNullDateDecl); decls.insert(GetYearFracDecl); + decls.insert(GetYearFracDecl); funs.insert(Round); funs.insert(IsLeapYear);funs.insert(DaysInMonth); funs.insert(DaysToDate);funs.insert(DateToDays); - funs.insert(GetNullDate);funs.insert(GetYearFrac); + funs.insert(GetYearFrac); } void OpAmorlinc::GenSlidingWindowFunction(std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments) @@ -4208,112 +4208,105 @@ void OpAmorlinc::GenSlidingWindowFunction(std::stringstream &ss, } ss << ") {\n"; ss << " int gid0 = get_global_id(0);\n"; - ss << " double tmp = " << GetBottom() <<";\n"; + ss << " double tmp = 0;\n"; ss << " double fCost,fRestVal,fPer,fRate;\n"; ss << " int nDate,nFirstPer,nBase;\n"; #ifdef ISNAN FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const - formula::SingleVectorRefToken *>(tmpCur0); FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const - formula::SingleVectorRefToken *>(tmpCur1); FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const - formula::SingleVectorRefToken *>(tmpCur2); FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const - formula::SingleVectorRefToken *>(tmpCur3); FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const - formula::SingleVectorRefToken *>(tmpCur4); FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR5= dynamic_cast<const - formula::SingleVectorRefToken *>(tmpCur5); FormulaToken *tmpCur6 = vSubArguments[6]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR6= dynamic_cast<const - formula::SingleVectorRefToken *>(tmpCur6); - ss<< " int buffer_Cost_len = "; - ss<< tmpCurDVR0->GetArrayLength(); - ss<< ";\n"; - ss<< " int buffer_Date_len = "; - ss<< tmpCurDVR1->GetArrayLength(); - ss << ";\n"; - ss<< " int buffer_FirstPer_len = "; - ss<< tmpCurDVR2->GetArrayLength(); - ss << ";\n"; - ss<< " int buffer_RestVal_len = "; - ss<< tmpCurDVR3->GetArrayLength(); - ss << ";\n"; - ss<< " int buffer_Per_len = "; - ss<< tmpCurDVR4->GetArrayLength(); - ss << ";\n"; - ss<< " int buffer_Rate_len = "; - ss<< tmpCurDVR5->GetArrayLength(); - ss << ";\n"; - ss<< " int buffer_Base_len = "; - ss<< tmpCurDVR6->GetArrayLength(); - ss << ";\n"; #endif #ifdef ISNAN - ss <<" if(gid0 >= buffer_Cost_len || isNan("; - ss <<vSubArguments[0]->GenSlidingWindowDeclRef(); - ss <<"))\n"; + if(tmpCur0->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur0); + ss <<" if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef(); + ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n"; ss <<" fCost = 0;\n else\n"; + } #endif ss << " fCost="; ss << vSubArguments[0]->GenSlidingWindowDeclRef(); ss <<";\n"; #ifdef ISNAN - ss <<" if(gid0 >= buffer_Date_len || isNan("; - ss <<vSubArguments[1]->GenSlidingWindowDeclRef(); - ss <<"))\n"; + if(tmpCur1->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur1); + ss <<" if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef(); + ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n"; ss <<" nDate = 0;\n else\n"; + } #endif ss << " nDate=(int)"; ss << vSubArguments[1]->GenSlidingWindowDeclRef(); ss << ";\n"; #ifdef ISNAN - ss <<" if(gid0 >= buffer_FirstPer_len || isNan("; - ss <<vSubArguments[2]->GenSlidingWindowDeclRef(); - ss <<"))\n"; + if(tmpCur2->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur2); + ss <<" if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef(); + ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n"; ss <<" nFirstPer = 0;\n else\n"; + } #endif ss << " nFirstPer=(int)"; ss << vSubArguments[2]->GenSlidingWindowDeclRef(); ss <<";\n"; #ifdef ISNAN - ss <<" if(gid0 >= buffer_RestVal_len || isNan("; - ss <<vSubArguments[3]->GenSlidingWindowDeclRef(); - ss <<"))\n"; + if(tmpCur3->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur3); + ss <<" if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef(); + ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n"; ss <<" fRestVal = 0;\n else\n"; + } #endif ss << " fRestVal="; ss << vSubArguments[3]->GenSlidingWindowDeclRef(); ss << ";\n"; #ifdef ISNAN - ss <<" if(gid0 >= buffer_Per_len || isNan("; - ss <<vSubArguments[4]->GenSlidingWindowDeclRef(); - ss <<"))\n"; + if(tmpCur4->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur4); + ss <<" if(isNan(" <<vSubArguments[4]->GenSlidingWindowDeclRef(); + ss <<")||(gid0 >="<<tmpCurDVR4->GetArrayLength()<<"))\n"; ss <<" fPer = 0;\n else\n"; + } #endif ss << " fPer = "; ss << vSubArguments[4]->GenSlidingWindowDeclRef(); ss <<";\n"; #ifdef ISNAN - ss <<" if(gid0 >= buffer_Rate_len || isNan("; - ss <<vSubArguments[5]->GenSlidingWindowDeclRef(); - ss <<"))\n"; + if(tmpCur5->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken*tmpCurDVR5= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur5); + ss <<" if(isNan(" <<vSubArguments[5]->GenSlidingWindowDeclRef(); + ss <<")||(gid0 >="<<tmpCurDVR5->GetArrayLength()<<"))\n"; ss <<" fRate = 0;\n else\n"; + } #endif ss << " fRate="; ss << vSubArguments[5]->GenSlidingWindowDeclRef(); ss << ";\n"; #ifdef ISNAN - ss <<" if(gid0 >= buffer_Base_len || isNan("; - ss <<vSubArguments[6]->GenSlidingWindowDeclRef(); - ss <<"))\n"; + if(tmpCur6->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken*tmpCurDVR6= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur6); + ss <<" if(isNan(" <<vSubArguments[6]->GenSlidingWindowDeclRef(); + ss <<")||(gid0 >="<<tmpCurDVR6->GetArrayLength()<<"))\n"; ss <<" nBase = 0;\n else\n"; + } #endif ss << " nBase = (int)"; ss << vSubArguments[6]->GenSlidingWindowDeclRef(); @@ -4321,10 +4314,10 @@ void OpAmorlinc::GenSlidingWindowFunction(std::stringstream &ss, ss <<" int nPer = convert_int( fPer );\n"; ss <<" double fOneRate = fCost * fRate;\n"; ss <<" double fCostDelta = fCost - fRestVal;\n"; - ss <<" double f0Rate = GetYearFrac( GetNullDate(),"; + ss <<" double f0Rate = GetYearFrac( 693594,"; ss <<"nDate, nFirstPer, nBase )* fRate * fCost;\n"; ss <<" int nNumOfFullPeriods = (int)"; - ss <<"( ( fCost - fRestVal - f0Rate) /fOneRate );\n"; + ss <<"( ( fCost - fRestVal - f0Rate) *pow(fOneRate,-1) );\n"; ss <<" if( nPer == 0 )\n"; ss <<" tmp = f0Rate;\n"; ss <<" else if( nPer <= nNumOfFullPeriods )\n"; |