Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to determine cause of L0 crashes #1057

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions source/adapters/level_zero/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterRetain(ur_adapter_handle_t) {
}

UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetLastError(
[[maybe_unused]] ur_adapter_handle_t
AdapterHandle, ///< [in] handle of the platform instance
ur_adapter_handle_t Adapter, ///< [in] handle of the platform instance
const char **Message, ///< [out] pointer to a C string where the adapter
///< specific error message will be stored.
[[maybe_unused]] int32_t
*Error ///< [out] pointer to an integer where the adapter specific
///< error code will be stored.
int32_t *Error ///< [out] pointer to an integer where the adapter specific
///< error code will be stored.
) {
AdapterHandle = &Adapter;
*Message = ErrorMessage;
Error = &ErrorAdapterNativeCode;

return ErrorMessageCode;
std::ignore = Adapter;
std::ignore = Message;
std::ignore = Error;
urPrint("[UR][L0] %s function not implemented!\n", __FUNCTION__);
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetInfo(ur_adapter_handle_t,
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/level_zero/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ ur_result_t calculateKernelWorkDimensions(
Device->ZeDeviceComputeProperties->maxGroupSizeX,
Device->ZeDeviceComputeProperties->maxGroupSizeY,
Device->ZeDeviceComputeProperties->maxGroupSizeZ};
GroupSize[I] = (std::min)(size_t(GroupSize[I]), GlobalWorkSize[I]);
GroupSize[I] = std::min(size_t(GroupSize[I]), GlobalWorkSize[I]);
while (GlobalWorkSize[I] % GroupSize[I]) {
--GroupSize[I];
}
Expand Down
13 changes: 5 additions & 8 deletions source/adapters/level_zero/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,13 @@ template <> zes_structure_type_t getZesStructureType<zes_mem_properties_t>() {
// Global variables for ZER_EXT_RESULT_ADAPTER_SPECIFIC_ERROR
thread_local ur_result_t ErrorMessageCode = UR_RESULT_SUCCESS;
thread_local char ErrorMessage[MaxMessageSize];
thread_local int32_t ErrorAdapterNativeCode;

// Utility function for setting a message and warning
[[maybe_unused]] void setErrorMessage(const char *pMessage,
ur_result_t ErrorCode,
int32_t AdapterErrorCode) {
assert(strlen(pMessage) <= MaxMessageSize);
strcpy(ErrorMessage, pMessage);
ErrorMessageCode = ErrorCode;
ErrorAdapterNativeCode = AdapterErrorCode;
[[maybe_unused]] void setErrorMessage(const char *message,
ur_result_t error_code) {
assert(strlen(message) <= MaxMessageSize);
strcpy(ErrorMessage, message);
ErrorMessageCode = error_code;
}

ur_result_t zerPluginGetLastError(char **message) {
Expand Down
6 changes: 2 additions & 4 deletions source/adapters/level_zero/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,7 @@ constexpr char ZE_SUPPORTED_EXTENSIONS[] =
constexpr size_t MaxMessageSize = 256;
extern thread_local ur_result_t ErrorMessageCode;
extern thread_local char ErrorMessage[MaxMessageSize];
extern thread_local int32_t ErrorAdapterNativeCode;

// Utility function for setting a message and warning
[[maybe_unused]] void setErrorMessage(const char *pMessage,
ur_result_t ErrorCode,
int32_t AdapterErrorCode);
[[maybe_unused]] void setErrorMessage(const char *message,
ur_result_t error_code);
7 changes: 3 additions & 4 deletions source/adapters/level_zero/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(

uint32_t ZeDeviceCount = MatchedDevices.size();

auto N = (std::min)(ZeDeviceCount, NumEntries);
auto N = std::min(ZeDeviceCount, NumEntries);
if (Devices)
std::copy_n(MatchedDevices.begin(), N, Devices);

Expand Down Expand Up @@ -631,8 +631,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(
case UR_DEVICE_INFO_GLOBAL_MEM_FREE: {
if (getenv("ZES_ENABLE_SYSMAN") == nullptr) {
setErrorMessage("Set ZES_ENABLE_SYSMAN=1 to obtain free memory",
UR_RESULT_ERROR_UNINITIALIZED,
static_cast<int32_t>(ZE_RESULT_ERROR_UNINITIALIZED));
UR_RESULT_SUCCESS);
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
}
// Only report device memory which zeMemAllocDevice can allocate from.
Expand Down Expand Up @@ -1240,7 +1239,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceSelectBinary(
uint32_t *SelectedBinaryInd = SelectedBinary;

// Find the appropriate device image, fallback to spirv if not found
constexpr uint32_t InvalidInd = (std::numeric_limits<uint32_t>::max)();
constexpr uint32_t InvalidInd = std::numeric_limits<uint32_t>::max();
uint32_t Spirv = InvalidInd;

for (uint32_t i = 0; i < NumBinaries; ++i) {
Expand Down
18 changes: 8 additions & 10 deletions source/adapters/level_zero/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch(
UR_RESULT_ERROR_INVALID_VALUE);
if (LocalWorkSize) {
// L0
UR_ASSERT(LocalWorkSize[0] < (std::numeric_limits<uint32_t>::max)(),
UR_ASSERT(LocalWorkSize[0] < std::numeric_limits<uint32_t>::max(),
UR_RESULT_ERROR_INVALID_VALUE);
UR_ASSERT(LocalWorkSize[1] < (std::numeric_limits<uint32_t>::max)(),
UR_ASSERT(LocalWorkSize[1] < std::numeric_limits<uint32_t>::max(),
UR_RESULT_ERROR_INVALID_VALUE);
UR_ASSERT(LocalWorkSize[2] < (std::numeric_limits<uint32_t>::max)(),
UR_ASSERT(LocalWorkSize[2] < std::numeric_limits<uint32_t>::max(),
UR_RESULT_ERROR_INVALID_VALUE);
WG[0] = static_cast<uint32_t>(LocalWorkSize[0]);
WG[1] = static_cast<uint32_t>(LocalWorkSize[1]);
Expand All @@ -110,7 +110,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch(
Queue->Device->ZeDeviceComputeProperties->maxGroupSizeX,
Queue->Device->ZeDeviceComputeProperties->maxGroupSizeY,
Queue->Device->ZeDeviceComputeProperties->maxGroupSizeZ};
GroupSize[I] = (std::min)(size_t(GroupSize[I]), GlobalWorkSize[I]);
GroupSize[I] = std::min(size_t(GroupSize[I]), GlobalWorkSize[I]);
while (GlobalWorkSize[I] % GroupSize[I]) {
--GroupSize[I];
}
Expand Down Expand Up @@ -284,9 +284,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableWrite(
(Program->ZeModule, Name, &GlobalVarSize, &GlobalVarPtr));
if (GlobalVarSize < Offset + Count) {
setErrorMessage("Write device global variable is out of range.",
UR_RESULT_ERROR_INVALID_VALUE,
static_cast<int32_t>(ZE_RESULT_ERROR_INVALID_ARGUMENT));
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
UR_RESULT_ERROR_INVALID_VALUE);
return UR_RESULT_ERROR_UNKNOWN;
}

// Copy engine is preferred only for host to device transfer.
Expand Down Expand Up @@ -334,9 +333,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableRead(
(Program->ZeModule, Name, &GlobalVarSize, &GlobalVarPtr));
if (GlobalVarSize < Offset + Count) {
setErrorMessage("Read from device global variable is out of range.",
UR_RESULT_ERROR_INVALID_VALUE,
static_cast<int32_t>(ZE_RESULT_ERROR_INVALID_ARGUMENT));
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
UR_RESULT_ERROR_INVALID_VALUE);
return UR_RESULT_ERROR_UNKNOWN;
}

// Copy engine is preferred only for host to device transfer.
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/level_zero/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGet(
if (*NumPlatforms == 0)
*NumPlatforms = URPlatformsCache->size();
else
*NumPlatforms = (std::min)(URPlatformsCache->size(), (size_t)NumEntries);
*NumPlatforms = std::min(URPlatformsCache->size(), (size_t)NumEntries);
}

return UR_RESULT_SUCCESS;
Expand Down
22 changes: 16 additions & 6 deletions source/adapters/level_zero/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,8 @@ ur_queue_handle_t_::ur_queue_handle_t_(
// Set-up to round-robin across allowed range of engines.
uint32_t FilterLowerIndex = getRangeOfAllowedComputeEngines().first;
uint32_t FilterUpperIndex = getRangeOfAllowedComputeEngines().second;
FilterUpperIndex = (std::min)((size_t)FilterUpperIndex,
FilterLowerIndex + ComputeQueues.size() - 1);
FilterUpperIndex = std::min((size_t)FilterUpperIndex,
FilterLowerIndex + ComputeQueues.size() - 1);
if (FilterLowerIndex <= FilterUpperIndex) {
ComputeQueueGroup.LowerIndex = FilterLowerIndex;
ComputeQueueGroup.UpperIndex = FilterUpperIndex;
Expand Down Expand Up @@ -959,8 +959,8 @@ ur_queue_handle_t_::ur_queue_handle_t_(
} else {
uint32_t FilterLowerIndex = Range.first;
uint32_t FilterUpperIndex = Range.second;
FilterUpperIndex = (std::min)((size_t)FilterUpperIndex,
FilterLowerIndex + CopyQueues.size() - 1);
FilterUpperIndex = std::min((size_t)FilterUpperIndex,
FilterLowerIndex + CopyQueues.size() - 1);
if (FilterLowerIndex <= FilterUpperIndex) {
CopyQueueGroup.ZeQueues = CopyQueues;
CopyQueueGroup.LowerIndex = FilterLowerIndex;
Expand Down Expand Up @@ -1406,8 +1406,18 @@ ur_result_t ur_queue_handle_t_::synchronize() {
if (ImmCmdList == Queue->CommandListMap.end())
return UR_RESULT_SUCCESS;

// wait for all commands previously submitted to this immediate command list
ZE2UR_CALL(zeCommandListHostSynchronize, (ImmCmdList->first, UINT64_MAX));
ur_event_handle_t Event{};
ur_result_t Res = createEventAndAssociateQueue(
reinterpret_cast<ur_queue_handle_t>(Queue), &Event,
UR_EXT_COMMAND_TYPE_USER, ImmCmdList, /* IsInternal */ false);
if (Res != UR_RESULT_SUCCESS)
return Res;
auto zeEvent = Event->ZeEvent;
ZE2UR_CALL(zeCommandListAppendBarrier,
(ImmCmdList->first, zeEvent, 0, nullptr));
ZE2UR_CALL(zeHostSynchronize, (zeEvent));
Event->Completed = true;
UR_CALL(urEventRelease(Event));

// Cleanup all events from the synced command list.
CleanupEventListFromResetCmdList(ImmCmdList->second.EventList, true);
Expand Down
30 changes: 6 additions & 24 deletions source/adapters/level_zero/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,8 @@ static ur_result_t USMDeviceAllocImpl(void **ResultPtr,
reinterpret_cast<std::uintptr_t>(*ResultPtr) % Alignment == 0,
UR_RESULT_ERROR_INVALID_VALUE);

// TODO: Return any non-success result from USMAllocationMakeResident once
// oneapi-src/level-zero-spec#240 is resolved.
auto Result = USMAllocationMakeResident(USMDeviceAllocationForceResidency,
Context, Device, *ResultPtr, Size);
if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY ||
Result == UR_RESULT_ERROR_OUT_OF_HOST_MEMORY) {
return Result;
}
USMAllocationMakeResident(USMDeviceAllocationForceResidency, Context, Device,
*ResultPtr, Size);
return UR_RESULT_SUCCESS;
}

Expand Down Expand Up @@ -231,14 +225,8 @@ static ur_result_t USMSharedAllocImpl(void **ResultPtr,
reinterpret_cast<std::uintptr_t>(*ResultPtr) % Alignment == 0,
UR_RESULT_ERROR_INVALID_VALUE);

// TODO: Return any non-success result from USMAllocationMakeResident once
// oneapi-src/level-zero-spec#240 is resolved.
auto Result = USMAllocationMakeResident(USMSharedAllocationForceResidency,
Context, Device, *ResultPtr, Size);
if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY ||
Result == UR_RESULT_ERROR_OUT_OF_HOST_MEMORY) {
return Result;
}
USMAllocationMakeResident(USMSharedAllocationForceResidency, Context, Device,
*ResultPtr, Size);

// TODO: Handle PI_MEM_ALLOC_DEVICE_READ_ONLY.
return UR_RESULT_SUCCESS;
Expand All @@ -259,14 +247,8 @@ static ur_result_t USMHostAllocImpl(void **ResultPtr,
reinterpret_cast<std::uintptr_t>(*ResultPtr) % Alignment == 0,
UR_RESULT_ERROR_INVALID_VALUE);

// TODO: Return any non-success result from USMAllocationMakeResident once
// oneapi-src/level-zero-spec#240 is resolved.
auto Result = USMAllocationMakeResident(USMHostAllocationForceResidency,
Context, nullptr, *ResultPtr, Size);
if (Result == UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY ||
Result == UR_RESULT_ERROR_OUT_OF_HOST_MEMORY) {
return Result;
}
USMAllocationMakeResident(USMHostAllocationForceResidency, Context, nullptr,
*ResultPtr, Size);
return UR_RESULT_SUCCESS;
}

Expand Down
1 change: 1 addition & 0 deletions test/conformance/runtime/runtime_adapter_level_zero.match
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
urAdapterGetLastErrorTest.Success
Loading