[Libreoffice-commits] core.git: sc/source

I-Jui Sung (Ray) ray at multicorewareinc.com
Sun Nov 17 20:35:54 PST 2013


 sc/source/core/opencl/formulagroupcl.cxx |   48 +++++++++++++++-------------
 sc/source/core/opencl/opbase.cxx         |   53 +++++++++++++++----------------
 sc/source/core/opencl/opbase.hxx         |   53 +++++++++++++++++++++++++------
 3 files changed, 96 insertions(+), 58 deletions(-)

New commits:
commit 434d445a93910f1745b140a5212198a452925dc6
Author: I-Jui (Ray) Sung <ray at multicorewareinc.com>
Date:   Sun Nov 17 22:33:50 2013 -0600

    GPU Calc: refactor: separate VectorRef out of DynamicKernelArgument
    
    Now DynamicKernelArgument is more an abstract base.
    
    Change-Id: Icc70fa9fe4ed2db3c5483099d99584ba30ac38f6

diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index a25f729..d5f7f0f 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -45,7 +45,7 @@ namespace sc { namespace opencl {
 
 
 /// Map the buffer used by an argument and do necessary argument setting
-size_t DynamicKernelArgument::Marshal(cl_kernel k, int argno, int, cl_program)
+size_t VectorRef::Marshal(cl_kernel k, int argno, int, cl_program)
 {
     FormulaToken *ref = mFormulaTree->GetFormulaToken();
     assert(mpClmem == NULL);
@@ -129,7 +129,6 @@ public:
     virtual size_t Marshal(cl_kernel k, int argno, int, cl_program)
     {
         FormulaToken *ref = mFormulaTree->GetFormulaToken();
-        assert(mpClmem == NULL);
         cl_uint hashCode = 0;
         if (ref->GetType() == formula::svString)
         {
@@ -277,12 +276,13 @@ public:
     }
 };
 
-class DynamicKernelStringArgument: public DynamicKernelArgument
+/// A vector of strings
+class DynamicKernelStringArgument: public VectorRef
 {
 public:
     DynamicKernelStringArgument(const std::string &s,
         FormulaTreeNodeRef ft):
-        DynamicKernelArgument(s, ft) {}
+        VectorRef(s, ft) {}
 
     virtual void GenSlidingWindowFunction(std::stringstream &) {}
     /// Generate declaration
@@ -357,15 +357,15 @@ size_t DynamicKernelStringArgument::Marshal(cl_kernel k, int argno, int, cl_prog
 }
 
 /// A mixed string/numberic vector
-class DynamicKernelMixedArgument: public DynamicKernelArgument
+class DynamicKernelMixedArgument: public VectorRef
 {
 public:
     DynamicKernelMixedArgument(const std::string &s,
         FormulaTreeNodeRef ft):
-        DynamicKernelArgument(s, ft), mStringArgument(s+"s", ft) {}
+        VectorRef(s, ft), mStringArgument(s+"s", ft) {}
     virtual void GenSlidingWindowDecl(std::stringstream& ss) const
     {
-        DynamicKernelArgument::GenSlidingWindowDecl(ss);
+        VectorRef::GenSlidingWindowDecl(ss);
         ss << ", ";
         mStringArgument.GenSlidingWindowDecl(ss);
     }
@@ -373,28 +373,28 @@ public:
     /// Generate declaration
     virtual void GenDecl(std::stringstream &ss) const
     {
-        DynamicKernelArgument::GenDecl(ss);
+        VectorRef::GenDecl(ss);
         ss << ", ";
         mStringArgument.GenDecl(ss);
     }
     virtual void GenDeclRef(std::stringstream &ss) const
     {
-        DynamicKernelArgument::GenDeclRef(ss);
+        VectorRef::GenDeclRef(ss);
         ss << ",";
         mStringArgument.GenDeclRef(ss);
     }
     virtual std::string GenSlidingWindowDeclRef(bool) const
     {
         std::stringstream ss;
-        ss << "(!isNan(" << DynamicKernelArgument::GenSlidingWindowDeclRef();
-        ss << ")?" << DynamicKernelArgument::GenSlidingWindowDeclRef();
+        ss << "(!isNan(" << VectorRef::GenSlidingWindowDeclRef();
+        ss << ")?" << VectorRef::GenSlidingWindowDeclRef();
         ss << ":" << mStringArgument.GenSlidingWindowDeclRef();
         ss << ")";
         return ss.str();
     }
     virtual size_t Marshal(cl_kernel k, int argno, int vw, cl_program p)
     {
-        int i = DynamicKernelArgument::Marshal(k, argno, vw, p);
+        int i = VectorRef::Marshal(k, argno, vw, p);
         i += mStringArgument.Marshal(k, argno+i, vw, p);
         return i;
     }
@@ -482,7 +482,8 @@ public:
         return ss.str();
     }
     /// Controls how the elements in the DoubleVectorRef are traversed
-    virtual size_t GenLoop(std::stringstream &ss, bool &needBody)
+    virtual size_t GenReductionLoopHeader(
+        std::stringstream &ss, bool &needBody)
     {
         assert(mpDVR);
         size_t nCurWindowSize = mpDVR->GetRefRowSize();
@@ -662,7 +663,7 @@ protected:
 class Reduction: public SlidingFunctionBase
 {
 public:
-    typedef DynamicKernelSlidingArgument<DynamicKernelArgument> NumericRange;
+    typedef DynamicKernelSlidingArgument<VectorRef> NumericRange;
     typedef DynamicKernelSlidingArgument<DynamicKernelStringArgument> StringRange;
 
     virtual void GenSlidingWindowFunction(std::stringstream &ss,
@@ -688,13 +689,14 @@ public:
             if (NumericRange *NR = dynamic_cast<NumericRange *> (vSubArguments[i].get()))
             {
                 bool needBody;
-                nItems += NR->GenLoop(ss, needBody);
+                nItems += NR->GenReductionLoopHeader(ss, needBody);
                 if (needBody == false) continue;
             }
             else if (StringRange *SR = dynamic_cast<StringRange *> (vSubArguments[i].get()))
             {
+                //did not handle yet
                 bool needBody;
-                nItems += SR->GenLoop(ss, needBody);   //did not handle yet
+                nItems += SR->GenReductionLoopHeader(ss, needBody);
                 if (needBody == false) continue;
             }
             else
@@ -1068,7 +1070,6 @@ public:
         }
         if (OpSumIfs *OpSumCodeGen = dynamic_cast<OpSumIfs*>(mpCodeGen.get()))
         {
-            assert(mpClmem == NULL);
             // Obtain cl context
             KernelEnv kEnv;
             OpenclDevice::setKernelEnv(&kEnv);
@@ -1085,10 +1086,13 @@ public:
                 size_t nCurWindowSize = slidingArgPtr -> GetWindowSize();
                 std::vector<cl_mem> vclmem;
 
-                for (SubArgumentsType::iterator it = mvSubArguments.begin(), e= mvSubArguments.end(); it!=e;
-                ++it)
+                for (SubArgumentsType::iterator it = mvSubArguments.begin(),
+                        e= mvSubArguments.end(); it!=e; ++it)
                 {
-                    vclmem.push_back((*it)->GetCLBuffer());
+                    if (VectorRef *VR = dynamic_cast<VectorRef *>(it->get()))
+                        vclmem.push_back(VR->GetCLBuffer());
+                    else
+                        vclmem.push_back(NULL);
                 }
                 mpClmem2 = clCreateBuffer(kEnv.mpkContext, CL_MEM_READ_WRITE,
                         sizeof(double)*nVectorWidth, NULL, &err);
@@ -1262,7 +1266,7 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                     if (pDVR->GetArrays()[0].mpNumericArray)
                         mvSubArguments.push_back(
                                 SubArgument(new DynamicKernelSlidingArgument
-                                    <DynamicKernelArgument>(ts, ft->Children[i], mpCodeGen)));
+                                    <VectorRef>(ts, ft->Children[i], mpCodeGen)));
                     else
                         mvSubArguments.push_back(
                                 SubArgument(new DynamicKernelSlidingArgument
@@ -1285,7 +1289,7 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                             pCodeGen->takeNumeric())
                     {
                         mvSubArguments.push_back(
-                                SubArgument(new DynamicKernelArgument(ts,
+                                SubArgument(new VectorRef(ts,
                                         ft->Children[i])));
                     }
                     else if (pSVR->GetArray().mpStringArray &&
diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx
index 7bcb429..a6beffb 100644
--- a/sc/source/core/opencl/opbase.cxx
+++ b/sc/source/core/opencl/opbase.cxx
@@ -17,51 +17,52 @@ namespace sc { namespace opencl {
 
 DynamicKernelArgument::DynamicKernelArgument(const std::string &s,
    FormulaTreeNodeRef ft):
-    mSymName(s), mFormulaTree(ft), mpClmem(NULL) {}
+    mSymName(s), mFormulaTree(ft) {}
 
-/// Generate declaration
-void DynamicKernelArgument::GenDecl(std::stringstream &ss) const
+/// Generate use/references to the argument
+void DynamicKernelArgument::GenDeclRef(std::stringstream &ss) const
 {
-    ss << "__global double *"<<mSymName;
+    ss << mSymName;
 }
 
-/// When declared as input to a sliding window function
-void DynamicKernelArgument::GenSlidingWindowDecl(std::stringstream &ss) const
+FormulaToken* DynamicKernelArgument::GetFormulaToken(void) const
 {
-    DynamicKernelArgument::GenDecl(ss);
+    return mFormulaTree->GetFormulaToken();
 }
 
-/// When referenced in a sliding window function
-std::string DynamicKernelArgument::GenSlidingWindowDeclRef(bool) const
-{
-    std::stringstream ss;
-    ss << mSymName << "[gid0]";
-    return ss.str();
-}
+VectorRef::VectorRef(const std::string &s, FormulaTreeNodeRef ft):
+    DynamicKernelArgument(s, ft), mpClmem(NULL) {}
 
-/// Generate use/references to the argument
-void DynamicKernelArgument::GenDeclRef(std::stringstream &ss) const
+VectorRef::~VectorRef()
 {
-    ss << mSymName;
-}
-
-DynamicKernelArgument::~DynamicKernelArgument()
-{
-    //std::cerr << "~DynamicKernelArgument: " << mSymName <<"\n";
     if (mpClmem) {
-        //std::cerr << "\tFreeing cl_mem of " << mSymName <<"\n";
         cl_int ret = clReleaseMemObject(mpClmem);
         if (ret != CL_SUCCESS)
             throw OpenCLError(ret);
     }
 }
 
-FormulaToken* DynamicKernelArgument::GetFormulaToken(void) const
+/// Generate declaration
+void VectorRef::GenDecl(std::stringstream &ss) const
 {
-    return mFormulaTree->GetFormulaToken();
+    ss << "__global double *"<<mSymName;
+}
+
+/// When declared as input to a sliding window function
+void VectorRef::GenSlidingWindowDecl(std::stringstream &ss) const
+{
+    VectorRef::GenDecl(ss);
+}
+
+/// When referenced in a sliding window function
+std::string VectorRef::GenSlidingWindowDeclRef(bool) const
+{
+    std::stringstream ss;
+    ss << mSymName << "[gid0]";
+    return ss.str();
 }
 
-size_t DynamicKernelArgument::GetWindowSize(void) const
+size_t VectorRef::GetWindowSize(void) const
 {
     FormulaToken *pCur = mFormulaTree->GetFormulaToken();
     assert(pCur);
diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx
index 6b475df..11b66df 100644
--- a/sc/source/core/opencl/opbase.hxx
+++ b/sc/source/core/opencl/opbase.hxx
@@ -68,15 +68,54 @@ private:
     formula::FormulaToken *const mpCurrentFormula;
 };
 
+/// (Partially) abstract base class for an operand
+class DynamicKernelArgument : boost::noncopyable
+{
+public:
+    DynamicKernelArgument(const std::string &s, FormulaTreeNodeRef ft);
+
+    const std::string &GetNameAsString(void) const { return mSymName; }
+    /// Generate declaration
+    virtual void GenDecl(std::stringstream &ss) const = 0;
+
+    /// When declared as input to a sliding window function
+    virtual void GenSlidingWindowDecl(std::stringstream &ss) const = 0;
+
+    /// When referenced in a sliding window function
+    virtual std::string GenSlidingWindowDeclRef(bool=false) const = 0;
+
+    /// Generate use/references to the argument
+    virtual void GenDeclRef(std::stringstream &ss) const;
+
+    /// Create buffer and pass the buffer to a given kernel
+    virtual size_t Marshal(cl_kernel, int, int, cl_program) = 0;
+
+    virtual ~DynamicKernelArgument() {}
+
+    virtual void GenSlidingWindowFunction(std::stringstream &) {}
+    const std::string &GetSymName(void) const { return mSymName; }
+    formula::FormulaToken *GetFormulaToken(void) const;
+    virtual size_t GetWindowSize(void) const = 0;
+    virtual std::string DumpOpName(void) const { return std::string(""); }
+    virtual void DumpInlineFun(std::set<std::string>& ,
+        std::set<std::string>& ) const {}
+    const std::string& GetName(void) const { return mSymName; }
+    virtual bool NeedParallelReduction(void) const { return false; }
+
+protected:
+    const std::string mSymName;
+    FormulaTreeNodeRef mFormulaTree;
+};
+
 /// Holds an input (read-only) argument reference to a SingleVectorRef.
 /// or a DoubleVectorRef for non-sliding-window argument of complex functions
 /// like SumOfProduct
 /// In most of the cases the argument is introduced
 /// by a Push operation in the given RPN.
-class DynamicKernelArgument : boost::noncopyable
+class VectorRef : public DynamicKernelArgument
 {
 public:
-    DynamicKernelArgument(const std::string &s, FormulaTreeNodeRef ft);
+    VectorRef(const std::string &s, FormulaTreeNodeRef ft);
 
     const std::string &GetNameAsString(void) const { return mSymName; }
     /// Generate declaration
@@ -88,13 +127,10 @@ public:
     /// When referenced in a sliding window function
     virtual std::string GenSlidingWindowDeclRef(bool=false) const;
 
-    /// Generate use/references to the argument
-    virtual void GenDeclRef(std::stringstream &ss) const;
-
     /// Create buffer and pass the buffer to a given kernel
     virtual size_t Marshal(cl_kernel, int, int, cl_program);
 
-    virtual ~DynamicKernelArgument();
+    virtual ~VectorRef();
 
     virtual void GenSlidingWindowFunction(std::stringstream &) {}
     const std::string &GetSymName(void) const { return mSymName; }
@@ -104,16 +140,13 @@ public:
     virtual void DumpInlineFun(std::set<std::string>& ,
         std::set<std::string>& ) const {}
     const std::string& GetName(void) const { return mSymName; }
-    cl_mem GetCLBuffer(void) const {return mpClmem; }
+    virtual cl_mem GetCLBuffer(void) const { return mpClmem; }
     virtual bool NeedParallelReduction(void) const { return false; }
 
 protected:
-    const std::string mSymName;
-    FormulaTreeNodeRef mFormulaTree;
     // Used by marshaling
     cl_mem mpClmem;
 };
-
 /// Abstract class for code generation
 
 class OpBase


More information about the Libreoffice-commits mailing list