Restrict Keyword - Restrict Keyword - 2025.1 English - UG1079

AI Engine Kernel and Graph Programming Guide (UG1079)

Document ID
UG1079
Release Date
2025-06-04
Version
2025.1 English

The C++ standard provides a compiler extension __restrict for C standard pointer qualifier restrict, intended to allow more aggressive compiler optimization, by explicitly stating that no memory dependency will be caused by pointer aliasing. The compiler, by default, does not distinguish between different accesses of the same array. Thus, if an array is accessed in the pipeline, the compiler assumes that pointers might point to the same location, thereby incurring a higher interval between loops. This makes it is essential in some situations to use a __restrict keyword to help guide the tool to achieve better performance. If a pointer is created with the restrict keyword, it is treated as a new object by the compiler. Pointers with the restrict keyword that point to the same location are treated independently by the compiler. The compiler can schedule the pointer access independently, which might impact the order of updates and cause undefined behavior. For detailed information about the concept of the __restrict keyword, see Using the Restrict Keyword in AI Engine Kernels.