Skip to content

Commit

Permalink
Merge from 'sycl' to 'sycl-web' (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
iclsrc committed Jan 25, 2021
2 parents 58920b6 + 697c018 commit 7989e30
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 72 deletions.
7 changes: 5 additions & 2 deletions buildbot/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ def do_configure(args):
sycl_dir = os.path.join(abs_src_dir, "sycl")
spirv_dir = os.path.join(abs_src_dir, "llvm-spirv")
xpti_dir = os.path.join(abs_src_dir, "xpti")
xptifw_dir = os.path.join(abs_src_dir, "xptifw")
libdevice_dir = os.path.join(abs_src_dir, "libdevice")
ocl_header_dir = os.path.join(abs_obj_dir, "OpenCL-Headers")
icd_loader_lib = os.path.join(abs_obj_dir, "OpenCL-ICD-Loader", "build")
llvm_targets_to_build = 'X86'
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot;xpti;libdevice'
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot;xpti;xptifw;libdevice'
libclc_targets_to_build = ''
sycl_build_pi_cuda = 'OFF'
sycl_werror = 'ON'
Expand Down Expand Up @@ -63,10 +64,12 @@ def do_configure(args):
"-DCMAKE_BUILD_TYPE={}".format(args.build_type),
"-DLLVM_ENABLE_ASSERTIONS={}".format(llvm_enable_assertions),
"-DLLVM_TARGETS_TO_BUILD={}".format(llvm_targets_to_build),
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot;xpti;libdevice",
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot;xpti;xptifw;libdevice",
"-DLLVM_EXTERNAL_SYCL_SOURCE_DIR={}".format(sycl_dir),
"-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR={}".format(spirv_dir),
"-DLLVM_EXTERNAL_XPTI_SOURCE_DIR={}".format(xpti_dir),
"-DXPTI_SOURCE_DIR={}".format(xpti_dir),
"-DLLVM_EXTERNAL_XPTIFW_SOURCE_DIR={}".format(xptifw_dir),
"-DLLVM_EXTERNAL_LIBDEVICE_SOURCE_DIR={}".format(libdevice_dir),
"-DLLVM_ENABLE_PROJECTS={}".format(llvm_enable_projects),
"-DLIBCLC_TARGETS_TO_BUILD={}".format(libclc_targets_to_build),
Expand Down
6 changes: 6 additions & 0 deletions sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ if (NOT WIN32)
COMPONENT sycl-headers-extras)
endif()

if (SYCL_ENABLE_XPTI_TRACING)
set(XPTIFW_LIBS xptifw)
endif()

# SYCL toolchain builds all components: compiler, libraries, headers, etc.
add_custom_target( sycl-toolchain
DEPENDS ${SYCL_RT_LIBS}
Expand All @@ -291,6 +295,7 @@ add_custom_target( sycl-toolchain
llvm-objcopy
sycl-post-link
sycl-ls
${XPTIFW_LIBS}
COMMENT "Building SYCL compiler toolchain..."
)

Expand Down Expand Up @@ -352,6 +357,7 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
pi_opencl
pi_level_zero
libsycldevice
${XPTIFW_LIBS}
)
if(OpenCL_INSTALL_KHRONOS_ICD_LOADER AND TARGET ocl-icd)
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS opencl-icd)
Expand Down
15 changes: 13 additions & 2 deletions xptifw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 2.8.9)
cmake_minimum_required(VERSION 3.8)

set(XPTI_VERSION 0.4.1)

project (xptifw VERSION "${XPTI_VERSION}" LANGUAGES CXX)

set(XPTIFW_DIR ${CMAKE_CURRENT_LIST_DIR})
# The XPTI framework requires the includes from
# the proxy implementation of XPTI
Expand All @@ -14,17 +17,25 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (default Release)" FORCE)
endif()

project (xptifw)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
endif()

set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/lib/${CMAKE_BUILD_TYPE})
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})

include_directories(${CMAKE_SOURCE_DIR}/include ${XPTI_DIR}/include)
add_subdirectory(src)
# TODO enable samples and tests back once build problems are resolved.
# Currently builds for unit tests and samples fail mostly with dllimport/dllexport
# mismatch problems:
# syclpi_collector.cpp(32): error C2491: 'xptiTraceInit': definition of dllimport function not allowed
if (0)
add_subdirectory(unit_test)
add_subdirectory(samples/basic_collector)
add_subdirectory(samples/syclpi_collector)
endif()
# The tests in basic_test are written using TBB, so these tests are enabled
# only if TBB has been enabled.
if (XPTI_ENABLE_TBB)
Expand Down
3 changes: 0 additions & 3 deletions xptifw/samples/basic_collector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
cmake_minimum_required(VERSION 2.8.9)
project (basic_collector)

file(GLOB SOURCES *.cpp)
include_directories(${XPTIFW_DIR}/include)
include_directories(${XPTI_DIR}/include)
Expand Down
3 changes: 0 additions & 3 deletions xptifw/samples/syclpi_collector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
cmake_minimum_required(VERSION 2.8.9)
project (syclpi_collector)

file(GLOB SOURCES *.cpp)
include_directories(${XPTIFW_DIR}/include)
include_directories(${XPTI_DIR}/include)
Expand Down
3 changes: 0 additions & 3 deletions xptifw/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
cmake_minimum_required(VERSION 2.8.9)
project (xptifw)

file(GLOB SOURCES *.cpp)
include_directories(${XPTIFW_DIR}/include)
include_directories(${XPTI_DIR}/include)
Expand Down
77 changes: 45 additions & 32 deletions xptifw/src/xpti_trace_framework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <cassert>
#include <cstdio>
#include <iostream>
#include <map>
#include <mutex>
#include <sstream>
Expand Down Expand Up @@ -113,10 +114,10 @@ class Subscribers {
// xptiTraceInit() and xptiTraceFinish() functions. If these are not
// present, then the plugin will be ruled an invalid plugin and unloaded
// from the process.
xpti::plugin_init_t InitFunc =
(xpti::plugin_init_t)g_helper.findFunction(Handle, "xptiTraceInit");
xpti::plugin_fini_t FiniFunc =
(xpti::plugin_fini_t)g_helper.findFunction(Handle, "xptiTraceFinish");
xpti::plugin_init_t InitFunc = reinterpret_cast<xpti::plugin_init_t>(
g_helper.findFunction(Handle, "xptiTraceInit"));
xpti::plugin_fini_t FiniFunc = reinterpret_cast<xpti::plugin_fini_t>(
g_helper.findFunction(Handle, "xptiTraceFinish"));
if (InitFunc && FiniFunc) {
// We appear to have loaded a valid plugin, so we will insert the
// plugin information into the two maps guarded by a lock
Expand All @@ -142,7 +143,7 @@ class Subscribers {
} else {
// Get error from errno
if (!Error.empty())
printf("[%s]: %s\n", Path, Error.c_str());
std::cout << '[' << Path << "]: " << Error << '\n';
}
return Handle;
}
Expand Down Expand Up @@ -215,7 +216,7 @@ class Subscribers {
auto SubscriberHandle = loadPlugin(Path.c_str());
if (!SubscriberHandle) {
ValidSubscribers--;
printf("Failed to load %s successfully...\n", Path.c_str());
std::cout << "Failed to load " << Path << " successfully\n";
}
}
}
Expand Down Expand Up @@ -265,7 +266,7 @@ class Tracepoints {
#endif

Tracepoints(xpti::StringTable &st)
: MUId(1), MInsertions(0), MRetrievals(0), MStringTableRef(st) {
: MUId(1), MStringTableRef(st), MInsertions(0), MRetrievals(0) {
// Nothing requires to be done at construction time
}

Expand Down Expand Up @@ -381,9 +382,9 @@ class Tracepoints {
//
void printStatistics() {
#ifdef XPTI_STATISTICS
printf("Tracepoint inserts : [%lu] \n", MInsertions.load());
printf("Tracepoint lookups : [%lu]\n", MRetrievals.load());
printf("Tracepoint Hashmap :\n");
std::cout << "Tracepoint inserts : " << MInsertions.load() << '\n';
std::cout << "Tracepoint lookups : " << MRetrievals.load() << '\n';
std::cout << "Tracepoint Hashmap :\n";
MPayloadLUT.printStatistics();
#endif
}
Expand All @@ -404,17 +405,19 @@ class Tracepoints {
if (Payload->flags == 0)
return HashValue;
// If the hash value has been cached, return and bail early
if (Payload->flags & (uint64_t)payload_flag_t::HashAvailable)
if (Payload->flags & static_cast<uint64_t>(payload_flag_t::HashAvailable))
return Payload->internal;

// Add the string information to the string table and use the string IDs
// (in addition to any unique addresses) to create a hash value
if ((Payload->flags & (uint64_t)payload_flag_t::NameAvailable)) {
if ((Payload->flags &
static_cast<uint64_t>(payload_flag_t::NameAvailable))) {
// Add the kernel name to the string table; if the add() returns the
// address to the string in the string table, we can avoid a query [TBD]
Payload->name_sid = MStringTableRef.add(Payload->name, &Payload->name);
// Payload->name = MStringTableRef.query(Payload->name_sid);
if (Payload->flags & (uint64_t)payload_flag_t::SourceFileAvailable) {
if (Payload->flags &
static_cast<uint64_t>(payload_flag_t::SourceFileAvailable)) {
// Add source file information ot string table
Payload->source_file_sid =
MStringTableRef.add(Payload->source_file, &Payload->source_file);
Expand All @@ -435,15 +438,20 @@ class Tracepoints {
// them. However, if we use the address, which would be the object
// address, they both will have different addresses even if they
// happen to be on the same line.
uint16_t NamePack = (uint16_t)(Payload->name_sid & 0x0000ffff);
// TODO think of a more portable way to do the same thing.
uint16_t NamePack =
static_cast<uint16_t>(Payload->name_sid & 0x0000ffff);
uint16_t SrcFileNamePack =
(uint16_t)(Payload->source_file_sid & 0x0000ffff);
static_cast<uint16_t>(Payload->source_file_sid & 0x0000ffff);
uint32_t KernelIDPack = XPTI_PACK16_RET32(SrcFileNamePack, NamePack);
uint32_t Address = (uint32_t)(
((uint64_t)Payload->code_ptr_va & 0x0000000ffffffff0) >> 4);
uint32_t Address = static_cast<uint32_t>(
(reinterpret_cast<uint64_t>(Payload->code_ptr_va) &
0x0000000ffffffff0) >>
4);
HashValue = XPTI_PACK32_RET64(Address, KernelIDPack);
// Cache the hash once it is computed
Payload->flags |= (uint64_t)payload_flag_t::HashAvailable;
Payload->flags |=
static_cast<uint64_t>(payload_flag_t::HashAvailable);
Payload->internal = HashValue;
return HashValue;
} else {
Expand All @@ -454,10 +462,11 @@ class Tracepoints {
// will use 22 bits of the source file and kernel name ids and form a
// 64-bit value with the middle 22-bits being zero representing the
// line number.
uint64_t LeftPart = 0, MiddlePart = 0, RightPart = 0,
Mask22Bits = 0x00000000003fffff;
uint64_t LeftPart = 0, MiddlePart = 0, RightPart = 0;
constexpr uint64_t Mask22Bits = 0x00000000003fffff;
// If line number info is available, extract 22-bits of it
if (Payload->flags & (uint64_t)payload_flag_t::LineInfoAvailable) {
if (Payload->flags &
static_cast<uint64_t>(payload_flag_t::LineInfoAvailable)) {
MiddlePart = Payload->line_no & Mask22Bits;
MiddlePart = MiddlePart << 22;
}
Expand All @@ -467,36 +476,40 @@ class Tracepoints {
// The rightmost 22-bits will represent the kernel name string id
RightPart = Payload->name_sid & Mask22Bits;
HashValue = LeftPart | MiddlePart | RightPart;
Payload->flags |= (uint64_t)payload_flag_t::HashAvailable;
Payload->flags |=
static_cast<uint64_t>(payload_flag_t::HashAvailable);
Payload->internal = HashValue;
return HashValue;
}
} else if (Payload->flags &
(uint64_t)payload_flag_t::CodePointerAvailable) {
static_cast<uint64_t>(payload_flag_t::CodePointerAvailable)) {
// We have both kernel name and kernel address; we use bits 5-36 from
// the address and combine it with the kernel name string ID
uint32_t Address = (uint32_t)(
((uint64_t)Payload->code_ptr_va & 0x0000000ffffffff0) >> 4);
uint32_t Address = static_cast<uint32_t>(
(reinterpret_cast<uint64_t>(Payload->code_ptr_va) &
0x0000000ffffffff0) >>
4);
HashValue = XPTI_PACK32_RET64(Address, Payload->name_sid);
Payload->flags |= (uint64_t)payload_flag_t::HashAvailable;
Payload->flags |= static_cast<uint64_t>(payload_flag_t::HashAvailable);
Payload->internal = HashValue;
return HashValue;
} else {
// We only have kernel name and this is suspect if the kernel names are
// not unique and will replace any previously stored payload information
if (Payload->name_sid != xpti::invalid_id) {
HashValue = XPTI_PACK32_RET64(0, Payload->name_sid);
Payload->flags |= (uint64_t)payload_flag_t::HashAvailable;
Payload->flags |=
static_cast<uint64_t>(payload_flag_t::HashAvailable);
Payload->internal = HashValue;
return HashValue;
}
}
} else if (Payload->flags &
(uint64_t)payload_flag_t::CodePointerAvailable) {
static_cast<uint64_t>(payload_flag_t::CodePointerAvailable)) {
// We are only going to look at Kernel address when kernel name is not
// available.
HashValue = (uint64_t)Payload->code_ptr_va;
Payload->flags |= (uint64_t)payload_flag_t::HashAvailable;
HashValue = reinterpret_cast<uint64_t>(Payload->code_ptr_va);
Payload->flags |= static_cast<uint64_t>(payload_flag_t::HashAvailable);
Payload->internal = HashValue;
return HashValue;
}
Expand Down Expand Up @@ -575,7 +588,7 @@ class Tracepoints {
#ifndef XPTI_USE_TBB
std::lock_guard<std::mutex> Lock(MCodePtrMutex);
#endif
MCodePtrLUT[(uint64_t)TempPayload.code_ptr_va] = UId;
MCodePtrLUT[reinterpret_cast<uint64_t>(TempPayload.code_ptr_va)] = UId;
}
// We also want to query the payload by universal ID that has been
// generated
Expand Down Expand Up @@ -888,7 +901,7 @@ class Notifications {
class Framework {
public:
Framework()
: MTracepoints(MStringTableRef), MUniversalIDs(0), MTraceEnabled(false) {
: MUniversalIDs(0), MTracepoints(MStringTableRef), MTraceEnabled(false) {
// Load all subscribers on construction
MSubscribers.loadFromEnvironmentVariable();
MTraceEnabled =
Expand Down
57 changes: 30 additions & 27 deletions xptifw/unit_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,39 @@ if (NOT EXISTS ${XPTI_SOURCE_DIR})
endif()
include_directories(${XPTI_SOURCE_DIR}/include)

# Download and unpack googletest at configure time
configure_file(../CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Only download Google Test outside of LLVM tree.
if (NOT DEFINED LLVM_EXTERNAL_XPTIFW_SOURCE_DIR)
# Download and unpack googletest at configure time
configure_file(../CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()

# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)

# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
# The gtest/gtest_main targets carry header search path
# dependencies automatically when using CMake 2.8.11 or
# later. Otherwise we have to add them here ourselves.
if (CMAKE_VERSION VERSION_LESS 2.8.11)
include_directories("${gtest_SOURCE_DIR}/include")
endif()
endif()

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

0 comments on commit 7989e30

Please sign in to comment.