[Libreoffice-commits] core.git: Branch 'feature/calc-pluggable-opencl' - sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Tue Sep 17 14:21:05 PDT 2013
sc/source/core/opencl/formulagroupcl.cxx | 62 +++++++++----------------------
sc/source/core/opencl/openclwrapper.cxx | 45 ++++++++++++++++++++++
2 files changed, 64 insertions(+), 43 deletions(-)
New commits:
commit 578ac5b901857e9490930512fff676e8567a9666
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Tue Sep 17 17:22:38 2013 -0400
Fix illegal memory access between malloc and memset.
Change-Id: I6f040e48a1a60b8f4fc1f2424a24ff362de9a31e
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 139a219..a311179 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -455,66 +455,54 @@ double * agency::calculate( int nOclOp,int rowSize,OclCalc &ocl_calc,uint *npOcl
{
case ocAdd:
{
- unsigned int nDataSize = 0;
SourceData *temp = formulaInterprt->srdDataPop();
SourceData *temp2 = formulaInterprt->srdDataPop();
- nDataSize = temp2->getDataSize();
dpLeftData = temp2->getDouleData();
dpRightData = temp->getDouleData();
- nDataSize = temp2->getDataSize();
double *rResult = NULL; // Point to the output data from GPU
- rResult = (double *)malloc( sizeof(double) * nDataSize );
+ rResult = (double *)malloc( sizeof(double) * rowSize );
memset(rResult,0,rowSize);
ocl_calc.oclHostArithmeticStash64Bits( "oclSignedAdd",dpLeftData,dpRightData,rResult,temp->getDataSize() );
- formulaInterprt->srdDataPush( new SourceData( rResult,nDataSize ) );
+ formulaInterprt->srdDataPush( new SourceData( rResult,rowSize ) );
break;
}
case ocSub:
{
- unsigned int nDataSize = 0;
SourceData *temp = formulaInterprt->srdDataPop();
SourceData *temp2 = formulaInterprt->srdDataPop();
- nDataSize = temp2->getDataSize();
dpLeftData = temp2->getDouleData();
dpRightData = temp->getDouleData();
- nDataSize = temp2->getDataSize();
double *rResult = NULL; // Point to the output data from GPU
- rResult = ( double * )malloc( sizeof(double) * nDataSize );
+ rResult = ( double * )malloc( sizeof(double) * rowSize );
memset( rResult,0,rowSize );
ocl_calc.oclHostArithmeticStash64Bits( "oclSignedSub",dpLeftData,dpRightData,rResult,temp->getDataSize() );
- formulaInterprt->srdDataPush( new SourceData(rResult,nDataSize) );
+ formulaInterprt->srdDataPush( new SourceData(rResult,rowSize) );
break;
}
case ocMul:
{
- unsigned int nDataSize = 0;
SourceData *temp = formulaInterprt->srdDataPop();
SourceData *temp2 = formulaInterprt->srdDataPop();
- nDataSize = temp2->getDataSize();
dpLeftData = temp2->getDouleData();
dpRightData = temp->getDouleData();
- nDataSize = temp2->getDataSize();
double *rResult = NULL; // Point to the output data from GPU
- rResult = (double *)malloc( sizeof(double) * nDataSize );
+ rResult = (double *)malloc( sizeof(double) * rowSize );
memset( rResult,0,rowSize );
ocl_calc.oclHostArithmeticStash64Bits( "oclSignedMul",dpLeftData,dpRightData,rResult,temp->getDataSize() );
- formulaInterprt->srdDataPush( new SourceData( rResult,nDataSize ) );
+ formulaInterprt->srdDataPush( new SourceData( rResult,rowSize ) );
break;
}
case ocDiv:
{
- unsigned int nDataSize = 0;
SourceData *temp = formulaInterprt->srdDataPop();
SourceData *temp2 = formulaInterprt->srdDataPop();
- nDataSize = temp2->getDataSize();
dpLeftData = temp2->getDouleData();
dpRightData = temp->getDouleData();
- nDataSize = temp2->getDataSize();
double *rResult = NULL; // Point to the output data from GPU
- rResult = ( double * )malloc( sizeof(double) * nDataSize );
+ rResult = ( double * )malloc( sizeof(double) * rowSize );
memset( rResult,0,rowSize );
ocl_calc.oclHostArithmeticStash64Bits( "oclSignedDiv",dpLeftData,dpRightData,rResult,temp->getDataSize() );
- formulaInterprt->srdDataPush( new SourceData( rResult,nDataSize ) );
+ formulaInterprt->srdDataPush( new SourceData( rResult,rowSize ) );
break;
}
case ocMax:
@@ -567,66 +555,54 @@ double * agency::calculate( int nOclOp,int rowSize,OclCalc &ocl_calc,uint *npOcl
{
case ocAdd:
{
- unsigned int nDataSize = 0;
SourceData *temp = formulaInterprt->srdDataPop();
SourceData *temp2 = formulaInterprt->srdDataPop();
- nDataSize = temp2->getDataSize();
dpLeftData = temp2->getDouleData();
dpRightData = temp->getDouleData();
- nDataSize = temp2->getDataSize();
double *rResult = NULL; // Point to the output data from GPU
- rResult = (double *)malloc( sizeof(double) * nDataSize );
+ rResult = (double *)malloc( sizeof(double) * rowSize );
memset(rResult,0,rowSize);
ocl_calc.oclHostArithmeticStash32Bits( "oclSignedAdd", dpLeftData, dpRightData, rResult, temp->getDataSize() );
- formulaInterprt->srdDataPush( new SourceData(rResult, nDataSize) );
+ formulaInterprt->srdDataPush( new SourceData(rResult, rowSize) );
break;
}
case ocSub:
{
- unsigned int nDataSize = 0;
SourceData *temp = formulaInterprt->srdDataPop();
SourceData *temp2 = formulaInterprt->srdDataPop();
- nDataSize = temp2->getDataSize();
dpLeftData = temp2->getDouleData();
dpRightData = temp->getDouleData();
- nDataSize = temp2->getDataSize();
double *rResult = NULL; // Point to the output data from GPU
- rResult = (double *)malloc( sizeof(double) * nDataSize );
+ rResult = (double *)malloc( sizeof(double) * rowSize );
memset( rResult, 0, rowSize );
ocl_calc.oclHostArithmeticStash32Bits( "oclSignedSub", dpLeftData, dpRightData, rResult, temp->getDataSize() );
- formulaInterprt->srdDataPush( new SourceData( rResult,nDataSize ) );
+ formulaInterprt->srdDataPush( new SourceData( rResult, rowSize ) );
break;
}
case ocMul:
{
- unsigned int nDataSize = 0;
SourceData *temp = formulaInterprt->srdDataPop();
SourceData *temp2 = formulaInterprt->srdDataPop();
- nDataSize = temp2->getDataSize();
dpLeftData = temp2->getDouleData();
dpRightData = temp->getDouleData();
- nDataSize = temp2->getDataSize();
double *rResult = NULL; // Point to the output data from GPU
- rResult = (double *)malloc(sizeof(double) * nDataSize );
+ rResult = (double *)malloc(sizeof(double) * rowSize );
memset( rResult, 0, rowSize );
ocl_calc.oclHostArithmeticStash32Bits( "oclSignedMul", dpLeftData, dpRightData, rResult, temp->getDataSize() );
- formulaInterprt->srdDataPush( new SourceData( rResult, nDataSize ) );
+ formulaInterprt->srdDataPush( new SourceData( rResult, rowSize ) );
break;
}
case ocDiv:
{
- unsigned int nDataSize = 0;
SourceData *temp = formulaInterprt->srdDataPop();
SourceData *temp2 = formulaInterprt->srdDataPop();
- nDataSize = temp2->getDataSize();
dpLeftData = temp2->getDouleData();
dpRightData = temp->getDouleData();
- nDataSize = temp2->getDataSize();
double *rResult = NULL; // Point to the output data from GPU
- rResult = (double *)malloc( sizeof(double) * nDataSize );
+ rResult = (double *)malloc( sizeof(double) * rowSize );
memset( rResult, 0, rowSize );
ocl_calc.oclHostArithmeticStash32Bits( "oclSignedDiv", dpLeftData, dpRightData, rResult, temp->getDataSize() );
- formulaInterprt->srdDataPush( new SourceData(rResult, nDataSize) );
+ formulaInterprt->srdDataPush( new SourceData(rResult, rowSize) );
break;
}
case ocMax:
@@ -636,7 +612,7 @@ double * agency::calculate( int nOclOp,int rowSize,OclCalc &ocl_calc,uint *npOcl
nDataSize = temp->getDataSize();
dpOclSrcData = temp->getDouleData();
double *rResult = NULL; // Point to the output data from GPU
- rResult = (double *)malloc(sizeof(double) * nDataSize );
+ rResult = (double *)malloc(sizeof(double) * rowSize );
memset(rResult,0,rowSize);
ocl_calc.oclHostFormulaStash32Bits( "oclFormulaMax", dpOclSrcData, npOclStartPos, npOclEndPos, rResult,nDataSize, rowSize );
formulaInterprt->srdDataPush( new SourceData( rResult, rowSize ) );
@@ -649,7 +625,7 @@ double * agency::calculate( int nOclOp,int rowSize,OclCalc &ocl_calc,uint *npOcl
nDataSize = temp->getDataSize();
dpOclSrcData = temp->getDouleData();
double *rResult = NULL; // Point to the output data from GPU
- rResult = (double *)malloc( sizeof(double) * nDataSize );
+ rResult = (double *)malloc( sizeof(double) * rowSize );
memset( rResult, 0, rowSize );
ocl_calc.oclHostFormulaStash32Bits( "oclFormulaMin", dpOclSrcData, npOclStartPos, npOclEndPos, rResult, nDataSize, rowSize );
formulaInterprt->srdDataPush( new SourceData( rResult, rowSize) );
@@ -662,7 +638,7 @@ double * agency::calculate( int nOclOp,int rowSize,OclCalc &ocl_calc,uint *npOcl
nDataSize = temp->getDataSize();
dpOclSrcData = temp->getDouleData();
double *rResult = NULL; // Point to the output data from GPU
- rResult = (double *)malloc( sizeof(double) * nDataSize );
+ rResult = (double *)malloc( sizeof(double) * rowSize );
memset( rResult, 0, rowSize);
ocl_calc.oclHostFormulaStash32Bits( "oclFormulaAverage", dpOclSrcData, npOclStartPos, npOclEndPos, rResult, nDataSize, rowSize );
formulaInterprt->srdDataPush( new SourceData( rResult, rowSize) );
diff --git a/sc/source/core/opencl/openclwrapper.cxx b/sc/source/core/opencl/openclwrapper.cxx
index 2b2f8f7..7bcd390 100644
--- a/sc/source/core/opencl/openclwrapper.cxx
+++ b/sc/source/core/opencl/openclwrapper.cxx
@@ -43,6 +43,49 @@
#define DEVICE_NAME_LENGTH 1024
+
+#include <stdio.h>
+#include <string>
+#include <sys/time.h>
+
+namespace {
+
+class stack_printer
+{
+public:
+ explicit stack_printer(const char* msg) :
+ msMsg(msg)
+ {
+ fprintf(stdout, "%s: --begin\n", msMsg.c_str());
+ mfStartTime = getTime();
+ }
+
+ ~stack_printer()
+ {
+ double fEndTime = getTime();
+ fprintf(stdout, "%s: --end (duration: %g sec)\n", msMsg.c_str(), (fEndTime - mfStartTime));
+ }
+
+ void printTime(int line) const
+ {
+ double fEndTime = getTime();
+ fprintf(stdout, "%s: --(%d) (duration: %g sec)\n", msMsg.c_str(), line, (fEndTime - mfStartTime));
+ }
+
+private:
+ double getTime() const
+ {
+ timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec + tv.tv_usec / 1000000.0;
+ }
+
+ ::std::string msMsg;
+ double mfStartTime;
+};
+
+}
+
using namespace std;
namespace sc { namespace opencl {
@@ -2752,6 +2795,8 @@ void compileKernels(const OUString* pDeviceId)
if (pDeviceId->isEmpty())
return;
+ stack_printer __stack_printer__("sc/opencl::compileKernels");
+ fprintf(stdout, "opencl::compileKernels: device = '%s'\n", rtl::OUStringToOString(*pDeviceId, RTL_TEXTENCODING_UTF8).getStr());
if (!switchOpenclDevice(pDeviceId, false))
return;
More information about the Libreoffice-commits
mailing list