|
| 1 | +// REQUIRES: level_zero || cuda, gpu |
| 2 | +// RUN: %{build} -o %t.out |
| 3 | +// RUN: %{run} %t.out |
| 4 | +// Extra run to check for leaks in Level Zero using UR_L0_LEAKS_DEBUG |
| 5 | +// RUN: %if level_zero %{env SYCL_PI_LEVEL_ZERO_USE_IMMEDIATE_COMMANDLISTS=0 %{l0_leak_check} %{run} %t.out 2>&1 | FileCheck %s --implicit-check-not=LEAK %} |
| 6 | +// Extra run to check for immediate-command-list in Level Zero |
| 7 | +// RUN: %if level_zero %{env SYCL_PI_LEVEL_ZERO_USE_IMMEDIATE_COMMANDLISTS=1 %{l0_leak_check} %{run} %t.out 2>&1 | FileCheck %s --implicit-check-not=LEAK %} |
| 8 | + |
| 9 | +// This test checks the profiling of an event returned |
| 10 | +// from graph submission with event::get_profiling_info(). |
| 11 | +// It first tests a graph made exclusively of memory operations, |
| 12 | +// then tests a graph made of kernels. This test uses USM isntead of buffers to |
| 13 | +// test the path with no implicit dependencies which bypasses the SYCL |
| 14 | +// scheduler. |
| 15 | +#define GRAPH_TESTS_VERBOSE_PRINT 0 |
| 16 | + |
| 17 | +#include "../graph_common.hpp" |
| 18 | + |
| 19 | +#include <sycl/properties/all_properties.hpp> |
| 20 | + |
| 21 | +// The test checks that get_profiling_info waits for command associated with |
| 22 | +// event to complete execution. |
| 23 | +int main() { |
| 24 | + device Dev; |
| 25 | + |
| 26 | + // Queue used for graph recording |
| 27 | + queue Queue{Dev}; |
| 28 | + |
| 29 | + // Queue that will be used for execution |
| 30 | + queue ExecutionQueue{Queue.get_device(), |
| 31 | + {sycl::property::queue::enable_profiling()}}; |
| 32 | + |
| 33 | + const size_t Size = 100000; |
| 34 | + int Data[Size] = {0}; |
| 35 | + for (size_t I = 0; I < Size; ++I) { |
| 36 | + Data[I] = I; |
| 37 | + } |
| 38 | + int Values[Size] = {0}; |
| 39 | + int *PtrFrom = malloc_device<int>(Size, Queue); |
| 40 | + int *PtrTo = malloc_device<int>(Size, Queue); |
| 41 | + Queue.copy(Data, PtrFrom, Size); |
| 42 | + Queue.copy(Values, PtrTo, Size); |
| 43 | + |
| 44 | + int *PtrA = malloc_device<int>(Size, Queue); |
| 45 | + int *PtrB = malloc_device<int>(Size, Queue); |
| 46 | + int *PtrC = malloc_device<int>(Size, Queue); |
| 47 | + |
| 48 | + Queue.copy(Data, PtrA, Size); |
| 49 | + Queue.copy(Values, PtrB, Size); |
| 50 | + Queue.copy(Values, PtrC, Size); |
| 51 | + |
| 52 | + Queue.wait_and_throw(); |
| 53 | + |
| 54 | + { // USM copy |
| 55 | + exp_ext::command_graph CopyGraph{Queue.get_context(), Queue.get_device()}; |
| 56 | + CopyGraph.begin_recording(Queue); |
| 57 | + |
| 58 | + Queue.submit([&](sycl::handler &Cgh) { |
| 59 | + Cgh.memcpy(PtrTo, PtrFrom, Size * sizeof(int)); |
| 60 | + }); |
| 61 | + |
| 62 | + CopyGraph.end_recording(Queue); |
| 63 | + |
| 64 | + // kernel launch |
| 65 | + exp_ext::command_graph KernelGraph{Queue.get_context(), Queue.get_device()}; |
| 66 | + KernelGraph.begin_recording(Queue); |
| 67 | + |
| 68 | + run_kernels_usm(Queue, Size, PtrA, PtrB, PtrC); |
| 69 | + |
| 70 | + KernelGraph.end_recording(Queue); |
| 71 | + |
| 72 | + auto CopyGraphExec = |
| 73 | + CopyGraph.finalize({exp_ext::property::graph::enable_profiling{}}); |
| 74 | + auto KernelGraphExec = |
| 75 | + KernelGraph.finalize({exp_ext::property::graph::enable_profiling{}}); |
| 76 | + |
| 77 | + event CopyEvent, KernelEvent1, KernelEvent2; |
| 78 | + // Run graphs |
| 79 | +#if GRAPH_TESTS_VERBOSE_PRINT |
| 80 | + auto StartCopyGraph = std::chrono::high_resolution_clock::now(); |
| 81 | +#endif |
| 82 | + CopyEvent = ExecutionQueue.submit( |
| 83 | + [&](handler &CGH) { CGH.ext_oneapi_graph(CopyGraphExec); }); |
| 84 | + ExecutionQueue.wait_and_throw(); |
| 85 | +#if GRAPH_TESTS_VERBOSE_PRINT |
| 86 | + auto EndCopyGraph = std::chrono::high_resolution_clock::now(); |
| 87 | + auto StartKernelSubmit1 = std::chrono::high_resolution_clock::now(); |
| 88 | +#endif |
| 89 | + KernelEvent1 = ExecutionQueue.submit( |
| 90 | + [&](handler &CGH) { CGH.ext_oneapi_graph(KernelGraphExec); }); |
| 91 | + ExecutionQueue.wait_and_throw(); |
| 92 | +#if GRAPH_TESTS_VERBOSE_PRINT |
| 93 | + auto endKernelSubmit1 = std::chrono::high_resolution_clock::now(); |
| 94 | + auto StartKernelSubmit2 = std::chrono::high_resolution_clock::now(); |
| 95 | +#endif |
| 96 | + KernelEvent2 = ExecutionQueue.submit( |
| 97 | + [&](handler &CGH) { CGH.ext_oneapi_graph(KernelGraphExec); }); |
| 98 | + ExecutionQueue.wait_and_throw(); |
| 99 | +#if GRAPH_TESTS_VERBOSE_PRINT |
| 100 | + auto endKernelSubmit2 = std::chrono::high_resolution_clock::now(); |
| 101 | + |
| 102 | + double DelayCopy = std::chrono::duration_cast<std::chrono::nanoseconds>( |
| 103 | + EndCopyGraph - StartCopyGraph) |
| 104 | + .count(); |
| 105 | + std::cout << "Copy Graph delay (in ns) : " << DelayCopy << std::endl; |
| 106 | + double DelayKernel1 = std::chrono::duration_cast<std::chrono::nanoseconds>( |
| 107 | + endKernelSubmit1 - StartKernelSubmit1) |
| 108 | + .count(); |
| 109 | + std::cout << "Kernel 1st Execution delay (in ns) : " << DelayKernel1 |
| 110 | + << std::endl; |
| 111 | + double DelayKernel2 = std::chrono::duration_cast<std::chrono::nanoseconds>( |
| 112 | + endKernelSubmit2 - StartKernelSubmit2) |
| 113 | + .count(); |
| 114 | + std::cout << "Kernel 2nd Execution delay (in ns) : " << DelayKernel2 |
| 115 | + << std::endl; |
| 116 | +#endif |
| 117 | + |
| 118 | + // Checks profiling times |
| 119 | + assert(verifyProfiling(CopyEvent) && verifyProfiling(KernelEvent1) && |
| 120 | + verifyProfiling(KernelEvent2) && |
| 121 | + compareProfiling(KernelEvent1, KernelEvent2)); |
| 122 | + } |
| 123 | + |
| 124 | + std::vector<int> HostData(Size); |
| 125 | + Queue.copy(PtrTo, HostData.data(), Size).wait_and_throw(); |
| 126 | + |
| 127 | + for (size_t I = 0; I < Size; ++I) { |
| 128 | + assert(HostData[I] == Data[I]); |
| 129 | + } |
| 130 | + |
| 131 | + return 0; |
| 132 | +} |
0 commit comments