The first one reads data, performs some initial computations and push data to the second process, which is pipelined. The third process read data from the pipelined process, performs some final computations and write the results.
Once I've finished to push data in the pipelined process i'm closing the input stream so that the pipeline get flushed. However, with Stage Master Debugger I'm seeing that only the first iteration works well. In the second iteration i'm seeing the pipeline doesn't get filled correctly and process is always returning 1.
Below there is a skeleton of my code. I hope you can help me to see what i'm doing wrong.
Thanks in advance and Kind Regards,
Diego.
CODE
void preProc(co_stream inputstr, co_stream outputstr, co_signal go, co_signal fin) {
int goData;
//Input/output vars
co_uint32 nSample;
IF_SIM(cosim_logwindow log;)
IF_SIM(log = cosim_logwindow_create("preProc");)
do { // Hardware processes run forever
co_stream_open(inputstr, O_RDONLY, UINT_TYPE(STREAMWIDTH));
co_stream_open(outputstr, O_WRONLY, UINT_TYPE(STREAMWIDTH));
// Read values from the stream
while (co_stream_read(inputstr, &nSample, sizeof ( co_uint32)) == co_err_none) {
//Some computation
co_par_break();
co_signal_post(go, 1); //Notify postProc to start
//More computations
co_par_break();
//Send data to upwind
co_stream_write(outputstr, &nSample, sizeof ( co_uint32));
co_stream_write(outputstr, &nSample, sizeof ( co_uint32));
co_stream_write(outputstr, &nSample, sizeof ( co_uint32));
co_stream_write(outputstr, &nSample, sizeof ( co_uint32));
co_stream_close(outputstr); //to flush pipeline
co_par_break(); //wait to avoid inter-blocking (?)
co_signal_wait(fin, &goData); // Wait for postProc to finish
}
co_stream_close(inputstr);
} while (1);
}
void postProc(co_stream inputstr, co_stream outputstr, co_signal go, co_signal fin) {
//Input/output vars
co_uint32 nSample;
int goData;
IF_SIM(cosim_logwindow log;)
IF_SIM(log = cosim_logwindow_create("postProc");)
do { // Hardware processes run forever
co_stream_open(inputstr, O_RDONLY, UINT_TYPE(STREAMWIDTH));
co_stream_open(outputstr, O_WRONLY, UINT_TYPE(STREAMWIDTH));
co_signal_wait(go, &goData); // Wait for preProc to read data problem numbers
co_par_break();
co_par_break();
co_par_break();
co_par_break();
co_par_break();
co_stream_read(inputstr, &nSample, sizeof ( co_uint32));
co_stream_read(inputstr, &nSample, sizeof ( co_uint32));
co_stream_read(inputstr, &nSample, sizeof ( co_uint32));
co_stream_read(inputstr, &nSample, sizeof ( co_uint32));
co_signal_post(fin, 1);
co_stream_close(inputstr);
co_stream_close(outputstr);
} while (1);
}
void upwind_residuals(co_stream inputResStr, co_stream outputResStr) {
co_uint32 salida, nSample;
IF_SIM(int samplesread; int sampleswritten;)
IF_SIM(cosim_logwindow log;)
IF_SIM(log = cosim_logwindow_create("upwind");)
do { // Hardware processes run forever
IF_SIM(samplesread = 0; sampleswritten = 0;)
co_stream_open(inputResStr, O_RDONLY, UINT_TYPE(STREAMWIDTH));
co_stream_open(outputResStr, O_WRONLY, UINT_TYPE(STREAMWIDTH));
salida = 0;
// Read values from the stream
while (co_stream_read(inputResStr, &nSample, sizeof ( co_uint32)) == co_err_none) {
#pragma CO PIPELINE
IF_SIM(samplesread++;)
salida++;
co_par_break();
co_par_break();
co_par_break();
co_par_break();
co_par_break();
co_stream_write(outputResStr, &salida, sizeof ( co_uint32));
//IF_SIM(cosim_logwindow_fwrite(log, "Instance %d wrote value %x\n", nInstance, nSample);)
IF_SIM(sampleswritten++;)
}
co_stream_close(inputResStr);
co_stream_close(outputResStr);
IF_SIM(cosim_logwindow_fwrite(log,
"Closing filter process (instance %d), samples read: %d, samples written: %d\n",
0/*nInstance*/, samplesread, sampleswritten);)
IF_SIM(break;) // Only run once for desktop simulation
} while (1);
}
int goData;
//Input/output vars
co_uint32 nSample;
IF_SIM(cosim_logwindow log;)
IF_SIM(log = cosim_logwindow_create("preProc");)
do { // Hardware processes run forever
co_stream_open(inputstr, O_RDONLY, UINT_TYPE(STREAMWIDTH));
co_stream_open(outputstr, O_WRONLY, UINT_TYPE(STREAMWIDTH));
// Read values from the stream
while (co_stream_read(inputstr, &nSample, sizeof ( co_uint32)) == co_err_none) {
//Some computation
co_par_break();
co_signal_post(go, 1); //Notify postProc to start
//More computations
co_par_break();
//Send data to upwind
co_stream_write(outputstr, &nSample, sizeof ( co_uint32));
co_stream_write(outputstr, &nSample, sizeof ( co_uint32));
co_stream_write(outputstr, &nSample, sizeof ( co_uint32));
co_stream_write(outputstr, &nSample, sizeof ( co_uint32));
co_stream_close(outputstr); //to flush pipeline
co_par_break(); //wait to avoid inter-blocking (?)
co_signal_wait(fin, &goData); // Wait for postProc to finish
}
co_stream_close(inputstr);
} while (1);
}
void postProc(co_stream inputstr, co_stream outputstr, co_signal go, co_signal fin) {
//Input/output vars
co_uint32 nSample;
int goData;
IF_SIM(cosim_logwindow log;)
IF_SIM(log = cosim_logwindow_create("postProc");)
do { // Hardware processes run forever
co_stream_open(inputstr, O_RDONLY, UINT_TYPE(STREAMWIDTH));
co_stream_open(outputstr, O_WRONLY, UINT_TYPE(STREAMWIDTH));
co_signal_wait(go, &goData); // Wait for preProc to read data problem numbers
co_par_break();
co_par_break();
co_par_break();
co_par_break();
co_par_break();
co_stream_read(inputstr, &nSample, sizeof ( co_uint32));
co_stream_read(inputstr, &nSample, sizeof ( co_uint32));
co_stream_read(inputstr, &nSample, sizeof ( co_uint32));
co_stream_read(inputstr, &nSample, sizeof ( co_uint32));
co_signal_post(fin, 1);
co_stream_close(inputstr);
co_stream_close(outputstr);
} while (1);
}
void upwind_residuals(co_stream inputResStr, co_stream outputResStr) {
co_uint32 salida, nSample;
IF_SIM(int samplesread; int sampleswritten;)
IF_SIM(cosim_logwindow log;)
IF_SIM(log = cosim_logwindow_create("upwind");)
do { // Hardware processes run forever
IF_SIM(samplesread = 0; sampleswritten = 0;)
co_stream_open(inputResStr, O_RDONLY, UINT_TYPE(STREAMWIDTH));
co_stream_open(outputResStr, O_WRONLY, UINT_TYPE(STREAMWIDTH));
salida = 0;
// Read values from the stream
while (co_stream_read(inputResStr, &nSample, sizeof ( co_uint32)) == co_err_none) {
#pragma CO PIPELINE
IF_SIM(samplesread++;)
salida++;
co_par_break();
co_par_break();
co_par_break();
co_par_break();
co_par_break();
co_stream_write(outputResStr, &salida, sizeof ( co_uint32));
//IF_SIM(cosim_logwindow_fwrite(log, "Instance %d wrote value %x\n", nInstance, nSample);)
IF_SIM(sampleswritten++;)
}
co_stream_close(inputResStr);
co_stream_close(outputResStr);
IF_SIM(cosim_logwindow_fwrite(log,
"Closing filter process (instance %d), samples read: %d, samples written: %d\n",
0/*nInstance*/, samplesread, sampleswritten);)
IF_SIM(break;) // Only run once for desktop simulation
} while (1);
}












