Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
b23fc4e4
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b23fc4e4
编写于
7月 09, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
7月 09, 2020
浏览文件
操作
浏览文件
下载
差异文件
!2938 Decouple the exception routines from Python.
Merge pull request !2938 from ZhangQinghua/master
上级
7fd22f8e
bde889ff
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
64 addition
and
12 deletion
+64
-12
mindspore/ccsrc/utils/log_adapter.cc
mindspore/ccsrc/utils/log_adapter.cc
+3
-10
mindspore/ccsrc/utils/log_adapter.h
mindspore/ccsrc/utils/log_adapter.h
+7
-0
mindspore/ccsrc/utils/log_adapter_py.cc
mindspore/ccsrc/utils/log_adapter_py.cc
+46
-0
tests/ut/cpp/operator/composite_test.cc
tests/ut/cpp/operator/composite_test.cc
+8
-2
未找到文件。
mindspore/ccsrc/utils/log_adapter.cc
浏览文件 @
b23fc4e4
...
...
@@ -18,7 +18,6 @@
#include <unistd.h>
#include <map>
#include "pybind11/pybind11.h"
#include "debug/trace.h"
// namespace to support utils module definition
...
...
@@ -219,16 +218,10 @@ void LogWriter::operator^(const LogStream &stream) const {
trace
::
TraceGraphEval
();
trace
::
GetEvalStackInfo
(
oss
);
if
(
exception_
type_
==
IndexErro
r
)
{
throw
pybind11
::
index_error
(
oss
.
str
());
if
(
exception_
handler_
!=
nullpt
r
)
{
exception_handler_
(
exception_type_
,
oss
.
str
());
}
if
(
exception_type_
==
ValueError
)
{
throw
pybind11
::
value_error
(
oss
.
str
());
}
if
(
exception_type_
==
TypeError
)
{
throw
pybind11
::
type_error
(
oss
.
str
());
}
pybind11
::
pybind11_fail
(
oss
.
str
());
throw
std
::
runtime_error
(
oss
.
str
());
}
static
std
::
string
GetEnv
(
const
std
::
string
&
envvar
)
{
...
...
mindspore/ccsrc/utils/log_adapter.h
浏览文件 @
b23fc4e4
...
...
@@ -22,6 +22,7 @@
#include <string>
#include <sstream>
#include <memory>
#include <functional>
#include "./overload.h"
#include "./securec.h"
#ifdef USE_GLOG
...
...
@@ -133,6 +134,8 @@ extern int g_ms_submodule_log_levels[] __attribute__((visibility("default")));
class
LogWriter
{
public:
using
ExceptionHandler
=
std
::
function
<
void
(
ExceptionType
,
const
std
::
string
&
msg
)
>
;
LogWriter
(
const
LocationInfo
&
location
,
MsLogLevel
log_level
,
SubModuleId
submodule
,
ExceptionType
excp_type
=
NoExceptionType
)
:
location_
(
location
),
log_level_
(
log_level
),
submodule_
(
submodule
),
exception_type_
(
excp_type
)
{}
...
...
@@ -141,6 +144,8 @@ class LogWriter {
void
operator
<
(
const
LogStream
&
stream
)
const
noexcept
__attribute__
((
visibility
(
"default"
)));
void
operator
^
(
const
LogStream
&
stream
)
const
__attribute__
((
noreturn
,
visibility
(
"default"
)));
static
void
set_exception_handler
(
ExceptionHandler
exception_handler
)
{
exception_handler_
=
exception_handler
;
}
private:
void
OutputLog
(
const
std
::
ostringstream
&
msg
)
const
;
...
...
@@ -148,6 +153,8 @@ class LogWriter {
MsLogLevel
log_level_
;
SubModuleId
submodule_
;
ExceptionType
exception_type_
;
inline
static
ExceptionHandler
exception_handler_
=
nullptr
;
};
#define MSLOG_IF(level, condition, excp_type) \
...
...
mindspore/ccsrc/utils/log_adapter_py.cc
0 → 100644
浏览文件 @
b23fc4e4
/**
* 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 "utils/log_adapter.h"
#include <string>
#include "pybind11/pybind11.h"
namespace
py
=
pybind11
;
namespace
mindspore
{
class
PyExceptionInitializer
{
public:
PyExceptionInitializer
()
{
mindspore
::
LogWriter
::
set_exception_handler
(
HandleExceptionPy
);
}
~
PyExceptionInitializer
()
=
default
;
private:
static
void
HandleExceptionPy
(
ExceptionType
exception_type
,
const
std
::
string
&
str
)
{
if
(
exception_type
==
IndexError
)
{
throw
py
::
index_error
(
str
);
}
if
(
exception_type
==
ValueError
)
{
throw
py
::
value_error
(
str
);
}
if
(
exception_type
==
TypeError
)
{
throw
py
::
type_error
(
str
);
}
py
::
pybind11_fail
(
str
);
}
};
static
PyExceptionInitializer
py_exception_initializer
;
}
// namespace mindspore
tests/ut/cpp/operator/composite_test.cc
浏览文件 @
b23fc4e4
...
...
@@ -127,11 +127,17 @@ TEST_F(TestComposite, test_TupleSlice_arg_one_number) {
try
{
trace
::
ClearTraceStack
();
engine_
->
Run
(
tupleSliceGraphPtr
,
args_spec_list
);
FAIL
()
<<
"Excepted exception
:
Args type is wrong"
;
FAIL
()
<<
"Excepted exception
:
Args type is wrong"
;
}
catch
(
pybind11
::
type_error
const
&
err
)
{
ASSERT_TRUE
(
true
);
}
catch
(
std
::
runtime_error
const
&
err
)
{
if
(
std
::
strstr
(
err
.
what
(),
"TypeError"
)
!=
nullptr
)
{
ASSERT_TRUE
(
true
);
}
else
{
FAIL
()
<<
"Excepted exception: Args type is wrong, message: "
<<
err
.
what
();
}
}
catch
(...)
{
FAIL
()
<<
"Excepted exception
:
Args type is wrong"
;
FAIL
()
<<
"Excepted exception
:
Args type is wrong"
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录