Loading...
Searching...
No Matches
Valgrind.hpp
Go to the documentation of this file.
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
#ifndef OPM_VALGRIND_HPP
#define OPM_VALGRIND_HPP
#if HAVE_VALGRIND
#include <valgrind/memcheck.h>
#endif
#include <opm/common/utility/gpuDecorators.hpp>
namespace Opm {
namespace Valgrind {
OPM_HOST_DEVICE inline bool IsRunning()
{
#if !defined NDEBUG && HAVE_VALGRIND && !OPM_IS_INSIDE_DEVICE_FUNCTION
return RUNNING_ON_VALGRIND;
#else
return false;
#endif
}
template <class T>
OPM_HOST_DEVICE inline bool CheckDefined([[maybe_unused]] const T& value)
{
#if !defined NDEBUG && HAVE_VALGRIND && !OPM_IS_INSIDE_DEVICE_FUNCTION
auto tmp = VALGRIND_CHECK_MEM_IS_DEFINED(&value, sizeof(T));
return tmp == 0;
#else
return true;
#endif
}
template <class T>
OPM_HOST_DEVICE inline bool CheckAddressable([[maybe_unused]] const T& value)
{
// if we run in debug mode AND we have valgrind AND we are NOT in a gpu function
#if !defined NDEBUG && HAVE_VALGRIND && !OPM_IS_INSIDE_DEVICE_FUNCTION
auto tmp = VALGRIND_CHECK_MEM_IS_ADDRESSABLE(&value, sizeof(T));
return tmp == 0;
#else
return true;
#endif
}
template <class T>
OPM_HOST_DEVICE inline bool CheckDefined([[maybe_unused]] const T* value,
[[maybe_unused]] int size)
{
#if !defined NDEBUG && HAVE_VALGRIND && !OPM_IS_INSIDE_DEVICE_FUNCTION
auto tmp = VALGRIND_CHECK_MEM_IS_DEFINED(value, size*sizeof(T));
return tmp == 0;
#else
return true;
#endif
}
template <class T>
OPM_HOST_DEVICE inline void SetUndefined([[maybe_unused]] const T& value)
{
#if !defined NDEBUG && HAVE_VALGRIND && !OPM_IS_INSIDE_DEVICE_FUNCTION
VALGRIND_MAKE_MEM_UNDEFINED(&value, sizeof(T));
#endif
}
template <class T>
OPM_HOST_DEVICE inline void SetUndefined([[maybe_unused]] const T* value,
[[maybe_unused]] int size)
{
#if !defined NDEBUG && HAVE_VALGRIND && !OPM_IS_INSIDE_DEVICE_FUNCTION
VALGRIND_MAKE_MEM_UNDEFINED(value, size*sizeof(T));
#endif
}
template <class T>
OPM_HOST_DEVICE inline void SetDefined([[maybe_unused]] const T& value)
{
#if !defined NDEBUG && HAVE_VALGRIND && !OPM_IS_INSIDE_DEVICE_FUNCTION
VALGRIND_MAKE_MEM_DEFINED(&value, sizeof(T));
#endif
}
template <class T>
OPM_HOST_DEVICE inline void SetDefined([[maybe_unused]] const T* value,
[[maybe_unused]] int n)
{
#if !defined NDEBUG && HAVE_VALGRIND && !OPM_IS_INSIDE_DEVICE_FUNCTION
VALGRIND_MAKE_MEM_DEFINED(value, n*sizeof(T));
#endif
}
template <class T>
OPM_HOST_DEVICE inline void SetNoAccess([[maybe_unused]] const T& value)
{
#if !defined NDEBUG && HAVE_VALGRIND && !OPM_IS_INSIDE_DEVICE_FUNCTION
VALGRIND_MAKE_MEM_NOACCESS(&value, sizeof(T));
#endif
}
template <class T>
OPM_HOST_DEVICE inline void SetNoAccess([[maybe_unused]] const T* value,
[[maybe_unused]] int size)
{
#if !defined NDEBUG && HAVE_VALGRIND && !OPM_IS_INSIDE_DEVICE_FUNCTION
VALGRIND_MAKE_MEM_NOACCESS(value, size*sizeof(T));
#endif
}
}} // namespace Valgrind, Opm
#endif
Opm::Valgrind::CheckAddressable
OPM_HOST_DEVICE bool CheckAddressable(const T &value)
Make valgrind complain if any of the memory occupied by an object is not addressable.
Definition Valgrind.hpp:108
Opm::Valgrind::IsRunning
OPM_HOST_DEVICE bool IsRunning()
Returns whether the program is running under Valgrind or not.
Definition Valgrind.hpp:42
Opm::Valgrind::SetDefined
OPM_HOST_DEVICE void SetDefined(const T &value)
Make the memory on which an object resides defined.
Definition Valgrind.hpp:225
Opm::Valgrind::SetUndefined
OPM_HOST_DEVICE void SetUndefined(const T &value)
Make the memory on which an object resides undefined in valgrind runs.
Definition Valgrind.hpp:174
Opm::Valgrind::CheckDefined
OPM_HOST_DEVICE bool CheckDefined(const T &value)
Make valgrind complain if any of the memory occupied by an object is undefined.
Definition Valgrind.hpp:76
Opm::Valgrind::SetNoAccess
OPM_HOST_DEVICE void SetNoAccess(const T &value)
Make valgrind complain if an object's memory is accessed.
Definition Valgrind.hpp:276
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30