本文整理汇总了C++中hls::stream::write方法的典型用法代码示例。如果您正苦于以下问题:C++ stream::write方法的具体用法?C++ stream::write怎么用?C++ stream::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hls::stream
的用法示例。
在下文中一共展示了stream::write方法的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: 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;
}
}
}
示例3: 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);
}
}
示例4: 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));
}
}
示例5:
// -----------------------------------------------------------
void lsupdate2SW_step ( const uint32_t step,
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_step\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)
{
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;
}
示例6: 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 );
}
}
示例7: 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;
}
}
示例8: 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);
}
}
示例9: 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);
}
}
示例10: 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);
}
}
示例11: 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) );
}
示例12: 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;
}
示例13: 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);
}
}
示例14: writeEntrance
/**
* Write out the entrance coordinates and directions
*/
void writeEntrance(hls::stream<uint32>& out) {
#pragma HLS INLINE
uint32 output = 0;
output |= openings[0]; // Entrance row
output <<= 4;
output |= openings[1]; // Entrance column
output <<= 4;
output |= openings[2]; // Entrance side
output <<= 4;
output |= openings[3]; // Exit row
output <<= 4;
output |= openings[4]; // Exit col
output <<= 4;
output |= openings[5]; // Exit side
out.write(output);
}
示例15: heston_kernel_ml
void heston_kernel_ml(const params_ml params, hls::stream<calc_t> &gaussian_rn1,
hls::stream<calc_t> &gaussian_rn2, hls::stream<calc_t> &prices) {
#pragma HLS interface ap_none port=params
#pragma HLS resource core=AXI4LiteS metadata="-bus_bundle params" \
variable=params
#pragma HLS interface ap_fifo port=gaussian_rn1
#pragma HLS resource core=AXI4Stream variable=gaussian_rn1
#pragma HLS interface ap_fifo port=gaussian_rn2
#pragma HLS resource core=AXI4Stream variable=gaussian_rn2
#pragma HLS interface ap_fifo port=prices
#pragma HLS resource core=AXI4Stream variable=prices
#pragma HLS resource core=AXI4LiteS metadata="-bus_bundle params" \
variable=return
// write block size to stream
prices.write(BLOCK_SIZE);
state_t state_coarse[BLOCK_SIZE];
#pragma HLS data_pack variable=state_coarse
state_t state_fine[BLOCK_SIZE];
#pragma HLS data_pack variable=state_fine
w_both_t w_both[BLOCK_SIZE];
#pragma HLS data_pack variable=w_both
ap_uint<6> upper_j = params.ml_constant + (params.do_multilevel ? 1 : 0);
for (uint32_t path = 0; path < params.path_cnt; path += BLOCK_SIZE) {
for (uint32_t step = 0; step != params.step_cnt_coarse; ++step) {
for (ap_uint<6> j = 0; j != upper_j; ++j) {
for (ap_uint<10> block_i = 0; block_i != BLOCK_SIZE;
++block_i) {
#pragma HLS PIPELINE II=1
bool is_fine = j != params.ml_constant;
//
// initialize
//
state_t l_state_coarse, l_state_fine;
w_both_t l_w_both;
if (step == 0 && j == 0) {
l_state_coarse = get_init_state(params);
l_state_fine = get_init_state(params);
l_w_both = get_w_zero();
} else {
l_state_coarse = state_coarse[block_i];
l_state_fine = state_fine[block_i];
l_w_both = w_both[block_i];
}
//
// calculate next step
//
state_t n_state_coarse, n_state_fine;
w_both_t n_w_both;
if (is_fine) {
// step fine
float w_stock = gaussian_rn1.read();
float w_vola = gaussian_rn2.read();
n_state_fine = get_next_step(params, l_state_fine,
w_stock, w_vola, true);
n_state_coarse = l_state_coarse;
// accumulate random numbers
n_w_both.w_stock = l_w_both.w_stock + w_stock;
n_w_both.w_vola = l_w_both.w_vola + w_vola;
} else {
// step coarse
n_state_coarse = get_next_step(params, l_state_coarse,
l_w_both.w_stock, l_w_both.w_vola, false);
n_state_fine = l_state_fine;
n_w_both = get_w_zero();
}
state_coarse[block_i] = n_state_coarse;
state_fine[block_i] = n_state_fine;
w_both[block_i] = n_w_both;
//
// write out
//
if ((step + 1 == params.step_cnt_coarse) &&
(j + 1 >= params.ml_constant)) {
if (is_fine) {
prices.write(get_log_price(n_state_fine));
} else {
prices.write(get_log_price(n_state_coarse));
}
}
}
}
}
}
}