arch/cell/cell_lib/spert_ppu.h

Go to the documentation of this file.
00001 #ifndef __SPE_RUNTIME_PPU_H__
00002 #define __SPE_RUNTIME_PPU_H__
00003 
00034 
00035 
00036 //#ifdef __cplusplus
00037 //extern "C" {
00038 //#endif
00039 #include <libspe2.h>
00040 //#ifdef __cplusplus
00041 //}
00042 //#endif
00043 
00044 #include "pthread.h"
00045 
00046 #include "spert.h"
00047 
00048 #include <stdio.h>
00049 
00050 
00052 // Defines
00053 
00055 #define DEBUG_DISPLAY  0   // Set to non-zero to have Offload API display debug info (also see SPE_DEBUG_DISPLAY in spert.h)
00056 
00061 #define NUM_SPE_THREADS  0
00062 
00068 #define CREATE_EACH_THREAD_ONE_BY_ONE   0  // Set this to non-zero to create and wait for each SPE thread one-by-one
00069 
00070 
00071 #ifdef __cplusplus
00072   #define DEFAULT_TO_NULL   = NULL
00073   #define DEFAULT_TO_NONE   = WORK_REQUEST_FLAGS_NONE
00074   #define DEFAULT_TO_ALLSET = 0xFFFFFFFF
00075 #else
00076   #define DEFAULT_TO_NULL
00077   #define DEFAULT_TO_NONE
00078   #define DEFAULT_TO_ALLSET
00079 #endif
00080 
00081 
00082 // WORK_REQUEST_STATE_xxx Defines
00083 #define WORK_REQUEST_STATE_MIN       (0)
00084 #define WORK_REQUEST_STATE_FREE      (0)
00085 #define WORK_REQUEST_STATE_INUSE     (1)
00086 #define WORK_REQUEST_STATE_FINISHED  (2)
00087 #define WORK_REQUEST_STATE_MAX       (2)
00088 
00089 // WRGROUP_STATE_xxx Defines
00090 #define WRGROUP_STATE_MIN      (0)
00091 #define WRGROUP_STATE_FREE     (1)  // Available to use
00092 #define WRGROUP_STATE_FILLING  (2)  // Work Requests are being added to it
00093 #define WRGROUP_STATE_FULL     (3)  // All Work Requests have been added, waiting for all Work Requests to complete
00094 #define WRGROUP_STATE_FINISHED (4)  // All Work Requests have completed
00095 #define WRGROUP_STATE_MAX      (4)
00096 
00097 
00099 // Externals
00100 
00105 extern spe_program_handle_t spert_main;
00106 
00107 
00109 // Data Structures
00110 
00112 typedef struct __wr_group {
00113 
00114   int numWRs;               
00115   int finishedCount;        
00116   int state;                
00117 
00118   void* userData;               
00119   void (*callbackFunc)(void*);  
00120 
00121   struct __wr_group *next;  
00122 
00123 } WRGroup;
00124 
00126 typedef WRGroup* WRGroupHandle;
00127 
00129 #define INVALID_WRGroupHandle (NULL)
00130 
00131 
00133 typedef struct __work_request {
00134 
00135   int isFirstInSet;  
00136   int state; 
00137   unsigned int speAffinityMask; 
00138 
00139   int speIndex;   
00140   int entryIndex; 
00141 
00142   int funcIndex;      
00143   void* readWritePtr; 
00144   int readWriteLen;   
00145   void* readOnlyPtr;  
00146   int readOnlyLen;    
00147   void* writeOnlyPtr; 
00148   int writeOnlyLen;   
00149   unsigned int flags; 
00150   void *userData;     
00151   volatile void (*callbackFunc)(void*);  // A pointer to a work request specific callback function
00152 
00153   DMAListEntry dmaList[SPE_DMA_LIST_LENGTH];
00154 
00155   WRGroupHandle wrGroupHandle;  
00156 
00157   struct __work_request *next;  
00158 
00159   int id;        // DEBUG
00160   int traceFlag; // DEBUG
00161 
00162 } WorkRequest;
00163 
00165 typedef WorkRequest* WRHandle;
00166 
00168 #define INVALID_WRHandle (NULL)
00169 
00170 
00174 typedef struct __spe_thread {
00175 
00176   SPEData *speData;   
00177   unsigned int messageQueuePtr;  
00178   int msgIndex;       
00179   int counter;        
00180 
00182   //speid_t speID;      ///< The ID for the thread
00183 
00185   spe_context_ptr_t speContext;
00186   unsigned int speEntry;
00187   spe_stop_info_t stopInfo;
00188   pthread_t pThread;
00189 
00190 } SPEThread;
00191 
00192 
00194 // Function Prototypes (Offload API)
00195 
00196 #ifdef __cplusplus
00197 extern "C" {
00198 #endif
00199 
00207 extern int InitOffloadAPI(void(*cbFunc)(void*) DEFAULT_TO_NULL,   
00208                           void(*gcbFunc)(void*) DEFAULT_TO_NULL,  
00209                           void(*errorFunc)(int,void*,WRHandle) DEFAULT_TO_NULL, 
00210                           char* timingFileName DEFAULT_TO_NULL    
00211                          );
00212 #ifndef __cplusplus
00213 //#define InitOffloadAPI() InitOffloadAPI(NULL, NULL, NULL, NULL)
00214 //#define InitOffloadAPI(cbf) InitOffloadAPI(cbf, NULL, NULL, NULL)
00215 //#define InitOffloadAPI(cbf, gcbf) InitOffloadAPI(cbf, gcbf, NULL, NULL)
00216 //#define InitOffloadAPI(cbf, gcbf, ef) InitOffloadAPI(cbf, gcbf, ef, NULL)
00217 #endif
00218 
00219 
00223 extern void CloseOffloadAPI();
00224 
00232 extern WRHandle sendWorkRequest(int funcIndex,      
00233                                 void* readWritePtr, 
00234                                 int readWriteLen,   
00235                                 void* readOnlyPtr,  
00236                                 int readOnlyLen,    
00237                                 void* writeOnlyPtr, 
00238                                 int writeOnlyLen,   
00239                                 void* userData DEFAULT_TO_NULL, 
00240                                 unsigned int flags DEFAULT_TO_NONE, 
00241                                 void (*callbackFunc)(void*) DEFAULT_TO_NULL, 
00242                                 WRGroupHandle wrGroupHandle DEFAULT_TO_NULL, 
00243                                 unsigned int speAffinityMask DEFAULT_TO_ALLSET  
00244                                );
00245 #ifndef __cplusplus
00246 #define sendWorkRequest(fi, rwp, rwl, rop, rol, wop, wol) sendWorkRequest(fi, rwp, rwl, rop, rol, wop, wol, NULL, WORK_REQUEST_FLAGS_NONE, NULL, NULL, -1)
00247 #define sendWorkRequest(fi, rwp, rwl, rop, rol, wop, wol, ud) sendWorkRequest(fi, rwp, rwl, rop, rol, wop, wol, ud, WORK_REQUEST_FLAGS_NONE, NULL, NULL, -1)
00248 #define sendWorkRequest(fi, rwp, rwl, rop, rol, wop, wol, ud, f) sendWorkRequest(fi, rwp, rwl, rop, rol, wop, wol, ud, f, NULL, NULL, -1)
00249 #define sendWorkRequest(fi, rwp, rwl, rop, rol, wop, wol, ud, f, cb) sendWorkRequest(fi, rwp, rwl, rop, rol, wop, wol, ud, f, cb, NULL, -1)
00250 #define sendWorkRequest(fi, rwp, rwl, rop, rol, wop, wol, ud, f, cb, gh) sendWorkRequest(fi, rwp, rwl, rop, rol, wop, wol, ud, f, cb, gh, -1)
00251 #endif
00252 
00261 extern WRHandle sendWorkRequest_list(int funcIndex,         
00262                                      unsigned int eah,      
00263                                      DMAListEntry* dmaList, 
00264                                      int numReadOnly,       
00265                                      int numReadWrite,      
00266                                      int numWriteOnly,      
00267                                      void* userData DEFAULT_TO_NULL, 
00268                                      unsigned int flags DEFAULT_TO_NONE, 
00269                                      void (*callbackFunc)(void*) DEFAULT_TO_NULL, 
00270                                      WRGroupHandle wrGroupHandle DEFAULT_TO_NULL, 
00271                                      unsigned int speAffinityMask DEFAULT_TO_ALLSET 
00272                                     );
00273 // Create some defines that will allow sendWorkRequest_list() to be called more easily
00274 #ifndef __cplusplus
00275 #define sendWorkRequest_list(fi, eah, dmal, nro, nrw, nwo) sendWorkRequest_list(fi, eah, dmal, nro, nrw, nwo, NULL, WORK_REQUEST_FLAGS_NONE, NULL, NULL, -1)
00276 #define sendWorkRequest_list(fi, eah, dmal, nro, nrw, nwo, ud) sendWorkRequest_list(fi, eah, dmal, nro, nrw, nwo, ud, WORK_REQUEST_FLAGS_NONE, NULL, NULL, -1)
00277 #define sendWorkRequest_list(fi, eah, dmal, nro, nrw, nwo, ud, f) sendWorkRequest_list(fi, eah, dmal, nro, nrw, nwo, ud, f, NULL, NULL, -1)
00278 #define sendWorkRequest_list(fi, eah, dmal, nro, nrw, nwo, ud, f, cb) sendWorkRequest_list(fi, eah, dmal, nro, nrw, nwo, ud, f, cb, NULL, -1)
00279 #define sendWorkRequest_list(fi, eah, dmal, nro, nrw, nwo, ud, f, cb, gh) sendWorkRequest_list(fi, eah, dmal, nro, nrw, nwo, ud, f, cb, gh, -1)
00280 #endif
00281 
00282 
00293 extern int isFinished(WRHandle wrHandle    
00294                      );
00295 
00299 void waitForWRHandle(WRHandle wrHandle     
00300                     );
00301 
00302 
00304 extern WRGroupHandle createWRGroup(void* userData DEFAULT_TO_NULL,              
00305                                    void (*callbackFunc)(void*) DEFAULT_TO_NULL  
00306                                   );
00307 #ifndef __cplusplus
00308 #define createWRGroup()    createWRGroup(NULL, NULL);
00309 #define createWRGroup(ud)  createWRGroup(ud, NULL);
00310 #endif
00311 
00312 
00314 extern void completeWRGroup(WRGroupHandle wrGroupHandle);
00315 
00316 
00318 extern int isWRGroupFinished(WRGroupHandle wrGroupHandle);
00319 
00320 
00322 extern void waitForWRGroupHandle(WRGroupHandle wrGroupHandle);
00323 
00324 
00327 extern void OffloadAPIProgress();
00328 
00329 
00332 extern void OffloadAPIDisplayConfig(FILE* fout);
00333 
00334 // DEBUG
00335 extern int getWorkRequestID(WRHandle wrHandle);
00336 extern void enableTrace();
00337 extern void disableTrace();
00338 
00339 // DEBUG
00340 extern void displayLastWRTimes();
00341 
00342 
00343 #ifdef __cplusplus
00344 }  // end extern "C"
00345 #endif
00346 
00347 
00350 #endif //__SPE_RUNTIME_PPU_H__

Generated on Sun Jun 29 13:29:05 2008 for Charm++ by  doxygen 1.5.1