Skip to content

Commit 2e31d5c

Browse files
Modernize Tested API example, replace cl_int (#2008)
1 parent e945898 commit 2e31d5c

File tree

2 files changed

+28
-36
lines changed

2 files changed

+28
-36
lines changed

documentation/library_guide/api_for_sycl_kernels/tested_standard_cpp_api.rst

+22-32
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,37 @@ Below is an example code that shows how to use ``oneapi::dpl::swap`` in SYCL dev
1717
#include <oneapi/dpl/utility>
1818
#include <sycl/sycl.hpp>
1919
#include <iostream>
20-
constexpr sycl::access::mode sycl_read_write = sycl::access::mode::read_write;
21-
class KernelSwap;
22-
void kernel_test() {
23-
sycl::queue deviceQueue;
24-
sycl::range<1> numOfItems{2};
25-
sycl::cl_int swap_num[2] = {4, 5};
26-
std::cout << swap_num[0] << ", " << swap_num[1] << std::endl;
27-
{
28-
sycl::buffer<sycl::cl_int, 1> swap_buffer
29-
(swap_num, numOfItems);
30-
deviceQueue.submit([&](sycl::handler &cgh) {
31-
auto swap_accessor = swap_buffer.get_access<sycl_read_write>(cgh);
32-
cgh.single_task<class KernelSwap>([=]() {
33-
int & num1 = swap_accessor[0];
34-
int & num2 = swap_accessor[1];
35-
oneapi::dpl::swap(num1, num2);
36-
});
37-
});
38-
}
39-
std::cout << swap_num[0] << ", " << swap_num[1] << std::endl;
40-
}
41-
int main() {
42-
kernel_test();
20+
#include <cstdint>
21+
int main()
22+
{
23+
sycl::queue queue;
24+
constexpr std::uint32_t size = 2;
25+
std::uint32_t data[size] = {4, 5};
26+
std::cout << "Initial data: " << data[0] << ", " << data[1] << std::endl;
27+
sycl::buffer<std::uint32_t> buffer(data, size);
28+
queue.submit([&](sycl::handler& cgh) {
29+
auto access = buffer.get_access(cgh, sycl::read_write);
30+
cgh.single_task<class KernelSwap>([=]() {
31+
oneapi::dpl::swap(access[0], access[1]);
32+
});
33+
}).wait();
34+
auto host_access = buffer.get_host_access(sycl::read_only);
35+
std::cout << "After swap: " << host_access[0] << ", " << host_access[1] << std::endl;
4336
return 0;
4437
}
4538
4639
Use the following command to build and run the program (assuming it resides in the ``kernel_swap.cpp file``):
4740

4841
.. code:: cpp
4942
50-
dpcpp kernel_swap.cpp -o kernel_swap.exe
51-
52-
./kernel_swap.exe
43+
icpx -fsycl kernel_swap.cpp -o kernel_swap && ./kernel_swap
5344
5445
The printed result is:
5546

5647
.. code:: cpp
5748
58-
4, 5
59-
60-
5, 4
49+
Initial data: 4, 5
50+
After swap: 5, 4
6151
6252
Tested Standard C++ API Reference
6353
=================================
@@ -468,11 +458,11 @@ libstdc++ (GNU) Provided with GCC*-7.5.0, GCC*-9.3
468458
libc++ (LLVM) Provided with Clang*-11.0
469459
--------------------------------------------- ---------------------------------------------
470460
Microsoft Visual C++* (MSVC) Standard Library Provided with Microsoft Visual Studio* 2017;
471-
Microsoft Visual Studio 2019; and Microsoft
461+
Microsoft Visual Studio 2019; and Microsoft
472462
Visual Studio 2022, version 17.0, preview 4.1.
473-
463+
474464
.. Note::
475-
465+
476466
Support for Microsoft Visual Studio 2017 is
477467
deprecated as of the Intel® oneAPI 2022.1
478468
release, and will be removed in a future

test/xpu_api/language.support/support.types/nullptr_t.pass.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@
2626
#include "support/test_macros.h"
2727
#include "support/utils.h"
2828

29+
#include <cstdint>
30+
2931
struct A
3032
{
3133
A(dpl::nullptr_t) {}
3234
};
3335

3436
template <class T>
3537
void
36-
test_conversions(cl_int& i)
38+
test_conversions(std::int32_t& i)
3739
{
3840
{
3941
T p = 0;
@@ -65,7 +67,7 @@ struct has_less<T, typename Voider<decltype(std::declval<T>() < nullptr)>::type>
6567

6668
template <class T>
6769
void
68-
test_comparisons(cl_int& i)
70+
test_comparisons(std::int32_t& i)
6971
{
7072
T p = nullptr;
7173
i += (p == nullptr);
@@ -79,7 +81,7 @@ test_comparisons(cl_int& i)
7981
# pragma clang diagnostic ignored "-Wnull-conversion"
8082
#endif
8183
void
82-
test_nullptr_conversions(cl_int& i)
84+
test_nullptr_conversions(std::int32_t& i)
8385
{
8486
// GCC does not accept this due to CWG Defect #1423
8587
// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1423
@@ -106,7 +108,7 @@ main()
106108
cgh.single_task<class KernelTest1>([=]() {
107109
static_assert(sizeof(dpl::nullptr_t) == sizeof(void*), "sizeof(dpl::nullptr_t) == sizeof(void*)");
108110

109-
cl_int i = 0;
111+
std::int32_t i = 0;
110112
{
111113
test_conversions<dpl::nullptr_t>(i);
112114
test_conversions<void*>(i);

0 commit comments

Comments
 (0)