-
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?
Conversation
src/ManagedArray.inl
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
should this be
#include <cassert>
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.
It can be <cassert>
or assert.h
. I think <assert.h> might valid too? What do you think @davidbeckingsale ?
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.
If they both work I'm okay with cassert.
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.
@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 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.
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.
cassert works for nvcc.
src/ManagedArray.inl
Outdated
@@ -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 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?
src/tests/managed_array_tests.cpp
Outdated
@@ -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 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?
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.
Should I remove yours? Or keep them as well?
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 think David's tests cover the space better...right? well at any rate, there needs to be a cuda test.
cmake/ChaiBasics.cmake
Outdated
@@ -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") |
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.
cmake/ChaiOptions.cmake
Outdated
@@ -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 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_*
src/config.hpp.in
Outdated
@@ -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 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_
src/tests/CMakeLists.txt
Outdated
@@ -55,10 +55,24 @@ blt_add_executable( | |||
SOURCES managed_array_tests.cpp | |||
DEPENDS_ON ${managed_array_test_depends}) | |||
|
|||
blt_add_executable( | |||
NAME managed_array_bounds_check_tests |
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'm not clear on the benefit of the extra file? These tests can just be guarded in the main file.
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.
But then the tests are only run if the option was specified to cmake...which isn't a big deal, but it also means that to enable the tests in travis, you would need to add an extra ci test. This way the bounds checking is always run for every ci test case.
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.
But they should only be run if the CMake option is on, otherwise the bounds are not checked...
7d63c8d
to
a0a6664
Compare
… upper and lower bounds tests.
46a1fa5
to
f38337d
Compare
I think this is looking good, but Im not sure why the nvcc builds are failing... Does this build locally for you? |
@davidbeckingsale It builds fine when I tried it on the rajaorg/compiler:nvcc8 docker image. This image uses gcc5. |
CMakeLists.txt
Outdated
@@ -71,6 +71,9 @@ endif() | |||
set(ENABLE_COPY_HEADERS On CACHE BOOL "") | |||
set(BLT_CXX_STD c++11 CACHE STRING "") | |||
|
|||
if( CMAKE_BUILD_TYPE STREQUAL "Debug" ) | |||
set( CHAI_ENABLE_BOUNDS_CHECK ON CACHE BOOL "Enable Bounds Checking for chai::ManagedArray<>::operator[]" FORCE ) |
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.
This should be an option
at the top of the CMakeLists file.
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.
Fixed.
Is this working now? Using assert on the device kills the kernel, but I believe you have to synchronize and check the error code on the host to actually see that there was a GPU assert. |
@adayton1 - give it a whirl and let me know 😄 |
@adayton1 , cmake will sometimes add a NDEBUG define which will cause asserts to no work. Will you be covering this case too? We see it in RAJA with the release build. |
#if defined(NDEBUG) | ||
#undef NDEBUG // This makes sure assert is enabled even for release builds | ||
#endif // defined(NDEBUG) | ||
|
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.
Could this have unintended consequences?
No description provided.