Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
Mace
提交
d218e459
Mace
项目概览
慢慢CG
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
d218e459
编写于
12月 08, 2017
作者:
Y
yejianwu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix binary name conflict
上级
f353e8c3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
74 addition
and
19 deletion
+74
-19
mace/core/runtime/opencl/opencl_runtime.cc
mace/core/runtime/opencl/opencl_runtime.cc
+70
-18
mace/core/runtime/opencl/opencl_runtime.h
mace/core/runtime/opencl/opencl_runtime.h
+4
-1
未找到文件。
mace/core/runtime/opencl/opencl_runtime.cc
浏览文件 @
d218e459
...
...
@@ -175,20 +175,58 @@ const std::map<std::string, std::string>
{
"space_to_batch"
,
"space_to_batch.cl"
},
};
const
std
::
map
<
std
::
string
,
std
::
string
>
OpenCLRuntime
::
binary_map_
=
{
{
"addn -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DINPUT_NUM=2"
,
"addn_f_2.bin"
},
{
"addn -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DINPUT_NUM=3"
,
"addn_f_3.bin"
},
{
"addn -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DINPUT_NUM=4"
,
"addn_f_4.bin"
},
{
"batch_norm -DCMD_DATA_TYPE=f -DDATA_TYPE=float"
,
"batch_norm_f.bin"
},
{
"bias_add -DCMD_DATA_TYPE=f -DDATA_TYPE=float"
,
"bias_add_f.bin"
},
{
"buffer_to_image -DCMD_DATA_TYPE=f -DDATA_TYPE=float"
,
"buffer_to_image_f.bin"
},
{
"buffer_to_image -DCMD_DATA_TYPE=h -DDATA_TYPE=half"
,
"buffer_to_image_h.bin"
},
{
"concat -DCMD_DATA_TYPE=f -DDATA_TYPE=float"
,
"concat_f.bin"
},
{
"concat -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DDIVISIBLE_FOUR"
,
"concat_f_div4.bin"
},
{
"concat -DCMD_DATA_TYPE=h -DDATA_TYPE=half -DDIVISIBLE_FOUR"
,
"concat_h_div4.bin"
},
{
"conv_2d -DBIAS -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DFUSED_RELU -DSTRIDE=1"
,
"conv_2d_bias_f_fusedrelu_1.bin"
},
{
"conv_2d -DBIAS -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DFUSED_RELU -DSTRIDE=2"
,
"conv_2d_bias_f_fusedrelu_2.bin"
},
{
"conv_2d -DBIAS -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DSTRIDE=1"
,
"conv_2d_bias_f_1.bin"
},
{
"conv_2d -DBIAS -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DSTRIDE=2"
,
"conv_2d_bias_f_2.bin"
},
{
"conv_2d_1x1 -DBIAS -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DFUSED_RELU -DSTRIDE=1"
,
"conv_2d_1x1_bias_f_fusedrelu_1.bin"
},
{
"conv_2d_1x1 -DBIAS -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DFUSED_RELU -DSTRIDE=2"
,
"conv_2d_1x1_bias_f_fusedrelu_2.bin"
},
{
"conv_2d_1x1 -DBIAS -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DSTRIDE=1"
,
"conv_2d_1x1_bias_f_1.bin"
},
{
"conv_2d_1x1 -DBIAS -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DSTRIDE=2"
,
"conv_2d_1x1_bias_f_2.bin"
},
{
"conv_2d_3x3 -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DSTRIDE=1"
,
"conv_2d_3x3_f_1.bin"
},
{
"conv_2d_3x3 -DBIAS -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DFUSED_RELU -DSTRIDE=1"
,
"conv_2d_3x3_bias_f_fusedrelu_1.bin"
},
{
"conv_2d_3x3 -DBIAS -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DFUSED_RELU -DSTRIDE=2"
,
"conv_2d_3x3_bias_f_fusedrelu_2.bin"
},
{
"conv_2d_3x3 -DBIAS -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DSTRIDE=1"
,
"conv_2d_3x3_bias_f_1.bin"
},
{
"conv_2d_3x3 -DBIAS -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DSTRIDE=2"
,
"conv_2d_3x3_bias_f_2.bin"
},
{
"depthwise_conv_3x3 -DBIAS -DDATA_TYPE=float"
,
"depthwise_conv_3x3_bias_f.bin"
},
{
"depthwise_conv_3x3 -DBIAS -DDATA_TYPE=float -DSTRIDE_1"
,
"depthwise_conv_3x3_bias_f_1.bin"
},
{
"pooling -DCMD_DATA_TYPE=f -DDATA_TYPE=float"
,
"pooling_f.bin"
},
{
"pooling -DCMD_DATA_TYPE=f -DDATA_TYPE=float -DPOOL_AVG"
,
"pooling_f_avg.bin"
},
{
"pooling -DCMD_DATA_TYPE=h -DDATA_TYPE=half -DFP16"
,
"pooling_h_fp16.bin"
},
{
"relu -DCMD_DATA_TYPE=f -DDATA_TYPE=float"
,
"relu_f.bin"
},
{
"resize_bilinear -DCMD_DATA_TYPE=f -DDATA_TYPE=float"
,
"resize_bilinear_f.bin"
},
{
"space_to_batch -DDATA_TYPE=float"
,
"space_to_batch_f.bin"
},
};
void
OpenCLRuntime
::
BuildProgram
(
const
std
::
string
&
program_file_name
,
const
std
::
string
&
binary_file_name
,
const
std
::
string
&
build_options
,
cl
::
Program
*
program
)
{
MACE_CHECK_NOTNULL
(
program
);
std
::
string
source_filename
=
kernel_path_
+
program_file_name
;
std
::
string
binary_filename
=
source_filename
+
"bin"
;
std
::
string
binary_filename
=
kernel_path_
+
binary_file_name
;
// Create program
if
(
std
::
ifstream
(
binary_filename
).
is_open
())
{
VLOG
(
1
)
<<
"Create program with binary: "
<<
binary_filename
;
std
::
string
kernel_binary
;
MACE_CHECK
(
ReadFile
(
binary_filename
,
kernel_binary
,
true
));
std
::
vector
<
unsigned
char
>
binaries
(
kernel_binary
.
begin
(),
kernel_binary
.
end
());
std
::
vector
<
unsigned
char
>
binaries
(
kernel_binary
.
begin
(),
kernel_binary
.
end
());
*
program
=
cl
::
Program
(
this
->
context
(),
{
device
()},
{
binaries
});
...
...
@@ -202,20 +240,28 @@ void OpenCLRuntime::BuildProgram(const std::string &program_file_name,
*
program
=
cl
::
Program
(
this
->
context
(),
sources
);
std
::
string
build_options_str
=
build_options
+
" -Werror -cl-mad-enable -cl-fast-relaxed-math -I"
+
kernel_path_
;
// TODO(heliangliang) -cl-unsafe-math-optimizations -cl-fast-relaxed-math
cl_int
ret
=
program
->
build
({
device
()},
build_options_str
.
c_str
());
if
(
ret
!=
CL_SUCCESS
)
{
if
(
program
->
getBuildInfo
<
CL_PROGRAM_BUILD_STATUS
>
(
device
())
==
CL_BUILD_ERROR
)
{
std
::
string
build_log
=
program
->
getBuildInfo
<
CL_PROGRAM_BUILD_LOG
>
(
device
());
LOG
(
INFO
)
<<
"Program build log: "
<<
build_log
;
}
LOG
(
FATAL
)
<<
"Build program failed: "
<<
ret
;
}
else
{
LOG
(
ERROR
)
<<
"Failed to open kernel file "
<<
binary_filename
<<
" and "
<<
source_filename
;
}
// Build program
std
::
string
build_options_str
=
build_options
+
" -Werror -cl-mad-enable -cl-fast-relaxed-math -I"
+
kernel_path_
;
// TODO(heliangliang) -cl-unsafe-math-optimizations -cl-fast-relaxed-math
cl_int
ret
=
program
->
build
({
device
()},
build_options_str
.
c_str
());
if
(
ret
!=
CL_SUCCESS
)
{
if
(
program
->
getBuildInfo
<
CL_PROGRAM_BUILD_STATUS
>
(
device
())
==
CL_BUILD_ERROR
)
{
std
::
string
build_log
=
program
->
getBuildInfo
<
CL_PROGRAM_BUILD_LOG
>
(
device
());
LOG
(
INFO
)
<<
"Program build log: "
<<
build_log
;
}
LOG
(
FATAL
)
<<
"Build program failed: "
<<
ret
;
}
// Write binary if necessary
if
(
!
std
::
ifstream
(
binary_filename
).
is_open
())
{
size_t
deviceListSize
=
1
;
size_t
*
programBinarySizes
=
new
size_t
[
deviceListSize
];
clGetProgramInfo
((
*
program
)(),
...
...
@@ -236,10 +282,8 @@ void OpenCLRuntime::BuildProgram(const std::string &program_file_name,
programBinarySizes
[
0
]);
WriteFile
(
binary_filename
,
content
,
true
);
}
else
{
LOG
(
ERROR
)
<<
"Failed to open kernel file "
<<
binary_filename
<<
" and "
<<
source_filename
;
}
}
cl
::
Kernel
OpenCLRuntime
::
BuildKernel
(
const
std
::
string
&
program_name
,
...
...
@@ -263,7 +307,15 @@ cl::Kernel OpenCLRuntime::BuildKernel(const std::string &program_name,
if
(
built_program_it
!=
built_program_map_
.
end
())
{
program
=
built_program_it
->
second
;
}
else
{
this
->
BuildProgram
(
program_file_name
,
build_options_str
,
&
program
);
std
::
string
binary_file_name
=
""
;
auto
binary_it
=
binary_map_
.
find
(
built_program_key
);
if
(
binary_it
!=
binary_map_
.
end
())
{
binary_file_name
=
binary_it
->
second
;
}
this
->
BuildProgram
(
program_file_name
,
binary_file_name
,
build_options_str
,
&
program
);
built_program_map_
.
emplace
(
built_program_key
,
program
);
}
return
cl
::
Kernel
(
program
,
kernel_name
.
c_str
());
...
...
mace/core/runtime/opencl/opencl_runtime.h
浏览文件 @
d218e459
...
...
@@ -44,7 +44,8 @@ class OpenCLRuntime {
OpenCLRuntime
(
const
OpenCLRuntime
&
)
=
delete
;
OpenCLRuntime
&
operator
=
(
const
OpenCLRuntime
&
)
=
delete
;
void
BuildProgram
(
const
std
::
string
&
kernel_name
,
void
BuildProgram
(
const
std
::
string
&
program_file_name
,
const
std
::
string
&
binary_file_name
,
const
std
::
string
&
build_options
,
cl
::
Program
*
program
);
...
...
@@ -62,6 +63,8 @@ class OpenCLRuntime {
std
::
string
>
program_map_
;
mutable
std
::
map
<
std
::
string
,
cl
::
Program
>
built_program_map_
;
static
const
std
::
map
<
std
::
string
,
std
::
string
>
binary_map_
;
};
}
// namespace mace
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录