forked from KhronosGroup/SYCL-CTS
/
usm_get_pointer_queries.cpp
87 lines (74 loc) · 2.76 KB
/
usm_get_pointer_queries.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
//
// SYCL 2020 Conformance Test Suite
//
// Provide verification to cooperation USM functions get_pointer_type and
// get_pointer_device with four memory allocation types: host, device, shared
// and non USM allocation.
//
*******************************************************************************/
#include "usm.h"
#include <cstring>
#define TEST_NAME usm_get_pointer_queries
namespace TEST_NAMESPACE {
using namespace sycl_cts;
template <sycl::usm::alloc alloc>
void run_check(const sycl::queue &queue, sycl_cts::util::logger &log) {
const auto &device{queue.get_device()};
const auto &context{queue.get_context()};
auto str_usm_alloc_type{usm::get_allocation_description<alloc>()};
if (device.has(usm::get_aspect<alloc>())) {
auto allocated_memory = usm::allocate_usm_memory<alloc, int>(queue);
const auto value = sycl::get_pointer_type(allocated_memory.get(), context);
if (alloc != value) {
FAIL(log, "sycl::get_pointer_type return " +
std::to_string(to_integral(value)) +
" type, expected sycl::usm::alloc::" +
std::string(str_usm_alloc_type) + " type");
}
if (sycl::get_pointer_device(allocated_memory.get(), context) != device) {
FAIL(log, "sycl::get_pointer_device return invalid device for " +
std::string(str_usm_alloc_type) + " type");
}
} else {
log.note("Device does not support " + std::string(str_usm_alloc_type) +
" allocation. Tests were skipped.");
}
}
/** Test instance
*/
class TEST_NAME : public sycl_cts::util::test_base {
public:
/** return information about this test
*/
void get_info(test_base::info &out) const override {
set_test_info(out, TOSTRING(TEST_NAME), TEST_FILE);
}
/** execute the test
*/
void run(util::logger &log) override {
try {
auto queue{util::get_cts_object::queue()};
{
int non_usm_allocated_memory{};
if (sycl::usm::alloc::unknown !=
sycl::get_pointer_type(&non_usm_allocated_memory,
queue.get_context())) {
FAIL(log,
"sycl::get_pointer_type return not sycl::usm::alloc::unknown "
"type");
}
}
run_check<sycl::usm::alloc::shared>(queue, log);
run_check<sycl::usm::alloc::device>(queue, log);
run_check<sycl::usm::alloc::host>(queue, log);
} catch (const cl::sycl::exception &e) {
log_exception(log, e);
auto errorMsg = "a SYCL exception was caught: " + std::string(e.what());
FAIL(log, errorMsg);
}
}
};
// construction of this proxy will register the above test
util::test_proxy<TEST_NAME> proxy;
} // namespace TEST_NAMESPACE