GPUOcelot

ReconvergenceMechanism.h

Go to the documentation of this file.
00001 
00008 #ifndef OCELOT_EXECUTIVE_RECONVERGENCEMECHANISM_H_INCLUDED
00009 #define OCELOT_EXECUTIVE_RECONVERGENCEMECHANISM_H_INCLUDED
00010 
00011 // C++ includes
00012 #include <deque>
00013 
00014 // Ocelot includes
00015 #include <ocelot/executive/interface/CTAContext.h>
00016 #include <ocelot/ir/interface/PTXOperand.h>
00017 #include <ocelot/ir/interface/Kernel.h>
00018 #include <ocelot/ir/interface/Texture.h>
00019 #include <ocelot/trace/interface/TraceEvent.h>
00020 
00022 
00023 namespace executive {
00024 
00025 class EmulatedKernel;
00026 class CooperativeThreadArray;
00027 
00031 class ReconvergenceMechanism {
00032 public:
00033   enum Type {
00034     Reconverge_IPDOM,
00035     Reconverge_Barrier,
00036     Reconverge_TFGen6,
00037     Reconverge_TFSortedStack,
00038     Reconverge_unknown
00039   };
00040     
00041 public:
00042   ReconvergenceMechanism(CooperativeThreadArray *cta);
00043   
00044 public:
00045 
00046   virtual ~ReconvergenceMechanism();
00047 
00049   virtual void initialize() = 0;
00050 
00052   // before instructions execute
00053   virtual void evalPredicate(executive::CTAContext &context) = 0;
00054   
00059   virtual bool eval_Bra(executive::CTAContext &context, 
00060     const ir::PTXInstruction &instr, 
00061     const boost::dynamic_bitset<> & branch, 
00062     const boost::dynamic_bitset<> & fallthrough) = 0;
00063 
00067   virtual void eval_Bar(executive::CTAContext &context,
00068     const ir::PTXInstruction &instr) = 0;
00069   
00073   virtual void eval_Reconverge(executive::CTAContext &context,
00074     const ir::PTXInstruction &instr) = 0;
00075   
00079   virtual void eval_Exit(executive::CTAContext &context,
00080     const ir::PTXInstruction &instr) = 0;
00081 
00085   virtual bool nextInstruction(executive::CTAContext &context,
00086     const ir::PTXInstruction::Opcode &opcode) = 0;
00087   
00089   virtual executive::CTAContext& getContext() = 0;
00090   
00092   virtual size_t stackSize() const = 0;
00093 
00095   virtual void push(executive::CTAContext&) = 0;
00096 
00098   virtual void pop() = 0;
00099   
00101   Type getType() const { return type; }
00102 
00104   static std::string toString(Type type);
00105 
00106 protected:
00107 
00109   Type type;
00110   
00112   CooperativeThreadArray *cta;
00113 };
00114 
00115 //
00116 //
00117 //
00118 
00119 class ReconvergenceIPDOM: public ReconvergenceMechanism {
00120 public:
00121 
00122   ReconvergenceIPDOM(CooperativeThreadArray *cta);
00123   ~ReconvergenceIPDOM();
00124   
00125   void initialize();
00126   void evalPredicate(executive::CTAContext &context);
00127   bool eval_Bra(executive::CTAContext &context, 
00128     const ir::PTXInstruction &instr, 
00129     const boost::dynamic_bitset<> & branch, 
00130     const boost::dynamic_bitset<> & fallthrough);
00131   void eval_Bar(executive::CTAContext &context,
00132     const ir::PTXInstruction &instr);
00133   void eval_Reconverge(executive::CTAContext &context,
00134     const ir::PTXInstruction &instr);
00135   void eval_Exit(executive::CTAContext &context,
00136     const ir::PTXInstruction &instr);
00137   bool nextInstruction(executive::CTAContext &context,
00138     const ir::PTXInstruction::Opcode &opcode);
00139 
00140   executive::CTAContext& getContext();
00141   size_t stackSize() const;
00142   void push(executive::CTAContext&);
00143   void pop();
00144   
00145 private:
00146   typedef std::vector<CTAContext> RuntimeStack;
00147   typedef std::vector<int>        PCStack;
00148 
00149 private:
00151   RuntimeStack runtimeStack;
00153   PCStack pcStack;
00154   unsigned int reconvergeEvents;
00155 };
00156 
00157 class ReconvergenceBarrier: public ReconvergenceMechanism {
00158 public:
00159 
00160   ReconvergenceBarrier(CooperativeThreadArray *cta);
00161   
00162   void initialize();
00163   void evalPredicate(executive::CTAContext &context);
00164   bool eval_Bra(executive::CTAContext &context, 
00165     const ir::PTXInstruction &instr, 
00166     const boost::dynamic_bitset<> & branch, 
00167     const boost::dynamic_bitset<> & fallthrough);
00168   void eval_Bar(executive::CTAContext &context,
00169     const ir::PTXInstruction &instr);
00170   void eval_Reconverge(executive::CTAContext &context,
00171     const ir::PTXInstruction &instr);
00172   void eval_Exit(executive::CTAContext &context,
00173     const ir::PTXInstruction &instr);
00174   bool nextInstruction(executive::CTAContext &context,
00175     const ir::PTXInstruction::Opcode &opcode);
00176 
00177   executive::CTAContext& getContext();
00178   size_t stackSize() const;
00179   void push(executive::CTAContext&);
00180   void pop();
00181   
00182 private:
00183   typedef std::vector<CTAContext> RuntimeStack;
00184 
00185 private:
00187   RuntimeStack runtimeStack;
00188 };
00189 
00190 
00191 class ReconvergenceTFGen6: public ReconvergenceMechanism {
00192 public:
00193   typedef std::vector <int> ThreadIdVector;
00194   
00195 public:
00196   ReconvergenceTFGen6(CooperativeThreadArray *cta);
00197 
00198   void initialize();
00199   void evalPredicate(executive::CTAContext &context);
00200   bool eval_Bra(executive::CTAContext &context, 
00201     const ir::PTXInstruction &instr, 
00202     const boost::dynamic_bitset<> & branch, 
00203     const boost::dynamic_bitset<> & fallthrough);
00204   void eval_Bar(executive::CTAContext &context,
00205     const ir::PTXInstruction &instr);
00206   void eval_Reconverge(executive::CTAContext &context,
00207     const ir::PTXInstruction &instr);
00208   void eval_Exit(executive::CTAContext &context,
00209     const ir::PTXInstruction &instr);
00210   bool nextInstruction(executive::CTAContext &context,
00211     const ir::PTXInstruction::Opcode &opcode);
00212 
00213   executive::CTAContext& getContext();
00214   size_t stackSize() const;
00215   void push(executive::CTAContext&);
00216   void pop();
00217   
00218 private:
00219   typedef std::vector<CTAContext> RuntimeStack;
00220 
00221 private:
00223   RuntimeStack runtimeStack;
00224 
00226   ThreadIdVector threadPCs;
00227 };
00228 
00229 class ReconvergenceTFSortedStack: public ReconvergenceMechanism {
00230 public:
00231   ReconvergenceTFSortedStack(CooperativeThreadArray *cta);
00232   ~ReconvergenceTFSortedStack();
00233 
00234   void initialize();
00235   void evalPredicate(executive::CTAContext &context);
00236   bool eval_Bra(executive::CTAContext &context, 
00237     const ir::PTXInstruction &instr, 
00238     const boost::dynamic_bitset<> & branch, 
00239     const boost::dynamic_bitset<> & fallthrough);
00240   void eval_Bar(executive::CTAContext &context,
00241     const ir::PTXInstruction &instr);
00242   void eval_Reconverge(executive::CTAContext &context,
00243     const ir::PTXInstruction &instr);
00244   void eval_Exit(executive::CTAContext &context,
00245     const ir::PTXInstruction &instr);
00246   bool nextInstruction(executive::CTAContext &context,
00247     const ir::PTXInstruction::Opcode &opcode);
00248 
00249   executive::CTAContext& getContext();
00250   size_t stackSize() const;
00251   void push(executive::CTAContext&);
00252   void pop();
00253 
00254 private:
00255   typedef std::map<int, CTAContext> RuntimeStack;
00256   typedef std::vector<RuntimeStack> StackVector; 
00257     
00258 public:
00259   StackVector stack;
00260   unsigned int reconvergeEvents;
00261 };
00262 }
00263 
00265 
00266 #endif
00267 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines