Browse Source

handler signal

Signed-off-by: zhupuxu <zhupuxu@huawei.com>
tags/v1.2.0-rc1
zhupuxu 5 years ago
parent
commit
e36175b0dc
4 changed files with 86 additions and 0 deletions
  1. +2
    -0
      mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc
  2. +48
    -0
      mindspore/ccsrc/runtime/device/ascend/signal_util.cc
  3. +35
    -0
      mindspore/ccsrc/runtime/device/ascend/signal_util.h
  4. +1
    -0
      tests/ut/cpp/CMakeLists.txt

+ 2
- 0
mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc View File

@@ -22,6 +22,7 @@
#include <exception>
#include <algorithm>
#include <thread>
#include "runtime/device/ascend/signal_util.h"
#include "debug/data_dump/e2e_dump_util.h"
#include "runtime/device/ascend/ascend_device_address.h"
#include "runtime/device/cpu/mpi/mpi_interface.h"
@@ -595,6 +596,7 @@ void AscendKernelRuntime::DumpTaskExceptionInfo(const session::KernelGraph *grap
}

bool AscendKernelRuntime::Run(session::KernelGraph *graph, bool is_task_sink) {
SignalGuard sg;
MS_EXCEPTION_IF_NULL(graph);
bool ret = false;
#if defined(_WIN32) || defined(_WIN64)


+ 48
- 0
mindspore/ccsrc/runtime/device/ascend/signal_util.cc View File

@@ -0,0 +1,48 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "runtime/device/ascend/signal_util.h"
#include <signal.h>
#include <iostream>
#include "utils/log_adapter.h"

namespace mindspore {
SignalGuard::SignalGuard() { RegisterHandlers(); }

SignalGuard::~SignalGuard() {
if (old_handler != nullptr) {
int_action.sa_sigaction = old_handler;
(void)sigemptyset(&int_action.sa_mask);
int_action.sa_flags = SA_RESTART | SA_SIGINFO;
(void)sigaction(SIGINT, &int_action, nullptr);
}
}

void SignalGuard::RegisterHandlers() {
struct sigaction old_int_action;
(void)sigaction(SIGINT, nullptr, &old_int_action);
if (old_int_action.sa_sigaction != nullptr) {
MS_LOG(INFO) << "The signal has been registered";
old_handler = old_int_action.sa_sigaction;
}
int_action.sa_sigaction = &IntHandler;
(void)sigemptyset(&int_action.sa_mask);
int_action.sa_flags = SA_RESTART | SA_SIGINFO;
(void)sigaction(SIGINT, &int_action, nullptr);
}

void SignalGuard::IntHandler(int, siginfo_t *, void *) { MS_LOG_EXCEPTION << "Exit"; }
} // namespace mindspore

+ 35
- 0
mindspore/ccsrc/runtime/device/ascend/signal_util.h View File

@@ -0,0 +1,35 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_SIGNAL_UTIL_H_
#define MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_SIGNAL_UTIL_H_

#include <signal.h>

namespace mindspore {
class SignalGuard {
public:
SignalGuard();
~SignalGuard();

private:
void RegisterHandlers();
static void IntHandler(int sig_num, siginfo_t *sig_info, void *context);

void (*old_handler)(int, siginfo_t *, void *) = nullptr;
struct sigaction int_action;
};
} // namespace mindspore
#endif // MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_SIGNAL_UTIL_H_

+ 1
- 0
tests/ut/cpp/CMakeLists.txt View File

@@ -95,6 +95,7 @@ file(GLOB_RECURSE MINDSPORE_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"../../../mindspore/ccsrc/runtime/device/convert_tensor_utils.cc"
"../../../mindspore/ccsrc/runtime/device/ascend/kernel_build_ascend.cc"
"../../../mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc"
"../../../mindspore/ccsrc/runtime/device/ascend/signal_util.cc"
"../../../mindspore/ccsrc/runtime/device/ascend/ascend_memory_manager.cc"
"../../../mindspore/ccsrc/runtime/device/ascend/ascend_device_address.cc"
"../../../mindspore/ccsrc/runtime/device/ascend/ascend_memory_pool.cc"


Loading…
Cancel
Save