|
| 1 | +// REQUIRES: level_zero |
| 2 | +// TODO: ZE_DEBUG=4 produces no output on Windows. Enable when fixed. |
| 3 | +// UNSUPPORTED: windows |
| 4 | + |
| 5 | +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out |
| 6 | + |
| 7 | +// RUN: env ZE_DEBUG=4 %GPU_RUN_PLACEHOLDER %t.out u 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-USM |
| 8 | +// RUN: env ZE_DEBUG=4 %GPU_RUN_PLACEHOLDER %t.out s 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-SMALL-BUF |
| 9 | +// RUN: env ZE_DEBUG=4 %GPU_RUN_PLACEHOLDER %t.out l 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-LARGE-BUF |
| 10 | + |
| 11 | +#include <CL/sycl.hpp> |
| 12 | +using namespace sycl; |
| 13 | + |
| 14 | +#include <array> |
| 15 | +#include <iostream> |
| 16 | + |
| 17 | +void direct_usm(queue &Q) { |
| 18 | + auto p1 = malloc_shared(1024, Q); |
| 19 | + auto p2 = malloc_host(1024, Q); |
| 20 | + auto p3 = malloc_device(1024, Q); |
| 21 | +} |
| 22 | + |
| 23 | +template <typename T> class K; |
| 24 | + |
| 25 | +template <typename T, size_t N> void sycl_buffer(queue &Q) { |
| 26 | + std::array<T, N> A, B, C; |
| 27 | + range<1> numElems{N}; |
| 28 | + buffer<T, 1> bufferA(A.data(), numElems); |
| 29 | + buffer<T, 1> bufferB(B.data(), numElems); |
| 30 | + buffer<T, 1> bufferC(C.data(), numElems); |
| 31 | + |
| 32 | + Q.submit([&](handler &cgh) { |
| 33 | + accessor accA{bufferA, cgh, read_only}; |
| 34 | + accessor accB{bufferB, cgh, read_only}; |
| 35 | + accessor accC{bufferC, cgh, write_only}; |
| 36 | + |
| 37 | + cgh.parallel_for<class K<T>>(numElems, |
| 38 | + [=](id<1> wiID) { |
| 39 | + accC[wiID] = accA[wiID] + accB[wiID]; |
| 40 | + }); |
| 41 | + }); |
| 42 | +} |
| 43 | + |
| 44 | +int main(int argc, char *argv[]) { |
| 45 | + if (argc != 2) |
| 46 | + return 1; |
| 47 | + |
| 48 | + queue Queue; |
| 49 | + auto D = Queue.get_device(); |
| 50 | + if (D.get_info<info::device::host_unified_memory>()) |
| 51 | + std::cerr << "Integrated GPU will use zeMemAllocHost\n"; |
| 52 | + else |
| 53 | + std::cerr << "Discrete GPU will use zeMemAllocDevice\n"; |
| 54 | + |
| 55 | + if (argv[1][0] == 'u') { |
| 56 | + // Try USM APIs |
| 57 | + // This will generate one each of zeMemAllocHost/Device/Shared |
| 58 | + std::cerr << "Direct USM\n"; |
| 59 | + direct_usm(Queue); |
| 60 | + } |
| 61 | + if (argv[1][0] == 's') { |
| 62 | + // Try small buffers |
| 63 | + // This will generate one zeMemAllocHost on Integrated or one |
| 64 | + // zeMemAllocDevice on Discrete GPU |
| 65 | + std::cerr << "Small buffers\n"; |
| 66 | + sycl_buffer<int, 4>(Queue); |
| 67 | + } |
| 68 | + if (argv[1][0] == 'l') { |
| 69 | + // Try large buffers |
| 70 | + // This will generate three zeMemAllocHost on Integrated or three |
| 71 | + // zeMemAllocDevice on Discrete GPU |
| 72 | + std::cerr << "Large buffers\n"; |
| 73 | + sycl_buffer<long, 10000>(Queue); |
| 74 | + } |
| 75 | + |
| 76 | + return 0; |
| 77 | +} |
| 78 | + |
| 79 | +// CHECK-USM: GPU will use {{zeMemAllocHost|zeMemAllocDevice}} |
| 80 | +// CHECK-USM: zeMemAllocDevice = 1 |
| 81 | +// CHECK-USM: zeMemAllocHost = 1 |
| 82 | +// CHECK-USM: zeMemAllocShared = 1 |
| 83 | +// CHECK-USM-SAME: zeMemFree = 3 |
| 84 | + |
| 85 | +// CHECK-SMALL-BUF: GPU will use [[API:zeMemAllocHost|zeMemAllocDevice]] |
| 86 | +// CHECK-SMALL-BUF: [[API]] = 1 |
| 87 | +// CHECK-SMALL-BUF: zeMemFree = 1 |
| 88 | + |
| 89 | +// CHECK-LARGE-BUF: GPU will use [[API:zeMemAllocHost|zeMemAllocDevice]] |
| 90 | +// CHECK-LARGE-BUF: [[API]] = 3 |
| 91 | +// CHECK-LARGE-BUF: zeMemFree = 3 |
0 commit comments