summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorhaochen <haochen@multicorewareinc.com>2014-05-29 09:09:55 +0800
committerMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2014-06-10 15:58:26 +0200
commitc3383aafa18ef9d03b04b2a4719e71fdfabc14eb (patch)
tree94fb5a2c16ef9d1154e035ab1d572d3eb271a02c /sc
parentaa294679810972d43f1ad0735319d9a06936210b (diff)
GPU Calc:Support string arguments in VLookup
Change-Id: Ic2400a13c07c5b08beccaeffef4899c8f8b43af8
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/opencl/formulagroupcl.cxx91
-rw-r--r--sc/source/core/opencl/op_spreadsheet.cxx49
-rw-r--r--sc/source/core/opencl/op_spreadsheet.hxx1
-rw-r--r--sc/source/core/opencl/opbase.cxx10
-rw-r--r--sc/source/core/opencl/opbase.hxx8
5 files changed, 124 insertions, 35 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 4f40e2567d00..c0b62f29f154 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -378,28 +378,55 @@ size_t DynamicKernelStringArgument::Marshal(cl_kernel k, int argno, int, cl_prog
vRef = pDVR->GetArrays()[mnIndex];
}
size_t szHostBuffer = nStrings * sizeof(cl_int);
- // Marshal strings. Right now we pass hashes of these string
- mpClmem = clCreateBuffer(kEnv.mpkContext,
- (cl_mem_flags) CL_MEM_READ_ONLY|CL_MEM_ALLOC_HOST_PTR,
- szHostBuffer, NULL, &err);
- if (CL_SUCCESS != err)
- throw OpenCLError(err, __FILE__, __LINE__);
- cl_uint *pHashBuffer = (cl_uint*)clEnqueueMapBuffer(
- kEnv.mpkCmdQueue, mpClmem, CL_TRUE, CL_MAP_WRITE, 0,
- szHostBuffer, 0, NULL, NULL, &err);
- if (CL_SUCCESS != err)
- throw OpenCLError(err, __FILE__, __LINE__);
- for (size_t i = 0; i < nStrings; i++)
+ cl_uint *pHashBuffer = NULL;
+
+ if ( vRef.mpStringArray != NULL)
{
- if (vRef.mpStringArray[i])
- {
- const OUString tmp = OUString(vRef.mpStringArray[i]);
- pHashBuffer[i] = tmp.hashCode();
- }
- else
+ // Marshal strings. Right now we pass hashes of these string
+ mpClmem = clCreateBuffer(kEnv.mpkContext,
+ (cl_mem_flags) CL_MEM_READ_ONLY|CL_MEM_ALLOC_HOST_PTR,
+ szHostBuffer, NULL, &err);
+ if (CL_SUCCESS != err)
+ throw OpenCLError(err, __FILE__, __LINE__);
+
+ pHashBuffer = (cl_uint*)clEnqueueMapBuffer(
+ kEnv.mpkCmdQueue, mpClmem, CL_TRUE, CL_MAP_WRITE, 0,
+ szHostBuffer, 0, NULL, NULL, &err);
+ if (CL_SUCCESS != err)
+ throw OpenCLError(err, __FILE__, __LINE__);
+
+ for (size_t i = 0; i < nStrings; i++)
{
+ if (vRef.mpStringArray[i])
+ {
+ const OUString tmp = OUString(vRef.mpStringArray[i]);
+ pHashBuffer[i] = tmp.hashCode();
+ }
+ else
+ {
+ pHashBuffer[i] = 0;
+ }
+ }
+ }
+ else
+ {
+ if (nStrings == 0)
+ szHostBuffer = sizeof(cl_int); // a dummy small value
+ // Marshal as a buffer of NANs
+ mpClmem = clCreateBuffer(kEnv.mpkContext,
+ (cl_mem_flags) CL_MEM_READ_ONLY|CL_MEM_ALLOC_HOST_PTR,
+ szHostBuffer, NULL, &err);
+ if (CL_SUCCESS != err)
+ throw OpenCLError(err, __FILE__, __LINE__);
+
+ cl_uint *pHashBuffer = (cl_uint*)clEnqueueMapBuffer(
+ kEnv.mpkCmdQueue, mpClmem, CL_TRUE, CL_MAP_WRITE, 0,
+ szHostBuffer, 0, NULL, NULL, &err);
+ if (CL_SUCCESS != err)
+ throw OpenCLError(err, __FILE__, __LINE__);
+
+ for (size_t i = 0; i < szHostBuffer/sizeof(cl_int); i++)
pHashBuffer[i] = 0;
- }
}
err = clEnqueueUnmapMemObject(kEnv.mpkCmdQueue, mpClmem,
pHashBuffer, 0, NULL, NULL);
@@ -425,6 +452,7 @@ public:
ss << ", ";
mStringArgument.GenSlidingWindowDecl(ss);
}
+ virtual bool IsMixedArgument() const SAL_OVERRIDE {return true;}
virtual void GenSlidingWindowFunction(std::stringstream &) SAL_OVERRIDE {}
/// Generate declaration
virtual void GenDecl(std::stringstream &ss) const SAL_OVERRIDE
@@ -439,12 +467,20 @@ public:
ss << ",";
mStringArgument.GenDeclRef(ss);
}
- virtual std::string GenSlidingWindowDeclRef(bool) const SAL_OVERRIDE
+ virtual void GenNumDeclRef(std::stringstream& ss) const SAL_OVERRIDE
+ {
+ VectorRef::GenSlidingWindowDecl(ss);
+ }
+ virtual void GenStringDeclRef(std::stringstream& ss) const SAL_OVERRIDE
+ {
+ mStringArgument.GenSlidingWindowDecl(ss);
+ }
+ virtual std::string GenSlidingWindowDeclRef(bool nested) const SAL_OVERRIDE
{
std::stringstream ss;
ss << "(!isNan(" << VectorRef::GenSlidingWindowDeclRef();
ss << ")?" << VectorRef::GenSlidingWindowDeclRef();
- ss << ":" << mStringArgument.GenSlidingWindowDeclRef();
+ ss << ":" << mStringArgument.GenSlidingWindowDeclRef(nested);
ss << ")";
return ss.str();
}
@@ -725,15 +761,16 @@ public:
ss << ",";
mStringArgument.GenDeclRef(ss);
}
- virtual std::string GenSlidingWindowDeclRef(bool) const SAL_OVERRIDE
+ virtual std::string GenSlidingWindowDeclRef(bool nested) const SAL_OVERRIDE
{
std::stringstream ss;
ss << "(!isNan(" << mDoubleArgument.GenSlidingWindowDeclRef();
ss << ")?" << mDoubleArgument.GenSlidingWindowDeclRef();
- ss << ":" << mStringArgument.GenSlidingWindowDeclRef();
+ ss << ":" << mStringArgument.GenSlidingWindowDeclRef(nested);
ss << ")";
return ss.str();
}
+ virtual bool IsMixedArgument() const SAL_OVERRIDE {return true;}
virtual std::string GenDoubleSlidingWindowDeclRef(bool=false) const SAL_OVERRIDE
{
std::stringstream ss;
@@ -746,6 +783,14 @@ public:
ss << mStringArgument.GenSlidingWindowDeclRef();
return ss.str();
}
+ virtual void GenNumDeclRef(std::stringstream& ss) const SAL_OVERRIDE
+ {
+ mDoubleArgument.GenDeclRef(ss);
+ }
+ virtual void GenStringDeclRef(std::stringstream& ss) const SAL_OVERRIDE
+ {
+ mStringArgument.GenDeclRef(ss);
+ }
virtual size_t Marshal(cl_kernel k, int argno, int vw, cl_program p) SAL_OVERRIDE
{
int i = mDoubleArgument.Marshal(k, argno, vw, p);
diff --git a/sc/source/core/opencl/op_spreadsheet.cxx b/sc/source/core/opencl/op_spreadsheet.cxx
index d2b78c907a3f..361085014542 100644
--- a/sc/source/core/opencl/op_spreadsheet.cxx
+++ b/sc/source/core/opencl/op_spreadsheet.cxx
@@ -157,10 +157,32 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss,
ss << " == ";
ss << j+1;
ss << ")\n";
- ss << " tmp = ";
- vSubArguments[1+j]->GenDeclRef(ss);
- ss << "[rowNum];\n";
+ if( !(vSubArguments[1+j]->IsMixedArgument()))
+ {
+ ss << "{";
+ ss << " tmp = ";
+ vSubArguments[1+j]->GenDeclRef(ss);
+ ss << "[rowNum];\n";
+ ss << "}";
+
+ }
+ else
+ {
+ ss << "{";
+
+ ss << " tmp = isNan(";
+ vSubArguments[1+j]->GenNumDeclRef(ss);
+ ss << "[rowNum]"<<")?";
+ vSubArguments[1+j]->GenNumDeclRef(ss);
+ ss << "[rowNum]:";
+ vSubArguments[1+j]->GenStringDeclRef(ss);
+ ss << "[rowNum];\n";
+ ss << "}";
+
+
+
+ }
}
ss << " return tmp;\n";
ss << " }\n";
@@ -221,9 +243,24 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss,
ss << " == ";
ss << j+1;
ss << ")\n";
- ss << " tmp = ";
- vSubArguments[1+j]->GenDeclRef(ss);
- ss << "[rowNum];\n";
+ ///Add MixedArguments for string support in Vlookup.
+ if( !(vSubArguments[1+j]->IsMixedArgument()))
+ {
+ ss << " tmp = ";
+ vSubArguments[1+j]->GenDeclRef(ss);
+ ss << "[rowNum];\n";
+ }
+ else
+ {
+ ss << " tmp = isNan(";
+ vSubArguments[1+j]->GenNumDeclRef(ss);
+ ss << "[rowNum]"<<")?";
+ vSubArguments[1+j]->GenNumDeclRef(ss);
+ ss << "[rowNum]:";
+ vSubArguments[1+j]->GenStringDeclRef(ss);
+ ss << "[rowNum];\n";
+ }
+
}
ss << " return tmp;\n";
diff --git a/sc/source/core/opencl/op_spreadsheet.hxx b/sc/source/core/opencl/op_spreadsheet.hxx
index 53a010973636..01795062b616 100644
--- a/sc/source/core/opencl/op_spreadsheet.hxx
+++ b/sc/source/core/opencl/op_spreadsheet.hxx
@@ -20,6 +20,7 @@ public:
virtual void GenSlidingWindowFunction(std::stringstream &ss,
const std::string &sSymName, SubArguments &vSubArguments) SAL_OVERRIDE;
virtual std::string BinFuncName(void) const SAL_OVERRIDE { return "VLookup"; }
+ virtual bool takeString() const SAL_OVERRIDE { return true; }
};
}}
diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx
index dfda1608a968..ccd653c938db 100644
--- a/sc/source/core/opencl/opbase.cxx
+++ b/sc/source/core/opencl/opbase.cxx
@@ -59,15 +59,15 @@ void VectorRef::GenSlidingWindowDecl(std::stringstream &ss) const
}
/// When referenced in a sliding window function
-std::string VectorRef::GenSlidingWindowDeclRef(bool) const
+std::string VectorRef::GenSlidingWindowDeclRef(bool nested) const
{
std::stringstream ss;
formula::SingleVectorRefToken *pSVR =
dynamic_cast<formula::SingleVectorRefToken*>(DynamicKernelArgument::GetFormulaToken());
- if (pSVR)
+ if (pSVR&&nested)
ss << "(gid0 < " << pSVR->GetArrayLength() << "?";
ss << mSymName << "[gid0]";
- if (pSVR)
+ if (pSVR&&nested)
ss << ":NAN)";
return ss.str();
}
@@ -155,7 +155,7 @@ void CheckVariables::CheckSubArgumentIsNan( std::stringstream & ss,
ss<< " if(";
}
ss<< "isNan(";
- ss<< vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss<< vSubArguments[i]->GenSlidingWindowDeclRef(false);
ss<<"))\n";
ss<< " tmp";
ss<< i;
@@ -164,7 +164,7 @@ void CheckVariables::CheckSubArgumentIsNan( std::stringstream & ss,
ss <<" tmp";
ss <<i;
ss << "=";
- ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss << vSubArguments[i]->GenSlidingWindowDeclRef(false);
ss<<";\n";
}
diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx
index 6cd04a9ee23e..d1d00058a02f 100644
--- a/sc/source/core/opencl/opbase.hxx
+++ b/sc/source/core/opencl/opbase.hxx
@@ -165,8 +165,14 @@ public:
virtual std::string GenStringSlidingWindowDeclRef(bool=false) const
{ return std::string(""); }
+ virtual bool IsMixedArgument() const
+ { return false; }
+
/// Generate use/references to the argument
virtual void GenDeclRef(std::stringstream &ss) const;
+ virtual void GenNumDeclRef(std::stringstream &ss) const{ss << ",";}
+
+ virtual void GenStringDeclRef(std::stringstream &ss) const{ss << ",";}
/// Create buffer and pass the buffer to a given kernel
virtual size_t Marshal(cl_kernel, int, int, cl_program) = 0;
@@ -205,7 +211,7 @@ public:
virtual void GenSlidingWindowDecl(std::stringstream &ss) const SAL_OVERRIDE;
/// When referenced in a sliding window function
- virtual std::string GenSlidingWindowDeclRef(bool=false) const SAL_OVERRIDE;
+ virtual std::string GenSlidingWindowDeclRef(bool=true) const SAL_OVERRIDE;
/// Create buffer and pass the buffer to a given kernel
virtual size_t Marshal(cl_kernel, int, int, cl_program) SAL_OVERRIDE;