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
Add new test for get_pointer_type and get_pointer_device USM API #131
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
15e506b
Add new test for get_pointer_type and get_pointer_device USM API
vasilytric bf245b8
Fix misprint in usm.h
vasilytric de3b975
Update usm.h file
vasilytric 99e4bde
Add constexpr to get_allocation_description() function's return type
vasilytric 684a2ec
Improve "static_assert" expression
vasilytric 22fe375
Revert "Improve "static_assert" expression"
vasilytric File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/******************************************************************************* | ||
// | ||
// SYCL 2020 Conformance Test Suite | ||
// | ||
// Common code for USM tests | ||
// | ||
*******************************************************************************/ | ||
|
||
#ifndef __SYCL_CTS_TEST_USM_USM_H | ||
#define __SYCL_CTS_TEST_USM_USM_H | ||
|
||
#include "../common/common.h" | ||
#include <memory> | ||
#include <string_view> | ||
|
||
namespace usm { | ||
|
||
/** @brief Return std::unique_ptr with allocated USM object | ||
* @tparam USM allocation type | ||
* @param queue sycl::queue class object | ||
*/ | ||
template <sycl::usm::alloc alloc, typename elems_typeT> | ||
auto allocate_usm_memory(const sycl::queue &queue, size_t num_elements = 1) { | ||
const auto &device{queue.get_device()}; | ||
const auto &context{queue.get_context()}; | ||
|
||
auto deleter = [=](elems_typeT *ptr) { sycl::free(ptr, context); }; | ||
|
||
if constexpr (alloc == sycl::usm::alloc::shared) { | ||
std::unique_ptr<elems_typeT, decltype(deleter)> usm_memory( | ||
sycl::malloc_shared<elems_typeT>(num_elements, device, context), | ||
deleter); | ||
return usm_memory; | ||
} else if constexpr (alloc == sycl::usm::alloc::device) { | ||
std::unique_ptr<elems_typeT, decltype(deleter)> usm_memory( | ||
sycl::malloc_device<elems_typeT>(num_elements, queue), deleter); | ||
return usm_memory; | ||
} else if constexpr (alloc == sycl::usm::alloc::host) { | ||
std::unique_ptr<elems_typeT, decltype(deleter)> usm_memory( | ||
sycl::malloc_host<elems_typeT>(num_elements, context), deleter); | ||
return usm_memory; | ||
} else { | ||
static_assert(alloc != alloc, "Unknown USM allocation type"); | ||
} | ||
}; | ||
|
||
/** @brief Returns an aspect depending on the type of allocated memory | ||
* @tparam alloc USM allocation type | ||
* @retval SYCL aspect that corresponds to allocated memory | ||
*/ | ||
template <const sycl::usm::alloc alloc> | ||
constexpr auto get_aspect() { | ||
if constexpr (alloc == sycl::usm::alloc::shared) { | ||
return sycl::aspect::usm_shared_allocations; | ||
} else if constexpr (alloc == sycl::usm::alloc::device) { | ||
return sycl::aspect::usm_device_allocations; | ||
} else if constexpr (alloc == sycl::usm::alloc::host) { | ||
return sycl::aspect::usm_host_allocations; | ||
} else { | ||
static_assert(alloc != alloc, "Unknown USM allocation type"); | ||
} | ||
} | ||
|
||
/** @brief Return string's description depending on the type of allocated memory | ||
* @tparam alloc USM allocation type | ||
* @retval String description of allocated memory | ||
*/ | ||
template <sycl::usm::alloc alloc> | ||
constexpr std::string_view get_allocation_description() { | ||
if constexpr (alloc == sycl::usm::alloc::shared) { | ||
return "shared"; | ||
} else if constexpr (alloc == sycl::usm::alloc::device) { | ||
return "device"; | ||
} else if constexpr (alloc == sycl::usm::alloc::host) { | ||
return "host"; | ||
} else { | ||
static_assert(alloc != alloc, "Unknown USM allocation type"); | ||
} | ||
} | ||
|
||
} // namespace usm | ||
|
||
#endif // __SYCL_CTS_TEST_USM_USM_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this to have a dependent
static_assert
to avoid triggering withfalse
independently from theif constexpr
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If i correctly understood you.
We using
static_assert
here to interrupt compilation if test developer try to allocate memory from non USM allocation type (here we using all available allocation types from SYCL2020 spec section #4.8.2. "Kinds of unified shared memory")There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My question was about
that you cannot probably use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that good decision, thanks for your advice
This change was made in: 684a2ec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@keryell @vasilytric I assume 684a2ec will break compilation due non-conditional static_assert. See SO thread for details
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@keryell Yes,
static_assert(false, "Unknown USM allocation type");
cannot be used