Skip to content
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

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmake/ChaiBasics.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@

set (CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-extended-lambda")
include(${CMAKE_SOURCE_DIR}/cmake/thirdparty/SetupChaiThirdparty.cmake)

include("${CMAKE_CURRENT_LIST_DIR}/ChaiOptions.cmake")
Copy link
Member Author

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.

2 changes: 2 additions & 0 deletions cmake/ChaiOptions.cmake
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 )
Copy link
Member Author

Choose a reason for hiding this comment

The 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 ENABLE_*

7 changes: 6 additions & 1 deletion src/ManagedArray.inl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#include "ManagedArray.hpp"
#include "ArrayManager.hpp"

#include <assert.h>
Copy link
Contributor

@rrsettgast rrsettgast Jun 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be
#include <cassert>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be <cassert> or assert.h . I think <assert.h> might valid too? What do you think @davidbeckingsale ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they both work I'm okay with cassert.

Copy link
Member

@rhornung67 rhornung67 Jun 13, 2018

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. My only concern was whether the assert.h you get when using nvcc was a different file which supplies the GPU assert definition. I think @artv3 has verified that both work however.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cassert works for nvcc.


namespace chai {

template<typename T>
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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];
}

Expand Down
1 change: 1 addition & 0 deletions src/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@
#cmakedefine CHAI_ENABLE_IMPLICIT_CONVERSIONS
#cmakedefine CHAI_DISABLE_RM
#cmakedefine CHAI_ENABLE_UM
#cmakedefine CHAI_ARRAY_BOUNDS_CHECK
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be CHAI_ENABLE_*, matching the option from the CMakeLists, prefixed with CHAI_


#endif // CHAI_config_HPP
10 changes: 9 additions & 1 deletion src/tests/managed_array_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ CUDA_TEST(ManagedArray, UserCallback)
#endif
#endif


#if defined(CHAI_ENABLE_CUDA)
CUDA_TEST(ManagedArray, Move)
{
Expand All @@ -410,3 +409,12 @@ CUDA_TEST(ManagedArray, Move)
array.free();
}
#endif // defined(CHAI_ENABLE_CUDA)

Copy link
Contributor

@rrsettgast rrsettgast Jun 12, 2018

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I remove yours? Or keep them as well?

Copy link
Contributor

@rrsettgast rrsettgast Jun 12, 2018

Choose a reason for hiding this comment

The 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