-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect overlapping memory in assignments #746
Comments
Hi UlIrich, Thanks for coming back on this. I changed my mind about this, I agree with you that in generic functions taking any kind of expression as its input, the programmer has no simple mean to decide whether to use I think that we can even go further and try to detect the need for temporaries at compile time. Note that this is not in contradiction with what you propose since there are cases where static check is not possible and in that cases we will rely on the dynamic one. This static check can be implemented after the dynamic one, though. About the implementation, I think it would be better to add a method in each expression type instead of centralizing it in a single class for the following reasons:
|
Note: as per discussions with Johan, I would go for the compile time cases first, but still be very coutious because it is easy to get it wrong... We would prefer to iron out the library on stability, cleanup, documentation before we take this on... |
Exactly.
For now, I wanted a simple design that was non-intrusive on xtensor, but a method in each expression certainly has advantages. The downside is that the method must be implemented in every expression, whereas a non-intrusive design can just implement the cases one cares about and return
I'm not sure to what extend this can succeed. I think it is very difficult to figure out the overlap of views at compile time. For example, two views referring to different z-slices of a 3D volume wouldn't overlap, but when the indices given to As a general remark: I've become more conservative about compile-time computations over the years. They have their downsides (more complex code, hard to explain to students, longer compilation times, crazy compiler errors), and the performance gains are often not big enough to justify these complications. |
You can also start with a non-intrusive approach that covers the important cases, and improve it later. |
At present, assignments create a temporary copy of the RHS, unless
noalias()
explicitly prevents it. In many cases, the possibility of aliasing can be ruled out by simply ensuring that the LHS memory has no overlap with the RHS memory. I think that the test will succeed quite often in real code (although I've never actually measured how often), freeing the programmer from the need to infer manually ifnoalias()
is permitted at any particular assignment. This is not only a simplification, but also takes care of many situations were the programmer just doesn't possess the required information to decide aboutnoalias()
(e.g. within a generic function that has no control over its inputs).I propose to implement such a check and use it in suitable assignment operations. To get an idea of how this works, you might want to have a look at xvigra's class overlapping_memory_checker and its use in assign_impl.
The text was updated successfully, but these errors were encountered: