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

Convert id tests to Catch2, update for SYCL 2020 #246

Merged
merged 6 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions ci/computecpp.filter
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exceptions
group
hierarchical
host_task
id
image
kernel
math_builtin_api
Expand Down
1 change: 0 additions & 1 deletion ci/dpcpp.filter
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ buffer
exceptions
handler
hierarchical
id
invoke
item
math_builtin_api
Expand Down
10 changes: 6 additions & 4 deletions tests/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SYCL 2020 Conformance Test Suite
//
// Copyright (c) 2020-2021 The Khronos Group Inc.
// Copyright (c) 2020-2022 The Khronos Group Inc.
// Copyright: (c) 2017 by Codeplay Software LTD. All Rights Reserved.
//
*******************************************************************************/
Expand All @@ -18,10 +18,12 @@
#include "../../util/math_vector.h"
#include "../../util/proxy.h"
#include "../../util/test_base.h"
#include "../common/cts_async_handler.h"
#include "../common/cts_selector.h"
#include "../common/get_cts_object.h"

#include "cts_async_handler.h"
#include "cts_selector.h"
#include "get_cts_object.h"
#include "macros.h"
#include "string_makers.h"

#include <cinttypes>
#include <numeric>
Expand Down
36 changes: 36 additions & 0 deletions tests/common/device_eval.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*******************************************************************************
//
// SYCL 2020 Conformance Test Suite
//
// Copyright (c) 2022 The Khronos Group Inc.
//
*******************************************************************************/

#ifndef __SYCLCTS_TESTS_COMMON_DEVICE_EVAL_H
#define __SYCLCTS_TESTS_COMMON_DEVICE_EVAL_H

#include <sycl/sycl.hpp>

#define DEVICE_EVAL_T(T, expr) \
([=]() { \
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
([=]() { \
([=] { \

sycl::buffer<std::decay_t<T>, 1> result_buf{1}; \
sycl_cts::util::get_cts_object::queue() \
.submit([=, &result_buf](sycl::handler& cgh) { \
sycl::accessor result{result_buf, cgh, sycl::write_only}; \
cgh.single_task([=]() { result[0] = expr; }); \
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
cgh.single_task([=]() { result[0] = expr; }); \
cgh.single_task([=] { result[0] = expr; }); \

}) \
.wait_and_throw(); \
sycl::host_accessor acc{result_buf, sycl::read_only}; \
return acc[0]; \
})()

/**
* Evaluates a given expression on the SYCL device and returns the result.
*
* Limitations:
* - Operands must exist in surrounding scope ([=] capture).
* - No lambda expressions (requires C++20). Use DEVICE_EVAL_T instead.
*/
#define DEVICE_EVAL(expr) DEVICE_EVAL_T(decltype(expr), expr)
Copy link
Member

Choose a reason for hiding this comment

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

Why using macros DEVICE_EVAL_T or DEVICE_EVAL at the first place instead of functions or lambdas?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what you mean, how would I pass an unevaluated expression into a function/lambda?

Copy link
Member

Choose a reason for hiding this comment

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

I see: no C++20. :-(


#endif // __SYCLCTS_TESTS_COMMON_DEVICE_EVAL_H
Copy link
Member

Choose a reason for hiding this comment

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

Missing EOL

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've added an .editorconfig file with the appropriate setting.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting https://editorconfig.org/
I didn't know about it.

35 changes: 35 additions & 0 deletions tests/common/string_makers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
//
// SYCL 2020 Conformance Test Suite
//
// Copyright (c) 2022 The Khronos Group Inc.
//
*******************************************************************************/

#ifndef __SYCLCTS_TESTS_COMMON_STRING_MAKERS_H
#define __SYCLCTS_TESTS_COMMON_STRING_MAKERS_H

#include <sstream>

#include <catch2/catch_tostring.hpp>
#include <sycl/sycl.hpp>

namespace Catch {
template <int Dimensions>
struct StringMaker<sycl::id<Dimensions>> {
static std::string convert(const sycl::id<Dimensions>& id) {
std::stringstream ss;
ss << "{";
for (int d = 0; d < Dimensions; ++d) {
ss << id[d];
if (d != Dimensions - 1) {
ss << ", ";
}
}
ss << "}";
return ss.str();
}
};
} // namespace Catch

#endif // __SYCLCTS_TESTS_COMMON_STRING_MAKERS_H
Copy link
Member

Choose a reason for hiding this comment

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

Missing EOL

Loading