Skip to content

Commit

Permalink
Merge branch 'oneapi-src:main' into add-sycl-bench
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszpn committed Sep 20, 2024
2 parents 379e1bd + 7384e2d commit 7af46ef
Show file tree
Hide file tree
Showing 82 changed files with 2,172 additions and 1,068 deletions.
147 changes: 108 additions & 39 deletions cmake/match.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Copyright (C) 2023 Intel Corporation
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
Expand All @@ -12,6 +12,8 @@
# List of available special tags:
# {{OPT}} - makes content in the same line as the tag optional
# {{IGNORE}} - ignores all content until the next successfully matched line or the end of the input
# {{NONDETERMINISTIC}} - order of match rules isn't important - each (non OPT) input line is paired with a match line
# in any order
# Special tags are mutually exclusive and are expected to be located at the start of a line.
#

Expand All @@ -20,15 +22,25 @@
import re
from enum import Enum

## @brief print a sequence of lines
def print_lines(lines, hint = None):
counter = 1
for l in lines:
hint_char = " "
if hint == counter - 1:
hint_char = ">"
print("{}{:4d}| {}".format(hint_char, counter, l.strip()))
counter += 1


## @brief print the whole content of input and match files
def print_content(input_lines, match_lines, ignored_lines):
print("--- Input Lines " + "-" * 64)
print("".join(input_lines).strip())
print("--- Match Lines " + "-" * 64)
print("".join(match_lines).strip())
print("--- Ignored Lines " + "-" * 62)
print("".join(ignored_lines).strip())
def print_content(input_lines, match_lines, ignored_lines, hint_input = None, hint_match = None):
print("------ Input Lines " + "-" * 61)
print_lines(input_lines, hint_input)
print("------ Match Lines " + "-" * 61)
print_lines(match_lines, hint_match)
print("------ Ignored Lines " + "-" * 59)
print_lines(ignored_lines)
print("-" * 80)


Expand All @@ -39,6 +51,24 @@ def print_incorrect_match(match_line, present, expected):
print("expected: " + expected)


## @brief print missing match line
def print_input_not_found(input_line, input):
print("Input line " + str(input_line) + " has no match line")
print("is: " + input)


## @brief print missing input line
def print_match_not_found(match_line, input):
print("Match line " + str(match_line) + " has no input line")
print("is: " + input)


## @brief print general syntax error
def print_error(text, match_line):
print("Line " + str(match_line) + " encountered an error")
print(text)


## @brief pattern matching script status values
class Status(Enum):
INPUT_END = 1
Expand All @@ -63,6 +93,7 @@ def check_status(input_lines, match_lines):
class Tag(Enum):
OPT = "{{OPT}}" # makes the line optional
IGNORE = "{{IGNORE}}" # ignores all input until next match or end of input file
NONDETERMINISTIC = "{{NONDETERMINISTIC}}" # switches on "deterministic mode"
COMMENT = "#" # comment - line ignored


Expand All @@ -88,32 +119,53 @@ def main():
)

ignored_lines = []
matched_lines = set()

input_idx = 0
match_idx = 0
tags_in_effect = []
deterministic_mode = False
while True:
# check file status
status = check_status(input_lines[input_idx:], match_lines[match_idx:])
if (status == Status.INPUT_AND_MATCH_END) or (status == Status.MATCH_END and Tag.IGNORE in tags_in_effect):
# all lines matched or the last line in match file is an ignore tag
sys.exit(0)
elif status == Status.MATCH_END:
print_incorrect_match(match_idx + 1, input_lines[input_idx].strip(), "");
print_content(input_lines, match_lines, ignored_lines)
sys.exit(1)
elif status == Status.INPUT_END:
# If we get to the end of the input, but still have pending matches,
# then that's a failure unless all pending matches are optional -
# otherwise we're done
while match_idx < len(match_lines):
if not (match_lines[match_idx].startswith(Tag.OPT.value) or
match_lines[match_idx].startswith(Tag.IGNORE.value)):
print_incorrect_match(match_idx + 1, "", match_lines[match_idx]);
print_content(input_lines, match_lines, ignored_lines)
if deterministic_mode:
if status == Status.INPUT_END:
# Convert the list of seen matches to the list of unseen matches
remaining_matches = set(range(len(match_lines))) - matched_lines
for m in remaining_matches:
line = match_lines[m]
if line.startswith(Tag.OPT.value) or line.startswith(Tag.NONDETERMINISTIC.value):
continue
print_match_not_found(m + 1, match_lines[m])
print_content(input_lines, match_lines, ignored_lines, hint_match=m)
sys.exit(1)
match_idx += 1
sys.exit(0)

sys.exit(0)
elif status == Status.MATCH_END:
print_input_not_found(input_idx + 1, input_lines[input_idx])
print_content(input_lines, match_lines, ignored_lines, hint_input=input_idx)
sys.exit(1)
else:
if (status == Status.INPUT_AND_MATCH_END) or (status == Status.MATCH_END and Tag.IGNORE in tags_in_effect):
# all lines matched or the last line in match file is an ignore tag
sys.exit(0)
elif status == Status.MATCH_END:
print_incorrect_match(input_idx + 1, input_lines[input_idx].strip(), "")
print_content(input_lines, match_lines, ignored_lines, hint_input=input_idx)
sys.exit(1)
elif status == Status.INPUT_END:
# If we get to the end of the input, but still have pending matches,
# then that's a failure unless all pending matches are optional -
# otherwise we're done
while match_idx < len(match_lines):
if not (match_lines[match_idx].startswith(Tag.OPT.value) or
match_lines[match_idx].startswith(Tag.IGNORE.value) or
match_lines[match_idx].startswith(Tag.NONDETERMINISTIC.value)):
print_incorrect_match(match_idx + 1, "", match_lines[match_idx])
print_content(input_lines, match_lines, ignored_lines, hint_match=match_idx)
sys.exit(1)
match_idx += 1
sys.exit(0)

input_line = input_lines[input_idx].strip() if input_idx < len(input_lines) else ""
match_line = match_lines[match_idx]
Expand All @@ -122,7 +174,15 @@ def main():
if match_line.startswith(Tag.OPT.value):
tags_in_effect.append(Tag.OPT)
match_line = match_line[len(Tag.OPT.value):]
elif match_line.startswith(Tag.NONDETERMINISTIC.value) and not deterministic_mode:
deterministic_mode = True
match_idx = 0
input_idx = 0
continue
elif match_line.startswith(Tag.IGNORE.value):
if deterministic_mode:
print_error(r"Can't use \{{IGNORE\}} in deterministic mode")
sys.exit(2)
tags_in_effect.append(Tag.IGNORE)
match_idx += 1
continue # line with ignore tag should be skipped
Expand All @@ -137,20 +197,29 @@ def main():
pattern += part

# match or process tags
if re.fullmatch(pattern, input_line):
input_idx += 1
match_idx += 1
tags_in_effect = []
elif Tag.OPT in tags_in_effect:
match_idx += 1
tags_in_effect.remove(Tag.OPT)
elif Tag.IGNORE in tags_in_effect:
ignored_lines.append(input_line + os.linesep)
input_idx += 1
if deterministic_mode:
if re.fullmatch(pattern, input_line) and match_idx not in matched_lines:
input_idx += 1
matched_lines.add(match_idx)
match_idx = 0
tags_in_effect = []
else:
match_idx += 1
else:
print_incorrect_match(match_idx + 1, input_line, match_line.strip())
print_content(input_lines, match_lines, ignored_lines)
sys.exit(1)
if re.fullmatch(pattern, input_line):
input_idx += 1
match_idx += 1
tags_in_effect = []
elif Tag.OPT in tags_in_effect:
match_idx += 1
tags_in_effect.remove(Tag.OPT)
elif Tag.IGNORE in tags_in_effect:
ignored_lines.append(input_line + os.linesep)
input_idx += 1
else:
print_incorrect_match(match_idx + 1, input_line, match_line.strip())
print_content(input_lines, match_lines, ignored_lines, hint_match=match_idx, hint_input=input_idx)
sys.exit(1)


if __name__ == "__main__":
Expand Down
12 changes: 8 additions & 4 deletions scripts/templates/trcddi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ namespace ur_tracing_layer
${th.make_pfncb_param_type(n, tags, obj)} params = { &${",&".join(th.make_param_lines(n, tags, obj, format=["name"]))} };
uint64_t instance = getContext()->notify_begin(${th.make_func_etor(n, tags, obj)}, "${th.make_func_name(n, tags, obj)}", &params);

getContext()->logger.info("---> ${th.make_func_name(n, tags, obj)}");
auto &logger = getContext()->logger;

logger.info("---> ${th.make_func_name(n, tags, obj)}");

${x}_result_t result = ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );

getContext()->notify_end(${th.make_func_etor(n, tags, obj)}, "${th.make_func_name(n, tags, obj)}", &params, &result, instance);

std::ostringstream args_str;
ur::extras::printFunctionParams(args_str, ${th.make_func_etor(n, tags, obj)}, &params);
getContext()->logger.info("({}) -> {};\n", args_str.str(), result);
if (logger.getLevel() <= logger::Level::INFO) {
std::ostringstream args_str;
ur::extras::printFunctionParams(args_str, ${th.make_func_etor(n, tags, obj)}, &params);
logger.info("({}) -> {};\n", args_str.str(), result);
}

return result;
}
Expand Down
12 changes: 6 additions & 6 deletions source/adapters/level_zero/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,11 @@ void globalAdapterOnDemandCleanup() {
}

ur_result_t adapterStateTeardown() {
bool LeakFound = false;

// Print the balance of various create/destroy native calls.
// The idea is to verify if the number of create(+) and destroy(-) calls are
// matched.
if (ZeCallCount && (UrL0LeaksDebug) != 0) {
bool LeakFound = false;
// clang-format off
//
// The format of this table is such that each row accounts for a
Expand Down Expand Up @@ -276,11 +275,12 @@ ur_result_t adapterStateTeardown() {
ZeCallCount->clear();
delete ZeCallCount;
ZeCallCount = nullptr;
if (LeakFound)
return UR_RESULT_ERROR_INVALID_MEM_OBJECT;
}
if (LeakFound)
return UR_RESULT_ERROR_INVALID_MEM_OBJECT;
// Due to multiple DLLMain definitions with SYCL, register to cleanup the
// Global Adapter after refcnt is 0

// Due to multiple DLLMain definitions with SYCL, register to cleanup the
// Global Adapter after refcnt is 0
#if defined(_WIN32)
umfTearDown();
std::atexit(globalAdapterOnDemandCleanup);
Expand Down
9 changes: 6 additions & 3 deletions source/adapters/level_zero/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,14 @@ ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *ZeName,
const char *ZeArgs, bool TraceError) {
logger::debug("ZE ---> {}{}", ZeName, ZeArgs);

if (UrL0LeaksDebug) {
++(*ZeCallCount)[ZeName];
if (ZeResult == ZE_RESULT_SUCCESS) {
if (UrL0LeaksDebug) {
++(*ZeCallCount)[ZeName];
}
return ZE_RESULT_SUCCESS;
}

if (ZeResult && TraceError) {
if (TraceError) {
const char *ErrorString = "Unknown";
zeParseError(ZeResult, ErrorString);
logger::error("Error ({}) in {}", ErrorString, ZeName);
Expand Down
18 changes: 14 additions & 4 deletions source/adapters/level_zero/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,12 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(

ur_event_handle_t ur_context_handle_t_::getEventFromContextCache(
bool HostVisible, bool WithProfiling, ur_device_handle_t Device,
bool CounterBasedEventEnabled) {
bool CounterBasedEventEnabled, bool UsingImmCmdList) {
std::scoped_lock<ur_mutex> Lock(EventCacheMutex);
auto Cache = getEventCache(HostVisible, WithProfiling, Device);
if (CounterBasedEventEnabled) {
Cache = getCounterBasedEventCache(WithProfiling, UsingImmCmdList, Device);
}
if (Cache->empty())
return nullptr;

Expand All @@ -585,9 +588,16 @@ void ur_context_handle_t_::addEventToContextCache(ur_event_handle_t Event) {
Device = Event->UrQueue->Device;
}

auto Cache = getEventCache(Event->isHostVisible(),
Event->isProfilingEnabled(), Device);
Cache->emplace_back(Event);
if (Event->CounterBasedEventsEnabled) {
auto Cache = getCounterBasedEventCache(
Event->isProfilingEnabled(),
!(Event->UrQueue) || (Event->UrQueue)->UsingImmCmdLists, Device);
Cache->emplace_back(Event);
} else {
auto Cache = getEventCache(Event->isHostVisible(),
Event->isProfilingEnabled(), Device);
Cache->emplace_back(Event);
}
}

ur_result_t
Expand Down
Loading

0 comments on commit 7af46ef

Please sign in to comment.