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 8 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 <cassert>

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
30 changes: 19 additions & 11 deletions src/tests/managed_array_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,20 +393,28 @@ CUDA_TEST(ManagedArray, UserCallback)
#endif
#endif


#if defined(CHAI_ENABLE_CUDA)
CUDA_TEST(ManagedArray, Move)
#if !defined(NDEBUG)
TEST(ManagedArray, OutOfRangeAccess)
{
chai::ManagedArray<float> array(10, chai::GPU);

forall(cuda(), 0, 10, [=] __device__ (int i) {
array[i] = i;
});
chai::ManagedArray<float> array(20);

array.move(chai::CPU);
EXPECT_DEATH(
forall(sequential(), 10, 50, [=] (int i) {
array[i] = 0.0f;
});,
"i < m_elems");
}

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.

ASSERT_EQ(array[5], 5);
#if defined(CHAI_ENABLE_CUDA)
CUDA_TEST(ManagedArray, OutOfRangeAccessGPU)
{
chai::ManagedArray<float> array(20);

array.free();
EXPECT_DEATH(
forall(cuda(), 10, 50, [=] __device__ (int i) {
array[i] = 0.0f;
});,
"i < m_elems");
}
#endif // defined(CHAI_ENABLE_CUDA)
#endif // !defined(NDEBUG)