本文整理汇总了C++中hls::stream类的典型用法代码示例。如果您正苦于以下问题:C++ stream类的具体用法?C++ stream怎么用?C++ stream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了stream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pricing
void pricing(hls::stream<float> in, hls::stream<float> out, hls::stream<float> out2, float strike_price) {
//#pragma HLS PIPELINE II=1
const int BLOCK = 64;
static ap_uint<32> res_cnt[BLOCK];
static float res_sum[BLOCK];
static float res_prod[BLOCK];
for (int i = 0; i < BLOCK; ++i) {
#pragma HLS PIPELINE II=1
float path = in.read();
float res = max_0(hls::expf(path) - strike_price);
ap_uint<32> l_cnt = res_cnt[i];
float l_sum = res_sum[i];
float l_prod = res_prod[i];
ap_uint<32> n_cnt = l_cnt + 1;
float delta = res - l_sum;
float n_sum = l_sum + delta / n_cnt;
float n_prod = l_prod + delta * (res - n_sum);
res_cnt[i] = n_cnt;
res_sum[i] = n_sum;
res_prod[i] = n_prod;
out.write(res_sum[i]);
out2.write(res_prod[i]);
}
//std::max(0.f, hls::expf(path) - strike_price);
}
示例2: dut
void dut(
hls::stream<bit32_t> &strm_in,
hls::stream<bit32_t> &strm_out
)
{
// -----------------------------
// YOUR CODE GOES HERE
// -----------------------------
digit in_digit;
bit4_t out_bit4;
// ------------------------------------------------------
// Input processing
// ------------------------------------------------------
// read the two input 32-bit words (low word first)
bit32_t input_lo = strm_in.read();
bit32_t input_hi = strm_in.read();
// Convert input raw bits to digit 49-bit representation via bit slicing
in_digit(31, 0) = input_lo;
in_digit(in_digit.length()-1, 32) = input_hi;
// ------------------------------------------------------
// Call digitrec
// ------------------------------------------------------
out_bit4 = digitrec( in_digit );
// ------------------------------------------------------
// Output processing
// ------------------------------------------------------
// Write out the recognized digit (0-9)
strm_out.write( out_bit4(out_bit4.length()-1, 0) );
}
示例3: fir_sw
void fir_sw(hls::stream<int> &input_val, hls::stream<int> &output_val)
{
int i;
static short shift_reg[TAPS] = {0};
const short coeff[TAPS] = {6,0,-4,-3,5,6,-6,-13,7,44,64,44,7,-13,
-6,6,5,-3,-4,0,6};
for(i=0; i < RUN_LENGTH; i++){
int sample;
sample = input_val.read();
//Shift Register
for(int j=0; j < TAPS-1; j++){
shift_reg[j] = shift_reg[j+1];
}
shift_reg[TAPS-1] = sample;
//Filter Operation
int acc = 0;
for(int k=0; k < TAPS; k++){
acc += shift_reg[k] * coeff[k];
}
output_val.write(acc);
}
}
示例4: writeDirections
/**
* Write the directions as u32 to the output AXI stream
*/
void writeDirections(hls::stream<uint32>& out, uint16 numDirections) {
#pragma HLS INLINE
out.write(numDirections);
uint16 directionIx = 0;
writeDirectionsLoop: for (uint8 i = 0; i < MAX_NUM_DIRECTIONS / DIRECTIONS_IN_BUS; i++) {
#pragma HLS LOOP_TRIPCOUNT min=8 max=32 // Min: MIN_NUM_DIRECTIONS / DIRECTIONS_IN_BUS (8) Max: MAX_NUM_DIRECTIONS / DIRECTIONS_IN_BUS (32) Actual: numDirections
uint32 output = 0;
// Compress from a series of u8 to a smaller series of u32 with padding
writeDirectionsShiftLoop: for (uint8 j = 0; j < DIRECTIONS_IN_BUS; j++) {
#pragma HLS UNROLL
output <<= DIRECTION_SIZE;
uint8 padChar = 0;
output |= i * DIRECTIONS_IN_BUS + j < numDirections ? directions[directionIx + j] : padChar;
}
out.write(output);
directionIx += DIRECTIONS_IN_BUS;
if (directionIx >= numDirections) {
break;
}
}
}
示例5: toplevel
void toplevel(hls::stream<uint32>& in, hls::stream<uint32>& out) {
#pragma HLS INTERFACE ap_fifo port=in
#pragma HLS INTERFACE ap_fifo port=out
#pragma HLS RESOURCE variable=in core=AXI4Stream
#pragma HLS RESOURCE variable=out core=AXI4Stream
#pragma HLS INTERFACE ap_ctrl_none port=return
#pragma HLS ARRAY_PARTITION variable=openings complete dim=1
#pragma HLS ARRAY_PARTITION variable=inGrid complete dim=1
#pragma HLS ARRAY_MAP variable=directions instance=instance1 horizontal
#pragma HLS ARRAY_MAP variable=tile instance=instance1 horizontal
uint8 tileCoords = in.read();
uint8 tileSize = in.read();
uint8 tileDataLen = in.read(); // Number of 32-bit bits
readData(in, tileDataLen);
uint8 numOpenings = findOpenings(tileSize);
out.write(tileCoords);
out.write(numOpenings);
if (numOpenings > 0) {
writeEntrance(out);
findDeadEnds(tileSize);
uint16 numDirections = findPath(tileSize);
writeDirections(out, numDirections);
}
}
示例6: antithetic
void antithetic(
hls::stream<float> &rn_in,
hls::stream<float> &rn_out_1,
hls::stream<float> &rn_out_2)
{
#pragma HLS interface ap_fifo port=rn_in
#pragma HLS resource core=AXI4Stream variable=rn_in
#pragma HLS interface ap_fifo port=rn_out_1
#pragma HLS resource core=AXI4Stream variable=rn_out_1
#pragma HLS interface ap_fifo port=rn_out_2
#pragma HLS resource core=AXI4Stream variable=rn_out_2
#pragma HLS interface ap_ctrl_none port=return
//for (int i = 0; i < 10 / 2; ++i) {
{
//while (true) {
#pragma HLS PIPELINE II=2
float r1 = rn_in.read();
float r2 = rn_in.read();
rn_out_1.write(r1);
rn_out_2.write(r2);
rn_out_1.write(negate(r1));
rn_out_2.write(negate(r2));
}
}
示例7: gauss_transform
void gauss_transform(
hls::stream<uint32_t> &uniform_rns,
hls::stream<float> &gaussian_rns) {
#pragma HLS interface ap_fifo port=uniform_rns
#pragma HLS resource core=AXI4Stream variable=uniform_rns
#pragma HLS interface ap_fifo port=gaussian_rns
#pragma HLS resource core=AXI4Stream variable=gaussian_rns
#pragma HLS interface ap_ctrl_none port=return
float u1, u2, r, z1, z2;
while (true){
//for (int i = 0; i < 100/2; ++i) {
#pragma HLS PIPELINE II=2
// intervall (0:1]
u1 = ((float)uniform_rns.read() + 1.f) * (float)(1.0 / 4294967296.0);
// intervall (0:2PI]
u2 = ((float)uniform_rns.read() + 1.f) * (float)(2 * M_PI / 4294967296.0);
r = hls::sqrtf(-2 * hls::logf(u1));
z1 = r * hls::cosf(u2);
z2 = r * hls::sinf(u2);
gaussian_rns.write(z1);
gaussian_rns.write(z2);
}
}
示例8: dut
void dut(
hls::stream<bit32_t> &strm_in,
hls::stream<bit32_t> &strm_out
)
{
// Declare the input and output variables
complex<float> out[4096];
complex<float> complex_In1[4096];
complex<float> complex_In2[4096];
float input_data_re = 0;
//-------------------------------------------------------
// Input processing
//-------------------------------------------------------
// Read the two input 32-bit words
bit32_t input1_lo;
bit32_t input2_hi;
bit32_t output_r;
bit32_t output_i;
for(int i = 0; i < 4096 ;i++)
{
input1_lo = strm_in.read();
input2_hi = strm_in.read();
input_data_re = input1_lo;
complex_In1[i] = complex<float>(input_data_re, 0);
input_data_re = input2_hi;
complex_In2[i] = complex<float>(input_data_re, 0);
}
// for(int m = 0; m < 4096 ;m++)
// {
//// input_data_re = in1[m];
// complex_In1[m] = complex<float>(80, 0);
//// input_data_re = in2[m];
// complex_In2[m] = complex<float>(80, 0);
// }
// ------------------------------------------------------
// Call Hybrid Imaging
// ------------------------------------------------------
hybrid_image(12, complex_In1, complex_In2, out );
// ------------------------------------------------------
// Output processing
// ------------------------------------------------------
// Write out the computed digit value
for(int i = 0; i < 4096 ;i++)
{
// printf("%f\n",out[i]);
// output = out[i];
output_r = out[i].real();
output_i = out[i].imag();
strm_out.write(output_r);
strm_out.write(output_i );
}
}
示例9: fill_gaussian_rng_stream
void fill_gaussian_rng_stream(hls::stream<calc_t> &rns, unsigned size) {
double z0, z1;
for (unsigned i = 0; i < size; ++i) {
box_muller(z0, z1);
rns.write(z0);
if (++i < size)
rns.write(z1);
}
}
示例10: accumSW
// -----------------------------------------------------------
void accumSW( const uint32_t stepsMC,
const uint32_t pathsMC,
hls::stream<float> &inData,
hls::stream<float> &outAccum )
{
printf("accumSW\n");
float sums[ACCUM_ELEM];
#pragma HLS RESOURCE variable=sums core=RAM_2P_BRAM
#pragma HLS DEPENDENCE variable=sums false
stepsLoop:for(uint32_t step=0; step<=stepsMC; ++step)
{
// ------------------------------------------
resetLoop:for(uint8_t i=0; i<ACCUM_ELEM; ++i)
{
#pragma HLS PIPELINE II=1 enable_flush
sums[i] = (float) 0.0f;
}
// ------------------------------------------
uint8_t index = (uint8_t) 0;
pathsLoop:for(uint32_t i=0; i<pathsMC; ++i)
{
#pragma HLS PIPELINE II=1 enable_flush
float data = inData.read();
float oldSum = sums[index];
float newSum = oldSum + data;
sums[index] = newSum;
index = (index<(ACCUM_ELEM-1))?++index:(uint8_t)0;
}
// ------------------------------------------
float totalSum = (float) 0.0f;
totalLoop:for(uint8_t i=0; i<ACCUM_ELEM;++i)
{
#pragma HLS PIPELINE II=1
totalSum += sums[i];
}
// ------------------------------------------
outAccum.write(totalSum);
}
return;
}
示例11: fe_wfl
void fe_wfl(hls::stream< ap_uint<32> > sampleFifo, hls::stream< ap_uint<32> > featureFifo, ap_uint<8> windowSize) {
#pragma HLS INTERFACE ap_ctrl_none port=return
#pragma HLS INTERFACE ap_fifo port=featureFifo
#pragma HLS INTERFACE ap_fifo port=sampleFifo
ap_uint<32> data;
ap_int<32> wflChannel1 = 0;
ap_int<32> wflChannel2 = 0;
ap_int<16> sampleChannel1 = 0;
ap_int<16> sampleChannel2 = 0;
ap_int<16> prevSampleChannel1 = 0;
ap_int<16> prevSampleChannel2 = 0;
ap_uint<8> cntSamples = 0;
// Wait for Samples to arrive in FIFO
while( windowSize == 0 ) {
}
while(1) {
wflChannel1 = 0;
wflChannel2 = 0;
// Count zero-crossing for channel 1 & 2
for(cntSamples = 0; cntSamples < windowSize; cntSamples++) {
// Read data from Sample-FIFO
// 2 16 bit Samples at one position in 32 bit FIFO => Process 2 channels in parallel
data = sampleFifo.read();
sampleChannel1 = data(15, 0);
sampleChannel2 = data(31, 16);
if (cntSamples > 0) {
wflChannel1 += abs2(sampleChannel1 - prevSampleChannel1);
wflChannel2 += abs2(sampleChannel2 - prevSampleChannel2);
}
prevSampleChannel1 = sampleChannel1;
prevSampleChannel2 = sampleChannel2;
}
// Write back features to Feature-FIFO
featureFifo.write(wflChannel1);
featureFifo.write(wflChannel2);
}
}
示例12:
// -----------------------------------------------------------
void lsupdate2SW ( const uint32_t stepsMC,
const uint32_t pathsMC,
const float discount,
hls::stream<float> &contin_in,
hls::stream<float> &payoff_in,
hls::stream<float> &cashFlow_in,
hls::stream<float> &cashFlow_out,
hls::stream<float> &cashFlowDisc_out,
hls::stream<float> &toAccum_out )
{
printf("lsupdate2SW\n");
zerosLoop:for(uint32_t path=0; path<pathsMC; ++path)
{
#pragma HLS PIPELINE II=1 enable_flush
// ---------------------------------
// write to outputs
cashFlow_out.write((float) 0.0f);
cashFlowDisc_out.write((float) 0.0f);
}
stepsLoop:for(uint32_t step=0; step<=stepsMC; ++step)
{
pathsLoop:for(uint32_t path=0; path<pathsMC; ++path)
{
#pragma HLS PIPELINE II=1 enable_flush
float continuation = contin_in.read();
float payoff = payoff_in.read();
float cashFlow = cashFlow_in.read();
float discountedCashFlow = discount * cashFlow;
// ---------------------------------
float newY;
if( (payoff > (float) 0.0f) && (payoff >= (float) continuation) )
newY = payoff;
else
newY = discountedCashFlow;
// ---------------------------------
// write to outputs
if(step < stepsMC)
cashFlow_out.write(newY);
if(step < stepsMC)
cashFlowDisc_out.write(discount * newY);
if(step == stepsMC)
toAccum_out.write(newY);
}
}
return;
}
示例13: cflowaccumregio
void cflowaccumregio( const uint32_t pathsMC,
float *totalSum,
hls::stream<float> &inData )
{
#pragma HLS INTERFACE s_axilite port=return bundle=CONTROL
#pragma HLS INTERFACE s_axilite port=pathsMC bundle=CONTROL
#pragma HLS INTERFACE s_axilite port=totalSum bundle=CONTROL
#pragma HLS INTERFACE axis register port=inData
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//static float sums[N];
float sums[NELEMENTS];
#pragma HLS RESOURCE variable=sums core=RAM_2P_BRAM
#pragma HLS dependence variable=sums false
resetLoop:for(uint8_t i=0; i<NELEMENTS; ++i)
{
#pragma HLS PIPELINE II=1
sums[i] = (float) 0.0f;
}
uint8_t index = (uint8_t) 0;
pathsLoop:for(uint32_t i=0; i<pathsMC; ++i)
{
#pragma HLS PIPELINE II=1
float data = inData.read();
float oldSum = sums[index];
float newSum = oldSum + data;
sums[index] = newSum;
index = (index<(NELEMENTS-1))?++index:(uint8_t)0;
}
float total = (float) 0.0f;
totalLoop:for(uint8_t i=0; i<NELEMENTS;++i)
{
#pragma HLS PIPELINE II=1
total += sums[i];
}
*totalSum = total;
return;
}
示例14: toplevel
//Top-level function
void toplevel(hls::stream<uint32> &input, hls::stream<uint32> &output) {
#pragma HLS INTERFACE ap_fifo port=input
#pragma HLS INTERFACE ap_fifo port=output
#pragma HLS RESOURCE variable=input core=AXI4Stream
#pragma HLS RESOURCE variable=output core=AXI4Stream
#pragma HLS INTERFACE ap_ctrl_none port=return
uint32 command;
init();
side = input.read();
ntiles = side * side;
for(u8 t = 0; t < ntiles; t++)
for (u8 e = 0; e < 4; e++)
tiles[t][e] = input.read();
mapcolours();
// we start off with tile 0 in position 0
avail &= ~BIT36(0);
seq = 1;
while (!terminate) {
if (seq == 1)
solve();
if (terminate) {
output.write(0);
break;
}
/* use magic flag to enforce sequencing */
seq = 0;
output.write(1);
if (seq == 0)
command = input.read();
seq = 1;
/* command 0: terminate */
if (command == 0)
break;
/* command 1: write output */
if (command == 1)
for (u8 p = 0; p < ntiles; p++)
for(u8 e = 0; e < 4; e++)
output.write(colour(p, e));
/* any other command (canonically 2) will cause search
* to continue without output */
if (seq == 0)
backtrack();
seq = 1;
}
}
示例15: readData
/**
* Read data from the AXI stream and convert from uint32 to uint1
*/
void readData(hls::stream<uint32> &in, uint8 tileDataLen) {
#pragma HLS INLINE
readLoop: for (uint8 i = 0; i < tileDataLen; i++) {
#pragma HLS LOOP_TRIPCOUNT min=5 max=18 // Min: MIN_TILE_DATA_32 (5) Max: MAX_TILE_DATA_32 (18) Actual: tileDataLen
inGrid[i] = in.read();
// Convert data from 18 * 32 => 576 * 1
readShiftLoop: for (uint8 j = 0; j < BUS_WIDTH; j++) {
#pragma HLS UNROLL
uint16 ix = i * BUS_WIDTH + (BUS_WIDTH - j - 1); // (BUS_WIDTH - j - 1) necessary to preserve direction
tile[ix] = (inGrid[i] & (1 << j)) ? 1 : 0;
}
}
}