Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cinn(py-dsl): parse compute of python dsl #57731

Merged
merged 3 commits into from
Oct 9, 2023

Conversation

6clc
Copy link
Contributor

@6clc 6clc commented Sep 26, 2023

PR types

Others

PR changes

Others

Description

Pcard-72423

拆分新特性:CINN Python DSL, 主PR和单测见:#56393

此PR只负责 解析python dsl中的compute定义

1. 装饰器@to_cinn_ir封装cinn的function kernel:

  • CinnLowerLevelIrJit支持从Jit运行时中数据类型、target类型、python ast。后续解析compute的信息都会从CinnLowerLevelIrJit这个类中获取。

  • CinnLowerLevelIrJit也支持静态获取上述信息,通过python的annotation来填充。

2. compute 语义解析
将整个AST分为三种类型:

  • stmts: Function, For, If, With ,对应封装上下文IR的PR: #57515

  • Assign: 表达式"lhs = rhs"的类型,Assign类型构成了stmts。
    python/cinn/compiler/expr_executor.py中的exec_expr方法将rhs解析成cinn ir Expr
    python/cinn/compiler/expr_executor.py中的exec_assign方法,将lhs=rhs表达的assign语义存储在局部变量表中。

  • Expr:组成Assign中的rhs

3. 变量管理

python/cinn/compiler/utils.py中的class VariableTable:用于管理Python DSL中定义的变量,主要是下面两个功能。

  • 每次Enter新的Context,会复制当前的变量表
  • 每次Exit Context,会删除当前Context增加的变量,恢复上一轮Context的变量表。

@paddle-bot
Copy link

paddle-bot bot commented Sep 26, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@6clc 6clc mentioned this pull request Sep 26, 2023
6 tasks
@6clc 6clc changed the title Cinn ir compute cinn(py-dsl): parse and execute python dsl Sep 26, 2023
@6clc 6clc force-pushed the cinn-ir-compute branch 2 times, most recently from 5424e3f to 08ebb0c Compare September 26, 2023 12:25
python/cinn/compiler/utils.py Outdated Show resolved Hide resolved
@6clc 6clc changed the title cinn(py-dsl): parse and execute python dsl cinn(py-dsl): parse compute of python dsl Sep 27, 2023
@paddle-ci-bot
Copy link

paddle-ci-bot bot commented Oct 5, 2023

Sorry to inform you that bf34e78's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

else:
raise Exception("Current Only support compile from CinnLowerLevelIrJit")

if just_convert:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this code?

It looks like just return llir_func

Copy link
Contributor Author

@6clc 6clc Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later PR will insert code here to convert llir_func to the RunTime Module of CINN. As follows

    if just_convert:
        return llir_func

    rt_module = llir_to_runtime_module(
        llir_func, kwargs["target"], fn.__name__, kwargs["arg_names"]
    )

    return rt_module

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please send me the PR immediately after this PR.

if is_node_parsed_in_schedule(node.value):
return
res = ExprExecutor(self.variables_table.get()).exec(node.value)
if res is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we simply line 244-249?

if res is not None and isinstance(res, ir.Expr):
    ir.link_to_parent_context(res)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@zhhsplendid zhhsplendid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhhsplendid zhhsplendid merged commit 86a31bd into PaddlePaddle:develop Oct 9, 2023
27 checks passed
Frida-a pushed a commit to Frida-a/Paddle that referenced this pull request Oct 14, 2023
拆分新特性:CINN Python DSL, 主PR和单测见:PaddlePaddle#56393

此PR只负责 解析python dsl中的compute定义

1. 装饰器@to_cinn_ir封装cinn的function kernel:

CinnLowerLevelIrJit支持从Jit运行时中数据类型、target类型、python ast。后续解析compute的信息都会从CinnLowerLevelIrJit这个类中获取。

CinnLowerLevelIrJit也支持静态获取上述信息,通过python的annotation来填充。

2. compute 语义解析
将整个AST分为三种类型:

stmts: Function, For, If, With ,对应封装上下文IR的PR: PaddlePaddle#57515

Assign: 表达式"lhs = rhs"的类型,Assign类型构成了stmts。
python/cinn/compiler/expr_executor.py中的exec_expr方法将rhs解析成cinn ir Expr
python/cinn/compiler/expr_executor.py中的exec_assign方法,将lhs=rhs表达的assign语义存储在局部变量表中。

Expr:组成Assign中的rhs。

3. 变量管理

python/cinn/compiler/utils.py中的class VariableTable:用于管理Python DSL中定义的变量,主要是下面两个功能。

每次Enter新的Context,会复制当前的变量表
每次Exit Context,会删除当前Context增加的变量,恢复上一轮Context的变量表。
jiahy0825 pushed a commit to jiahy0825/Paddle that referenced this pull request Oct 16, 2023
拆分新特性:CINN Python DSL, 主PR和单测见:PaddlePaddle#56393

此PR只负责 解析python dsl中的compute定义

1. 装饰器@to_cinn_ir封装cinn的function kernel:

CinnLowerLevelIrJit支持从Jit运行时中数据类型、target类型、python ast。后续解析compute的信息都会从CinnLowerLevelIrJit这个类中获取。

CinnLowerLevelIrJit也支持静态获取上述信息,通过python的annotation来填充。

2. compute 语义解析
将整个AST分为三种类型:

stmts: Function, For, If, With ,对应封装上下文IR的PR: PaddlePaddle#57515

Assign: 表达式"lhs = rhs"的类型,Assign类型构成了stmts。
python/cinn/compiler/expr_executor.py中的exec_expr方法将rhs解析成cinn ir Expr
python/cinn/compiler/expr_executor.py中的exec_assign方法,将lhs=rhs表达的assign语义存储在局部变量表中。

Expr:组成Assign中的rhs。

3. 变量管理

python/cinn/compiler/utils.py中的class VariableTable:用于管理Python DSL中定义的变量,主要是下面两个功能。

每次Enter新的Context,会复制当前的变量表
每次Exit Context,会删除当前Context增加的变量,恢复上一轮Context的变量表。
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
拆分新特性:CINN Python DSL, 主PR和单测见:PaddlePaddle#56393

此PR只负责 解析python dsl中的compute定义

1. 装饰器@to_cinn_ir封装cinn的function kernel:

CinnLowerLevelIrJit支持从Jit运行时中数据类型、target类型、python ast。后续解析compute的信息都会从CinnLowerLevelIrJit这个类中获取。

CinnLowerLevelIrJit也支持静态获取上述信息,通过python的annotation来填充。

2. compute 语义解析
将整个AST分为三种类型:

stmts: Function, For, If, With ,对应封装上下文IR的PR: PaddlePaddle#57515

Assign: 表达式"lhs = rhs"的类型,Assign类型构成了stmts。
python/cinn/compiler/expr_executor.py中的exec_expr方法将rhs解析成cinn ir Expr
python/cinn/compiler/expr_executor.py中的exec_assign方法,将lhs=rhs表达的assign语义存储在局部变量表中。

Expr:组成Assign中的rhs。

3. 变量管理

python/cinn/compiler/utils.py中的class VariableTable:用于管理Python DSL中定义的变量,主要是下面两个功能。

每次Enter新的Context,会复制当前的变量表
每次Exit Context,会删除当前Context增加的变量,恢复上一轮Context的变量表。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants