-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:khuck/xpress-apex into develop
- Loading branch information
Showing
44 changed files
with
7,353 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# - Try to find LibLEVEL0 | ||
# Once done this will define | ||
# LEVEL0_FOUND - System has LEVEL0 | ||
# LEVEL0_INCLUDE_DIRS - The LEVEL0 include directories | ||
# LEVEL0_LIBRARIES - The libraries needed to use LEVEL0 | ||
# LEVEL0_DEFINITIONS - Compiler switches required for using LEVEL0 | ||
|
||
if(NOT DEFINED $LEVEL0_ROOT) | ||
if(DEFINED ENV{LEVEL0_ROOT}) | ||
# message(" env LEVEL0_ROOT is defined as $ENV{LEVEL0_ROOT}") | ||
set(LEVEL0_ROOT $ENV{LEVEL0_ROOT}) | ||
endif() | ||
endif() | ||
|
||
find_path(LEVEL0_INCLUDE_DIR NAMES level_zero/ze_api.h | ||
HINTS ${LEVEL0_ROOT}/include /usr ${LEVEL0_ROOT}) | ||
|
||
find_library(LEVEL0_LIBRARY NAMES ze_loader | ||
HINTS ${LEVEL0_ROOT} ${LEVEL0_ROOT}/lib64 ${LEVEL0_ROOT}/lib /usr/lib64 /usr/lib) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
# handle the QUIETLY and REQUIRED arguments and set LEVEL0_FOUND to TRUE | ||
# if all listed variables are TRUE | ||
find_package_handle_standard_args(LEVEL0 DEFAULT_MSG | ||
LEVEL0_LIBRARY LEVEL0_INCLUDE_DIR) | ||
|
||
mark_as_advanced(LEVEL0_INCLUDE_DIR LEVEL0_LIBRARY) | ||
|
||
if(LEVEL0_FOUND) | ||
set(LEVEL0_LIBRARIES ${LEVEL0_LIBRARY} ) | ||
set(LEVEL0_INCLUDE_DIRS ${LEVEL0_INCLUDE_DIR}) | ||
set(LEVEL0_DIR ${LEVEL0_ROOT}) | ||
add_definitions(-DAPEX_HAVE_LEVEL0) | ||
endif() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#if __has_include(<cxxabi.h>) | ||
#define HAVE_CXXABI 1 | ||
#include <cxxabi.h> | ||
#include <cstring> | ||
#else | ||
#define HAVE_CXXABI 0 | ||
#endif | ||
#include <string> | ||
|
||
#include "pti_assert.h" | ||
|
||
namespace utils { | ||
|
||
static inline std::string Demangle(const char* name) { | ||
PTI_ASSERT(name != nullptr); | ||
|
||
#if HAVE_CXXABI | ||
int status = 0; | ||
char* demangled = abi::__cxa_demangle(name, nullptr, 0, &status); | ||
if (status != 0) { | ||
return name; | ||
} | ||
|
||
constexpr const char* const prefix_to_skip = "typeinfo name for "; | ||
const size_t prefix_to_skip_len = strlen(prefix_to_skip); | ||
const size_t shift = | ||
(std::strncmp(demangled, prefix_to_skip, prefix_to_skip_len) == 0) ? | ||
prefix_to_skip_len : 0; | ||
|
||
std::string result(demangled + shift); | ||
free(demangled); | ||
return result; | ||
#else | ||
return name; | ||
#endif | ||
} | ||
|
||
} // namespace utils | ||
|
||
#undef HAVE_CXXABI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//============================================================== | ||
// Copyright © 2020 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// ============================================================= | ||
|
||
#pragma once | ||
|
||
#ifdef NDEBUG | ||
#undef NDEBUG | ||
#include <assert.h> | ||
#define NDEBUG | ||
#else | ||
#include <assert.h> | ||
#endif | ||
|
||
#define PTI_ASSERT(X) assert(X) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
//============================================================== | ||
// Copyright (C) Intel Corporation | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// ============================================================= | ||
|
||
#pragma once | ||
|
||
#if defined(_WIN32) | ||
#include <windows.h> | ||
#else | ||
#include <unistd.h> | ||
#include <sys/syscall.h> | ||
#endif | ||
|
||
#include <stdint.h> | ||
|
||
#include <fstream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "pti_assert.h" | ||
|
||
#define STRINGIFY(x) #x | ||
#define TOSTRING(x) STRINGIFY(x) | ||
|
||
#define MAX_STR_SIZE 1024 | ||
|
||
#define BYTES_IN_MBYTES (1024 * 1024) | ||
|
||
#define NSEC_IN_USEC 1000 | ||
#define MSEC_IN_SEC 1000 | ||
#define NSEC_IN_MSEC 1000000 | ||
#define NSEC_IN_SEC 1000000000 | ||
|
||
namespace utils { | ||
|
||
struct Comparator { | ||
template<typename T> | ||
bool operator()(const T& left, const T& right) const { | ||
if (left.second != right.second) { | ||
return left.second > right.second; | ||
} | ||
return left.first > right.first; | ||
} | ||
}; | ||
|
||
#if defined(__gnu_linux__) | ||
|
||
inline uint64_t GetTime(clockid_t id) { | ||
timespec ts{0,0}; | ||
int status = clock_gettime(id, &ts); | ||
PTI_ASSERT(status == 0); | ||
return ts.tv_sec * NSEC_IN_SEC + ts.tv_nsec; | ||
} | ||
|
||
inline uint64_t ConvertClockMonotonicToRaw(uint64_t clock_monotonic) { | ||
uint64_t raw = GetTime(CLOCK_MONOTONIC_RAW); | ||
uint64_t monotonic = GetTime(CLOCK_MONOTONIC); | ||
return (raw > monotonic) ? | ||
clock_monotonic + (raw - monotonic) : | ||
clock_monotonic - (monotonic - raw); | ||
} | ||
|
||
#endif | ||
|
||
inline std::string GetFilePath(const std::string& filename) { | ||
PTI_ASSERT(!filename.empty()); | ||
|
||
size_t pos = filename.find_last_of("/\\"); | ||
if (pos == std::string::npos) { | ||
return ""; | ||
} | ||
|
||
return filename.substr(0, pos + 1); | ||
} | ||
|
||
inline std::string GetExecutablePath() { | ||
char buffer[MAX_STR_SIZE] = { 0 }; | ||
#if defined(_WIN32) | ||
DWORD status = GetModuleFileNameA(nullptr, buffer, MAX_STR_SIZE); | ||
PTI_ASSERT(status > 0); | ||
#else | ||
ssize_t status = readlink("/proc/self/exe", buffer, MAX_STR_SIZE); | ||
PTI_ASSERT(status > 0); | ||
#endif | ||
return GetFilePath(buffer); | ||
} | ||
|
||
inline std::string GetExecutableName() { | ||
char buffer[MAX_STR_SIZE] = { 0 }; | ||
#if defined(_WIN32) | ||
DWORD status = GetModuleFileNameA(nullptr, buffer, MAX_STR_SIZE); | ||
PTI_ASSERT(status > 0); | ||
#else | ||
ssize_t status = readlink("/proc/self/exe", buffer, MAX_STR_SIZE); | ||
PTI_ASSERT(status > 0); | ||
#endif | ||
std::string path(buffer); | ||
return path.substr(path.find_last_of("/\\") + 1); | ||
} | ||
|
||
inline std::vector<uint8_t> LoadBinaryFile(const std::string& path) { | ||
std::vector<uint8_t> binary; | ||
std::ifstream stream(path, std::ios::in | std::ios::binary); | ||
if (!stream.good()) { | ||
return binary; | ||
} | ||
|
||
stream.seekg(0, std::ifstream::end); | ||
size_t size = stream.tellg(); | ||
stream.seekg(0, std::ifstream::beg); | ||
if (size == 0) { | ||
return binary; | ||
} | ||
|
||
binary.resize(size); | ||
stream.read(reinterpret_cast<char *>(binary.data()), size); | ||
return binary; | ||
} | ||
|
||
inline void SetEnv(const char* name, const char* value) { | ||
PTI_ASSERT(name != nullptr); | ||
PTI_ASSERT(value != nullptr); | ||
|
||
int status = 0; | ||
#if defined(_WIN32) | ||
std::string str = std::string(name) + "=" + value; | ||
status = _putenv(str.c_str()); | ||
#else | ||
status = setenv(name, value, 1); | ||
#endif | ||
PTI_ASSERT(status == 0); | ||
} | ||
|
||
inline std::string GetEnv(const char* name) { | ||
PTI_ASSERT(name != nullptr); | ||
#if defined(_WIN32) | ||
char* value = nullptr; | ||
errno_t status = _dupenv_s(&value, nullptr, name); | ||
PTI_ASSERT(status == 0); | ||
if (value == nullptr) { | ||
return std::string(); | ||
} | ||
std::string result(value); | ||
free(value); | ||
return result; | ||
#else | ||
const char* value = getenv(name); | ||
if (value == nullptr) { | ||
return std::string(); | ||
} | ||
return std::string(value); | ||
#endif | ||
} | ||
|
||
inline uint32_t GetPid() { | ||
#if defined(_WIN32) | ||
return GetCurrentProcessId(); | ||
#else | ||
return getpid(); | ||
#endif | ||
} | ||
|
||
inline uint32_t GetTid() { | ||
#if defined(_WIN32) | ||
return GetCurrentThreadId(); | ||
#else | ||
#ifdef SYS_gettid | ||
return syscall(SYS_gettid); | ||
#else | ||
#error "SYS_gettid is unavailable on this system" | ||
#endif | ||
#endif | ||
} | ||
|
||
inline uint64_t GetSystemTime() { | ||
#if defined(_WIN32) | ||
LARGE_INTEGER ticks{0}; | ||
LARGE_INTEGER frequency{0}; | ||
BOOL status = QueryPerformanceFrequency(&frequency); | ||
PTI_ASSERT(status != 0); | ||
status = QueryPerformanceCounter(&ticks); | ||
PTI_ASSERT(status != 0); | ||
return ticks.QuadPart * (NSEC_IN_SEC / frequency.QuadPart); | ||
#else | ||
return GetTime(CLOCK_MONOTONIC_RAW); | ||
#endif | ||
} | ||
|
||
inline size_t LowerBound(const std::vector<uint64_t>& data, uint64_t value) { | ||
size_t start = 0; | ||
size_t end = data.size(); | ||
while (start < end) { | ||
size_t middle = (start + end) / 2; | ||
if (value <= data[middle]) { | ||
end = middle; | ||
} else { | ||
start = middle + 1; | ||
} | ||
} | ||
return start; | ||
} | ||
|
||
inline size_t UpperBound(const std::vector<uint64_t>& data, uint64_t value) { | ||
size_t start = 0; | ||
size_t end = data.size(); | ||
while (start < end) { | ||
size_t middle = (start + end) / 2; | ||
if (value >= data[middle]) { | ||
start = middle + 1; | ||
} else { | ||
end = middle; | ||
} | ||
} | ||
return start; | ||
} | ||
|
||
} // namespace utils | ||
|
Oops, something went wrong.