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

Modernize Tested API example, replace cl_int #2008

Merged
merged 5 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,37 @@ Below is an example code that shows how to use ``oneapi::dpl::swap`` in SYCL dev
#include <oneapi/dpl/utility>
#include <sycl/sycl.hpp>
#include <iostream>
constexpr sycl::access::mode sycl_read_write = sycl::access::mode::read_write;
class KernelSwap;
void kernel_test() {
sycl::queue deviceQueue;
sycl::range<1> numOfItems{2};
sycl::cl_int swap_num[2] = {4, 5};
std::cout << swap_num[0] << ", " << swap_num[1] << std::endl;
{
sycl::buffer<sycl::cl_int, 1> swap_buffer
(swap_num, numOfItems);
deviceQueue.submit([&](sycl::handler &cgh) {
auto swap_accessor = swap_buffer.get_access<sycl_read_write>(cgh);
cgh.single_task<class KernelSwap>([=]() {
int & num1 = swap_accessor[0];
int & num2 = swap_accessor[1];
oneapi::dpl::swap(num1, num2);
});
});
}
std::cout << swap_num[0] << ", " << swap_num[1] << std::endl;
}
int main() {
kernel_test();
#include <cstdint>
int main()
{
sycl::queue queue;
constexpr std::uint32_t size = 2;
std::uint32_t data[size] = {4, 5};
std::cout << "Initial data: " << data[0] << ", " << data[1] << std::endl;
sycl::buffer<std::uint32_t> buffer(data, size);
queue.submit([&](sycl::handler& cgh) {
auto access = buffer.get_access(cgh, sycl::read_write);
cgh.single_task<class KernelSwap>([=]() {
oneapi::dpl::swap(access[0], access[1]);
});
}).wait();
auto host_access = buffer.get_host_access(sycl::read_only);
std::cout << "After swap: " << host_access[0] << ", " << host_access[1] << std::endl;
return 0;
}

Use the following command to build and run the program (assuming it resides in the ``kernel_swap.cpp file``):

.. code:: cpp

dpcpp kernel_swap.cpp -o kernel_swap.exe

./kernel_swap.exe
icpx -fsycl kernel_swap.cpp -o kernel_swap && ./kernel_swap

The printed result is:

.. code:: cpp

4, 5

5, 4
Initial data: 4, 5
After swap: 5, 4

Tested Standard C++ API Reference
=================================
Expand Down Expand Up @@ -468,11 +458,11 @@ libstdc++ (GNU) Provided with GCC*-7.5.0, GCC*-9.3
libc++ (LLVM) Provided with Clang*-11.0
--------------------------------------------- ---------------------------------------------
Microsoft Visual C++* (MSVC) Standard Library Provided with Microsoft Visual Studio* 2017;
Microsoft Visual Studio 2019; and Microsoft
Microsoft Visual Studio 2019; and Microsoft
Visual Studio 2022, version 17.0, preview 4.1.

.. Note::

Support for Microsoft Visual Studio 2017 is
deprecated as of the Intel® oneAPI 2022.1
release, and will be removed in a future
Expand Down
10 changes: 6 additions & 4 deletions test/xpu_api/language.support/support.types/nullptr_t.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
#include "support/test_macros.h"
#include "support/utils.h"

#include <cstdint>

struct A
{
A(dpl::nullptr_t) {}
};

template <class T>
void
test_conversions(cl_int& i)
test_conversions(std::int32_t& i)
{
{
T p = 0;
Expand Down Expand Up @@ -65,7 +67,7 @@ struct has_less<T, typename Voider<decltype(std::declval<T>() < nullptr)>::type>

template <class T>
void
test_comparisons(cl_int& i)
test_comparisons(std::int32_t& i)
{
T p = nullptr;
i += (p == nullptr);
Expand All @@ -79,7 +81,7 @@ test_comparisons(cl_int& i)
# pragma clang diagnostic ignored "-Wnull-conversion"
#endif
void
test_nullptr_conversions(cl_int& i)
test_nullptr_conversions(std::int32_t& i)
{
// GCC does not accept this due to CWG Defect #1423
// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1423
Expand All @@ -106,7 +108,7 @@ main()
cgh.single_task<class KernelTest1>([=]() {
static_assert(sizeof(dpl::nullptr_t) == sizeof(void*), "sizeof(dpl::nullptr_t) == sizeof(void*)");

cl_int i = 0;
std::int32_t i = 0;
{
test_conversions<dpl::nullptr_t>(i);
test_conversions<void*>(i);
Expand Down
Loading