UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

AR# 60434

2014.1 Vivado HLS - What is a "volatile" data type and when to use it?

Description

This Answer Record describes the "volatile" data type with an example for Vivado HLS.

The behavior is the same as the "C" behavior.

Solution

Volatile Type:

The volatile qualifier impacts how many reads or writes are performed in the RTL when pointers are accessed multiple times on function interfaces. 

Limitation:

Arbitrary precision types do not support the volatile qualifier for arithmetic operations. Any arbitrary precision data types using the volatile qualifier must be assigned to a non-volatile data type before being used in arithmetic expression 

Recommendation:

You must use the volatile qualifier on any function argument accessed multiple times.

The volatile qualifier tells the C compiler (and Vivado HLS) to make no assumptions about the pointer accesses. That is, the data is volatile and may change. 

Example:

Target is to achieve 4 reads and 2 writes as a multi-pointer access. Data types are C integers of typedef "int".

Directives used in both case:

#pragma HLS INTERFACE ap_fifo depth=4 port=d_i

#pragma HLS INTERFACE ap_fifo depth=2 port=d_o 

Without Volatile:

void pointer_stream_bad ( dout_t *d_o, din_t *d_i) {

din_t acc = 0;

acc += *d_i;

acc += *d_i;

*d_o = acc;

acc += *d_i;

acc += *d_i;

*d_o = acc;

}

 

Cosim result:

Din         Dout

0              0

1              4

2              8

3              12


Waveform:

vol_1.jpg



With Volatile:

void pointer_stream_better ( volatile dout_t *d_o, volatile din_t *d_i) {

din_t acc = 0;

acc += *d_i;

acc += *d_i;

*d_o = acc;

acc += *d_i;

acc += *d_i;

*d_o = acc;

}

 

Cosim Result:

Din         Dout

0               1

1               6

2

3

 

Waveform:

vol_2.png




Vivado HLS example for volatile type:

Open Example Project> Coding Style Examples> pointer_stream_better

Further Reading:

Please refer to the latest version of the Vivado HLS User Guide 902.

With reference to the 2014.1 version, please refer to page 368: http://www.xilinx.com/support/documentation/sw_manuals/xilinx2014_1/ug902-vivado-high-level-synthesis.pdf

Linked Answer Records

Master Answer Records

Answer Number Answer Title Version Found Version Resolved
47431 Xilinx Vivado HLS Solution Center - Design Assistant N/A N/A
AR# 60434
Date Created 04/28/2014
Last Updated 05/02/2014
Status Active
Type Solution Center
Tools
  • Vivado Design Suite - 2014.1
  • Vivado Design Suite