Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
d0224b83
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
d0224b83
编写于
8月 16, 2023
作者:
傅
傅剑寒
提交者:
GitHub
8月 16, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【CINN】Remove if_simplify and rewrite block_simplify (#56307)
* remove if_simplify and rewrite block_simplify * delete unused if_simplify
上级
f272d693
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
1 addition
and
184 deletion
+1
-184
paddle/cinn/optim/CMakeLists.txt
paddle/cinn/optim/CMakeLists.txt
+0
-2
paddle/cinn/optim/if_simplify.cc
paddle/cinn/optim/if_simplify.cc
+0
-57
paddle/cinn/optim/if_simplify.h
paddle/cinn/optim/if_simplify.h
+0
-22
paddle/cinn/optim/if_simplify_test.cc
paddle/cinn/optim/if_simplify_test.cc
+0
-72
paddle/cinn/optim/ir_simplify.cc
paddle/cinn/optim/ir_simplify.cc
+1
-26
paddle/cinn/optim/optimize.cc
paddle/cinn/optim/optimize.cc
+0
-5
未找到文件。
paddle/cinn/optim/CMakeLists.txt
浏览文件 @
d0224b83
...
@@ -24,7 +24,6 @@ gather_srcs(
...
@@ -24,7 +24,6 @@ gather_srcs(
buffer_assign.cc
buffer_assign.cc
replace_const_param_to_integer.cc
replace_const_param_to_integer.cc
cast_simplify.cc
cast_simplify.cc
if_simplify.cc
lower_intrin.cc
lower_intrin.cc
cast_bool_to_int8.cc
cast_bool_to_int8.cc
collect_undefined_vars.cc
collect_undefined_vars.cc
...
@@ -60,7 +59,6 @@ cinn_cc_test(test_optimize SRCS optimize_test.cc DEPS cinncore)
...
@@ -60,7 +59,6 @@ cinn_cc_test(test_optimize SRCS optimize_test.cc DEPS cinncore)
cinn_cc_test
(
test_cache_read_write_replace SRCS
cinn_cc_test
(
test_cache_read_write_replace SRCS
cache_read_write_replace_test.cc DEPS cinncore
)
cache_read_write_replace_test.cc DEPS cinncore
)
cinn_cc_test
(
test_cast_simplify SRCS cast_simplify_test.cc DEPS cinncore
)
cinn_cc_test
(
test_cast_simplify SRCS cast_simplify_test.cc DEPS cinncore
)
cinn_cc_test
(
test_if_simplify SRCS if_simplify_test.cc DEPS cinncore
)
cinn_cc_test
(
test_remove_schedule_block SRCS remove_schedule_block_test.cc DEPS
cinn_cc_test
(
test_remove_schedule_block SRCS remove_schedule_block_test.cc DEPS
cinncore
)
cinncore
)
cinn_cc_test
(
test_unroll_loops SRCS unroll_loops_test.cc DEPS cinncore
)
cinn_cc_test
(
test_unroll_loops SRCS unroll_loops_test.cc DEPS cinncore
)
paddle/cinn/optim/if_simplify.cc
已删除
100644 → 0
浏览文件 @
f272d693
// Copyright (c) 2021 CINN Authors. All Rights Reserved.
//
// 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 "paddle/cinn/optim/if_simplify.h"
#include "paddle/cinn/ir/utils/ir_mutator.h"
namespace
cinn
::
optim
{
namespace
{
struct
Mutator
:
public
ir
::
IRMutator
<>
{
using
ir
::
IRMutator
<>::
Visit
;
void
Visit
(
const
ir
::
IfThenElse
*
op
,
Expr
*
expr
)
{
auto
*
condition_int
=
op
->
condition
.
As
<
ir
::
IntImm
>
();
auto
*
condition_uint
=
op
->
condition
.
As
<
ir
::
UIntImm
>
();
int64_t
value
;
if
(
condition_int
||
condition_uint
)
{
if
(
condition_int
)
{
value
=
condition_int
->
value
;
}
else
{
value
=
condition_uint
->
value
;
}
if
(
value
)
{
*
expr
=
op
->
true_case
;
}
else
{
if
(
op
->
false_case
.
defined
())
{
*
expr
=
op
->
false_case
;
}
else
{
// null condition
*
expr
=
ir
::
Block
::
Make
({});
}
}
}
}
};
}
// namespace
void
IfSimplify
(
Expr
*
e
)
{
Mutator
mutator
;
mutator
.
Visit
(
e
,
e
);
}
}
// namespace cinn::optim
paddle/cinn/optim/if_simplify.h
已删除
100644 → 0
浏览文件 @
f272d693
// Copyright (c) 2021 CINN Authors. All Rights Reserved.
//
// 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.
#pragma once
#include "paddle/cinn/ir/ir.h"
namespace
cinn
::
optim
{
void
IfSimplify
(
Expr
*
e
);
}
// namespace cinn::optim
paddle/cinn/optim/if_simplify_test.cc
已删除
100644 → 0
浏览文件 @
f272d693
// Copyright (c) 2021 CINN Authors. All Rights Reserved.
//
// 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 "paddle/cinn/optim/if_simplify.h"
#include <gtest/gtest.h>
#include <string>
#include "paddle/cinn/ir/utils/ir_printer.h"
namespace
cinn
::
optim
{
TEST
(
IfSimplify
,
if_true
)
{
Var
n
(
"n"
);
auto
e
=
ir
::
IfThenElse
::
Make
(
Expr
(
1
)
/*true*/
,
ir
::
Let
::
Make
(
n
,
Expr
(
1
)),
ir
::
Let
::
Make
(
n
,
Expr
(
2
)));
LOG
(
INFO
)
<<
"
\n
"
<<
e
;
IfSimplify
(
&
e
);
LOG
(
INFO
)
<<
e
;
ASSERT_EQ
(
utils
::
GetStreamCnt
(
e
),
"int32 n = 1"
);
}
TEST
(
IfSimplify
,
if_false
)
{
Var
n
(
"n"
);
auto
e
=
ir
::
IfThenElse
::
Make
(
Expr
(
0
)
/*false*/
,
ir
::
Let
::
Make
(
n
,
Expr
(
1
)),
ir
::
Let
::
Make
(
n
,
Expr
(
2
)));
LOG
(
INFO
)
<<
"
\n
"
<<
e
;
IfSimplify
(
&
e
);
LOG
(
INFO
)
<<
e
;
ASSERT_EQ
(
utils
::
GetStreamCnt
(
e
),
"int32 n = 2"
);
}
TEST
(
IfSimplify
,
if_else_empty
)
{
Var
n
(
"n"
);
auto
e
=
ir
::
IfThenElse
::
Make
(
Expr
(
0
)
/*false*/
,
ir
::
Let
::
Make
(
n
,
Expr
(
1
)));
LOG
(
INFO
)
<<
"
\n
"
<<
e
;
IfSimplify
(
&
e
);
LOG
(
INFO
)
<<
e
;
std
::
string
target
=
utils
::
Trim
(
R"ROC(
{
}
)ROC"
);
ASSERT_EQ
(
utils
::
GetStreamCnt
(
e
),
target
);
}
}
// namespace cinn::optim
paddle/cinn/optim/ir_simplify.cc
浏览文件 @
d0224b83
...
@@ -299,9 +299,6 @@ struct SimplifyBlocksMutator : public ir::IRMutator<> {
...
@@ -299,9 +299,6 @@ struct SimplifyBlocksMutator : public ir::IRMutator<> {
*
expr
=
node
->
stmts
[
0
];
*
expr
=
node
->
stmts
[
0
];
Visit
(
expr
,
expr
);
Visit
(
expr
,
expr
);
}
else
{
}
else
{
for
(
auto
&
s
:
node
->
stmts
)
{
Visit
(
&
s
,
&
s
);
}
std
::
vector
<
Expr
>
stmts
;
std
::
vector
<
Expr
>
stmts
;
for
(
auto
&
s
:
node
->
stmts
)
{
for
(
auto
&
s
:
node
->
stmts
)
{
if
(
s
.
As
<
ir
::
Block
>
())
{
if
(
s
.
As
<
ir
::
Block
>
())
{
...
@@ -311,35 +308,13 @@ struct SimplifyBlocksMutator : public ir::IRMutator<> {
...
@@ -311,35 +308,13 @@ struct SimplifyBlocksMutator : public ir::IRMutator<> {
stmts
.
push_back
(
inner_stmt
);
stmts
.
push_back
(
inner_stmt
);
}
}
}
else
{
}
else
{
IRMutator
<>::
Visit
(
&
s
,
&
s
);
stmts
.
push_back
(
s
);
stmts
.
push_back
(
s
);
}
}
}
}
expr
->
As
<
ir
::
Block
>
()
->
stmts
=
stmts
;
expr
->
As
<
ir
::
Block
>
()
->
stmts
=
stmts
;
}
}
}
}
void
Visit
(
const
IfThenElse
*
op
,
Expr
*
expr
)
override
{
if
(
op
->
condition
.
As
<
ir
::
UIntImm
>
())
{
if
(
op
->
condition
.
as_bool
()
==
false
)
{
VLOG
(
6
)
<<
"Simplify ir::IfThenElse false block"
;
if
(
expr
->
As
<
IfThenElse
>
()
->
false_case
.
defined
())
{
*
expr
=
expr
->
As
<
IfThenElse
>
()
->
false_case
;
}
else
{
*
expr
=
ir
::
Block
::
Make
({});
}
}
else
{
if
(
expr
->
As
<
IfThenElse
>
()
->
true_case
.
defined
())
{
VLOG
(
6
)
<<
"Simplify ir::IfThenElse true block"
;
*
expr
=
expr
->
As
<
IfThenElse
>
()
->
true_case
;
}
else
{
*
expr
=
ir
::
Block
::
Make
({});
}
}
ir
::
IRMutator
<
ir
::
Expr
*>::
Visit
(
expr
,
expr
);
return
;
}
ir
::
IRMutator
<
ir
::
Expr
*>::
Visit
(
op
,
expr
);
}
};
};
struct
SimplifyForLoopsMutator
:
public
ir
::
IRMutator
<>
{
struct
SimplifyForLoopsMutator
:
public
ir
::
IRMutator
<>
{
...
...
paddle/cinn/optim/optimize.cc
浏览文件 @
d0224b83
...
@@ -23,7 +23,6 @@
...
@@ -23,7 +23,6 @@
#include "paddle/cinn/optim/eliminate_broadcast_in_forloop.h"
#include "paddle/cinn/optim/eliminate_broadcast_in_forloop.h"
#include "paddle/cinn/optim/extern_call_process.h"
#include "paddle/cinn/optim/extern_call_process.h"
#include "paddle/cinn/optim/fold_cinn_call_arguments.h"
#include "paddle/cinn/optim/fold_cinn_call_arguments.h"
#include "paddle/cinn/optim/if_simplify.h"
#include "paddle/cinn/optim/insert_debug_log_callee.h"
#include "paddle/cinn/optim/insert_debug_log_callee.h"
#include "paddle/cinn/optim/ir_simplify.h"
#include "paddle/cinn/optim/ir_simplify.h"
#include "paddle/cinn/optim/lower_function_call_bind_vars.h"
#include "paddle/cinn/optim/lower_function_call_bind_vars.h"
...
@@ -79,10 +78,6 @@ Expr Optimize(Expr e,
...
@@ -79,10 +78,6 @@ Expr Optimize(Expr e,
Simplify
(
&
copied
);
Simplify
(
&
copied
);
VLOG
(
10
)
<<
"After Optimize Simplify:"
<<
copied
;
VLOG
(
10
)
<<
"After Optimize Simplify:"
<<
copied
;
// TODO(LiuYang): I attends to remove this part code, I integate it into
// ifthenelse part IfSimplify(&copied); VLOG(10) << "After Optimize
// IfSimplify:" << copied;
if
(
runtime_debug_info
)
{
if
(
runtime_debug_info
)
{
LOG
(
WARNING
)
<<
"Turn on runtime debug information output"
;
LOG
(
WARNING
)
<<
"Turn on runtime debug information output"
;
InsertDebugLogCallee
(
&
copied
);
InsertDebugLogCallee
(
&
copied
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录