Skip to content

Commit

Permalink
Revert "No inline for assertion (AMReX-Codes#1345)"
Browse files Browse the repository at this point in the history
This reverts commit 68c5d38.
  • Loading branch information
kweide authored Sep 28, 2020
1 parent 510e168 commit 3c9f8cb
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 85 deletions.
58 changes: 46 additions & 12 deletions Src/Base/AMReX.H
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <AMReX_GpuAssert.H>
#include <AMReX_ccse-mpi.H>
#include <AMReX_Exception.H>
#include <AMReX_Extension.H>
#include <AMReX_INT.H>
#include <AMReX_REAL.H>
#include <AMReX_Math.H>
Expand Down Expand Up @@ -97,29 +96,64 @@ namespace amrex

//! Print out message to cerr and exit via amrex::Abort().
void Error (const std::string& msg);

AMREX_GPU_EXTERNAL AMREX_GPU_HOST_DEVICE AMREX_NO_INLINE
void Error (const char * msg = 0);
namespace detail { void Error_host_doit (const char * msg); }
AMREX_GPU_HOST_DEVICE inline
void Error (const char * msg = 0) {
#if AMREX_DEVICE_COMPILE
if (msg) AMREX_DEVICE_PRINTF("Error %s\n", msg);
AMREX_DEVICE_ASSERT(0);
#else
detail::Error_host_doit(msg);
#endif
}

//! Print out warning message to cerr.
void Warning (const std::string& msg);

AMREX_GPU_EXTERNAL AMREX_GPU_HOST_DEVICE AMREX_NO_INLINE
void Warning (const char * msg);
namespace detail { void Warning_host_doit (const char * msg); }
AMREX_GPU_HOST_DEVICE inline
void Warning (const char * msg) {
#if AMREX_DEVICE_COMPILE
if (msg) AMREX_DEVICE_PRINTF("Warning %s\n", msg);
#else
detail::Warning_host_doit(msg);
#endif
}

//! Print out message to cerr and exit via abort().
void Abort (const std::string& msg);

AMREX_GPU_EXTERNAL AMREX_GPU_HOST_DEVICE AMREX_NO_INLINE
void Abort (const char * msg = 0);
namespace detail { void Abort_host_doit (const char * msg); }
AMREX_GPU_HOST_DEVICE inline
void Abort (const char * msg = 0) {
#if AMREX_DEVICE_COMPILE
if (msg) AMREX_DEVICE_PRINTF("Abort %s\n", msg);
AMREX_DEVICE_ASSERT(0);
#else
detail::Abort_host_doit(msg);
#endif
}

/**
* \brief Prints assertion failed messages to cerr and exits
* via abort(). Intended for use by the BL_ASSERT() macro
* in <AMReX_BLassert.H>.
*/
AMREX_GPU_EXTERNAL AMREX_GPU_HOST_DEVICE AMREX_NO_INLINE
void Assert (const char* EX, const char* file, int line, const char* msg = nullptr);
namespace detail { void Assert_host_doit (const char* EX, const char* file, int line,
const char* msg); }
AMREX_GPU_HOST_DEVICE inline
void Assert (const char* EX, const char* file, int line, const char* msg = nullptr) {
#if AMREX_DEVICE_COMPILE
if (msg) {
AMREX_DEVICE_PRINTF("Assertion `%s' failed, file \"%s\", line %d, Msg: %s",
EX, file, line, msg);
} else {
AMREX_DEVICE_PRINTF("Assertion `%s' failed, file \"%s\", line %d",
EX, file, line);
}
AMREX_DEVICE_ASSERT(0);
#else
detail::Assert_host_doit(EX, file, line, msg);
#endif
}

/**
* \brief This is used by amrex::Error(), amrex::Abort(), and amrex::Assert()
Expand Down
94 changes: 26 additions & 68 deletions Src/Base/AMReX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,10 @@ amrex::write_to_stderr_without_buffering (const char* str)
}
}

namespace {
// Having both host and device versions to avoid compiler warning
AMREX_GPU_HOST_DEVICE
static
void
write_lib_id(const char* msg)
{
#if AMREX_DEVICE_COMPILE
amrex::ignore_unused(msg);
#else
fflush(0);
const char* const s = "amrex::";
fwrite(s, strlen(s), 1, stderr);
Expand All @@ -165,73 +160,31 @@ write_lib_id(const char* msg)
fwrite(msg, strlen(msg), 1, stderr);
fwrite("::", 2, 1, stderr);
}
#endif
}
}

void
amrex::Error (const std::string& msg)
{
Error(msg.c_str());
}

void
amrex::Abort (const std::string& msg)
{
Abort(msg.c_str());
}

void
amrex::Warning (const std::string& msg)
{
Warning(msg.c_str());
}

AMREX_GPU_HOST_DEVICE
void
amrex::Error (const char * msg)
amrex::detail::Error_host_doit (const char* msg)
{
#if AMREX_DEVICE_COMPILE
if (msg) AMREX_DEVICE_PRINTF("Error %s\n", msg);
AMREX_DEVICE_ASSERT(0);
#else
if (system::error_handler) {
system::error_handler(msg);
} else if (system::throw_exception) {
throw RuntimeError(msg);
} else {
write_lib_id("Error");
write_to_stderr_without_buffering(msg);
#ifdef _OPENMP
#pragma omp critical (amrex_abort_omp_critical)
#endif
ParallelDescriptor::Abort();
}
#endif
}

AMREX_GPU_HOST_DEVICE
void
amrex::Warning (const char * msg)
amrex::Error (const std::string& msg)
{
#if AMREX_DEVICE_COMPILE
if (msg) AMREX_DEVICE_PRINTF("Warning %s\n", msg);
#else
if (msg)
{
amrex::Print(Print::AllProcs,amrex::ErrorStream()) << msg << '!' << '\n';
}
#endif
Error(msg.c_str());
}

AMREX_GPU_HOST_DEVICE
void
amrex::Abort (const char * msg)
amrex::detail::Abort_host_doit (const char* msg)
{
#if AMREX_DEVICE_COMPILE
if (msg) AMREX_DEVICE_PRINTF("Abort %s\n", msg);
AMREX_DEVICE_ASSERT(0);
#else
if (system::error_handler) {
system::error_handler(msg);
} else if (system::throw_exception) {
Expand All @@ -244,23 +197,32 @@ amrex::Abort (const char * msg)
#endif
ParallelDescriptor::Abort();
}
#endif
}

AMREX_GPU_HOST_DEVICE
void
amrex::Assert (const char* EX, const char* file, int line, const char* msg)
amrex::Abort (const std::string& msg)
{
#if AMREX_DEVICE_COMPILE
if (msg) {
AMREX_DEVICE_PRINTF("Assertion `%s' failed, file \"%s\", line %d, Msg: %s",
EX, file, line, msg);
} else {
AMREX_DEVICE_PRINTF("Assertion `%s' failed, file \"%s\", line %d",
EX, file, line);
Abort(msg.c_str());
}

void
amrex::detail::Warning_host_doit (const char* msg)
{
if (msg)
{
amrex::Print(Print::AllProcs,amrex::ErrorStream()) << msg << '!' << '\n';
}
AMREX_DEVICE_ASSERT(0);
#else
}

void
amrex::Warning (const std::string& msg)
{
Warning(msg.c_str());
}

void
amrex::detail::Assert_host_doit (const char* EX, const char* file, int line, const char* msg)
{
const int N = 512;

char buf[N];
Expand Down Expand Up @@ -288,12 +250,8 @@ amrex::Assert (const char* EX, const char* file, int line, const char* msg)
throw RuntimeError(buf);
} else {
write_to_stderr_without_buffering(buf);
#ifdef _OPENMP
#pragma omp critical (amrex_abort_omp_critical)
#endif
ParallelDescriptor::Abort();
}
#endif
}

namespace
Expand Down
2 changes: 1 addition & 1 deletion Src/Base/AMReX_Extension.H
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
#endif

// no inline
#if defined(__GNUC__) || defined(__clang__) || defined(__CUDACC__) || defined(__HIP__) || defined(__SYCL_COMPILER_VERSION)
#if defined(__GNUC__)
#define AMREX_NO_INLINE __attribute__((noinline))
#else
#define AMREX_NO_INLINE
Expand Down
6 changes: 2 additions & 4 deletions Src/Base/AMReX_GpuDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,13 +1043,11 @@ std::size_t
Device::freeMemAvailable ()
{
#ifdef AMREX_USE_GPU
std::size_t f;
#ifndef AMREX_USE_DPCPP
std::size_t t;
#endif
std::size_t f, t;
AMREX_HIP_OR_CUDA_OR_DPCPP( AMREX_HIP_SAFE_CALL(hipMemGetInfo(&f,&t));,
AMREX_CUDA_SAFE_CALL(cudaMemGetInfo(&f,&t));,
f = device_prop.totalGlobalMem; ); // xxxxx DPCPP todo
amrex::ignore_unused(t);
return f;
#else
return 0;
Expand Down

0 comments on commit 3c9f8cb

Please sign in to comment.