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

Conversation

davidbeckingsale
Copy link
Member

No description provided.

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

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

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

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

@@ -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_*

@@ -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_

@@ -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
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'm not clear on the benefit of the extra file? These tests can just be guarded in the main file.

Copy link
Contributor

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.

Copy link
Member Author

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

@rrsettgast rrsettgast force-pushed the feature/CHAI-44-debug-range-check branch from 7d63c8d to a0a6664 Compare June 14, 2018 23:08
@rrsettgast rrsettgast force-pushed the feature/CHAI-44-debug-range-check branch from 46a1fa5 to f38337d Compare June 15, 2018 00:10
@davidbeckingsale
Copy link
Member Author

I think this is looking good, but Im not sure why the nvcc builds are failing...

Does this build locally for you?

@rrsettgast
Copy link
Contributor

@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 )
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 an option at the top of the CMakeLists file.

Copy link
Member

Choose a reason for hiding this comment

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

Fixed.

@adayton1
Copy link
Member

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.

@davidbeckingsale
Copy link
Member Author

@adayton1 - give it a whirl and let me know 😄

@artv3
Copy link
Member

artv3 commented Sep 16, 2019

@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)

Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants