Skip to content

Commit ee149e6

Browse files
authored
[PTI-LIB] Fix compilation in Rocky 8 container (#789)
The metrics_perf sample was using threads but was not linking pthreads, this properly links pthreads. Also, clean up some code modernization issues and CMake. Signed-off-by: Schilling, Matthew <[email protected]>
1 parent 204dbba commit ee149e6

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

sdk/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ CheckExperimentalFilesystem()
102102
# Check and Get Dependencies
103103
GetSpdlog()
104104

105-
find_package(Xpti)
105+
if(NOT TARGET Xpti::xpti)
106+
find_package(Xpti)
107+
endif()
106108

107109
set(PTI_L0_LOADER 1.26.3)
108110
set(PTI_L0_LOADER_COMMIT_HASH "354190cd2e7aa485b55a39c91d108413a94cc5e1")
109111

110-
if(NOT PROJECT_IS_TOP_LEVEL)
111-
find_package(LevelZero ${PTI_L0_LOADER} REQUIRED)
112-
else()
112+
if(NOT TARGET LevelZero::level-zero)
113113
find_package(LevelZero ${PTI_L0_LOADER})
114114
endif()
115115

sdk/samples/metrics_perf/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ target_compile_options(metrics_perf PUBLIC -fsycl)
2121
target_include_directories(metrics_perf
2222
PRIVATE "${PROJECT_SOURCE_DIR}/../samples_utilities")
2323

24+
if (NOT TARGET Threads::Threads)
25+
find_package(Threads REQUIRED)
26+
endif()
27+
2428
if (NOT TARGET Pti::pti_view)
2529
find_package(Pti REQUIRED)
2630
endif()
2731

28-
target_link_libraries(metrics_perf PUBLIC Pti::pti_view LevelZero::level-zero)
32+
target_link_libraries(metrics_perf PUBLIC Pti::pti_view Threads::Threads)
2933

sdk/samples/metrics_perf/metrics_perf.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <chrono>
1212
#include <cmath>
1313
#include <cstdlib>
14-
#include <future>
1514
#include <iomanip>
1615
#include <iostream>
1716
#include <sycl/sycl.hpp>
@@ -328,7 +327,7 @@ std::chrono::duration<double> RunMultiThreadedTest(const std::vector<sycl::queue
328327
auto start_time = std::chrono::high_resolution_clock::now();
329328

330329
std::vector<std::thread> threads;
331-
size_t thread_count = (std::min)(queues.size(), size_t(2));
330+
size_t thread_count = (std::min)(queues.size(), static_cast<size_t>(2));
332331

333332
for (size_t i = 0; i < thread_count; ++i) {
334333
std::string thread_name = "NoProfile-Thread-" + std::to_string(i);
@@ -355,7 +354,7 @@ std::chrono::duration<double> RunMultiThreadedProfilingTest(
355354
auto start_time = std::chrono::high_resolution_clock::now();
356355

357356
std::vector<std::thread> threads;
358-
size_t thread_count = (std::min)({device_handles.size(), queues.size(), size_t(2)});
357+
size_t thread_count = (std::min)({device_handles.size(), queues.size(), static_cast<size_t>(2)});
359358

360359
for (size_t i = 0; i < thread_count; ++i) {
361360
std::string thread_name = "Thread-" + std::to_string(i);
@@ -461,7 +460,7 @@ int main(int argc, char* argv[]) {
461460
return EXIT_FAILURE;
462461
}
463462

464-
size_t num_queues = (std::min)({all_devices.size(), g_devices.size(), size_t(2)});
463+
size_t num_queues = (std::min)({all_devices.size(), g_devices.size(), static_cast<size_t>(2)});
465464
sycl::property_list prop_list{sycl::property::queue::in_order()};
466465

467466
for (size_t i = 0; i < num_queues; ++i) {
@@ -494,9 +493,10 @@ int main(int argc, char* argv[]) {
494493
std::cout << "g_devices[" << i << "]._handle: " << g_devices[i]._handle << std::endl;
495494
std::cout << "g_devices[" << i << "] UUID: ";
496495
for (size_t j = 0; j < PTI_MAX_DEVICE_UUID_SIZE; ++j) {
497-
printf("%02x", g_devices[i]._uuid[j]);
496+
std::cout << std::hex << std::setw(2) << std::setfill('0')
497+
<< static_cast<unsigned int>(g_devices[i]._uuid[j]);
498498
}
499-
std::cout << std::endl;
499+
std::cout << std::dec << std::setfill(' ') << std::endl;
500500
}
501501

502502
std::cout << std::endl;
@@ -535,7 +535,8 @@ int main(int argc, char* argv[]) {
535535
double multi_baseline_throughput = 0.0;
536536
double multi_profiling_throughput = 0.0;
537537
double multi_overhead_pct = 0.0;
538-
std::chrono::duration<double> multi_baseline_time, multi_profiling_time;
538+
std::chrono::duration<double> multi_baseline_time{};
539+
std::chrono::duration<double> multi_profiling_time{};
539540

540541
// Only run multi-threaded tests if we have multiple devices/queues
541542
if (queues.size() >= 2 && g_devices.size() >= 2) {

0 commit comments

Comments
 (0)