Skip to content

Commit

Permalink
test: extent ALPAKA_CHECK to show better error messages
Browse files Browse the repository at this point in the history
To know where a test fails the line and file can be very usefull.
  • Loading branch information
psychocoderHPC committed Jul 29, 2022
1 parent 0b96515 commit 2ee4cdf
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions include/alpaka/test/Check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,39 @@

#pragma once

#include <alpaka/core/BoostPredef.hpp>

#include <cstdio>

// TODO: SYCL doesn't have a way to detect if we're looking at device or host code. This needs a workaround so that
// SYCL and other back-ends are compatible.
#ifdef ALPAKA_ACC_SYCL_ENABLED
# define ALPAKA_CHECK(success, expression) \
# define ALPAKA_CHECK_DO(file, line, success, expression) \
do \
{ \
if(!(expression)) \
{ \
acc.cout << "ALPAKA_CHECK failed because '!(" << #expression << ")'\n"; \
acc.cout << "ALPAKA_CHECK failed because '!(" << #expression << ")' in " << file << ":" << line \
<< "\n"; \
success = false; \
} \
} while(0)
#else
# define ALPAKA_CHECK(success, expression) \
# define ALPAKA_CHECK_DO(file, line, success, expression) \
do \
{ \
if(!(expression)) \
{ \
printf("ALPAKA_CHECK failed because '!(%s)'\n", #expression); \
printf("ALPAKA_CHECK failed because '!(%s)' in %s:%d\n", #expression, file, line); \
success = false; \
} \
} while(0)
#endif

#if BOOST_LANG_HIP == BOOST_VERSION_NUMBER(4, 5, 0)
// Do not forward the file name to avoid the compiler crashes with: "error: stack size limit exceeded (181056) in
// _ZN6alpaka16uniform_cuda_hip..."
# define ALPAKA_CHECK(success, expression) ALPAKA_CHECK_DO("unknown", __LINE__, success, expression)
#else
# define ALPAKA_CHECK(success, expression) ALPAKA_CHECK_DO(__FILE__, __LINE__, success, expression)
#endif

0 comments on commit 2ee4cdf

Please sign in to comment.