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