Skip to content

Commit 036370d

Browse files
[SYCL][XPTI] Unify data types used for code location (#19433)
Column and line numbers used to be represented as different data types (including both size and sign) in different parts of code. This commit aligned them all to `uint32_t` which seems to be used under the hood by both XPTI and UR. The only exception here is `code_location` struct fields: since it is a part of `handler`, we can't change data types there just yet without it breaking ABI. However, all APIs have been changed to use the new unified types to reduce amount of type casts necessary in the code that uses them. This PR belongs to a series which prepares SYCL RT codebase to be buildable with `-Wconversion` flag that is required per our SDL processes.
1 parent 999d788 commit 036370d

File tree

6 files changed

+35
-24
lines changed

6 files changed

+35
-24
lines changed

sycl/include/sycl/detail/common.hpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
#include <sycl/detail/defines_elementary.hpp> // for __SYCL_ALWAYS_INLINE
1515
#include <sycl/detail/export.hpp> // for __SYCL_EXPORT
1616

17-
#include <array> // for array
18-
#include <cassert> // for assert
19-
#include <cstddef> // for size_t
17+
#include <array> // for array
18+
#include <cassert> // for assert
19+
#include <cstddef> // for size_t
20+
#include <cstdint>
2021
#include <string> // for allocator, operator+
2122
#include <type_traits> // for enable_if_t
2223
#include <utility> // for index_sequence, make_i...
@@ -69,8 +70,8 @@ struct code_location {
6970
static constexpr code_location
7071
current(const char *fileName = __CODELOC_FILE_NAME,
7172
const char *funcName = __CODELOC_FUNCTION,
72-
unsigned long lineNo = __CODELOC_LINE,
73-
unsigned long columnNo = __CODELOC_COLUMN) noexcept {
73+
uint32_t lineNo = __CODELOC_LINE,
74+
uint32_t columnNo = __CODELOC_COLUMN) noexcept {
7475
return code_location(fileName, funcName, lineNo, columnNo);
7576
}
7677

@@ -79,23 +80,34 @@ struct code_location {
7980
#undef __CODELOC_LINE
8081
#undef __CODELOC_COLUMN
8182

82-
constexpr code_location(const char *file, const char *func, int line,
83-
int col) noexcept
83+
constexpr code_location(const char *file, const char *func, uint32_t line,
84+
uint32_t col) noexcept
8485
: MFileName(file), MFunctionName(func), MLineNo(line), MColumnNo(col) {}
8586

8687
constexpr code_location() noexcept
87-
: MFileName(nullptr), MFunctionName(nullptr), MLineNo(0), MColumnNo(0) {}
88+
: MFileName(nullptr), MFunctionName(nullptr), MLineNo(0u), MColumnNo(0u) {
89+
}
8890

89-
constexpr unsigned long lineNumber() const noexcept { return MLineNo; }
90-
constexpr unsigned long columnNumber() const noexcept { return MColumnNo; }
91+
constexpr uint32_t lineNumber() const noexcept {
92+
return static_cast<uint32_t>(MLineNo);
93+
}
94+
constexpr uint32_t columnNumber() const noexcept {
95+
return static_cast<uint32_t>(MColumnNo);
96+
}
9197
constexpr const char *fileName() const noexcept { return MFileName; }
9298
constexpr const char *functionName() const noexcept { return MFunctionName; }
9399

94100
private:
95101
const char *MFileName;
96102
const char *MFunctionName;
103+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
104+
// For preserving layout of handler class
97105
unsigned long MLineNo;
98106
unsigned long MColumnNo;
107+
#else
108+
uint32_t MLineNo;
109+
uint32_t MColumnNo;
110+
#endif
99111
};
100112

101113
/// @brief Data type that manages the code_location information in TLS

sycl/source/detail/cg.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class CG {
240240
// Storage for function name and source file name
241241
std::string MFunctionName, MFileName;
242242
// Storage for line and column of code location
243-
int32_t MLine, MColumn;
243+
uint32_t MLine, MColumn;
244244
bool MIsTopCodeLoc;
245245
};
246246

sycl/source/detail/queue_impl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,10 @@ void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc,
544544
xpti::addMetadata(WaitEvent, "sym_function_name", CodeLoc.functionName());
545545
xpti::addMetadata(WaitEvent, "sym_source_file_name", CodeLoc.fileName());
546546
xpti::addMetadata(WaitEvent, "sym_line_no",
547-
static_cast<int32_t>((CodeLoc.lineNumber())));
548-
xpti::addMetadata(WaitEvent, "sym_column_no",
549-
static_cast<int32_t>((CodeLoc.columnNumber())));
547+
static_cast<xpti::object_id_t>((CodeLoc.lineNumber())));
548+
xpti::addMetadata(
549+
WaitEvent, "sym_column_no",
550+
static_cast<xpti::object_id_t>((CodeLoc.columnNumber())));
550551
}
551552
xptiNotifySubscribers(StreamID, xpti::trace_wait_begin, nullptr, WaitEvent,
552553
QWaitInstanceNo,

sycl/source/detail/scheduler/commands.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,9 +1022,9 @@ void Command::copySubmissionCodeLocation() {
10221022
if (TData.functionName())
10231023
MSubmissionFunctionName = TData.functionName();
10241024
if (MSubmissionFileName.size() || MSubmissionFunctionName.size())
1025-
MSubmissionCodeLocation = {
1026-
MSubmissionFileName.c_str(), MSubmissionFunctionName.c_str(),
1027-
(int)TData.lineNumber(), (int)TData.columnNumber()};
1025+
MSubmissionCodeLocation = {MSubmissionFileName.c_str(),
1026+
MSubmissionFunctionName.c_str(),
1027+
TData.lineNumber(), TData.columnNumber()};
10281028
#endif
10291029
}
10301030

xpti/include/xpti/xpti_data_types.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,15 +578,13 @@ struct payload_t {
578578
/// @param codeptr (Optional) Pointer to the code location associated with
579579
/// this payload.
580580
///
581-
payload_t(const char *kname, const char *sf, int line, int col,
581+
payload_t(const char *kname, const char *sf, uint32_t line, uint32_t col,
582582
const void *codeptr = nullptr) {
583583
code_ptr_va = codeptr; ///< Override the default initialization
584584
name = kname; ///< Override the default initialization
585585
source_file = sf; ///< Override the default initialization
586-
line_no =
587-
static_cast<uint32_t>(line); ///< Override the default initialization
588-
column_no =
589-
static_cast<uint32_t>(col); ///< Override the default initialization
586+
line_no = line; ///< Override the default initialization
587+
column_no = col; ///< Override the default initialization
590588
// If the incoming name is null, we ensure that the flags are set correctly
591589
if (kname && kname[0] != '\0') {
592590
flags = (uint64_t)payload_flag_t::NameAvailable;

xpti/include/xpti/xpti_trace_framework.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,8 +1593,8 @@ class tracepoint_t {
15931593
// Constructor that makes calls to xpti API layer to register strings and
15941594
// create the Universal ID that is stored in the TLS entry for lookup; this
15951595
// constructor is needed when only code location information is available
1596-
tracepoint_t(const char *fileName, const char *funcName, int line, int column,
1597-
void *codeptr = nullptr)
1596+
tracepoint_t(const char *fileName, const char *funcName, uint32_t line,
1597+
uint32_t column, void *codeptr = nullptr)
15981598
: m_payload(nullptr), m_top(false) {
15991599
// If tracing is not enabled, don't do anything
16001600
if (!xptiTraceEnabled())

0 commit comments

Comments
 (0)