|
| 1 | +// REQUIRES: level_zero || cuda, gpu |
| 2 | +// RUN: %{build} -o %t.out |
| 3 | +// RUN: %{run} %t.out 2>&1 |
| 4 | +// RUN: %if ext_oneapi_level_zero %{env UR_L0_LEAKS_DEBUG=1 %{run} %t.out 2>&1 | FileCheck --implicit-check-not=LEAK %s %} |
| 5 | + |
| 6 | +// This test checks the profiling of an event returned |
| 7 | +// from graph submission with event::get_profiling_info(). |
| 8 | +// It first tests a graph made exclusively of memory operations, |
| 9 | +// then tests a graph made of kernels. |
| 10 | +// The second run is to check that there are no leaks reported with the embedded |
| 11 | +// UR_L0_LEAKS_DEBUG testing capability. |
| 12 | + |
| 13 | +#include "graph_common.hpp" |
| 14 | + |
| 15 | +#define GRAPH_TESTS_VERBOSE_PRINT 0 |
| 16 | + |
| 17 | +#if GRAPH_TESTS_VERBOSE_PRINT |
| 18 | +#include <chrono> |
| 19 | +#endif |
| 20 | + |
| 21 | +bool verifyProfiling(event Event) { |
| 22 | + auto Submit = |
| 23 | + Event.get_profiling_info<sycl::info::event_profiling::command_submit>(); |
| 24 | + auto Start = |
| 25 | + Event.get_profiling_info<sycl::info::event_profiling::command_start>(); |
| 26 | + auto End = |
| 27 | + Event.get_profiling_info<sycl::info::event_profiling::command_end>(); |
| 28 | + |
| 29 | +#if GRAPH_TESTS_VERBOSE_PRINT |
| 30 | + std::cout << "Submit = " << Submit << std::endl; |
| 31 | + std::cout << "Start = " << Start << std::endl; |
| 32 | + std::cout << "End = " << End << " ( " << (End - Start) << " ) " |
| 33 | + << " => full ( " << (End - Submit) << " ) " << std::endl; |
| 34 | +#endif |
| 35 | + |
| 36 | + assert((Submit && Start && End) && "Profiling information failed."); |
| 37 | + assert(Submit <= Start); |
| 38 | + assert(Start < End); |
| 39 | + |
| 40 | + bool Pass = sycl::info::event_command_status::complete == |
| 41 | + Event.get_info<sycl::info::event::command_execution_status>(); |
| 42 | + |
| 43 | + return Pass; |
| 44 | +} |
| 45 | + |
| 46 | +bool compareProfiling(event Event1, event Event2) { |
| 47 | + assert(Event1 != Event2); |
| 48 | + |
| 49 | + auto SubmitEvent1 = |
| 50 | + Event1.get_profiling_info<sycl::info::event_profiling::command_submit>(); |
| 51 | + auto StartEvent1 = |
| 52 | + Event1.get_profiling_info<sycl::info::event_profiling::command_start>(); |
| 53 | + auto EndEvent1 = |
| 54 | + Event1.get_profiling_info<sycl::info::event_profiling::command_end>(); |
| 55 | + assert((SubmitEvent1 && StartEvent1 && EndEvent1) && |
| 56 | + "Profiling information failed."); |
| 57 | + |
| 58 | + auto SubmitEvent2 = |
| 59 | + Event2.get_profiling_info<sycl::info::event_profiling::command_submit>(); |
| 60 | + auto StartEvent2 = |
| 61 | + Event2.get_profiling_info<sycl::info::event_profiling::command_start>(); |
| 62 | + auto EndEvent2 = |
| 63 | + Event2.get_profiling_info<sycl::info::event_profiling::command_end>(); |
| 64 | + assert((SubmitEvent2 && StartEvent2 && EndEvent2) && |
| 65 | + "Profiling information failed."); |
| 66 | + |
| 67 | + assert(SubmitEvent1 != SubmitEvent2); |
| 68 | + assert(StartEvent1 != StartEvent2); |
| 69 | + assert(EndEvent1 != EndEvent2); |
| 70 | + |
| 71 | + bool Pass1 = sycl::info::event_command_status::complete == |
| 72 | + Event1.get_info<sycl::info::event::command_execution_status>(); |
| 73 | + bool Pass2 = sycl::info::event_command_status::complete == |
| 74 | + Event2.get_info<sycl::info::event::command_execution_status>(); |
| 75 | + |
| 76 | + return (Pass1 && Pass2); |
| 77 | +} |
| 78 | + |
| 79 | +// The test checks that get_profiling_info waits for command asccociated with |
| 80 | +// event to complete execution. |
| 81 | +int main() { |
| 82 | + device Dev; |
| 83 | + queue Queue{Dev, |
| 84 | + {sycl::ext::intel::property::queue::no_immediate_command_list{}, |
| 85 | + sycl::property::queue::enable_profiling()}}; |
| 86 | + |
| 87 | + const size_t Size = 100000; |
| 88 | + int Data[Size] = {0}; |
| 89 | + for (size_t I = 0; I < Size; ++I) { |
| 90 | + Data[I] = I; |
| 91 | + } |
| 92 | + int Values[Size] = {0}; |
| 93 | + |
| 94 | + buffer<int, 1> BufferFrom(Data, range<1>(Size)); |
| 95 | + buffer<int, 1> BufferTo(Values, range<1>(Size)); |
| 96 | + |
| 97 | + buffer<int, 1> BufferA(Data, range<1>(Size)); |
| 98 | + buffer<int, 1> BufferB(Values, range<1>(Size)); |
| 99 | + buffer<int, 1> BufferC(Values, range<1>(Size)); |
| 100 | + |
| 101 | + BufferFrom.set_write_back(false); |
| 102 | + BufferTo.set_write_back(false); |
| 103 | + BufferA.set_write_back(false); |
| 104 | + BufferB.set_write_back(false); |
| 105 | + BufferC.set_write_back(false); |
| 106 | + { // buffer copy |
| 107 | + exp_ext::command_graph CopyGraph{ |
| 108 | + Queue.get_context(), |
| 109 | + Queue.get_device(), |
| 110 | + {exp_ext::property::graph::assume_buffer_outlives_graph{}}}; |
| 111 | + CopyGraph.begin_recording(Queue); |
| 112 | + |
| 113 | + Queue.submit([&](sycl::handler &Cgh) { |
| 114 | + accessor<int, 1, access::mode::read, access::target::device> AccessorFrom( |
| 115 | + BufferFrom, Cgh, range<1>(Size)); |
| 116 | + accessor<int, 1, access::mode::write, access::target::device> AccessorTo( |
| 117 | + BufferTo, Cgh, range<1>(Size)); |
| 118 | + Cgh.copy(AccessorFrom, AccessorTo); |
| 119 | + }); |
| 120 | + |
| 121 | + CopyGraph.end_recording(Queue); |
| 122 | + |
| 123 | + // kernel launch |
| 124 | + exp_ext::command_graph KernelGraph{ |
| 125 | + Queue.get_context(), |
| 126 | + Queue.get_device(), |
| 127 | + {exp_ext::property::graph::assume_buffer_outlives_graph{}}}; |
| 128 | + KernelGraph.begin_recording(Queue); |
| 129 | + |
| 130 | + run_kernels(Queue, Size, BufferA, BufferB, BufferC); |
| 131 | + |
| 132 | + KernelGraph.end_recording(Queue); |
| 133 | + |
| 134 | + auto CopyGraphExec = CopyGraph.finalize(); |
| 135 | + auto KernelGraphExec = KernelGraph.finalize(); |
| 136 | + |
| 137 | + event CopyEvent, KernelEvent1, KernelEvent2; |
| 138 | + // Run graphs |
| 139 | +#if GRAPH_TESTS_VERBOSE_PRINT |
| 140 | + auto StartCopyGraph = std::chrono::high_resolution_clock::now(); |
| 141 | +#endif |
| 142 | + CopyEvent = Queue.submit( |
| 143 | + [&](handler &CGH) { CGH.ext_oneapi_graph(CopyGraphExec); }); |
| 144 | + Queue.wait_and_throw(); |
| 145 | +#if GRAPH_TESTS_VERBOSE_PRINT |
| 146 | + auto EndCopyGraph = std::chrono::high_resolution_clock::now(); |
| 147 | + auto StartKernelSubmit1 = std::chrono::high_resolution_clock::now(); |
| 148 | +#endif |
| 149 | + KernelEvent1 = Queue.submit( |
| 150 | + [&](handler &CGH) { CGH.ext_oneapi_graph(KernelGraphExec); }); |
| 151 | + Queue.wait_and_throw(); |
| 152 | +#if GRAPH_TESTS_VERBOSE_PRINT |
| 153 | + auto endKernelSubmit1 = std::chrono::high_resolution_clock::now(); |
| 154 | + auto StartKernelSubmit2 = std::chrono::high_resolution_clock::now(); |
| 155 | +#endif |
| 156 | + KernelEvent2 = Queue.submit( |
| 157 | + [&](handler &CGH) { CGH.ext_oneapi_graph(KernelGraphExec); }); |
| 158 | + Queue.wait_and_throw(); |
| 159 | +#if GRAPH_TESTS_VERBOSE_PRINT |
| 160 | + auto endKernelSubmit2 = std::chrono::high_resolution_clock::now(); |
| 161 | + |
| 162 | + double DelayCopy = std::chrono::duration_cast<std::chrono::nanoseconds>( |
| 163 | + EndCopyGraph - StartCopyGraph) |
| 164 | + .count(); |
| 165 | + std::cout << "Copy Graph delay (in ns) : " << DelayCopy << std::endl; |
| 166 | + double DelayKernel1 = std::chrono::duration_cast<std::chrono::nanoseconds>( |
| 167 | + endKernelSubmit1 - StartKernelSubmit1) |
| 168 | + .count(); |
| 169 | + std::cout << "Kernel 1st Execution delay (in ns) : " << DelayKernel1 |
| 170 | + << std::endl; |
| 171 | + double DelayKernel2 = std::chrono::duration_cast<std::chrono::nanoseconds>( |
| 172 | + endKernelSubmit2 - StartKernelSubmit2) |
| 173 | + .count(); |
| 174 | + std::cout << "Kernel 2nd Execution delay (in ns) : " << DelayKernel2 |
| 175 | + << std::endl; |
| 176 | +#endif |
| 177 | + |
| 178 | + // Checks profiling times |
| 179 | + assert(verifyProfiling(CopyEvent) && verifyProfiling(KernelEvent1) && |
| 180 | + verifyProfiling(KernelEvent2) && |
| 181 | + compareProfiling(KernelEvent1, KernelEvent2)); |
| 182 | + } |
| 183 | + |
| 184 | + host_accessor HostData(BufferTo); |
| 185 | + for (size_t I = 0; I < Size; ++I) { |
| 186 | + assert(HostData[I] == Values[I]); |
| 187 | + } |
| 188 | + |
| 189 | + return 0; |
| 190 | +} |
0 commit comments