00001 #ifndef _MODEL_H_NOU_ 00002 #define _MODEL_H_NOU_ 00003 00004 #include <string> 00005 #include <vector> 00006 #include <CL/cl.h> 00007 #include "cellspace.h" 00008 00009 using namespace std; 00010 00011 class Machine; 00020 class Model 00021 { 00022 protected: 00023 cl_program program; 00024 vector<CellSpace*> patterns; 00025 public: 00026 Model(Machine *parent); 00027 virtual ~Model(); 00028 Machine* getParent(){ return parent; } 00029 void addChild(CellSpace *child); 00030 void removeChild(CellSpace *child); 00037 virtual void run(CellSpace *pattern, int which, int iteration = 1) = 0; 00041 virtual int getCellSize() = 0; 00046 virtual void loadSource() = 0; 00053 virtual void renderToTexture(CellSpace *pattern, int which, cl_mem tex) = 0; 00054 protected: 00055 cl_int build(string source, string options); 00056 cl_kernel kernel, render_kernel; 00057 Machine *parent; 00058 }; 00066 class SynchronousModel : public Model 00067 { 00068 public: 00069 SynchronousModel(Machine *parent, string model_definition); 00070 int getCellSize(){ return sizeof(int)*2; } 00071 void loadSource(); 00072 void run(CellSpace *pattern, int which, int iteration = 1); 00073 virtual void renderToTexture(CellSpace *pattern, int which, cl_mem tex); 00074 private: 00075 string source; 00076 }; 00077 00078 class AsynchronousModel : public Model 00079 { 00080 private: 00081 int queue_len,neighbor; 00082 cl_kernel init_kernel,intermediate_kernel; 00083 public: 00084 AsynchronousModel(Machine* parent, string model_definition); 00085 ~AsynchronousModel(); 00086 int getCellSize(); 00087 void loadSource(); 00088 void run(CellSpace *pattern, int which, int iteration = 1); 00089 void renderToTexture(CellSpace *pattern, int which, cl_mem tex); 00090 void initialize(CellSpace *pattern, float *data); 00091 }; 00092 00093 #endif // _MODEL_H_NOU_