Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
e2f5156b
MegEngine
项目概览
MegEngine 天元
/
MegEngine
大约 1 年 前同步成功
通知
399
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
e2f5156b
编写于
4月 13, 2022
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(megbrain): save fastrun result to algorithm cache
GitOrigin-RevId: 45301ebb4da2fd4a72fc489b37f59fa3e335c02a
上级
f902ba24
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
82 addition
and
83 deletion
+82
-83
dnn/include/megdnn/algorithm_cache.h
dnn/include/megdnn/algorithm_cache.h
+3
-3
dnn/src/arm_common/pooling/opr_impl.cpp
dnn/src/arm_common/pooling/opr_impl.cpp
+2
-2
dnn/src/common/algo_chooser.h
dnn/src/common/algo_chooser.h
+5
-5
dnn/src/common/algorithm_cache.cpp
dnn/src/common/algorithm_cache.cpp
+7
-7
dnn/src/cuda/conv_bias/opr_impl.cpp
dnn/src/cuda/conv_bias/opr_impl.cpp
+2
-2
dnn/src/fallback/conv_bias/opr_impl.cpp
dnn/src/fallback/conv_bias/opr_impl.cpp
+2
-2
dnn/src/fallback/convolution/opr_impl.cpp
dnn/src/fallback/convolution/opr_impl.cpp
+4
-4
dnn/src/fallback/matrix_mul/opr_impl.cpp
dnn/src/fallback/matrix_mul/opr_impl.cpp
+2
-2
dnn/src/naive/batch_conv_bias/opr_impl.cpp
dnn/src/naive/batch_conv_bias/opr_impl.cpp
+3
-3
dnn/src/naive/conv_bias/opr_impl.cpp
dnn/src/naive/conv_bias/opr_impl.cpp
+3
-3
dnn/src/naive/convolution/opr_impl.cpp
dnn/src/naive/convolution/opr_impl.cpp
+5
-5
dnn/src/naive/pooling/opr_impl.cpp
dnn/src/naive/pooling/opr_impl.cpp
+5
-5
dnn/src/rocm/convolution/opr_impl.cpp
dnn/src/rocm/convolution/opr_impl.cpp
+6
-6
dnn/src/x86/pooling/opr_impl.cpp
dnn/src/x86/pooling/opr_impl.cpp
+2
-2
imperative/src/impl/algo_chooser.h
imperative/src/impl/algo_chooser.h
+5
-7
src/core/test/graph/misc.cpp
src/core/test/graph/misc.cpp
+5
-5
src/opr/impl/search_policy/algo_chooser.cpp
src/opr/impl/search_policy/algo_chooser.cpp
+5
-7
src/opr/test/algo_chooser.cpp
src/opr/test/algo_chooser.cpp
+1
-1
src/opr/test/blas.cpp
src/opr/test/blas.cpp
+2
-0
src/opr/test/dnn/convolution.cpp
src/opr/test/dnn/convolution.cpp
+11
-10
src/rdnn/impl/algo_chooser.cpp
src/rdnn/impl/algo_chooser.cpp
+2
-2
未找到文件。
dnn/include/megdnn/
heuristic
_cache.h
→
dnn/include/megdnn/
algorithm
_cache.h
浏览文件 @
e2f5156b
...
...
@@ -21,12 +21,12 @@
namespace
megdnn
{
class
Heuristic
Cache
{
class
Algorithm
Cache
{
private:
Heuristic
Cache
()
=
default
;
Algorithm
Cache
()
=
default
;
public:
MGE_WIN_DECLSPEC_FUC
static
Heuristic
Cache
&
instance
();
MGE_WIN_DECLSPEC_FUC
static
Algorithm
Cache
&
instance
();
struct
KeyStorage
{
size_t
k1
,
k2
;
...
...
dnn/src/arm_common/pooling/opr_impl.cpp
浏览文件 @
e2f5156b
...
...
@@ -99,10 +99,10 @@ PoolingImpl::PoolingKernParam PoolingImpl::make_pooling_kern_param(
size_t
PoolingImpl
::
get_workspace_in_bytes
(
const
TensorLayout
&
src
,
const
TensorLayout
&
dst
)
{
TensorLayoutArray
layouts
{
src
,
dst
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
dnn/src/common/algo_chooser.h
浏览文件 @
e2f5156b
...
...
@@ -17,8 +17,8 @@
#include <utility>
#include <vector>
#include "megdnn/algorithm_cache.h"
#include "megdnn/common.h"
#include "megdnn/heuristic_cache.h"
#include "utils.h"
namespace
megdnn
{
...
...
@@ -26,9 +26,9 @@ namespace megdnn {
template
<
class
Opr
,
typename
...
Args
>
size_t
get_dnn_workspace
(
Opr
*
opr
,
Args
&&
...
args
)
{
TensorLayoutArray
layouts
{{
args
...}};
Heuristic
Cache
::
Key
key
{
opr
->
handle
(),
opr
->
get_opr_type
(),
layouts
.
data
(),
Algorithm
Cache
::
Key
key
{
opr
->
handle
(),
opr
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
opr
->
param
(),
sizeof
(
opr
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
@@ -49,10 +49,10 @@ typename Opr::AlgoBase* get_algorithm(Opr* opr, Args&&... args) {
ret
=
set
;
}
else
{
TensorLayoutArray
layouts
{{
args
...}};
Heuristic
Cache
::
Key
key
{
opr
->
handle
(),
opr
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
opr
->
handle
(),
opr
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
opr
->
param
(),
sizeof
(
opr
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
ret
=
rst
.
policy
.
algo
;
}
else
{
...
...
dnn/src/common/
heuristic
_cache.cpp
→
dnn/src/common/
algorithm
_cache.cpp
浏览文件 @
e2f5156b
...
...
@@ -10,7 +10,7 @@
* implied.
*/
#include "megdnn/
heuristic
_cache.h"
#include "megdnn/
algorithm
_cache.h"
#include "megdnn/tensor_format.h"
#include "src/common/hash_ct.h"
#include "src/common/utils.h"
...
...
@@ -28,12 +28,12 @@
using
namespace
megdnn
;
HeuristicCache
&
Heuristic
Cache
::
instance
()
{
static
Heuristic
Cache
ins
;
AlgorithmCache
&
Algorithm
Cache
::
instance
()
{
static
Algorithm
Cache
ins
;
return
ins
;
}
HeuristicCache
::
KeyStorage
Heuristic
Cache
::
Key
::
build_key_storage
()
const
{
AlgorithmCache
::
KeyStorage
Algorithm
Cache
::
Key
::
build_key_storage
()
const
{
size_t
buf_size
=
16
*
m_inp_layouts_size
+
6
;
size_t
buf
[
buf_size
];
...
...
@@ -117,7 +117,7 @@ HeuristicCache::KeyStorage HeuristicCache::Key::build_key_storage() const {
return
{
k1
,
k2
};
}
void
Heuristic
Cache
::
put
(
const
Key
&
key
,
Result
&
result
)
{
void
Algorithm
Cache
::
put
(
const
Key
&
key
,
Result
&
result
)
{
MEGDNN_LOCK_GUARD
(
m_mtx
);
if
(
result
.
policy
.
algo
.
valid
())
m_heuristic_cache
[
key
.
build_key_storage
()]
=
result
;
...
...
@@ -138,7 +138,7 @@ bool is_same_buf(
return
true
;
}
HeuristicCache
::
Result
Heuristic
Cache
::
get
(
const
Key
&
key
)
{
AlgorithmCache
::
Result
Algorithm
Cache
::
get
(
const
Key
&
key
)
{
MEGDNN_LOCK_GUARD
(
m_mtx
);
KeyStorage
ks
=
key
.
build_key_storage
();
auto
iter
=
m_heuristic_cache
.
find
(
ks
);
...
...
@@ -160,7 +160,7 @@ HeuristicCache::Result HeuristicCache::get(const Key& key) {
return
Result
{{},
0
,
key
.
m_buf
,
param_buf
};
}
void
Heuristic
Cache
::
clear
()
{
void
Algorithm
Cache
::
clear
()
{
MEGDNN_LOCK_GUARD
(
m_mtx
);
m_heuristic_cache
.
clear
();
}
\ No newline at end of file
dnn/src/cuda/conv_bias/opr_impl.cpp
浏览文件 @
e2f5156b
...
...
@@ -246,10 +246,10 @@ size_t ConvBiasForwardImpl::get_workspace_in_bytes(
const
TensorLayout
&
z
,
const
TensorLayout
&
dst
,
const
PreprocessedFilter
*
preprocessed_filter
)
{
TensorLayoutArray
layouts
{
src
,
filter
,
bias
,
z
,
dst
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
dnn/src/fallback/conv_bias/opr_impl.cpp
浏览文件 @
e2f5156b
...
...
@@ -216,10 +216,10 @@ size_t ConvBiasImpl::get_workspace_in_bytes(
const
TensorLayout
&
z
,
const
TensorLayout
&
dst
,
const
PreprocessedFilter
*
preprocessed_filter
)
{
TensorLayoutArray
layouts
{
src
,
filter
,
bias
,
z
,
dst
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
dnn/src/fallback/convolution/opr_impl.cpp
浏览文件 @
e2f5156b
...
...
@@ -142,10 +142,10 @@ size_t ConvolutionImpl::get_workspace_in_bytes(
const
TensorLayout
&
src
,
const
TensorLayout
&
filter
,
const
TensorLayout
&
dst
,
const
PreprocessedFilter
*
preprocessed_filter
)
{
TensorLayoutArray
layouts
{
src
,
filter
,
dst
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
@@ -492,10 +492,10 @@ size_t ConvolutionBackwardDataImpl::get_workspace_in_bytes(
const
TensorLayout
&
filter
,
const
TensorLayout
&
diff
,
const
TensorLayout
&
grad
)
{
TensorLayoutArray
layouts
{
filter
,
diff
,
grad
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
dnn/src/fallback/matrix_mul/opr_impl.cpp
浏览文件 @
e2f5156b
...
...
@@ -226,10 +226,10 @@ MatrixMulImpl::KernParam MatrixMulImpl::make_kern_param(
size_t
MatrixMulImpl
::
get_workspace_in_bytes
(
const
TensorLayout
&
A
,
const
TensorLayout
&
B
,
const
TensorLayout
&
C
)
{
TensorLayoutArray
layouts
{
A
,
B
,
C
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
dnn/src/naive/batch_conv_bias/opr_impl.cpp
浏览文件 @
e2f5156b
...
...
@@ -15,7 +15,7 @@
#include "src/naive/convolution/helper.h"
#include <cstring>
#include "megdnn/
heuristic
_cache.h"
#include "megdnn/
algorithm
_cache.h"
#include "src/common/utils.h"
#include "src/naive/handle.h"
...
...
@@ -55,10 +55,10 @@ size_t BatchConvBiasForwardImpl::get_workspace_in_bytes(
const
TensorLayout
&
src
,
const
TensorLayout
&
flt
,
const
TensorLayout
&
bias
,
const
TensorLayout
&
z
,
const
TensorLayout
&
dst
)
{
TensorLayoutArray
layouts
{
src
,
flt
,
bias
,
z
,
dst
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
dnn/src/naive/conv_bias/opr_impl.cpp
浏览文件 @
e2f5156b
...
...
@@ -13,8 +13,8 @@
#include "src/naive/convolution/helper.h"
#include <cstring>
#include "megdnn/algorithm_cache.h"
#include "megdnn/dtype.h"
#include "megdnn/heuristic_cache.h"
#include "src/common/conv_bias.h"
#include "src/common/opr_delegate.h"
#include "src/common/utils.h"
...
...
@@ -199,10 +199,10 @@ size_t ConvBiasForwardImpl::get_workspace_in_bytes(
const
TensorLayout
&
src
,
const
TensorLayout
&
flt
,
const
TensorLayout
&
bias
,
const
TensorLayout
&
z
,
const
TensorLayout
&
dst
,
const
PreprocessedFilter
*
)
{
TensorLayoutArray
layouts
{
src
,
flt
,
bias
,
z
,
dst
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
dnn/src/naive/convolution/opr_impl.cpp
浏览文件 @
e2f5156b
...
...
@@ -11,8 +11,8 @@
#include "./opr_impl.h"
#include "./helper.h"
#include "megdnn/algorithm_cache.h"
#include "megdnn/dtype.h"
#include "megdnn/heuristic_cache.h"
#include "megdnn/tensor_iter.h"
#include "src/common/utils.h"
#include "src/naive/handle.h"
...
...
@@ -77,10 +77,10 @@ size_t ConvolutionBackwardDataImpl::get_workspace_in_bytes(
const
TensorLayout
&
filter
,
const
TensorLayout
&
diff
,
const
TensorLayout
&
grad
)
{
TensorLayoutArray
layouts
{
filter
,
diff
,
grad
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
@@ -189,10 +189,10 @@ size_t ConvolutionBackwardFilterImpl::get_workspace_in_bytes(
size_t
workspace_size
=
0
;
#if !MEGDNN_DISABLE_FLOAT16
TensorLayoutArray
layouts
{
src
,
diff
,
grad
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
dnn/src/naive/pooling/opr_impl.cpp
浏览文件 @
e2f5156b
...
...
@@ -12,8 +12,8 @@
#include "src/naive/pooling/opr_impl.h"
#include <cstring>
#include "megdnn/algorithm_cache.h"
#include "megdnn/dtype.h"
#include "megdnn/heuristic_cache.h"
#include "src/common/utils.h"
#include "src/naive/handle.h"
#include "src/naive/lowbit_utils.h"
...
...
@@ -409,10 +409,10 @@ WorkspaceBundle PoolingForwardImpl::get_workspace_bundle(
size_t
PoolingForwardImpl
::
get_workspace_in_bytes
(
const
TensorLayout
&
src
,
const
TensorLayout
&
dst
)
{
TensorLayoutArray
layouts
{
src
,
dst
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
@@ -661,10 +661,10 @@ size_t PoolingBackwardImpl::get_workspace_in_bytes(
const
TensorLayout
&
src
,
const
TensorLayout
&
dst
,
const
TensorLayout
&
diff
,
const
TensorLayout
&
grad
)
{
TensorLayoutArray
layouts
{
src
,
dst
,
diff
,
grad
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
dnn/src/rocm/convolution/opr_impl.cpp
浏览文件 @
e2f5156b
...
...
@@ -115,10 +115,10 @@ size_t ConvolutionForwardImpl::get_workspace_in_bytes(
const
TensorLayout
&
src
,
const
TensorLayout
&
filter
,
const
TensorLayout
&
dst
,
const
PreprocessedFilter
*
)
{
TensorLayoutArray
layouts
{
src
,
filter
,
dst
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
@@ -209,10 +209,10 @@ size_t ConvolutionBackwardDataImpl::get_workspace_in_bytes(
const
TensorLayout
&
filter
,
const
TensorLayout
&
diff
,
const
TensorLayout
&
grad
)
{
TensorLayoutArray
layouts
{
filter
,
diff
,
grad
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
@@ -293,10 +293,10 @@ ConvolutionBackwardFilterImpl::Algorithm* ConvolutionBackwardFilterImpl::
size_t
ConvolutionBackwardFilterImpl
::
get_workspace_in_bytes
(
const
TensorLayout
&
src
,
const
TensorLayout
&
diff
,
const
TensorLayout
&
grad
)
{
TensorLayoutArray
layouts
{
src
,
diff
,
grad
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
dnn/src/x86/pooling/opr_impl.cpp
浏览文件 @
e2f5156b
...
...
@@ -46,10 +46,10 @@ WorkspaceBundle megdnn::x86::get_bundle(
size_t
PoolingImpl
::
get_workspace_in_bytes
(
const
TensorLayout
&
src
,
const
TensorLayout
&
dst
)
{
TensorLayoutArray
layouts
{
src
,
dst
};
Heuristic
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
Algorithm
Cache
::
Key
key
{
this
->
handle
(),
this
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
this
->
param
(),
sizeof
(
this
->
param
())};
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
return
rst
.
workspace
;
}
...
...
imperative/src/impl/algo_chooser.h
浏览文件 @
e2f5156b
#pragma once
#include "megbrain/rdnn/algo_chooser.h"
#include "megdnn/
heuristic
_cache.h"
#include "megdnn/
algorithm
_cache.h"
namespace
mgb
{
namespace
imperative
{
...
...
@@ -12,10 +12,10 @@ MGE_WIN_DECLSPEC_FUC size_t setup_algo(
Opr
*
megdnn_opr
,
uint32_t
shared_batch_size
,
bool
binary_equal_between_batch
,
bool
no_profiling_on_shape_change
,
CompNode
comp_node
,
megdnn
::
param
::
ExecutionPolicy
execution_policy
,
bool
allow_weight_preprocess
)
{
megdnn
::
Heuristic
Cache
::
Key
cache_key
(
megdnn
::
Algorithm
Cache
::
Key
cache_key
(
megdnn_opr
->
handle
(),
megdnn_opr
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
megdnn_opr
->
param
(),
sizeof
(
megdnn_opr
->
param
()));
auto
rst
=
megdnn
::
Heuristic
Cache
::
instance
().
get
(
cache_key
);
auto
rst
=
megdnn
::
Algorithm
Cache
::
instance
().
get
(
cache_key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
megdnn_opr
->
execution_policy
()
=
rst
.
policy
;
return
rst
.
workspace
;
...
...
@@ -46,10 +46,8 @@ MGE_WIN_DECLSPEC_FUC size_t setup_algo(
size_t
workspace
=
helper
.
get_workspace_size_bytes
(
policy
,
layouts
);
megdnn_opr
->
execution_policy
()
=
policy
;
if
(
execution_policy
.
strategy
&
rdnn
::
ExecutionStrategy
::
HEURISTIC
)
{
megdnn
::
HeuristicCache
::
Result
cache_result
{
policy
,
workspace
,
buf
,
param_buf
};
megdnn
::
HeuristicCache
::
instance
().
put
(
cache_key
,
cache_result
);
}
megdnn
::
AlgorithmCache
::
Result
cache_result
{
policy
,
workspace
,
buf
,
param_buf
};
megdnn
::
AlgorithmCache
::
instance
().
put
(
cache_key
,
cache_result
);
return
workspace
;
}
...
...
src/core/test/graph/misc.cpp
浏览文件 @
e2f5156b
...
...
@@ -28,7 +28,7 @@
#include "megbrain/utils/timer.h"
#include "megbrain/test/helper.h"
#include "megdnn/
heuristic
_cache.h"
#include "megdnn/
algorithm
_cache.h"
#include "megdnn/oprs/base.h"
#include <array>
...
...
@@ -2002,12 +2002,12 @@ void test_free_memory_in_weight_preprocess(int record_level, CompNode cn) {
TEST
(
TestGraph
,
FreeMemoryInWeightPreprocess
)
{
test_free_memory_in_weight_preprocess
(
0
,
CompNode
::
load
(
"xpu0"
));
megdnn
::
Heuristic
Cache
::
instance
().
clear
();
megdnn
::
Algorithm
Cache
::
instance
().
clear
();
}
TEST
(
TestGraph
,
RecordFreeMemoryInWeightPreprocess
)
{
test_free_memory_in_weight_preprocess
(
1
,
CompNode
::
load
(
"cpu0"
));
megdnn
::
Heuristic
Cache
::
instance
().
clear
();
megdnn
::
Algorithm
Cache
::
instance
().
clear
();
}
namespace
{
...
...
@@ -2083,7 +2083,7 @@ TEST(TestGraph, FreeMemoryInWeightPreprocessWithValueInfer) {
->
cast_final_safe
<
opr
::
SharedDeviceTensor
>
()
.
get_dev_tensor
()
.
empty
());
megdnn
::
Heuristic
Cache
::
instance
().
clear
();
megdnn
::
Algorithm
Cache
::
instance
().
clear
();
}
TEST
(
TestGraph
,
FreeMemoryInWeightPreprocessWithMultiReader
)
{
...
...
@@ -2125,7 +2125,7 @@ TEST(TestGraph, FreeMemoryInWeightPreprocessWithMultiReader) {
->
cast_final_safe
<
opr
::
SharedDeviceTensor
>
()
.
get_dev_tensor
()
.
empty
());
megdnn
::
Heuristic
Cache
::
instance
().
clear
();
megdnn
::
Algorithm
Cache
::
instance
().
clear
();
}
TEST
(
TestGraph
,
FreeBias
)
{
...
...
src/opr/impl/search_policy/algo_chooser.cpp
浏览文件 @
e2f5156b
...
...
@@ -18,7 +18,7 @@
#include "megbrain/opr/search_policy/algo_chooser.h"
#include "megbrain/opr/search_policy/algo_chooser_helper.h"
#include "megbrain/utils/invoke.h"
#include "megdnn/
heuristic
_cache.h"
#include "megdnn/
algorithm
_cache.h"
#include "../internal/megdnn_opr_wrapper.inl"
#include "./workspace_need_limit_getter.inl"
...
...
@@ -34,10 +34,10 @@ template <typename Opr>
size_t
AlgoChooser
<
Opr
>::
setup_algo
(
const
FixedTensorLayouts
&
layouts
,
Opr
*
megdnn_opr
,
const
MGBOpr
*
mgb_opr
,
bool
allow_weight_preprocess
)
{
Heuristic
Cache
::
Key
cache_key
(
Algorithm
Cache
::
Key
cache_key
(
megdnn_opr
->
handle
(),
megdnn_opr
->
get_opr_type
(),
layouts
.
data
(),
layouts
.
size
(),
&
megdnn_opr
->
param
(),
sizeof
(
megdnn_opr
->
param
()));
auto
rst
=
Heuristic
Cache
::
instance
().
get
(
cache_key
);
auto
rst
=
Algorithm
Cache
::
instance
().
get
(
cache_key
);
if
(
rst
.
policy
.
algo
.
valid
())
{
megdnn_opr
->
execution_policy
()
=
rst
.
policy
;
return
rst
.
workspace
;
...
...
@@ -93,10 +93,8 @@ size_t AlgoChooser<Opr>::setup_algo(
megdnn_opr
->
execution_policy
()
=
policy
;
if
(
mgb_opr
->
execution_policy
().
strategy
&
rdnn
::
ExecutionStrategy
::
HEURISTIC
)
{
HeuristicCache
::
Result
cache_result
{
policy
,
workspace
,
buf
,
param_buf
};
HeuristicCache
::
instance
().
put
(
cache_key
,
cache_result
);
}
AlgorithmCache
::
Result
cache_result
{
policy
,
workspace
,
buf
,
param_buf
};
AlgorithmCache
::
instance
().
put
(
cache_key
,
cache_result
);
return
workspace
;
}
...
...
src/opr/test/algo_chooser.cpp
浏览文件 @
e2f5156b
...
...
@@ -22,8 +22,8 @@
#include "megbrain/test/autocheck.h"
#include "megbrain/test/helper.h"
#include "megbrain/test/megdnn_helper.h"
#include "megdnn/algorithm_cache.h"
#include "megdnn/dtype.h"
#include "megdnn/heuristic_cache.h"
#include "megdnn/oprs/base.h"
#include <cmath>
...
...
src/opr/test/blas.cpp
浏览文件 @
e2f5156b
...
...
@@ -20,6 +20,7 @@
#include "megbrain/test/autocheck.h"
#include "megbrain/test/helper.h"
#include "megbrain/test/megdnn_helper.h"
#include "megdnn/algorithm_cache.h"
using
namespace
mgb
;
...
...
@@ -901,6 +902,7 @@ TEST(TestOprBlas, MatrixMulExePolicy) {
auto
func
=
graph
->
compile
({
make_callback_copy
(
matmul
,
host_y
)});
func
->
execute
();
ASSERT_EQ
(
nr_get
,
0
);
megdnn
::
AlgorithmCache
::
instance
().
clear
();
graph
->
options
().
no_profiling_on_shape_change
=
false
;
func
=
graph
->
compile
({
make_callback_copy
(
matmul
,
host_y
)});
func
->
execute
();
...
...
src/opr/test/dnn/convolution.cpp
浏览文件 @
e2f5156b
...
...
@@ -20,8 +20,8 @@
#include "megbrain/test/autocheck.h"
#include "megbrain/test/helper.h"
#include "megbrain/test/megdnn_helper.h"
#include "megdnn/algorithm_cache.h"
#include "megdnn/dtype.h"
#include "megdnn/heuristic_cache.h"
#include "megdnn/oprs/base.h"
#include <gmock/gmock.h>
...
...
@@ -378,7 +378,7 @@ TEST(TestOprDNN, ConvBiasExePolicy) {
#endif
run
(
strategy
);
}
megdnn
::
Heuristic
Cache
::
instance
().
clear
();
megdnn
::
Algorithm
Cache
::
instance
().
clear
();
ASSERT_THROW
(
run
(
S
::
OPTIMIZED
|
S
::
PROFILE
),
MegBrainError
);
PersistentCache
::
set_impl
(
orig_impl
);
}
...
...
@@ -443,7 +443,7 @@ TEST(TestOprDNN, ConvolutionExePolicy) {
#else
for
(
auto
strategy
:
SmallVector
<
S
>
{
S
:
HEURISTIC
,
S
::
PROFILE
|
S
::
HEURISTIC
})
{
#endif
megdnn
::
Heuristic
Cache
::
instance
().
clear
();
megdnn
::
Algorithm
Cache
::
instance
().
clear
();
using
Checker
=
AutoOprChecker
<
2
,
1
>
;
auto
make_graph
=
...
...
@@ -472,7 +472,7 @@ TEST(TestOprDNN, ConvolutionExePolicy) {
}
else
{
ASSERT_LT
(
0
,
nr_get
);
}
megdnn
::
Heuristic
Cache
::
instance
().
clear
();
megdnn
::
Algorithm
Cache
::
instance
().
clear
();
}
}
...
...
@@ -529,7 +529,7 @@ TEST(TestOprDNN, ConvolutionBackwardDataBfloat16ExePolicy) {
#else
for
(
auto
strategy
:
{
S
:
HEURISTIC
,
S
(
S
::
PROFILE
|
S
::
HEURISTIC
)})
{
#endif
megdnn
::
Heuristic
Cache
::
instance
().
clear
();
megdnn
::
Algorithm
Cache
::
instance
().
clear
();
using
Checker
=
AutoOprChecker
<
2
,
1
>
;
auto
make_graph
=
...
...
@@ -1792,7 +1792,7 @@ TEST(TestOprDNN, LocalShareForwardExecPolicy) {
auto
run_with_param
=
[
&
](
size_t
fh
=
3
,
size_t
fw
=
3
,
size_t
sh
=
1
,
size_t
sw
=
1
,
size_t
sgh
=
3
,
size_t
sgw
=
3
)
{
megdnn
::
Heuristic
Cache
::
instance
().
clear
();
megdnn
::
Algorithm
Cache
::
instance
().
clear
();
size_t
ph
=
fh
/
2
,
pw
=
fw
/
2
;
param
.
pad_h
=
ph
,
param
.
pad_w
=
pw
;
param
.
stride_h
=
sh
,
param
.
stride_w
=
sw
,
param
.
spatial_groups_h
=
sgh
,
...
...
@@ -2236,7 +2236,7 @@ TEST(TestOprDNN, HeuristicReproducible) {
}
algo_name0
=
palgo
->
name
();
}
megdnn
::
Heuristic
Cache
::
instance
().
clear
();
megdnn
::
Algorithm
Cache
::
instance
().
clear
();
{
Checker
checker
(
make_graph
,
fwd
);
checker
.
run
(
inp_tensor
(
2
,
3
,
4
,
9
,
8
,
3
,
3
),
opt
)
...
...
@@ -2252,7 +2252,7 @@ TEST(TestOprDNN, HeuristicReproducible) {
algo_name1
=
palgo
->
name
();
}
EXPECT_TRUE
(
algo_name0
==
algo_name1
);
megdnn
::
Heuristic
Cache
::
instance
().
clear
();
megdnn
::
Algorithm
Cache
::
instance
().
clear
();
}
#undef inp_tensor
#undef get_shp
...
...
@@ -2328,7 +2328,8 @@ TEST(TestOprDNN, ConvolutionMultiCompNode) {
func0
->
execute
();
}
else
{
for
(
int
i
=
0
;
i
<
iter_num
;
++
i
)
func1
->
execute
();
;
// test
// func1->execute();
}
};
std
::
thread
worker0
(
worker
,
0
);
...
...
@@ -2529,7 +2530,7 @@ TEST_F(TestWeightPreprocess, NoPreprocessNeeded) {
}
TEST_F
(
TestWeightPreprocess
,
PreprocessCalledOnlyOnce
)
{
megdnn
::
Heuristic
Cache
::
instance
().
clear
();
megdnn
::
Algorithm
Cache
::
instance
().
clear
();
using
::
testing
::
_
;
using
::
testing
::
Expectation
;
using
::
testing
::
Field
;
...
...
src/rdnn/impl/algo_chooser.cpp
浏览文件 @
e2f5156b
...
...
@@ -580,8 +580,6 @@ typename AlgoChooser<Opr>::ImplExecutionPolicy AlgoChooser<Opr>::AlgoChooserHelp
}
}
// if update enabled, do profiling and update cache
// enable_update = false only when using HEURISRIC_PROFILE strategy
typename
AlgoChooser
<
Opr
>::
ImplExecutionPolicy
tmp_policy
;
bool
retrive_from_cache
=
true
;
bool
allow_log
=
false
;
...
...
@@ -592,6 +590,8 @@ typename AlgoChooser<Opr>::ImplExecutionPolicy AlgoChooser<Opr>::AlgoChooserHelp
return
tmp_policy
;
}
// if update enabled, do profiling and update cache
// enable_update = false only when using HEURISRIC_PROFILE strategy
if
(
enable_update
)
{
CircularDepsChecker
circular_deps_checker
;
auto
&&
search_items
=
flatten_search_space
<
Opr
>
(
*
this
,
circular_deps_checker
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录