summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-11-18 14:46:30 -0600
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-11-18 15:59:14 -0600
commitc935a91260aaba79300cf516bac044ebb8dc7ef9 (patch)
tree15c2af3e23c7897f46392ff2ead136236271b0e1
parent45d4b9b5e354578a81960c1b4b56e934f1e4b704 (diff)
GPU Calc: implement horizontal ranges as multiple VectorRefs
AMLOEXT-242 Fix Change-Id: Ia3deb221528230554b7c431e926b10428441666a
-rw-r--r--sc/source/core/opencl/formulagroupcl.cxx54
-rw-r--r--sc/source/core/opencl/opbase.cxx12
-rw-r--r--sc/source/core/opencl/opbase.hxx7
3 files changed, 47 insertions, 26 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index a863c94c6635..3a63c9205943 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -65,9 +65,10 @@ size_t VectorRef::Marshal(cl_kernel k, int argno, int, cl_program)
const formula::DoubleVectorRefToken* pDVR =
dynamic_cast< const formula::DoubleVectorRefToken* >(ref);
assert(pDVR);
- if (pDVR->GetArrays()[0].mpNumericArray == NULL)
+ if (pDVR->GetArrays()[mnIndex].mpNumericArray == NULL)
throw Unhandled();
- pHostBuffer = const_cast<double*>(pDVR->GetArrays()[0].mpNumericArray);
+ pHostBuffer = const_cast<double*>(
+ pDVR->GetArrays()[mnIndex].mpNumericArray);
szHostBuffer = pDVR->GetArrayLength() * sizeof(double);
} else {
throw Unhandled();
@@ -281,8 +282,8 @@ class DynamicKernelStringArgument: public VectorRef
{
public:
DynamicKernelStringArgument(const std::string &s,
- FormulaTreeNodeRef ft):
- VectorRef(s, ft) {}
+ FormulaTreeNodeRef ft, int index = 0):
+ VectorRef(s, ft, index) {}
virtual void GenSlidingWindowFunction(std::stringstream &) {}
/// Generate declaration
@@ -319,7 +320,7 @@ size_t DynamicKernelStringArgument::Marshal(cl_kernel k, int argno, int, cl_prog
dynamic_cast< const formula::DoubleVectorRefToken* >(ref);
assert(pDVR);
nStrings = pDVR->GetArrayLength();
- vRef = pDVR->GetArrays()[0];
+ vRef = pDVR->GetArrays()[mnIndex];
}
size_t szHostBuffer = nStrings * sizeof(cl_int);
// Marshal strings. Right now we pass hashes of these string
@@ -411,8 +412,9 @@ class DynamicKernelSlidingArgument: public Base
{
public:
DynamicKernelSlidingArgument(const std::string &s,
- FormulaTreeNodeRef ft, boost::shared_ptr<SlidingFunctionBase> &CodeGen):
- Base(s, ft), mpCodeGen(CodeGen), mpClmem2(NULL)
+ FormulaTreeNodeRef ft, boost::shared_ptr<SlidingFunctionBase> &CodeGen,
+ int index=0):
+ Base(s, ft, index), mpCodeGen(CodeGen), mpClmem2(NULL)
{
FormulaToken *t = ft->GetFormulaToken();
if (t->GetType() != formula::svDoubleVectorRef)
@@ -491,9 +493,6 @@ public:
std::stringstream &ss, bool &needBody)
{
assert(mpDVR);
- // Do not handle horizontal double vectors yet
- if (mpDVR->GetArrays().size() > 1)
- throw Unhandled();
size_t nCurWindowSize = mpDVR->GetRefRowSize();
if (dynamic_cast<OpSum*>(mpCodeGen.get()))
{
@@ -528,6 +527,15 @@ public:
}
}
needBody = true;
+
+ // No need to generate a for-loop for degenerated cases
+ if (nCurWindowSize == 1)
+ {
+ ss << "if (gid0 <" << mpDVR->GetArrayLength();
+ ss << ")\n\t{\tint i = 0;\n\t\t";
+ return nCurWindowSize;
+ }
+
ss << "for (int i = ";
if (!bIsStartFixed && bIsEndFixed)
{
@@ -579,10 +587,10 @@ public:
size_t nInput = mpDVR->GetArrayLength();
size_t nCurWindowSize = mpDVR->GetRefRowSize();
// create clmem buffer
- if (mpDVR->GetArrays()[0].mpNumericArray == NULL)
+ if (mpDVR->GetArrays()[Base::mnIndex].mpNumericArray == NULL)
throw Unhandled();
double *pHostBuffer = const_cast<double*>(
- mpDVR->GetArrays()[0].mpNumericArray);
+ mpDVR->GetArrays()[Base::mnIndex].mpNumericArray);
size_t szHostBuffer = nInput * sizeof(double);
Base::mpClmem = clCreateBuffer(kEnv.mpkContext,
(cl_mem_flags) CL_MEM_READ_ONLY|CL_MEM_USE_HOST_PTR,
@@ -1269,15 +1277,19 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
const formula::DoubleVectorRefToken* pDVR =
dynamic_cast< const formula::DoubleVectorRefToken* >(pChild);
assert(pDVR);
- if (pDVR->GetArrays()[0].mpNumericArray)
- mvSubArguments.push_back(
- SubArgument(new DynamicKernelSlidingArgument
- <VectorRef>(ts, ft->Children[i], mpCodeGen)));
- else
- mvSubArguments.push_back(
- SubArgument(new DynamicKernelSlidingArgument
- <DynamicKernelStringArgument>(
- ts, ft->Children[i], mpCodeGen)));
+ for (size_t j = 0; j < pDVR->GetArrays().size(); ++j)
+ {
+ if (pDVR->GetArrays()[j].mpNumericArray)
+ mvSubArguments.push_back(
+ SubArgument(new DynamicKernelSlidingArgument
+ <VectorRef>(
+ ts, ft->Children[i], mpCodeGen, j)));
+ else
+ mvSubArguments.push_back(
+ SubArgument(new DynamicKernelSlidingArgument
+ <DynamicKernelStringArgument>(
+ ts, ft->Children[i], mpCodeGen, j)));
+ }
} else if (pChild->GetType() == formula::svSingleVectorRef) {
const formula::SingleVectorRefToken* pSVR =
dynamic_cast< const formula::SingleVectorRefToken* >(pChild);
diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx
index a6beffbf1f18..95657df491a3 100644
--- a/sc/source/core/opencl/opbase.cxx
+++ b/sc/source/core/opencl/opbase.cxx
@@ -30,8 +30,16 @@ FormulaToken* DynamicKernelArgument::GetFormulaToken(void) const
return mFormulaTree->GetFormulaToken();
}
-VectorRef::VectorRef(const std::string &s, FormulaTreeNodeRef ft):
- DynamicKernelArgument(s, ft), mpClmem(NULL) {}
+VectorRef::VectorRef(const std::string &s, FormulaTreeNodeRef ft, int idx):
+ DynamicKernelArgument(s, ft), mpClmem(NULL), mnIndex(idx)
+{
+ if (mnIndex)
+ {
+ std::stringstream ss;
+ ss << mSymName << "s" << mnIndex;
+ mSymName = ss.str();
+ }
+}
VectorRef::~VectorRef()
{
diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx
index 11b66df1c8b8..d921119aede1 100644
--- a/sc/source/core/opencl/opbase.hxx
+++ b/sc/source/core/opencl/opbase.hxx
@@ -103,7 +103,7 @@ public:
virtual bool NeedParallelReduction(void) const { return false; }
protected:
- const std::string mSymName;
+ std::string mSymName;
FormulaTreeNodeRef mFormulaTree;
};
@@ -115,12 +115,11 @@ protected:
class VectorRef : public DynamicKernelArgument
{
public:
- VectorRef(const std::string &s, FormulaTreeNodeRef ft);
+ VectorRef(const std::string &s, FormulaTreeNodeRef ft, int index = 0);
const std::string &GetNameAsString(void) const { return mSymName; }
/// Generate declaration
virtual void GenDecl(std::stringstream &ss) const;
-
/// When declared as input to a sliding window function
virtual void GenSlidingWindowDecl(std::stringstream &ss) const;
@@ -146,6 +145,8 @@ public:
protected:
// Used by marshaling
cl_mem mpClmem;
+ // index in multiple double vector refs that have multiple ranges
+ const int mnIndex;
};
/// Abstract class for code generation