Skip to content

Commit

Permalink
Merge pull request oneapi-src#1802 from nrspruit/fix_immediate_cmdlis…
Browse files Browse the repository at this point in the history
…t_reuse

[L0] Fix immediate command list use in Command Queues
  • Loading branch information
aarongreig authored and pbalcer committed Jul 5, 2024
2 parents 4030080 + 665d4a6 commit 9d46a9c
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 418 deletions.
12 changes: 6 additions & 6 deletions scripts/templates/ldrddi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace ur_loader
size_t adapterIndex = 0;
if( nullptr != ${obj['params'][1]['name']} && ${obj['params'][0]['name']} !=0)
{
for( auto& platform : context->platforms )
for( auto& platform : getContext()->platforms )
{
if(platform.initStatus != ${X}_RESULT_SUCCESS)
continue;
Expand All @@ -81,7 +81,7 @@ namespace ur_loader

if( ${obj['params'][2]['name']} != nullptr )
{
*${obj['params'][2]['name']} = static_cast<uint32_t>(context->platforms.size());
*${obj['params'][2]['name']} = static_cast<uint32_t>(getContext()->platforms.size());
}

%elif re.match(r"\w+PlatformGet$", th.make_func_name(n, tags, obj)):
Expand Down Expand Up @@ -360,13 +360,13 @@ ${tbl['export']['name']}(
if( nullptr == pDdiTable )
return ${X}_RESULT_ERROR_INVALID_NULL_POINTER;
if( ur_loader::context->version < version )
if( ur_loader::getContext()->version < version )
return ${X}_RESULT_ERROR_UNSUPPORTED_VERSION;
${x}_result_t result = ${X}_RESULT_SUCCESS;
// Load the device-platform DDI tables
for( auto& platform : ur_loader::context->platforms )
for( auto& platform : ur_loader::getContext()->platforms )
{
if(platform.initStatus != ${X}_RESULT_SUCCESS)
continue;
Expand All @@ -379,7 +379,7 @@ ${tbl['export']['name']}(
if( ${X}_RESULT_SUCCESS == result )
{
if( ur_loader::context->platforms.size() != 1 || ur_loader::context->forceIntercept )
if( ur_loader::getContext()->platforms.size() != 1 || ur_loader::getContext()->forceIntercept )
{
// return pointers to loader's DDIs
%for obj in tbl['functions']:
Expand All @@ -397,7 +397,7 @@ ${tbl['export']['name']}(
else
{
// return pointers directly to platform's DDIs
*pDdiTable = ur_loader::context->platforms.front().dditable.${n}.${tbl['name']};
*pDdiTable = ur_loader::getContext()->platforms.front().dditable.${n}.${tbl['name']};
}
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/templates/libapi.cpp.mako
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ try {
%endfor

static ${x}_result_t result = ${X}_RESULT_SUCCESS;
std::call_once(${x}_lib::context->initOnce, [device_flags, hLoaderConfig]() {
result = ${x}_lib::context->Init(device_flags, hLoaderConfig);
std::call_once(${x}_lib::getContext()->initOnce, [device_flags, hLoaderConfig]() {
result = ${x}_lib::getContext()->Init(device_flags, hLoaderConfig);
});

return result;
%elif th.obj_traits.is_loader_only(obj):
return ur_lib::${th.make_func_name(n, tags, obj)}(${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );
%else:
auto ${th.make_pfn_name(n, tags, obj)} = ${x}_lib::context->${n}DdiTable.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)};
auto ${th.make_pfn_name(n, tags, obj)} = ${x}_lib::getContext()->${n}DdiTable.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)};
if( nullptr == ${th.make_pfn_name(n, tags, obj)} )
return ${X}_RESULT_ERROR_UNINITIALIZED;

Expand Down
4 changes: 4 additions & 0 deletions source/adapters/level_zero/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ ur_result_t ur_context_handle_t_::getAvailableCommandList(
!(ZeCommandListIt->second.InOrderList)) {
continue;
}
// Only allow to reuse Regular Command Lists
if (ZeCommandListIt->second.IsImmediate) {
continue;
}
auto &ZeCommandList = ZeCommandListIt->first;
auto it = Queue->CommandListMap.find(ZeCommandList);
if (it != Queue->CommandListMap.end()) {
Expand Down
1 change: 1 addition & 0 deletions source/adapters/level_zero/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
struct l0_command_list_cache_info {
ZeStruct<ze_command_queue_desc_t> ZeQueueDesc;
bool InOrderList = false;
bool IsImmediate = false;
};

struct ur_context_handle_t_ : _ur_object {
Expand Down
11 changes: 7 additions & 4 deletions source/adapters/level_zero/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ ur_result_t ur_queue_handle_legacy_t_::queueRelease() {
struct l0_command_list_cache_info ListInfo;
ListInfo.ZeQueueDesc = it->second.ZeQueueDesc;
ListInfo.InOrderList = it->second.IsInOrderList;
ListInfo.IsImmediate = it->second.IsImmediate;
ZeCommandListCache.push_back({it->first, ListInfo});
} else {
// A non-reusable comamnd list that came from a make_queue call is
Expand Down Expand Up @@ -745,7 +746,8 @@ void ur_queue_handle_legacy_t_::ur_queue_group_t::setImmCmdList(
.insert(std::pair<ze_command_list_handle_t, ur_command_list_info_t>{
ZeCommandList,
ur_command_list_info_t(nullptr, true, false, nullptr, ZeQueueDesc,
queue->useCompletionBatching(), false)})
queue->useCompletionBatching(), false,
false, true)})
.first);
}

Expand Down Expand Up @@ -2080,6 +2082,7 @@ ur_result_t ur_queue_handle_legacy_t_::resetCommandList(
struct l0_command_list_cache_info ListInfo;
ListInfo.ZeQueueDesc = CommandList->second.ZeQueueDesc;
ListInfo.InOrderList = CommandList->second.IsInOrderList;
ListInfo.IsImmediate = CommandList->second.IsImmediate;
ZeCommandListCache.push_back({CommandList->first, ListInfo});
}

Expand Down Expand Up @@ -2430,9 +2433,9 @@ ur_queue_handle_legacy_t_::ur_queue_group_t::getImmCmdList() {
Queue->CommandListMap
.insert(std::pair<ze_command_list_handle_t, ur_command_list_info_t>{
ZeCommandList,
ur_command_list_info_t(nullptr, true, false, nullptr,
ZeCommandQueueDesc,
Queue->useCompletionBatching())})
ur_command_list_info_t(
nullptr, true, false, nullptr, ZeCommandQueueDesc,
Queue->useCompletionBatching(), true, false, true)})
.first;

return ImmCmdLists[Index];
Expand Down
6 changes: 4 additions & 2 deletions source/adapters/level_zero/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ struct ur_command_list_info_t {
bool IsClosed, ze_command_queue_handle_t ZeQueue,
ZeStruct<ze_command_queue_desc_t> ZeQueueDesc,
bool UseCompletionBatching, bool CanReuse = true,
bool IsInOrderList = false)
bool IsInOrderList = false, bool IsImmediate = false)
: ZeFence(ZeFence), ZeFenceInUse(ZeFenceInUse), IsClosed(IsClosed),
ZeQueue(ZeQueue), ZeQueueDesc(ZeQueueDesc),
IsInOrderList(IsInOrderList), CanReuse(CanReuse) {
IsInOrderList(IsInOrderList), CanReuse(CanReuse),
IsImmediate(IsImmediate) {
if (UseCompletionBatching) {
completions = ur_completion_batches();
}
Expand Down Expand Up @@ -204,6 +205,7 @@ struct ur_command_list_info_t {
// Indicates if this is an inorder list
bool IsInOrderList;
bool CanReuse;
bool IsImmediate;

// Helper functions to tell if this is a copy command-list.
bool isCopy(ur_queue_handle_legacy_t Queue) const;
Expand Down
4 changes: 0 additions & 4 deletions source/loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,10 @@ if(WIN32)
target_sources(ur_loader
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/windows/adapter_search.cpp
${CMAKE_CURRENT_SOURCE_DIR}/windows/lib_init.cpp
${CMAKE_CURRENT_SOURCE_DIR}/windows/loader_init.cpp
)
else()
target_sources(ur_loader
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/linux/adapter_search.cpp
${CMAKE_CURRENT_SOURCE_DIR}/linux/lib_init.cpp
${CMAKE_CURRENT_SOURCE_DIR}/linux/loader_init.cpp
)
endif()
21 changes: 0 additions & 21 deletions source/loader/linux/lib_init.cpp

This file was deleted.

21 changes: 0 additions & 21 deletions source/loader/linux/loader_init.cpp

This file was deleted.

Loading

0 comments on commit 9d46a9c

Please sign in to comment.