2021-02-23 17:57:27 +00:00
|
|
|
/*
|
2022-03-29 15:39:27 +00:00
|
|
|
* Copyright (C) 2021-2022 Intel Corporation
|
2021-02-23 17:57:27 +00:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2021-03-03 12:09:39 +00:00
|
|
|
#include "level_zero/tools/source/debug/debug_handlers.h"
|
|
|
|
|
|
2022-09-01 12:58:13 +00:00
|
|
|
#include "shared/source/os_interface/debug_env_reader.h"
|
|
|
|
|
|
2022-03-29 15:39:27 +00:00
|
|
|
#include "level_zero/core/source/device/device_imp.h"
|
2021-02-23 17:57:27 +00:00
|
|
|
#include "level_zero/tools/source/debug/debug_session.h"
|
|
|
|
|
|
|
|
|
|
namespace L0 {
|
2021-03-03 12:09:39 +00:00
|
|
|
namespace DebugApiHandlers {
|
2022-07-29 11:26:12 +00:00
|
|
|
|
|
|
|
|
std::mutex debugSessionMutex;
|
|
|
|
|
|
2021-02-23 17:57:27 +00:00
|
|
|
ze_result_t debugAttach(zet_device_handle_t hDevice, const zet_debug_config_t *config, zet_debug_session_handle_t *phDebug) {
|
2022-03-29 15:39:27 +00:00
|
|
|
ze_result_t result = ZE_RESULT_SUCCESS;
|
2022-07-29 11:26:12 +00:00
|
|
|
|
|
|
|
|
if (!L0::Device::fromHandle(hDevice)->getNEODevice()->isSubDevice() && NEO::DebugManager.flags.ExperimentalEnableTileAttach.get()) {
|
|
|
|
|
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 12:58:13 +00:00
|
|
|
NEO::EnvironmentVariableReader envReader;
|
|
|
|
|
auto affinityMask = envReader.getSetting("ZE_AFFINITY_MASK", std::string(""));
|
|
|
|
|
|
|
|
|
|
if (!affinityMask.empty()) {
|
|
|
|
|
NEO::printDebugString(NEO::DebugManager.flags.PrintDebugMessages.get(), stdout,
|
|
|
|
|
"%s", "ZE_AFFINITY_MASK is not recommended while using program debug API\n");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-29 15:39:27 +00:00
|
|
|
auto session = L0::Device::fromHandle(hDevice)->getDebugSession(*config);
|
|
|
|
|
|
2022-07-29 11:26:12 +00:00
|
|
|
std::unique_lock<std::mutex> lock(debugSessionMutex);
|
2022-03-29 15:39:27 +00:00
|
|
|
if (!session) {
|
|
|
|
|
session = L0::Device::fromHandle(hDevice)->createDebugSession(*config, result);
|
|
|
|
|
}
|
|
|
|
|
if (session) {
|
|
|
|
|
*phDebug = session->toHandle();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2021-02-23 17:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-29 15:39:27 +00:00
|
|
|
ze_result_t debugDetach(zet_debug_session_handle_t hDebug) {
|
|
|
|
|
auto session = L0::DebugSession::fromHandle(hDebug);
|
|
|
|
|
if (session) {
|
|
|
|
|
auto device = session->getConnectedDevice();
|
|
|
|
|
device->removeDebugSession();
|
2022-07-29 11:26:12 +00:00
|
|
|
|
2022-03-29 15:39:27 +00:00
|
|
|
session->closeConnection();
|
2022-07-29 11:26:12 +00:00
|
|
|
if (!device->getNEODevice()->isSubDevice()) {
|
|
|
|
|
delete session;
|
|
|
|
|
} else {
|
|
|
|
|
std::unique_lock<std::mutex> lock(debugSessionMutex);
|
|
|
|
|
auto rootL0Device = device->getNEODevice()->getRootDevice()->getSpecializedDevice<DeviceImp>();
|
|
|
|
|
zet_debug_config_t dummy = {};
|
|
|
|
|
auto rootSession = rootL0Device->getDebugSession(dummy);
|
|
|
|
|
rootSession->detachTileDebugSession(session);
|
|
|
|
|
|
|
|
|
|
if (rootSession->areAllTileDebugSessionDetached()) {
|
|
|
|
|
|
|
|
|
|
rootL0Device->removeDebugSession();
|
|
|
|
|
delete rootSession;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-29 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
return ZE_RESULT_SUCCESS;
|
|
|
|
|
}
|
2021-03-03 12:09:39 +00:00
|
|
|
|
2022-03-29 15:39:27 +00:00
|
|
|
ze_result_t debugReadEvent(zet_debug_session_handle_t hDebug, uint64_t timeout, zet_debug_event_t *event) { return L0::DebugSession::fromHandle(hDebug)->readEvent(timeout, event); }
|
2021-03-03 12:09:39 +00:00
|
|
|
|
2022-03-29 15:39:27 +00:00
|
|
|
ze_result_t debugInterrupt(zet_debug_session_handle_t hDebug, ze_device_thread_t thread) { return L0::DebugSession::fromHandle(hDebug)->interrupt(thread); }
|
2021-03-03 12:09:39 +00:00
|
|
|
|
2022-03-29 15:39:27 +00:00
|
|
|
ze_result_t debugResume(zet_debug_session_handle_t hDebug, ze_device_thread_t thread) { return L0::DebugSession::fromHandle(hDebug)->resume(thread); }
|
2021-03-03 12:09:39 +00:00
|
|
|
|
|
|
|
|
ze_result_t debugReadMemory(zet_debug_session_handle_t hDebug, ze_device_thread_t thread, const zet_debug_memory_space_desc_t *desc, size_t size, void *buffer) {
|
2022-03-29 15:39:27 +00:00
|
|
|
return L0::DebugSession::fromHandle(hDebug)->readMemory(thread, desc, size, buffer);
|
2021-03-03 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ze_result_t debugWriteMemory(zet_debug_session_handle_t hDebug, ze_device_thread_t thread, const zet_debug_memory_space_desc_t *desc, size_t size, const void *buffer) {
|
2022-03-29 15:39:27 +00:00
|
|
|
return L0::DebugSession::fromHandle(hDebug)->writeMemory(thread, desc, size, buffer);
|
2021-03-03 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-29 15:39:27 +00:00
|
|
|
ze_result_t debugAcknowledgeEvent(zet_debug_session_handle_t hDebug, const zet_debug_event_t *event) {
|
|
|
|
|
return L0::DebugSession::fromHandle(hDebug)->acknowledgeEvent(event);
|
|
|
|
|
}
|
2021-03-03 12:09:39 +00:00
|
|
|
|
|
|
|
|
ze_result_t debugGetRegisterSetProperties(zet_device_handle_t hDevice, uint32_t *pCount, zet_debug_regset_properties_t *pRegisterSetProperties) {
|
2022-03-29 15:39:27 +00:00
|
|
|
return L0::DebugSession::getRegisterSetProperties(L0::Device::fromHandle(hDevice), pCount, pRegisterSetProperties);
|
2021-03-03 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-22 18:45:53 -04:00
|
|
|
ze_result_t debugReadRegisters(zet_debug_session_handle_t hDebug, ze_device_thread_t thread, uint32_t type, uint32_t start, uint32_t count, void *pRegisterValues) {
|
2022-03-29 15:39:27 +00:00
|
|
|
return L0::DebugSession::fromHandle(hDebug)->readRegisters(thread, type, start, count, pRegisterValues);
|
2021-03-03 12:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-22 18:45:53 -04:00
|
|
|
ze_result_t debugWriteRegisters(zet_debug_session_handle_t hDebug, ze_device_thread_t thread, uint32_t type, uint32_t start, uint32_t count, void *pRegisterValues) {
|
2022-03-29 15:39:27 +00:00
|
|
|
return L0::DebugSession::fromHandle(hDebug)->writeRegisters(thread, type, start, count, pRegisterValues);
|
2021-03-03 12:09:39 +00:00
|
|
|
}
|
2022-03-29 15:39:27 +00:00
|
|
|
|
2021-03-03 12:09:39 +00:00
|
|
|
} // namespace DebugApiHandlers
|
2022-03-29 15:39:27 +00:00
|
|
|
} // namespace L0
|