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

test: extend ALPAKA_CHECK to show better error messages #1770

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions include/alpaka/test/Check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,46 @@

#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(printMsg, 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"; \
Comment on lines +24 to +25
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
acc.cout << "ALPAKA_CHECK failed because '!(" << #expression << ")' in " << file << ":" << line \
<< "\n"; \
acc.cout << "ALPAKA_CHECK failed because '!(" << #expression << ")' in " << __FILE__<< ":" << __LINE__\
<< "\n"; \

You should be able to use the file and line macros directly inside the macro definition and not pass them around.

success = false; \
} \
} while(0)
#else
# define ALPAKA_CHECK(success, expression) \
# define ALPAKA_CHECK_DO(printMsg, 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)
// disable message print to avoid compiler error: 'error: stack size limit exceeded (181896) in _ZN6alpaka...'
# define ALPAKA_CHECK(printMsg, file, line, success, expression) \
do \
{ \
if(!(expression)) \
{ \
printf("ALPAKA_CHECK failed because '!(%s)' in %s:%d\n", #expression, file, line); \
bernhardmgruber marked this conversation as resolved.
Show resolved Hide resolved
success = false; \
} \
} while(0)
#else
# define ALPAKA_CHECK(success, expression) ALPAKA_CHECK_DO(__FILE__, __LINE__, success, expression)
#endif