/[escript]/branches/clazy/escriptcore/src/DataLazy.cpp
ViewVC logotype

Diff of /branches/clazy/escriptcore/src/DataLazy.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2176 by phornby, Wed Dec 17 08:21:29 2008 UTC revision 2177 by jfenwick, Wed Dec 17 23:51:23 2008 UTC
# Line 38  bool privdebug=false; Line 38  bool privdebug=false;
38  #define DISABLEDEBUG privdebug=false;  #define DISABLEDEBUG privdebug=false;
39  }  }
40    
41    #define SIZELIMIT
42    // #define SIZELIMIT if ((m_height>7) || (m_children>127)) {cerr << "\n!!!!!!! SIZE LIMIT EXCEEDED " << m_children << ";" << m_height << endl << toString() << endl; resolveToIdentity();}
43    
44    
45  /*  /*
46  How does DataLazy work?  How does DataLazy work?
47  ~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~~~~~~
# Line 273  GTPShape(DataAbstract_ptr left, DataAbst Line 277  GTPShape(DataAbstract_ptr left, DataAbst
277    return shape2;    return shape2;
278  }  }
279    
   
 // determine the number of points in the result of "left op right"  
 // note that determining the resultLength for G_TENSORPROD is more complex and will not be processed here  
 // size_t  
 // resultLength(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op)  
 // {  
 //    switch (getOpgroup(op))  
 //    {  
 //    case G_BINARY: return left->getLength();  
 //    case G_UNARY: return left->getLength();  
 //    case G_NP1OUT: return left->getLength();  
 //    default:  
 //  throw DataException("Programmer Error - attempt to getLength() for operator "+opToString(op)+".");  
 //    }  
 // }  
   
280  // determine the number of samples requires to evaluate an expression combining left and right  // determine the number of samples requires to evaluate an expression combining left and right
281  // NP1OUT needs an extra buffer because we can't write the answers over the top of the input.  // NP1OUT needs an extra buffer because we can't write the answers over the top of the input.
282  // The same goes for G_TENSORPROD  // The same goes for G_TENSORPROD
# Line 330  opToString(ES_optype op) Line 318  opToString(ES_optype op)
318    
319    
320  DataLazy::DataLazy(DataAbstract_ptr p)  DataLazy::DataLazy(DataAbstract_ptr p)
321      : parent(p->getFunctionSpace(),p->getShape()),      : parent(p->getFunctionSpace(),p->getShape())
     m_op(IDENTITY),  
     m_axis_offset(0),  
     m_transpose(0),  
     m_SL(0), m_SM(0), m_SR(0)  
322  {  {
323     if (p->isLazy())     if (p->isLazy())
324     {     {
# Line 345  DataLazy::DataLazy(DataAbstract_ptr p) Line 329  DataLazy::DataLazy(DataAbstract_ptr p)
329     }     }
330     else     else
331     {     {
332      m_id=dynamic_pointer_cast<DataReady>(p);      DataReady_ptr dr=dynamic_pointer_cast<DataReady>(p);
333      if(p->isConstant()) {m_readytype='C';}      makeIdentity(dr);
     else if(p->isExpanded()) {m_readytype='E';}  
     else if (p->isTagged()) {m_readytype='T';}  
     else {throw DataException("Unknown DataReady instance in DataLazy constructor.");}  
334     }     }
    m_buffsRequired=1;  
    m_samplesize=getNumDPPSample()*getNoValues();  
    m_maxsamplesize=m_samplesize;  
335  LAZYDEBUG(cout << "(1)Lazy created with " << m_samplesize << endl;)  LAZYDEBUG(cout << "(1)Lazy created with " << m_samplesize << endl;)
336  }  }
337    
# Line 386  DataLazy::DataLazy(DataAbstract_ptr left Line 364  DataLazy::DataLazy(DataAbstract_ptr left
364     m_buffsRequired=calcBuffs(m_left, m_right,m_op); // yeah m_right will be null at this point     m_buffsRequired=calcBuffs(m_left, m_right,m_op); // yeah m_right will be null at this point
365     m_samplesize=getNumDPPSample()*getNoValues();     m_samplesize=getNumDPPSample()*getNoValues();
366     m_maxsamplesize=max(m_samplesize,m_left->getMaxSampleSize());     m_maxsamplesize=max(m_samplesize,m_left->getMaxSampleSize());
367       m_children=m_left->m_children+1;
368       m_height=m_left->m_height+1;
369       SIZELIMIT
370  }  }
371    
372    
# Line 447  DataLazy::DataLazy(DataAbstract_ptr left Line 428  DataLazy::DataLazy(DataAbstract_ptr left
428     m_samplesize=getNumDPPSample()*getNoValues();     m_samplesize=getNumDPPSample()*getNoValues();
429     m_maxsamplesize=max(max(m_samplesize,m_right->getMaxSampleSize()),m_left->getMaxSampleSize());       m_maxsamplesize=max(max(m_samplesize,m_right->getMaxSampleSize()),m_left->getMaxSampleSize());  
430     m_buffsRequired=calcBuffs(m_left, m_right,m_op);     m_buffsRequired=calcBuffs(m_left, m_right,m_op);
431       m_children=m_left->m_children+m_right->m_children+2;
432       m_height=max(m_left->m_height,m_right->m_height)+1;
433       SIZELIMIT
434  LAZYDEBUG(cout << "(3)Lazy created with " << m_samplesize << endl;)  LAZYDEBUG(cout << "(3)Lazy created with " << m_samplesize << endl;)
435  }  }
436    
# Line 511  DataLazy::DataLazy(DataAbstract_ptr left Line 495  DataLazy::DataLazy(DataAbstract_ptr left
495     m_samplesize=getNumDPPSample()*getNoValues();     m_samplesize=getNumDPPSample()*getNoValues();
496     m_maxsamplesize=max(max(m_samplesize,m_right->getMaxSampleSize()),m_left->getMaxSampleSize());       m_maxsamplesize=max(max(m_samplesize,m_right->getMaxSampleSize()),m_left->getMaxSampleSize());  
497     m_buffsRequired=calcBuffs(m_left, m_right,m_op);     m_buffsRequired=calcBuffs(m_left, m_right,m_op);
498       m_children=m_left->m_children+m_right->m_children+2;
499       m_height=max(m_left->m_height,m_right->m_height)+1;
500       SIZELIMIT
501  LAZYDEBUG(cout << "(4)Lazy created with " << m_samplesize << endl;)  LAZYDEBUG(cout << "(4)Lazy created with " << m_samplesize << endl;)
502  }  }
503    
# Line 540  DataLazy::DataLazy(DataAbstract_ptr left Line 527  DataLazy::DataLazy(DataAbstract_ptr left
527     m_buffsRequired=calcBuffs(m_left, m_right,m_op); // yeah m_right will be null at this point     m_buffsRequired=calcBuffs(m_left, m_right,m_op); // yeah m_right will be null at this point
528     m_samplesize=getNumDPPSample()*getNoValues();     m_samplesize=getNumDPPSample()*getNoValues();
529     m_maxsamplesize=max(m_samplesize,m_left->getMaxSampleSize());     m_maxsamplesize=max(m_samplesize,m_left->getMaxSampleSize());
530       m_children=m_left->m_children+1;
531       m_height=m_left->m_height+1;
532       SIZELIMIT
533  LAZYDEBUG(cout << "(5)Lazy created with " << m_samplesize << endl;)  LAZYDEBUG(cout << "(5)Lazy created with " << m_samplesize << endl;)
534  }  }
535    
# Line 568  DataLazy::DataLazy(DataAbstract_ptr left Line 558  DataLazy::DataLazy(DataAbstract_ptr left
558     m_buffsRequired=calcBuffs(m_left, m_right,m_op); // yeah m_right will be null at this point     m_buffsRequired=calcBuffs(m_left, m_right,m_op); // yeah m_right will be null at this point
559     m_samplesize=getNumDPPSample()*getNoValues();     m_samplesize=getNumDPPSample()*getNoValues();
560     m_maxsamplesize=max(m_samplesize,m_left->getMaxSampleSize());     m_maxsamplesize=max(m_samplesize,m_left->getMaxSampleSize());
561       m_children=m_left->m_children+1;
562       m_height=m_left->m_height+1;
563       SIZELIMIT
564  LAZYDEBUG(cout << "(6)Lazy created with " << m_samplesize << endl;)  LAZYDEBUG(cout << "(6)Lazy created with " << m_samplesize << endl;)
565  }  }
566    
# Line 1139  LAZYDEBUG(cout << "Resolve binary: " << Line 1132  LAZYDEBUG(cout << "Resolve binary: " <<
1132             rightstep=0;             rightstep=0;
1133             orightstep=1;             orightstep=1;
1134             leftstep=1;             leftstep=1;
1135             oleftstep=(RN ? -(int)leftsize : 0);             oleftstep=(LN ? -(int)leftsize : 0);
1136             numsteps=leftsize;             numsteps=leftsize;
1137             onumsteps=m_right->getNumDPPSample();             onumsteps=m_right->getNumDPPSample();
1138          }          }
# Line 1333  LAZYDEBUG(cout << "Finish  sample " << t Line 1326  LAZYDEBUG(cout << "Finish  sample " << t
1326    
1327  }  }
1328    
1329    // This needs to do the work of the idenity constructor
1330    void
1331    DataLazy::resolveToIdentity()
1332    {
1333       if (m_op==IDENTITY)
1334        return;
1335       DataReady_ptr p=resolve();
1336       makeIdentity(p);
1337    }
1338    
1339    void DataLazy::makeIdentity(const DataReady_ptr& p)
1340    {
1341       m_op=IDENTITY;
1342       m_axis_offset=0;
1343       m_transpose=0;
1344       m_SL=m_SM=m_SR=0;
1345       m_children=m_height=0;
1346       m_id=p;
1347       if(p->isConstant()) {m_readytype='C';}
1348       else if(p->isExpanded()) {m_readytype='E';}
1349       else if (p->isTagged()) {m_readytype='T';}
1350       else {throw DataException("Unknown DataReady instance in convertToIdentity constructor.");}
1351       m_buffsRequired=1;
1352       m_samplesize=p->getNumDPPSample()*p->getNoValues();
1353       m_maxsamplesize=m_samplesize;
1354       m_left.reset();
1355       m_right.reset();
1356    }
1357    
1358  // To simplify the memory management, all threads operate on one large vector, rather than one each.  // To simplify the memory management, all threads operate on one large vector, rather than one each.
1359  // Each sample is evaluated independently and copied into the result DataExpanded.  // Each sample is evaluated independently and copied into the result DataExpanded.
# Line 1410  DataLazy::toString() const Line 1431  DataLazy::toString() const
1431  void  void
1432  DataLazy::intoString(ostringstream& oss) const  DataLazy::intoString(ostringstream& oss) const
1433  {  {
1434      oss << "[" << m_children <<";"<<m_height <<"]";
1435    switch (getOpgroup(m_op))    switch (getOpgroup(m_op))
1436    {    {
1437    case G_IDENTITY:    case G_IDENTITY:

Legend:
Removed from v.2176  
changed lines
  Added in v.2177

  ViewVC Help
Powered by ViewVC 1.1.26