Skip to content

Commit 0c0b586

Browse files
authored
[XPTI][INFRA] Sample E2E data collection timing test for XPTI (#13045)
XPTI has unit tests that time the cost of each individual framework action, but an E2E timing test isn't available. This PR adds a new sample collector that shows how data can be pulled from the SYCL runtime using XPTI and provides timing information for the callback handler costs/event. Allows: 1. Zero cost application with XPTI_TRACE_ENABLE=0 2. Zero cost callback handlers when run in calibration mode 3. Full E2E test when run with "--format none" which gives the average cost of callback handlers/event --------- Signed-off-by: Vasanth Tovinkere <[email protected]>
1 parent bf93fbd commit 0c0b586

14 files changed

+2229
-140
lines changed

sycl/doc/design/SYCLInstrumentationUsingXPTI.md

Lines changed: 4 additions & 3 deletions
Large diffs are not rendered by default.

xptifw/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ project (xptifw VERSION "${XPTI_VERSION}" LANGUAGES CXX)
66
set(CMAKE_CXX_STANDARD 17)
77

88
set(XPTIFW_DIR ${CMAKE_CURRENT_LIST_DIR})
9+
set(SAMPLES_DIR ${CMAKE_CURRENT_LIST_DIR}/samples)
910

1011
# The XPTI framework requires the includes from
1112
# the proxy implementation of XPTI
@@ -68,6 +69,7 @@ endif()
6869
if (XPTI_BUILD_SAMPLES)
6970
add_subdirectory(samples/basic_collector)
7071
add_subdirectory(samples/syclpi_collector)
72+
add_subdirectory(samples/sycl_perf_collector)
7173
add_subdirectory(basic_test)
7274
endif()
7375

xptifw/basic_test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
file(GLOB SOURCES *.cpp *.hpp)
22
include_directories(${XPTIFW_DIR}/include)
33
include_directories(${XPTI_DIR}/include)
4+
include_directories(${SAMPLES_DIR}/include)
45

56
add_executable(XPTIFWBasicTests ${SOURCES})
67
target_link_libraries(XPTIFWBasicTests PRIVATE xptifw ${CMAKE_DL_LIBS})

xptifw/basic_test/cl_processor.hpp

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99

1010
#include "xpti/xpti_trace_framework.hpp"
11+
#include "xpti_helpers.hpp"
1112

1213
#include <chrono>
1314
#include <iomanip>
@@ -26,12 +27,6 @@ namespace test {
2627
namespace utils {
2728
enum class OptionType { Boolean, Integer, Float, String, Range };
2829

29-
// We are using C++ 11, hence we cannot use
30-
// std::variant or std::any
31-
using table_row_t = std::map<int, long double>;
32-
using table_t = std::map<int, table_row_t>;
33-
using titles_t = std::vector<std::string>;
34-
3530
class ScopedTimer {
3631
public:
3732
using time_unit_t =
@@ -301,56 +296,6 @@ class CommandLineParser {
301296
std::string MAppName;
302297
};
303298

304-
class TableModel {
305-
public:
306-
using row_titles_t = std::map<int, std::string>;
307-
308-
TableModel() {}
309-
310-
void setHeaders(titles_t &Titles) { MColumnTitles = Titles; }
311-
312-
table_row_t &addRow(int Row, std::string &RowName) {
313-
if (MRowTitles.count(Row)) {
314-
std::cout << "Warning: Row title already specified!\n";
315-
}
316-
MRowTitles[Row] = RowName;
317-
return MTable[Row];
318-
}
319-
320-
table_row_t &addRow(int Row, const char *RowName) {
321-
if (MRowTitles.count(Row)) {
322-
std::cout << "Warning: Row title already specified!\n";
323-
}
324-
MRowTitles[Row] = RowName;
325-
return MTable[Row];
326-
}
327-
328-
table_row_t &operator[](int Row) { return MTable[Row]; }
329-
330-
void print() {
331-
std::cout << std::setw(14) << " ";
332-
for (auto &Title : MColumnTitles) {
333-
std::cout << std::setw(14) << Title; // Column headers
334-
}
335-
std::cout << "\n";
336-
337-
for (auto &Row : MTable) {
338-
std::cout << std::setw(14) << MRowTitles[Row.first];
339-
for (auto &Data : Row.second) {
340-
std::cout << std::fixed << std::setw(14) << std::setprecision(0)
341-
<< Data.second;
342-
}
343-
std::cout << "\n";
344-
}
345-
std::cout << "\n";
346-
}
347-
348-
private:
349-
titles_t MColumnTitles;
350-
row_titles_t MRowTitles;
351-
table_t MTable;
352-
};
353-
354299
class RangeDecoder {
355300
public:
356301
RangeDecoder(std::string &RangeStr) : MRange(RangeStr) {
@@ -436,16 +381,16 @@ class TestCorrectness {
436381
private:
437382
void runStringTableTests();
438383
void runStringTableTestThreads(int RunNo, int NThreads,
439-
test::utils::TableModel &Table);
384+
xpti::utils::TableModel &Table);
440385
void runTracepointTests();
441386
void runTracepointTestThreads(int RunNo, int nt,
442-
test::utils::TableModel &Table);
387+
xpti::utils::TableModel &Table);
443388
void runNotificationTests();
444389
void runNotificationTestThreads(int RunNo, int NThreads,
445-
test::utils::TableModel &Table);
390+
xpti::utils::TableModel &Table);
446391

447392
test::utils::CommandLineParser &MParser;
448-
test::utils::TableModel MTable;
393+
xpti::utils::TableModel MTable;
449394
std::set<long> MThreads, MTests;
450395
long MTracepoints;
451396
const char *MSource = "foo.cpp";
@@ -598,13 +543,13 @@ class TestPerformance {
598543
private:
599544
void runDataStructureTests();
600545
void runDataStructureTestsThreads(int RunNo, int NThreads,
601-
test::utils::TableModel &Table);
546+
xpti::utils::TableModel &Table);
602547
void runInstrumentationTests();
603548
void runInstrumentationTestsThreads(int RunNo, int NThreads,
604-
test::utils::TableModel &Table);
549+
xpti::utils::TableModel &Table);
605550

606551
test::utils::CommandLineParser &MParser;
607-
test::utils::TableModel MTable;
552+
xpti::utils::TableModel MTable;
608553
std::set<long> MThreads, MTests;
609554
long MTracepoints;
610555
long MTracepointInstances;

xptifw/basic_test/performance_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum class FWColumns {
5454
};
5555

5656
void TestPerformance::runDataStructureTestsThreads(
57-
int RunNo, int NumThreads, test::utils::TableModel &Model) {
57+
int RunNo, int NumThreads, xpti::utils::TableModel &Model) {
5858
xptiReset();
5959
uint64_t TimeInNS;
6060
double ElapsedTime;
@@ -402,9 +402,9 @@ void TestPerformance::runDataStructureTestsThreads(
402402
}
403403

404404
void TestPerformance::runDataStructureTests() {
405-
test::utils::TableModel Model;
405+
xpti::utils::TableModel Model;
406406

407-
test::utils::titles_t Columns{"Threads", "Str.Insert", "Str.Lookup",
407+
xpti::utils::titles_t Columns{"Threads", "Str.Insert", "Str.Lookup",
408408
"St.Ins/Lu", "TP Create", "TP Un-Cached",
409409
"TP FW-Cached", "TP Local", "Notify"};
410410
std::cout << std::setw(Columns.size() * 15 / 2)
@@ -426,7 +426,7 @@ void TestPerformance::runDataStructureTests() {
426426
}
427427

428428
void TestPerformance::runInstrumentationTestsThreads(
429-
int RunNo, int NumThreads, test::utils::TableModel &Model) {
429+
int RunNo, int NumThreads, xpti::utils::TableModel &Model) {
430430
xptiReset();
431431
uint64_t TimeInNS;
432432
double ElapsedTime;
@@ -535,9 +535,9 @@ void TestPerformance::runInstrumentationTestsThreads(
535535
}
536536

537537
void TestPerformance::runInstrumentationTests() {
538-
test::utils::TableModel Model;
538+
xpti::utils::TableModel Model;
539539

540-
test::utils::titles_t Columns{
540+
xpti::utils::titles_t Columns{
541541
"Threads", "TP LU+Notify(ns)", "TP Create(ns)", "Ev/s,cb=10",
542542
"Ev/s,cb=100", "Ev/s,cb=500", "Ev/s,cb=1000", "Ev/s,cb=2000"};
543543
std::cout << std::setw(Columns.size() * 15 / 2) << "Framework Tests\n";

xptifw/basic_test/semantic_tests.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ enum class TPColumns {
8888
enum class NColumns { Threads, Notifications, PassRate };
8989

9090
void TestCorrectness::runStringTableTestThreads(
91-
int RunNo, int NumThreads, test::utils::TableModel &Model) {
91+
int RunNo, int NumThreads, xpti::utils::TableModel &Model) {
9292
xptiReset();
9393
constexpr int NumStrings = 1000;
9494

@@ -184,9 +184,9 @@ void TestCorrectness::runStringTableTestThreads(
184184
}
185185

186186
void TestCorrectness::runStringTableTests() {
187-
test::utils::TableModel Model;
187+
xpti::utils::TableModel Model;
188188

189-
test::utils::titles_t Columns{"Threads", "Insert", "Lookup", "Duplicate",
189+
xpti::utils::titles_t Columns{"Threads", "Insert", "Lookup", "Duplicate",
190190
"Pass rate"};
191191
std::cout << std::setw(25) << "String Table Tests\n";
192192
Model.setHeaders(Columns);
@@ -207,7 +207,7 @@ void TestCorrectness::runStringTableTests() {
207207
}
208208

209209
void TestCorrectness::runTracepointTestThreads(int RunNo, int NumThreads,
210-
test::utils::TableModel &Model) {
210+
xpti::utils::TableModel &Model) {
211211
xptiReset();
212212
constexpr int TracepointCount = 1000;
213213

@@ -348,9 +348,9 @@ void TestCorrectness::runTracepointTestThreads(int RunNo, int NumThreads,
348348
}
349349

350350
void TestCorrectness::runTracepointTests() {
351-
test::utils::TableModel Model;
351+
xpti::utils::TableModel Model;
352352

353-
test::utils::titles_t Columns{"Threads", "Create", "Lookup",
353+
xpti::utils::titles_t Columns{"Threads", "Create", "Lookup",
354354
"Duplicate", "Payload", "Pass rate"};
355355
std::cout << std::setw(25) << "Tracepoint Tests\n";
356356
Model.setHeaders(Columns);
@@ -371,7 +371,7 @@ void TestCorrectness::runTracepointTests() {
371371
}
372372

373373
void TestCorrectness::runNotificationTestThreads(
374-
int RunNo, int NumThreads, test::utils::TableModel &Model) {
374+
int RunNo, int NumThreads, xpti::utils::TableModel &Model) {
375375
xptiReset();
376376
int TPCount = 30, CallbackCount = TPCount * 30;
377377
std::vector<xpti::payload_t *> Payloads;
@@ -502,9 +502,9 @@ void TestCorrectness::runNotificationTestThreads(
502502
}
503503

504504
void TestCorrectness::runNotificationTests() {
505-
test::utils::TableModel Model;
505+
xpti::utils::TableModel Model;
506506

507-
test::utils::titles_t Columns{"Threads", "Notify", "Pass rate"};
507+
xpti::utils::titles_t Columns{"Threads", "Notify", "Pass rate"};
508508
std::cout << std::setw(25) << "Notification Tests\n";
509509
Model.setHeaders(Columns);
510510

xptifw/samples/basic_collector/basic_collector.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
static uint8_t GStreamID = 0;
2121
std::mutex GIOMutex;
22-
xpti::ThreadID GThreadIDEnum;
2322

2423
// The lone callback function we are going to use to demonstrate how to attach
2524
// the collector to the running executable
@@ -111,9 +110,10 @@ XPTI_CALLBACK_API void tpCallback(uint16_t TraceType,
111110
xpti::trace_event_data_t *Event,
112111
uint64_t Instance, const void *UserData) {
113112
auto Payload = xptiQueryPayload(Event);
114-
xpti::timer::tick_t Time = xpti::timer::rdtsc();
115-
auto TID = xpti::timer::getThreadID();
116-
uint32_t CPU = GThreadIDEnum.enumID(TID);
113+
xpti::utils::timer::measurement_t M;
114+
uint64_t Time = M.clock();
115+
auto TID = M.thread();
116+
uint32_t CPU = M.cpu();
117117
std::string Name;
118118

119119
if (Payload->name_sid() != xpti::invalid_id) {

0 commit comments

Comments
 (0)