Questions tagged [restrict-qualifier]

Restrict is a keyword that could applied to a pointer to an object. It makes this pointer the one and only way to access the data of that object.

The restrict-qualifier tells the compiler that if the memory accessed by the restrict-qualified pointer is modified, no other pointers will access it.

The compiler may use this hint to optimize the restrict-qualified pointers in such a way, that would otherwise cause incorrect or undefined behavior.

C++ supports restrict keyword for compatibility with C. However, a C++ compiler will ignore the restrict keyword, because in C++ "restrict" is a valid variable name. C++ compilers, though, have a special __restrict__ qualifier.

In-detail information along with examples can be found on the IBM website.

128 questions
1
vote
2 answers

Why am I getting the error message: "restrict" not allowed?

I'm writing a CUDA kernel and want to __restrict__ some of my parameters. I'm getting the error message: "restrict" is not allowed Is it not allowed for some variable types? For some combinations of parameters? Because of some compiler flags?…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
1 answer

defining a variable as auto restrict

As I understand restrict, it marks a pointer as being the only reference to particular data within a function. I usually see it used in function parameters, but this is also seems to be beneficial: char *restrict a = get_some_string( ); char…
Dave
  • 44,275
  • 12
  • 65
  • 105
0
votes
1 answer

Why compiler does not optimise RAM lookups?

https://godbolt.org/z/dK9v7En5v For following C++ code #include #include void Send(uint32_t); void SendBuffer(uint32_t* __restrict__ buff, size_t n) { for (size_t i = 0; i < n; ++i) { Send(buff[0]); …
pvl
  • 958
  • 1
  • 6
  • 12
0
votes
3 answers

Using restrict to express possible partial overlap

Given type definitions struct a { int a; }; struct b { int b; struct a ba;}; and a function taking struct a* a and struct b* b, the type information expresses possible overlap between a->a and b->ba.a but no overlap on b->b. Therefore in a function…
0
votes
1 answer

Why is cuda pointer memory access slower than global device memory access?

#include #include #include #include #include #include #include "cuda_runtime.h" #include "device_launch_parameters.h" __device__ int foo[16]; __device__ int…
tigertang
  • 445
  • 1
  • 6
  • 18
0
votes
0 answers

Restrict qualifier on class member pointers

I've a program like this, where I've to abstract pointers using a class. I'd like the compiler to optimize the unrolled loop in the main function below assuming no pointer aliasing. How can I effectively use __restrict construct in this scenario?…
vb000
  • 81
  • 1
  • 5
0
votes
4 answers

Does Clang misunderstand the 'const' pointer specifier?

In the code below I saw that clang fails to perform better optimisation without implicit restrict pointer specifier: #include #include #include typedef struct { uint32_t event_type; uintptr_t …
0
votes
1 answer

restrict-pointer-type template arguments and overriding virtual methods of a templated base class

The following should, I believe, compile and link, but doesn't: template class A { public: virtual int foo(S arg) = 0; virtual ~A() { } }; class B : public A { public: int foo(int* __restrict__ arg) override…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
1 answer

Potentially undefined behaviour with restricted pointers

Here are four code fragments. Why is this code guaranteed (or not guaranteed) to produce well defined behaviour? Restricted "circular references": struct B; struct A { struct B *restrict b1, *restrict b2; }; struct B { struct A *restrict a1,…
0
votes
1 answer

How to combine __restrict__ with an array pointed to by a __constant__ pointer?

This will be a bit of a funky question I assume and if I need to elaborate, please say so. The situation is as follows: I have about 2 gigs of GPU memory containing my random numbers and I need to use those in many different functions. To prevent…
ikku100
  • 809
  • 1
  • 7
  • 16
0
votes
1 answer

Verbose but readable explanation of restrict qualifier?

I've finally taken an interest in some C99 features, and now I'm having trouble understanding the relevant sections of the C99 draft. I know that restrict is a promise that two restrict qualified pointers will not point to the same object, but my…
Subsentient
  • 554
  • 3
  • 12
0
votes
1 answer

Calling function with restricted arguments that are already restricted in current scope

I have trouble understanding what restrict means in terms with calling functions with already restricted variables. Wikipedia tells me: The restrict keyword is a declaration of intent given by the programmer to the compiler. It says that for the…
0
votes
2 answers

Does a pointer to const have the same effect as __restrict?

When we have constant data, e.g. in the form double const * const or double const * does this give the compiler the same information as __restrict / does it have the same effect? As far as I understand, __restrict basically promises, that the…
embert
  • 7,336
  • 10
  • 49
  • 78
0
votes
2 answers

Application of Pointer Aliasing Rule (Pointer to Addess of Itself)

I ran into a nasty schrödinbug recently. While trying to load a file into a flat memory representation, the author had written code like this: class Line final { public: int stuff[3]; char* data; } //... Line* line = /*...*/; //Trying to…
geometrian
  • 14,775
  • 10
  • 56
  • 132
0
votes
1 answer

Specialising templates on C++AMP restricted lambdas

Using the insight of this question (and a few others) I have been able to write the following for interrogating normal lambda function type infromation (i.e. return type, argument count etc) // helper classes…
1 2 3
8
9