Skip to content

Commit 697c018

Browse files
author
Alexander Batashev
authored
[XPTIFW] Enable in-tree build (#2959)
1 parent 645db17 commit 697c018

File tree

8 files changed

+99
-72
lines changed

8 files changed

+99
-72
lines changed

buildbot/configure.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ def do_configure(args):
1717
sycl_dir = os.path.join(abs_src_dir, "sycl")
1818
spirv_dir = os.path.join(abs_src_dir, "llvm-spirv")
1919
xpti_dir = os.path.join(abs_src_dir, "xpti")
20+
xptifw_dir = os.path.join(abs_src_dir, "xptifw")
2021
libdevice_dir = os.path.join(abs_src_dir, "libdevice")
2122
ocl_header_dir = os.path.join(abs_obj_dir, "OpenCL-Headers")
2223
icd_loader_lib = os.path.join(abs_obj_dir, "OpenCL-ICD-Loader", "build")
2324
llvm_targets_to_build = 'X86'
24-
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot;xpti;libdevice'
25+
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot;xpti;xptifw;libdevice'
2526
libclc_targets_to_build = ''
2627
sycl_build_pi_cuda = 'OFF'
2728
sycl_werror = 'ON'
@@ -63,10 +64,12 @@ def do_configure(args):
6364
"-DCMAKE_BUILD_TYPE={}".format(args.build_type),
6465
"-DLLVM_ENABLE_ASSERTIONS={}".format(llvm_enable_assertions),
6566
"-DLLVM_TARGETS_TO_BUILD={}".format(llvm_targets_to_build),
66-
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot;xpti;libdevice",
67+
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot;xpti;xptifw;libdevice",
6768
"-DLLVM_EXTERNAL_SYCL_SOURCE_DIR={}".format(sycl_dir),
6869
"-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR={}".format(spirv_dir),
6970
"-DLLVM_EXTERNAL_XPTI_SOURCE_DIR={}".format(xpti_dir),
71+
"-DXPTI_SOURCE_DIR={}".format(xpti_dir),
72+
"-DLLVM_EXTERNAL_XPTIFW_SOURCE_DIR={}".format(xptifw_dir),
7073
"-DLLVM_EXTERNAL_LIBDEVICE_SOURCE_DIR={}".format(libdevice_dir),
7174
"-DLLVM_ENABLE_PROJECTS={}".format(llvm_enable_projects),
7275
"-DLIBCLC_TARGETS_TO_BUILD={}".format(libclc_targets_to_build),

sycl/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ if (NOT WIN32)
274274
COMPONENT sycl-headers-extras)
275275
endif()
276276

277+
if (SYCL_ENABLE_XPTI_TRACING)
278+
set(XPTIFW_LIBS xptifw)
279+
endif()
280+
277281
# SYCL toolchain builds all components: compiler, libraries, headers, etc.
278282
add_custom_target( sycl-toolchain
279283
DEPENDS ${SYCL_RT_LIBS}
@@ -291,6 +295,7 @@ add_custom_target( sycl-toolchain
291295
llvm-objcopy
292296
sycl-post-link
293297
sycl-ls
298+
${XPTIFW_LIBS}
294299
COMMENT "Building SYCL compiler toolchain..."
295300
)
296301

@@ -352,6 +357,7 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
352357
pi_opencl
353358
pi_level_zero
354359
libsycldevice
360+
${XPTIFW_LIBS}
355361
)
356362
if(OpenCL_INSTALL_KHRONOS_ICD_LOADER AND TARGET ocl-icd)
357363
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS opencl-icd)

xptifw/CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
cmake_minimum_required(VERSION 2.8.9)
1+
cmake_minimum_required(VERSION 3.8)
22

33
set(XPTI_VERSION 0.4.1)
4+
5+
project (xptifw VERSION "${XPTI_VERSION}" LANGUAGES CXX)
6+
47
set(XPTIFW_DIR ${CMAKE_CURRENT_LIST_DIR})
58
# The XPTI framework requires the includes from
69
# the proxy implementation of XPTI
@@ -14,17 +17,25 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
1417
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (default Release)" FORCE)
1518
endif()
1619

17-
project (xptifw)
20+
if(MSVC)
21+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
22+
endif()
1823

1924
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/lib/${CMAKE_BUILD_TYPE})
2025
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
2126
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
2227

2328
include_directories(${CMAKE_SOURCE_DIR}/include ${XPTI_DIR}/include)
2429
add_subdirectory(src)
30+
# TODO enable samples and tests back once build problems are resolved.
31+
# Currently builds for unit tests and samples fail mostly with dllimport/dllexport
32+
# mismatch problems:
33+
# syclpi_collector.cpp(32): error C2491: 'xptiTraceInit': definition of dllimport function not allowed
34+
if (0)
2535
add_subdirectory(unit_test)
2636
add_subdirectory(samples/basic_collector)
2737
add_subdirectory(samples/syclpi_collector)
38+
endif()
2839
# The tests in basic_test are written using TBB, so these tests are enabled
2940
# only if TBB has been enabled.
3041
if (XPTI_ENABLE_TBB)

xptifw/samples/basic_collector/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
cmake_minimum_required(VERSION 2.8.9)
2-
project (basic_collector)
3-
41
file(GLOB SOURCES *.cpp)
52
include_directories(${XPTIFW_DIR}/include)
63
include_directories(${XPTI_DIR}/include)

xptifw/samples/syclpi_collector/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
cmake_minimum_required(VERSION 2.8.9)
2-
project (syclpi_collector)
3-
41
file(GLOB SOURCES *.cpp)
52
include_directories(${XPTIFW_DIR}/include)
63
include_directories(${XPTI_DIR}/include)

xptifw/src/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
cmake_minimum_required(VERSION 2.8.9)
2-
project (xptifw)
3-
41
file(GLOB SOURCES *.cpp)
52
include_directories(${XPTIFW_DIR}/include)
63
include_directories(${XPTI_DIR}/include)

xptifw/src/xpti_trace_framework.cpp

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <cassert>
1111
#include <cstdio>
12+
#include <iostream>
1213
#include <map>
1314
#include <mutex>
1415
#include <sstream>
@@ -113,10 +114,10 @@ class Subscribers {
113114
// xptiTraceInit() and xptiTraceFinish() functions. If these are not
114115
// present, then the plugin will be ruled an invalid plugin and unloaded
115116
// from the process.
116-
xpti::plugin_init_t InitFunc =
117-
(xpti::plugin_init_t)g_helper.findFunction(Handle, "xptiTraceInit");
118-
xpti::plugin_fini_t FiniFunc =
119-
(xpti::plugin_fini_t)g_helper.findFunction(Handle, "xptiTraceFinish");
117+
xpti::plugin_init_t InitFunc = reinterpret_cast<xpti::plugin_init_t>(
118+
g_helper.findFunction(Handle, "xptiTraceInit"));
119+
xpti::plugin_fini_t FiniFunc = reinterpret_cast<xpti::plugin_fini_t>(
120+
g_helper.findFunction(Handle, "xptiTraceFinish"));
120121
if (InitFunc && FiniFunc) {
121122
// We appear to have loaded a valid plugin, so we will insert the
122123
// plugin information into the two maps guarded by a lock
@@ -142,7 +143,7 @@ class Subscribers {
142143
} else {
143144
// Get error from errno
144145
if (!Error.empty())
145-
printf("[%s]: %s\n", Path, Error.c_str());
146+
std::cout << '[' << Path << "]: " << Error << '\n';
146147
}
147148
return Handle;
148149
}
@@ -215,7 +216,7 @@ class Subscribers {
215216
auto SubscriberHandle = loadPlugin(Path.c_str());
216217
if (!SubscriberHandle) {
217218
ValidSubscribers--;
218-
printf("Failed to load %s successfully...\n", Path.c_str());
219+
std::cout << "Failed to load " << Path << " successfully\n";
219220
}
220221
}
221222
}
@@ -265,7 +266,7 @@ class Tracepoints {
265266
#endif
266267

267268
Tracepoints(xpti::StringTable &st)
268-
: MUId(1), MInsertions(0), MRetrievals(0), MStringTableRef(st) {
269+
: MUId(1), MStringTableRef(st), MInsertions(0), MRetrievals(0) {
269270
// Nothing requires to be done at construction time
270271
}
271272

@@ -381,9 +382,9 @@ class Tracepoints {
381382
//
382383
void printStatistics() {
383384
#ifdef XPTI_STATISTICS
384-
printf("Tracepoint inserts : [%lu] \n", MInsertions.load());
385-
printf("Tracepoint lookups : [%lu]\n", MRetrievals.load());
386-
printf("Tracepoint Hashmap :\n");
385+
std::cout << "Tracepoint inserts : " << MInsertions.load() << '\n';
386+
std::cout << "Tracepoint lookups : " << MRetrievals.load() << '\n';
387+
std::cout << "Tracepoint Hashmap :\n";
387388
MPayloadLUT.printStatistics();
388389
#endif
389390
}
@@ -404,17 +405,19 @@ class Tracepoints {
404405
if (Payload->flags == 0)
405406
return HashValue;
406407
// If the hash value has been cached, return and bail early
407-
if (Payload->flags & (uint64_t)payload_flag_t::HashAvailable)
408+
if (Payload->flags & static_cast<uint64_t>(payload_flag_t::HashAvailable))
408409
return Payload->internal;
409410

410411
// Add the string information to the string table and use the string IDs
411412
// (in addition to any unique addresses) to create a hash value
412-
if ((Payload->flags & (uint64_t)payload_flag_t::NameAvailable)) {
413+
if ((Payload->flags &
414+
static_cast<uint64_t>(payload_flag_t::NameAvailable))) {
413415
// Add the kernel name to the string table; if the add() returns the
414416
// address to the string in the string table, we can avoid a query [TBD]
415417
Payload->name_sid = MStringTableRef.add(Payload->name, &Payload->name);
416418
// Payload->name = MStringTableRef.query(Payload->name_sid);
417-
if (Payload->flags & (uint64_t)payload_flag_t::SourceFileAvailable) {
419+
if (Payload->flags &
420+
static_cast<uint64_t>(payload_flag_t::SourceFileAvailable)) {
418421
// Add source file information ot string table
419422
Payload->source_file_sid =
420423
MStringTableRef.add(Payload->source_file, &Payload->source_file);
@@ -435,15 +438,20 @@ class Tracepoints {
435438
// them. However, if we use the address, which would be the object
436439
// address, they both will have different addresses even if they
437440
// happen to be on the same line.
438-
uint16_t NamePack = (uint16_t)(Payload->name_sid & 0x0000ffff);
441+
// TODO think of a more portable way to do the same thing.
442+
uint16_t NamePack =
443+
static_cast<uint16_t>(Payload->name_sid & 0x0000ffff);
439444
uint16_t SrcFileNamePack =
440-
(uint16_t)(Payload->source_file_sid & 0x0000ffff);
445+
static_cast<uint16_t>(Payload->source_file_sid & 0x0000ffff);
441446
uint32_t KernelIDPack = XPTI_PACK16_RET32(SrcFileNamePack, NamePack);
442-
uint32_t Address = (uint32_t)(
443-
((uint64_t)Payload->code_ptr_va & 0x0000000ffffffff0) >> 4);
447+
uint32_t Address = static_cast<uint32_t>(
448+
(reinterpret_cast<uint64_t>(Payload->code_ptr_va) &
449+
0x0000000ffffffff0) >>
450+
4);
444451
HashValue = XPTI_PACK32_RET64(Address, KernelIDPack);
445452
// Cache the hash once it is computed
446-
Payload->flags |= (uint64_t)payload_flag_t::HashAvailable;
453+
Payload->flags |=
454+
static_cast<uint64_t>(payload_flag_t::HashAvailable);
447455
Payload->internal = HashValue;
448456
return HashValue;
449457
} else {
@@ -454,10 +462,11 @@ class Tracepoints {
454462
// will use 22 bits of the source file and kernel name ids and form a
455463
// 64-bit value with the middle 22-bits being zero representing the
456464
// line number.
457-
uint64_t LeftPart = 0, MiddlePart = 0, RightPart = 0,
458-
Mask22Bits = 0x00000000003fffff;
465+
uint64_t LeftPart = 0, MiddlePart = 0, RightPart = 0;
466+
constexpr uint64_t Mask22Bits = 0x00000000003fffff;
459467
// If line number info is available, extract 22-bits of it
460-
if (Payload->flags & (uint64_t)payload_flag_t::LineInfoAvailable) {
468+
if (Payload->flags &
469+
static_cast<uint64_t>(payload_flag_t::LineInfoAvailable)) {
461470
MiddlePart = Payload->line_no & Mask22Bits;
462471
MiddlePart = MiddlePart << 22;
463472
}
@@ -467,36 +476,40 @@ class Tracepoints {
467476
// The rightmost 22-bits will represent the kernel name string id
468477
RightPart = Payload->name_sid & Mask22Bits;
469478
HashValue = LeftPart | MiddlePart | RightPart;
470-
Payload->flags |= (uint64_t)payload_flag_t::HashAvailable;
479+
Payload->flags |=
480+
static_cast<uint64_t>(payload_flag_t::HashAvailable);
471481
Payload->internal = HashValue;
472482
return HashValue;
473483
}
474484
} else if (Payload->flags &
475-
(uint64_t)payload_flag_t::CodePointerAvailable) {
485+
static_cast<uint64_t>(payload_flag_t::CodePointerAvailable)) {
476486
// We have both kernel name and kernel address; we use bits 5-36 from
477487
// the address and combine it with the kernel name string ID
478-
uint32_t Address = (uint32_t)(
479-
((uint64_t)Payload->code_ptr_va & 0x0000000ffffffff0) >> 4);
488+
uint32_t Address = static_cast<uint32_t>(
489+
(reinterpret_cast<uint64_t>(Payload->code_ptr_va) &
490+
0x0000000ffffffff0) >>
491+
4);
480492
HashValue = XPTI_PACK32_RET64(Address, Payload->name_sid);
481-
Payload->flags |= (uint64_t)payload_flag_t::HashAvailable;
493+
Payload->flags |= static_cast<uint64_t>(payload_flag_t::HashAvailable);
482494
Payload->internal = HashValue;
483495
return HashValue;
484496
} else {
485497
// We only have kernel name and this is suspect if the kernel names are
486498
// not unique and will replace any previously stored payload information
487499
if (Payload->name_sid != xpti::invalid_id) {
488500
HashValue = XPTI_PACK32_RET64(0, Payload->name_sid);
489-
Payload->flags |= (uint64_t)payload_flag_t::HashAvailable;
501+
Payload->flags |=
502+
static_cast<uint64_t>(payload_flag_t::HashAvailable);
490503
Payload->internal = HashValue;
491504
return HashValue;
492505
}
493506
}
494507
} else if (Payload->flags &
495-
(uint64_t)payload_flag_t::CodePointerAvailable) {
508+
static_cast<uint64_t>(payload_flag_t::CodePointerAvailable)) {
496509
// We are only going to look at Kernel address when kernel name is not
497510
// available.
498-
HashValue = (uint64_t)Payload->code_ptr_va;
499-
Payload->flags |= (uint64_t)payload_flag_t::HashAvailable;
511+
HashValue = reinterpret_cast<uint64_t>(Payload->code_ptr_va);
512+
Payload->flags |= static_cast<uint64_t>(payload_flag_t::HashAvailable);
500513
Payload->internal = HashValue;
501514
return HashValue;
502515
}
@@ -575,7 +588,7 @@ class Tracepoints {
575588
#ifndef XPTI_USE_TBB
576589
std::lock_guard<std::mutex> Lock(MCodePtrMutex);
577590
#endif
578-
MCodePtrLUT[(uint64_t)TempPayload.code_ptr_va] = UId;
591+
MCodePtrLUT[reinterpret_cast<uint64_t>(TempPayload.code_ptr_va)] = UId;
579592
}
580593
// We also want to query the payload by universal ID that has been
581594
// generated
@@ -888,7 +901,7 @@ class Notifications {
888901
class Framework {
889902
public:
890903
Framework()
891-
: MTracepoints(MStringTableRef), MUniversalIDs(0), MTraceEnabled(false) {
904+
: MUniversalIDs(0), MTracepoints(MStringTableRef), MTraceEnabled(false) {
892905
// Load all subscribers on construction
893906
MSubscribers.loadFromEnvironmentVariable();
894907
MTraceEnabled =

xptifw/unit_test/CMakeLists.txt

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,39 @@ if (NOT EXISTS ${XPTI_SOURCE_DIR})
33
endif()
44
include_directories(${XPTI_SOURCE_DIR}/include)
55

6-
# Download and unpack googletest at configure time
7-
configure_file(../CMakeLists.txt.in googletest-download/CMakeLists.txt)
8-
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
9-
RESULT_VARIABLE result
10-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
11-
if(result)
12-
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
13-
endif()
14-
execute_process(COMMAND ${CMAKE_COMMAND} --build .
15-
RESULT_VARIABLE result
16-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
17-
if(result)
18-
message(FATAL_ERROR "Build step for googletest failed: ${result}")
19-
endif()
6+
# Only download Google Test outside of LLVM tree.
7+
if (NOT DEFINED LLVM_EXTERNAL_XPTIFW_SOURCE_DIR)
8+
# Download and unpack googletest at configure time
9+
configure_file(../CMakeLists.txt.in googletest-download/CMakeLists.txt)
10+
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
11+
RESULT_VARIABLE result
12+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
13+
if(result)
14+
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
15+
endif()
16+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
17+
RESULT_VARIABLE result
18+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
19+
if(result)
20+
message(FATAL_ERROR "Build step for googletest failed: ${result}")
21+
endif()
2022

21-
# Prevent overriding the parent project's compiler/linker
22-
# settings on Windows
23-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
23+
# Prevent overriding the parent project's compiler/linker
24+
# settings on Windows
25+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
2426

25-
# Add googletest directly to our build. This defines
26-
# the gtest and gtest_main targets.
27-
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
28-
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
29-
EXCLUDE_FROM_ALL)
27+
# Add googletest directly to our build. This defines
28+
# the gtest and gtest_main targets.
29+
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
30+
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
31+
EXCLUDE_FROM_ALL)
3032

31-
# The gtest/gtest_main targets carry header search path
32-
# dependencies automatically when using CMake 2.8.11 or
33-
# later. Otherwise we have to add them here ourselves.
34-
if (CMAKE_VERSION VERSION_LESS 2.8.11)
35-
include_directories("${gtest_SOURCE_DIR}/include")
33+
# The gtest/gtest_main targets carry header search path
34+
# dependencies automatically when using CMake 2.8.11 or
35+
# later. Otherwise we have to add them here ourselves.
36+
if (CMAKE_VERSION VERSION_LESS 2.8.11)
37+
include_directories("${gtest_SOURCE_DIR}/include")
38+
endif()
3639
endif()
3740

3841
# Now simply link against gtest or gtest_main as needed. Eg

0 commit comments

Comments
 (0)