@@ -17,47 +17,37 @@ Below is an example code that shows how to use ``oneapi::dpl::swap`` in SYCL dev
17
17
#include <oneapi/dpl/utility>
18
18
#include <sycl/sycl.hpp>
19
19
#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;
43
36
return 0;
44
37
}
45
38
46
39
Use the following command to build and run the program (assuming it resides in the ``kernel_swap.cpp file ``):
47
40
48
41
.. code :: cpp
49
42
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
53
44
54
45
The printed result is:
55
46
56
47
.. code :: cpp
57
48
58
- 4, 5
59
-
60
- 5, 4
49
+ Initial data: 4, 5
50
+ After swap: 5, 4
61
51
62
52
Tested Standard C++ API Reference
63
53
=================================
@@ -468,11 +458,11 @@ libstdc++ (GNU) Provided with GCC*-7.5.0, GCC*-9.3
468
458
libc++ (LLVM) Provided with Clang*-11.0
469
459
--------------------------------------------- ---------------------------------------------
470
460
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
472
462
Visual Studio 2022, version 17.0, preview 4.1.
473
-
463
+
474
464
.. Note::
475
-
465
+
476
466
Support for Microsoft Visual Studio 2017 is
477
467
deprecated as of the Intel® oneAPI 2022.1
478
468
release, and will be removed in a future
0 commit comments