-
Notifications
You must be signed in to change notification settings - Fork 89
Add check so end iterator is not dereferenced
#150
Add check so end iterator is not dereferenced
#150
Conversation
The current behaviour of `get_node` in the virtual pointer mapper will use `lower_bound` to get the buffer which is not less than the input pointer. If the pointer mapper has only allocated one buffer, and we are looking up a pointer offset into that buffer then the call to `lower_bound` will return an iterator pointing past the end of the map. This means we cannot dereference this iterator, as it does not point into the map, but we still want to decrement this iterator to get the buffer that the virtual pointer is referencing. By adding a check for whether the iterator is the end we can short circuit the iterator dereference, and so avoid this problem without otherwise changing the behaviour of the pointer mapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix, I am surprised we haven't seen this issue before. Could you add a test for this case to ensure we don't break it?
|
The current tests exhibit this behaviour, but silently pass until you turn on debug iterators (eg. using I'm not sure what a more explicit test would look like. |
|
@jwlawson is correct - the first time we tried the SDK on Windows after the virtual pointer was added, it failed because Windows debug builds use checked iterators by default. Unfortunately the _GLIBCXX_DEBUG isn't totally safe - you can't pass containers between TUs that have DEBUG and not DEBUG, so I'm not sure you could reliably create a test that links against a non-_GLIBCXX_DEBUG ComputeCpp. It might work if you do target_definitions() on the tests... The test "offset" fails when built in debug mode. If it definitely doesn't share containers with the library, it should work! |
|
@Ruyk how about a compromise: I can push a separate MR that sets -D_GLIBCXX_DEBUG=1 for some of the tests for the virtual pointer, and we merge this as a fix? (It might in general be difficult to "force" the error, since the PointerMapper stuff is fairly opaque, so we can't really do a check inside the test). If nothing else, given that lower_bound() can return end(), we need to check for that before dereferencing. I'd like to get this merged. |
* Add explicit tests option to CMakeLists.txt This option has existed for some time, but was never explicitly written in the main CMake file. While adding this, some old unused lines were removed from the CMake (the directory has long not been set by FindComputeCpp.cmake, so the lines were totally useless). * This commit removes the unnessasary usage of the buffer allocator in virtual pointer. * Add check so `end` iterator is not dereferenced (codeplaysoftware#150) The current behaviour of `get_node` in the virtual pointer mapper will use `lower_bound` to get the buffer which is not less than the input pointer. If the pointer mapper has only allocated one buffer, and we are looking up a pointer offset into that buffer then the call to `lower_bound` will return an iterator pointing past the end of the map. This means we cannot dereference this iterator, as it does not point into the map, but we still want to decrement this iterator to get the buffer that the virtual pointer is referencing. By adding a check for whether the iterator is the end we can short circuit the iterator dereference, and so avoid this problem without otherwise changing the behaviour of the pointer mapper. * Fix type shadowing (codeplaysoftware#152) The type buffer_t is defined in the class PointerMapper and redefined to a different type in get_buffer which results in shadowing warnings. SYCLmalloc doesn't have this issue but the alias should probably be changed for consistency. * Add property_list parameter to syclmalloc (codeplaysoftware#157) Property lists are useful, and we still want to pass them to buffers through the SYCL malloc interface. In addition, a related test was failing because of an interface change, and has been removed. * Improve portability of FindComputeCpp.cmake Contains improvements designed to improve the reliablity of FindComputeCpp.cmake, brought on by the MSVC policy of supporting only two Clang versions at any given time. * Added way to check MSVC STL/Clang compatibility * Fix and simplify force-include for MSVC * Ensure device compiler arguments are always stored as CMake list * Added initial example of builtin kernel Small sample showing how to use built-in kernels in ComputeCpp. * Warn when computecpp_info can't be found Fixes issue codeplaysoftware#126 but allows for optional ComputeCpp use. * Add synchronous error handling sample (codeplaysoftware#163) Specifically this shows a device selector that fails to find a device. Similar effect could be achieved with the fallback queue. This should fix codeplaysoftware#105. * Move compiler checks to separate module (codeplaysoftware#160) Moving these compiler checks to a separate module keeps the main FindComputeCpp.cmake clean and makes the checks "opt-in", if you know that you won't need the check for your project. * Changes to the tiled-convolution branch * Use `handler::copy` instead of copying in kernel * Initialize output data to zero * Only create single temporary buffer object * Use on-chip memory for temporary buffer objects * Made `compute_index` a single function * Added existing sample from master * As `tiled-convolution-standard` * `input_data_info` * Changed OpenCL parameters * Addressed many PR comments * `constexpr matrix_size_t` * Typo fixes and formatting * Validate returns `bool` * No need to specifiy global buffer target * CMake cleanup * Display profiling
The current behaviour of
get_nodein the virtual pointer mapper willuse
lower_boundto get the buffer which is not less than the inputpointer. If the pointer mapper has only allocated one buffer, and we are
looking up a pointer offset into that buffer then the call to
lower_boundwill return an iterator pointing past the end of the map.This means we cannot dereference this iterator, as it does not point
into the map, but we still want to decrement this iterator to get the
buffer that the virtual pointer is referencing.
By adding a check for whether the iterator is the end we can short
circuit the iterator dereference, and so avoid this problem without
otherwise changing the behaviour of the pointer mapper.