25 SpuLibspe2Support::SpuLibspe2Support(spe_program_handle_t *speprog,
int numThreads)
27 this->program = speprog;
28 this->numThreads = ((numThreads <= spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1)) ? numThreads : spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1));
32 SpuLibspe2Support::~SpuLibspe2Support()
43 spe_context_ptr_t context;
55 btSpuStatus& spuStatus = m_activeSpuStatus[taskDesc->
m_taskId];
58 spuStatus.m_commandId = uiCommand;
59 spuStatus.m_status = Spu_Status_Occupied;
60 spuStatus.m_taskDesc.p = taskDesc;
63 context = data[taskDesc->
m_taskId].context;
79 btSpuStatus& spuStatus = m_activeSpuStatus[taskDesc->
taskId];
82 spuStatus.m_commandId = uiCommand;
83 spuStatus.m_status = Spu_Status_Occupied;
84 spuStatus.m_taskDesc.p = taskDesc;
87 context = data[taskDesc->
taskId].context;
104 unsigned int event = Spu_Mailbox_Event_Task;
105 spe_in_mbox_write(context, &event, 1, SPE_MBOX_ANY_NONBLOCKING);
110 void SpuLibspe2Support::waitForResponse(
unsigned int *puiArgument0,
unsigned int *puiArgument1)
124 for (
int i=0;i<m_activeSpuStatus.size();i++)
126 if ( m_activeSpuStatus[i].m_status == Spu_Status_Free)
138 btSpuStatus& spuStatus = m_activeSpuStatus[last];
145 *puiArgument0 = spuStatus.m_taskId;
146 *puiArgument1 = spuStatus.m_status;
152 void SpuLibspe2Support::startSPU()
154 this->internal_startSPU();
160 void SpuLibspe2Support::internal_startSPU()
162 m_activeSpuStatus.resize(numThreads);
165 for (
int i=0; i < numThreads; i++)
168 if(data[i].context == NULL)
172 if ((data[i].context = spe_context_create(0, NULL)) == NULL)
174 perror (
"Failed creating context");
179 if(spe_program_load(data[i].context, this->program))
181 perror (
"Failed loading program");
185 m_activeSpuStatus[i].m_status = Spu_Status_Startup;
186 m_activeSpuStatus[i].m_taskId = i;
187 m_activeSpuStatus[i].m_commandId = 0;
188 m_activeSpuStatus[i].m_lsMemory.p = NULL;
191 data[i].entry = SPE_DEFAULT_ENTRY;
193 data[i].argp.p = &m_activeSpuStatus[i];
194 data[i].envp.p = NULL;
197 if (pthread_create(&data[i].pthread, NULL, &ppu_pthread_function, &(data[i]) ))
199 perror (
"Failed creating thread");
211 for (
int i=0; i < numThreads; i++)
213 if(data[i].context != NULL)
215 while( m_activeSpuStatus[i].m_status == Spu_Status_Startup)
220 printf(
"Spu %d is ready\n", i);
226 void SpuLibspe2Support::stopSPU()
230 for ( i = 0; i < this->numThreads; i++ )
233 unsigned int event = Spu_Mailbox_Event_Shutdown;
234 spe_context_ptr_t context = data[i].context;
235 spe_in_mbox_write(context, &event, 1, SPE_MBOX_ALL_BLOCKING);
236 pthread_join (data[i].pthread, NULL);
240 spe_image_close(program);
242 for ( i = 0; i < this->numThreads; i++ )
244 if(data[i].context != NULL)
246 spe_context_destroy (data[i].context);
250 m_activeSpuStatus.clear();
struct CollisionTask_LocalStoreMemory * m_lsMemory
Task Description for SPU collision detection.
Make sure no destructors are called on this memory.
#define CMD_SAMPLE_TASK_COMMAND
#define CMD_GATHER_AND_PROCESS_PAIRLIST