Scatter behavior and possible alternatives

20 views
Skip to first unread message

Nihon Vasserman

unread,
Mar 31, 2023, 2:31:39 PM3/31/23
to Accelerate
Hello,

I need a function similar to scatter which would allow to substitute values in a vector provided new values and indices.

Documentation on scatter mentions that if an index appears more than once, then the result is undefined. I wanted to clarify that part. Does undefined mean that a random index among all repetitions will be used or that it is possible to run into some actual UB errors? For my case, the first option is desired, however after a bit of testing it seems that while everything works correctly with LLVM.Native, I non-deterministically get segmentation faults with LLVM.PTX.

Is there a way to write a scatter-like function that would not segfault on multiple occurrences of the same index?

Trevor L. McDonell

unread,
Apr 3, 2023, 5:22:39 AM4/3/23
to Accelerate
Hi!

Welcome to the Accelerate mailing list! (:

For the scatter function, it means that if the destination index appears more than once, then there is no guarantee of which particular value will be finally written to that index, as the order of the permutations is not specified. The values themselves still come from the vector of source values, of course, so you shouldn't see garbage values appear (that would be a bug). In the CPU backend you are more likely to get consistent behaviour because the CPU code has relatively low concurrency (few threads, which just loop over the array start-to-end), but that's just by accident. Either way you shouldn't get segmentation faults, however, so that could indeed be a bug (unless an out-of-bounds index was used).

Note that scatter is just a simplified wrapper over the permute function: with that function you can specify what to do when the same index is given more than once (i.e. by combining the old and new values with the given operator; with scatter it just overwrites the old value, hence the non-deterministic behaviour).

Hope that helps!

Cheers,
-Trevor


Nihon Vasserman

unread,
Apr 26, 2023, 8:51:41 AM4/26/23
to Accelerate
Thank you!

понедельник, 3 апреля 2023 г. в 12:22:39 UTC+3, Trevor L. McDonell:
Reply all
Reply to author
Forward
0 new messages