-
Notifications
You must be signed in to change notification settings - Fork 789
[SYCL] get kernel info with free functions #18866
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
Merged
aelovikov-intel
merged 11 commits into
intel:sycl
from
dklochkov-emb:sycl-get-kernel-info-with-free-functions
Jun 17, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b645e04
[SYCL] add kernel info for free functions
dklochkov-emb df5717f
[SYCL] remove unnecessary changes
dklochkov-emb 9241e10
[SYCL] use free function traits for all new functions
dklochkov-emb f071293
[SYCL] fix syntax
dklochkov-emb 06d3b13
Merge remote-tracking branch 'upstream/sycl' into sycl-get-kernel-inf…
dklochkov-emb ac1020e
[SYCL] update error message in test
dklochkov-emb b1736fb
[SYCL] fix namespace
dklochkov-emb edc4310
[SYCL] add unsupported line into new tests
dklochkov-emb 800188d
[SYCL] do not duplicate namespaces and implementation
dklochkov-emb 688350a
[SYCL] add clang test of integration header with 2 properties
dklochkov-emb ae6c323
[SYCL] add xfail for cpu device
dklochkov-emb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,132 @@ | ||
// REQUIRES: aspect-usm_shared_allocations | ||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
|
||
// XFAIL: cpu | ||
// XFAIL-TRACKER: CMPLRLLVM-68536 | ||
// UNSUPPORTED: cuda, hip | ||
// UNSUPPORTED-INTENDED: Not implemented yet for Nvidia/AMD backends. | ||
|
||
#include <iostream> | ||
#include <sycl/ext/oneapi/free_function_queries.hpp> | ||
#include <sycl/ext/oneapi/get_kernel_info.hpp> | ||
#include <sycl/kernel_bundle.hpp> | ||
#include <sycl/usm.hpp> | ||
|
||
namespace syclext = sycl::ext::oneapi; | ||
namespace syclexp = sycl::ext::oneapi::experimental; | ||
|
||
static constexpr size_t NUM = 1024; | ||
static constexpr size_t WGSIZE = 16; | ||
|
||
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::work_group_size<WGSIZE>)) | ||
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<1>)) | ||
void func(float start, float *ptr) { | ||
size_t id = syclext::this_work_item::get_nd_item<1>().get_global_linear_id(); | ||
ptr[id] = start + static_cast<float>(id); | ||
} | ||
|
||
bool check_result(int *ptr) { | ||
for (size_t i = 0; i < NUM; ++i) { | ||
const int expected = 3 + static_cast<int>(i); | ||
if (ptr[i] != expected) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
static bool call_kernel_code(sycl::queue &q, sycl::kernel &kernel) { | ||
int *ptr = sycl::malloc_shared<int>(NUM, q); | ||
q.submit([&](sycl::handler &cgh) { | ||
cgh.set_args(3, ptr); | ||
sycl::nd_range ndr{{NUM}, {WGSIZE}}; | ||
cgh.parallel_for(ndr, kernel); | ||
}).wait(); | ||
const bool ret = check_result(ptr); | ||
sycl::free(ptr, q); | ||
return ret; | ||
} | ||
|
||
bool test_ctxt_dev(sycl::kernel &k, sycl::queue &q) { | ||
const auto wg_size_cmp = | ||
k.get_info<sycl::info::kernel_device_specific::work_group_size>( | ||
q.get_device()); | ||
const auto wg_size = syclexp::get_kernel_info< | ||
func, sycl::info::kernel_device_specific::work_group_size>( | ||
q.get_context(), q.get_device()); | ||
if (wg_size_cmp != wg_size) | ||
std::cerr << "Work group size from get_info: " << wg_size_cmp | ||
<< " is not equal to work group size from get_kernel_info: " | ||
<< wg_size << std::endl; | ||
return wg_size_cmp == wg_size; | ||
} | ||
|
||
bool test_ctxt(sycl::kernel &k, sycl::queue &q) { | ||
dklochkov-emb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const auto attributes = | ||
syclexp::get_kernel_info<func, sycl::info::kernel::attributes>( | ||
q.get_context()); | ||
const std::string wg_size_str = "work_group_size("; | ||
if (attributes.empty() || attributes.find(wg_size_str) == std::string::npos) { | ||
std::cerr << "Work group size attribute is not found in kernel attributes, " | ||
"attributes:" | ||
<< attributes << std::endl; | ||
return false; | ||
} | ||
auto wg_size_pos = attributes.find(wg_size_str); | ||
wg_size_pos += wg_size_str.size(); | ||
const auto comma_pos = attributes.find(',', wg_size_pos); | ||
if (comma_pos == std::string::npos) { | ||
std::cerr << "Comma not found in work group size attribute string" | ||
<< std::endl; | ||
return false; | ||
} | ||
|
||
const auto wg_size_str_value = | ||
attributes.substr(wg_size_pos, comma_pos - wg_size_pos); | ||
const size_t wg_size = std::stoul(wg_size_str_value); | ||
if (wg_size != WGSIZE) { | ||
std::cerr << "Work group size from attributes: " << wg_size | ||
<< " is not equal to expected work group size: " << WGSIZE | ||
<< std::endl; | ||
return false; | ||
} | ||
|
||
if (const auto wg_size_cmp = | ||
k.get_info<sycl::info::kernel_device_specific::work_group_size>( | ||
q.get_device()); | ||
wg_size_cmp < wg_size) { | ||
std::cerr << "Work group size from get_info: " << wg_size_cmp | ||
<< " is less work group size from attributes: " << wg_size | ||
<< std::endl; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool test_queue(sycl::kernel &k, sycl::queue &q) { | ||
const auto wg_size_cmp = | ||
k.get_info<sycl::info::kernel_device_specific::work_group_size>( | ||
q.get_device()); | ||
const auto wg_size = syclexp::get_kernel_info< | ||
func, sycl::info::kernel_device_specific::work_group_size>(q); | ||
if (wg_size_cmp != wg_size) | ||
std::cerr << "Work group size from get_info: " << wg_size_cmp | ||
<< " is not equal to work group size from get_kernel_info: " | ||
<< wg_size << std::endl; | ||
return wg_size_cmp == wg_size; | ||
} | ||
|
||
int main() { | ||
sycl::queue q; | ||
sycl::context ctxt = q.get_context(); | ||
|
||
auto exe_bndl = | ||
syclexp::get_kernel_bundle<func, sycl::bundle_state::executable>(ctxt); | ||
sycl::kernel k_func = exe_bndl.template ext_oneapi_get_kernel<func>(); | ||
call_kernel_code(q, k_func); | ||
|
||
bool ret = test_ctxt_dev(k_func, q); | ||
ret &= test_ctxt(k_func, q); | ||
ret &= test_queue(k_func, q); | ||
return ret ? 0 : 1; | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.