Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
e6914060
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e6914060
编写于
9月 17, 2020
作者:
L
luohang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[xpu] adjust XPU_L3_LOCK_REQUIRED implements
test=develop test=xpu
上级
8a6f1475
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
38 deletion
+52
-38
lite/backends/xpu/target_wrapper.cc
lite/backends/xpu/target_wrapper.cc
+2
-0
lite/core/context.h
lite/core/context.h
+40
-0
lite/core/program.cc
lite/core/program.cc
+10
-38
未找到文件。
lite/backends/xpu/target_wrapper.cc
浏览文件 @
e6914060
...
...
@@ -13,6 +13,7 @@
// limitations under the License.
#include "lite/backends/xpu/target_wrapper.h"
#include "lite/core/context.h"
#include "lite/utils/macros.h"
namespace
paddle
{
...
...
@@ -78,6 +79,7 @@ XPUScratchPadGuard TargetWrapperXPU::MallocScratchPad(size_t size,
std
::
string
TargetWrapperXPU
::
multi_encoder_precision
;
// NOLINT
int
TargetWrapperXPU
::
workspace_l3_size_per_thread
{
0
};
LITE_THREAD_LOCAL
xdnn
::
Context
*
TargetWrapperXPU
::
tls_raw_ctx_
{
nullptr
};
int
Context
<
TargetType
::
kXPU
>::
_reentrant
{
0
};
}
// namespace lite
}
// namespace paddle
lite/core/context.h
浏览文件 @
e6914060
...
...
@@ -29,6 +29,7 @@
#include "lite/backends/mlu/mlu_utils.h"
#endif
#ifdef LITE_WITH_XPU
#include <fcntl.h>
#include "lite/backends/xpu/xpu_header_sitter.h"
#endif
...
...
@@ -188,6 +189,45 @@ class Context<TargetType::kXPU> {
}
std
::
string
name
()
const
{
return
"XPUContext"
;
}
inline
static
int
LockXPU
()
{
_reentrant
=
0
;
int
xpu_l3_lock_fd
=
-
1
;
struct
flock
f_lock
;
f_lock
.
l_whence
=
0
;
f_lock
.
l_len
=
0
;
if
(
_reentrant
==
0
)
{
int
pd
=
0
;
// TODO(luohang): need get from lite api
std
::
string
buf
=
"/opt/xpu_lock"
+
std
::
to_string
(
pd
);
xpu_l3_lock_fd
=
open
(
buf
.
c_str
(),
O_RDWR
);
CHECK
(
xpu_l3_lock_fd
>
0
)
<<
"open "
<<
buf
<<
" failed: "
<<
xpu_l3_lock_fd
;
// lock
f_lock
.
l_type
=
F_WRLCK
;
fcntl
(
xpu_l3_lock_fd
,
F_SETLKW
,
&
f_lock
);
}
_reentrant
++
;
return
xpu_l3_lock_fd
;
}
inline
static
void
ReleaseXPU
(
int
lock_fd
)
{
if
(
lock_fd
<
0
)
return
;
if
(
_reentrant
==
1
)
{
struct
flock
f_lock
;
f_lock
.
l_whence
=
0
;
f_lock
.
l_len
=
0
;
f_lock
.
l_type
=
F_UNLCK
;
fcntl
(
lock_fd
,
F_SETLKW
,
&
f_lock
);
close
(
lock_fd
);
}
_reentrant
--
;
}
private:
static
int
_reentrant
;
};
#endif
...
...
lite/core/program.cc
浏览文件 @
e6914060
...
...
@@ -292,8 +292,17 @@ void RuntimeProgram::Run() {
if
(
inst
.
need_sync
())
{
inst
.
Sync
();
}
#endif
#ifdef LITE_WITH_XPU
auto
need_lock_l3
=
std
::
getenv
(
"XPU_L3_LOCK_REQUIRED"
);
int
lock_fd
=
-
1
;
if
(
need_lock_l3
)
lock_fd
=
Context
<
TargetType
::
kXPU
>::
LockXPU
();
#endif
inst
.
Run
();
#ifdef LITE_WITH_XPU
if
(
need_lock_l3
&&
lock_fd
>=
0
)
Context
<
TargetType
::
kXPU
>::
ReleaseXPU
(
lock_fd
);
#endif
#ifdef LITE_WITH_PRECISION_PROFILE
#ifndef LITE_WITH_FPGA
precision_profiler_summary
+=
...
...
@@ -442,44 +451,7 @@ void Instruction::Run() {
CHECK
(
op_
->
CheckShape
());
}
#ifdef LITE_WITH_XPU
static
int
reentrant
=
0
;
int
xpu_l3_lock_fd
;
auto
need_lock_l3
=
std
::
getenv
(
"XPU_L3_LOCK_REQUIRED"
);
struct
flock
f_lock
;
f_lock
.
l_whence
=
0
;
f_lock
.
l_len
=
0
;
if
(
reentrant
==
0
)
{
if
(
need_lock_l3
)
{
int
pd
=
0
;
// TODO(luohang): need get from lite api
std
::
string
buf
=
"/opt/xpu_lock"
+
std
::
to_string
(
pd
);
xpu_l3_lock_fd
=
open
(
buf
.
c_str
(),
O_RDWR
);
CHECK
(
xpu_l3_lock_fd
>
0
)
<<
"open "
<<
buf
<<
" failed: "
<<
xpu_l3_lock_fd
;
// lock
f_lock
.
l_type
=
F_WRLCK
;
fcntl
(
xpu_l3_lock_fd
,
F_SETLKW
,
&
f_lock
);
}
else
{
xpu_l3_lock_fd
=
-
1
;
}
}
reentrant
++
;
#endif
bool
run_res
=
op_
->
run_once
()
&&
has_run_
;
#ifdef LITE_WITH_XPU
if
(
need_lock_l3
&&
reentrant
==
1
)
{
f_lock
.
l_type
=
F_UNLCK
;
fcntl
(
xpu_l3_lock_fd
,
F_SETLKW
,
&
f_lock
);
close
(
xpu_l3_lock_fd
);
}
reentrant
--
;
#endif
if
(
run_res
)
{
if
(
op_
->
run_once
()
&&
has_run_
)
{
return
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录