|
| 1 | +// RUN: %clangxx -fsycl %s -o %t1.out |
| 2 | +// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out |
| 3 | +// RUN: %CPU_RUN_PLACEHOLDER %t1.out |
| 4 | +// RUN: %GPU_RUN_PLACEHOLDER %t1.out |
| 5 | + |
| 6 | +//==-------------- pointer_query.cpp - Pointer Query test ------------------==// |
| 7 | +// |
| 8 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 9 | +// See https://llvm.org/LICENSE.txt for license information. |
| 10 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 11 | +// |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +#include <CL/sycl.hpp> |
| 15 | + |
| 16 | +using namespace cl::sycl; |
| 17 | + |
| 18 | +int main() { |
| 19 | + int *array = nullptr; |
| 20 | + const int N = 4; |
| 21 | + queue q; |
| 22 | + auto dev = q.get_device(); |
| 23 | + auto ctxt = q.get_context(); |
| 24 | + |
| 25 | + if (!(dev.get_info<info::device::usm_device_allocations>() && |
| 26 | + dev.get_info<info::device::usm_shared_allocations>() && |
| 27 | + dev.get_info<info::device::usm_host_allocations>())) |
| 28 | + return 0; |
| 29 | + |
| 30 | + usm::alloc Kind; |
| 31 | + device D; |
| 32 | + |
| 33 | + // Test device allocs |
| 34 | + array = (int *)malloc_device(N * sizeof(int), q); |
| 35 | + if (array == nullptr) { |
| 36 | + return 1; |
| 37 | + } |
| 38 | + Kind = get_pointer_type(array, ctxt); |
| 39 | + if (ctxt.is_host()) { |
| 40 | + // for now, host device treats all allocations |
| 41 | + // as host allocations |
| 42 | + if (Kind != usm::alloc::host) { |
| 43 | + return 2; |
| 44 | + } |
| 45 | + } else { |
| 46 | + if (Kind != usm::alloc::device) { |
| 47 | + return 3; |
| 48 | + } |
| 49 | + } |
| 50 | + D = get_pointer_device(array, ctxt); |
| 51 | + if (D != dev) { |
| 52 | + return 4; |
| 53 | + } |
| 54 | + free(array, ctxt); |
| 55 | + |
| 56 | + // Test shared allocs |
| 57 | + array = (int *)malloc_shared(N * sizeof(int), q); |
| 58 | + if (array == nullptr) { |
| 59 | + return 5; |
| 60 | + } |
| 61 | + Kind = get_pointer_type(array, ctxt); |
| 62 | + if (ctxt.is_host()) { |
| 63 | + // for now, host device treats all allocations |
| 64 | + // as host allocations |
| 65 | + if (Kind != usm::alloc::host) { |
| 66 | + return 6; |
| 67 | + } |
| 68 | + } else { |
| 69 | + if (Kind != usm::alloc::shared) { |
| 70 | + return 7; |
| 71 | + } |
| 72 | + } |
| 73 | + D = get_pointer_device(array, ctxt); |
| 74 | + if (D != dev) { |
| 75 | + return 8; |
| 76 | + } |
| 77 | + free(array, ctxt); |
| 78 | + |
| 79 | + // Test host allocs |
| 80 | + array = (int *)malloc_host(N * sizeof(int), q); |
| 81 | + if (array == nullptr) { |
| 82 | + return 9; |
| 83 | + } |
| 84 | + Kind = get_pointer_type(array, ctxt); |
| 85 | + if (Kind != usm::alloc::host) { |
| 86 | + return 10; |
| 87 | + } |
| 88 | + D = get_pointer_device(array, ctxt); |
| 89 | + if (!D.is_host()) { |
| 90 | + return 11; |
| 91 | + } |
| 92 | + free(array, ctxt); |
| 93 | + |
| 94 | + return 0; |
| 95 | +} |
0 commit comments