-
Notifications
You must be signed in to change notification settings - Fork 22
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
Assert on out-of-range accesses #37
base: develop
Are you sure you want to change the base?
Changes from 7 commits
e1f32c4
a7bde92
827c11a
6a7b929
a989c60
5bbb458
e81eb80
908df3f
a0a6664
f38337d
a7af717
6c55bf9
dfa4b55
deba461
183358a
4eb6636
495e9b4
56044d4
a2526d8
6f9e038
87375a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
option( CHAI_ARRAY_BOUNDS_CHECK "Enables Bounds Checking for chai::ManagedArray<>::operator[]" OFF ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This option can go in the main CMakeLists, and should be of the form |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,8 @@ | |
#include "ManagedArray.hpp" | ||
#include "ArrayManager.hpp" | ||
|
||
#include <assert.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If they both work I'm okay with cassert. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @artv3 @davidbeckingsale @rrsettgast as a style and consistency point, I think it's best to use C++ header files; i.e., cassert instead of assert.h. In particular the C++ headers (without .h) are guaranteed to be standard compliant and this may not be the case for the *.h forms. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. My only concern was whether the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cassert works for nvcc. |
||
|
||
namespace chai { | ||
|
||
template<typename T> | ||
|
@@ -117,7 +119,7 @@ CHAI_HOST_DEVICE ManagedArray<T>::ManagedArray(ManagedArray const& other): | |
*/ | ||
if (!std::is_const<T>::value) { | ||
CHAI_LOG("ManagedArray", "T is non-const, registering touch of pointer" << m_active_pointer); | ||
T_non_const* non_const_pointer = const_cast<T_non_const*>(m_active_pointer); | ||
// T_non_const* non_const_pointer = const_cast<T_non_const*>(m_active_pointer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @davidbeckingsale this was a compilation warning for unused variable. is it needed for something? |
||
m_resource_manager->registerTouch(m_pointer_record); | ||
} | ||
#endif | ||
|
@@ -207,6 +209,9 @@ template<typename T> | |
template<typename Idx> | ||
CHAI_INLINE | ||
CHAI_HOST_DEVICE T& ManagedArray<T>::operator[](const Idx i) const { | ||
#if defined(CHAI_ARRAY_BOUNDS_CHECK) | ||
assert( i>=0 && static_cast<size_t>(i) < m_elems ); | ||
#endif | ||
return m_active_pointer[i]; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,5 +47,6 @@ | |
#cmakedefine CHAI_ENABLE_IMPLICIT_CONVERSIONS | ||
#cmakedefine CHAI_DISABLE_RM | ||
#cmakedefine CHAI_ENABLE_UM | ||
#cmakedefine CHAI_ARRAY_BOUNDS_CHECK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
|
||
#endif // CHAI_config_HPP |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,7 +393,6 @@ CUDA_TEST(ManagedArray, UserCallback) | |
#endif | ||
#endif | ||
|
||
|
||
#if defined(CHAI_ENABLE_CUDA) | ||
CUDA_TEST(ManagedArray, Move) | ||
{ | ||
|
@@ -410,3 +409,12 @@ CUDA_TEST(ManagedArray, Move) | |
array.free(); | ||
} | ||
#endif // defined(CHAI_ENABLE_CUDA) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @artv3 I think that the intention was to use @davidbeckingsale tests. Can you revert this file to his commit if that is a better idea? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I remove yours? Or keep them as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think David's tests cover the space better...right? well at any rate, there needs to be a cuda test. |
||
#if defined(CHAI_ARRAY_BOUNDS_CHECK) | ||
TEST(ManagedArray_DeathTest, RangeCheck) { | ||
chai::ManagedArray<float> array(10); | ||
|
||
EXPECT_DEATH_IF_SUPPORTED( array[-1], ".*" ); | ||
EXPECT_DEATH_IF_SUPPORTED( array[10], ".*" ); | ||
} | ||
#endif |
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.
I don't think we need this extra file.