Skip to content

Commit

Permalink
Merge pull request #246 from psalz/convert-id-tests-catch2
Browse files Browse the repository at this point in the history
  • Loading branch information
psalz authored Jan 31, 2022
2 parents 98481ef + 970fbc0 commit d4d5aaf
Show file tree
Hide file tree
Showing 7 changed files with 566 additions and 309 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# editorconfig.org

root = true

[*]
end_of_line = lf
insert_final_newline = true
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
kernel_args
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 @@ -17,10 +17,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) \
([=] { \
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; }); \
}) \
.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)

#endif // __SYCLCTS_TESTS_COMMON_DEVICE_EVAL_H
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
Loading

0 comments on commit d4d5aaf

Please sign in to comment.