|
3 | 3 | // RUN: env SYCL_DEVICE_TYPE=GPU %t.out
|
4 | 4 | // RUN: env SYCL_DEVICE_TYPE=HOST %t.out
|
5 | 5 |
|
6 |
| - |
7 |
| -//==-------------- usm_free.cpp - SYCL USM free malloc_shared and free test -------------==// |
| 6 | +//==-------------- usm_free.cpp - SYCL USM free malloc_shared and free test |
| 7 | +//-------------==// |
8 | 8 | //
|
9 |
| -// This test checks if users will successfully allocate 160, 0, and -16 bytes of shared |
10 |
| -// memory, and also test user can call free() without worrying about nullptr or invalid |
11 |
| -// memory descriptor returned from malloc. |
| 9 | +// This test checks if users will successfully allocate 160, 0, and -16 bytes of |
| 10 | +// shared memory, and also test user can call free() without worrying about |
| 11 | +// nullptr or invalid memory descriptor returned from malloc. |
12 | 12 | //==-------------------------------------------------------------------------------------==//
|
13 | 13 |
|
14 | 14 | #include <CL/sycl.hpp>
|
15 | 15 | #include <iostream>
|
16 | 16 | #include <stdlib.h>
|
17 | 17 | using namespace cl::sycl;
|
18 | 18 |
|
19 |
| -int main(int argc, char * argv[]) { |
| 19 | +int main(int argc, char *argv[]) { |
20 | 20 | auto exception_handler = [](cl::sycl::exception_list exceptions) {
|
21 | 21 | for (std::exception_ptr const &e : exceptions) {
|
22 | 22 | try {
|
23 |
| - std::rethrow_exception(e); |
24 |
| - } |
25 |
| - catch (cl::sycl::exception const &e) { |
26 |
| - std::cout << "Caught asynchronous SYCL " |
27 |
| - "exception:\n" |
28 |
| - << e.what() << std::endl; |
| 23 | + std::rethrow_exception(e); |
| 24 | + } catch (cl::sycl::exception const &e) { |
| 25 | + std::cout << "Caught asynchronous SYCL " |
| 26 | + "exception:\n" |
| 27 | + << e.what() << std::endl; |
29 | 28 | }
|
30 | 29 | }
|
31 | 30 | };
|
32 | 31 |
|
33 | 32 | queue myQueue(default_selector{}, exception_handler);
|
34 | 33 | std::cout << "Device: " << myQueue.get_device().get_info<info::device::name>()
|
35 |
| - << std::endl; |
36 |
| - |
| 34 | + << std::endl; |
| 35 | + |
37 | 36 | double *ia = (double *)malloc_shared(160, myQueue);
|
38 | 37 | double *ja = (double *)malloc_shared(0, myQueue);
|
39 | 38 | double *result = (double *)malloc_shared(-16, myQueue);
|
40 | 39 |
|
41 |
| - std::cout << "ia : " << ia << " ja: " << ja << " result : " << result << std::endl; |
| 40 | + std::cout << "ia : " << ia << " ja: " << ja << " result : " << result |
| 41 | + << std::endl; |
42 | 42 |
|
43 | 43 | // followings should not throws CL_INVALID_VALUE
|
44 |
| - free(ia, myQueue); |
45 |
| - free(nullptr); |
46 |
| - free(ja, myQueue); |
47 |
| - free(result, myQueue); |
| 44 | + cl::sycl::free(ia, myQueue); |
| 45 | + cl::sycl::free(nullptr, myQueue); |
| 46 | + cl::sycl::free(ja, myQueue); |
| 47 | + cl::sycl::free(result, myQueue); |
48 | 48 |
|
49 | 49 | return 0;
|
50 | 50 | }
|
0 commit comments