-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Paddle Inference ]use python to generate cutlass code #50603
[Paddle Inference ]use python to generate cutlass code #50603
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
我觉得有个小问题,虽然kernel是生成的,但我觉得你这个PR应该包含生成的cu文件。 假设我开发另外一个功能,我重新cmake,cmake走到你生成kernel的逻辑,会生成 |
感谢review!已经添加到了.gitignore了! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
该PR完成功能:将之前合入代码进行了模版化生成替换
class CbrAct(enum.Enum): | ||
Identity = 1 | ||
Relu = 2 | ||
Silu = 3 | ||
|
||
|
||
ActCutlassTag = { | ||
CbrAct.Identity: 'cutlass::epilogue::thread::Identity', | ||
CbrAct.Silu: 'cutlass::epilogue::thread::SiLu', | ||
CbrAct.Relu: 'cutlass::epilogue::thread::ReLu', | ||
} | ||
|
||
# some global variables used, now we only support these residual blocks | ||
EpiResBlocks = [ | ||
(CbrAct.Silu, "cutlass::plus", CbrAct.Identity), | ||
(CbrAct.Identity, "cutlass::plus", CbrAct.Relu), | ||
] | ||
|
||
UnderScoreName = { | ||
EpiResBlocks[0]: "conv2d_bias_silu_add", | ||
EpiResBlocks[1]: "conv2d_bias_add_relu", | ||
} | ||
|
||
CamelName = { | ||
EpiResBlocks[0]: "Conv2dBiasSiluAdd", | ||
EpiResBlocks[1]: "Conv2dBiasAddRelu", | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里枚举定义,是不是能单独拿出来共用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里枚举定义,是不是能单独拿出来共用
这里是为了在生成函数代码时候,用来生成函数名字的。不同的后处理对应不同的函数名字。
paddle/phi/kernels/fusion/cutlass/conv2d/conv2d_bias_residual.py
Outdated
Show resolved
Hide resolved
.gitignore 加上
|
paddle/phi/kernels/CMakeLists.txt
Outdated
execute_process( | ||
COMMAND ${sh_cmd} ${sh_arg0} | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/fusion/cutlass") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成add_custom_target 形式
add_custom_target( | |
eager_python_c_codegen | |
COMMAND | |
"${PYTHON_EXECUTABLE}" | |
"${PADDLE_SOURCE_DIR}/paddle/fluid/eager/auto_code_generator/generator/python_c_gen.py" | |
"--api_yaml_path=${api_yaml_path},${fwd_api_yaml_path}" | |
"--output_path=${tmp_python_c_output_path}" | |
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_python_c_output_path} | |
${python_c_output_path} | |
VERBATIM) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成add_custom_target 形式
add_custom_target( eager_python_c_codegen COMMAND "${PYTHON_EXECUTABLE}" "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/auto_code_generator/generator/python_c_gen.py" "--api_yaml_path=${api_yaml_path},${fwd_api_yaml_path}" "--output_path=${tmp_python_c_output_path}" COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmp_python_c_output_path} ${python_c_output_path} VERBATIM)
由于kernel_declare的函数原因,必须在cmake时候产生文件,所以目前只能用execute_process(
来生成文件
done! |
.gitignore
Outdated
@@ -96,4 +96,6 @@ paddle/fluid/prim/api/generated/prim_api/* | |||
paddle/fluid/framework/__init__.py | |||
paddle/phi/api/profiler/__init__.py | |||
python/paddle/incubate/fleet/parameter_server/pslib/ps_pb2.py | |||
paddle/phi/kernels/fusion/cutlass/conv2d/conv2d_bias_act.cu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
生成的文件加入.gitignore
|
||
# this is used for leaky_relu, this activation need a fuse_alpha parameter | ||
|
||
cba_kernel_alpha = cba_kernel_no_alpha.replace( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有些激活函数。例如leaky_relu需要参数alpha,因此定义了cba_kernel_alpha供使用!
"epi_part": "${epi_func}< ${element_c}, ${epilogue_vector_length}, ${element_accum}, ${element_epilogue}>", | ||
} | ||
|
||
cba_kernel_no_alpha = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分是传递一些参数给conv kernel使用的代码
@@ -62,12 +62,14 @@ __global__ void naive_conv2d_kernel(const half *input, | |||
int dilation_w, | |||
int oh, | |||
int ow, | |||
int groups, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个baseline函数支持了group conv,为以后的cutlass group conv和depthwise conv做支持!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1, 有单元测试不?
2, 后续需要文档, 每增加一个新的模板生成代码,需要修改那些文件。 看起来C++、Python都需要修改
).replace( | ||
"typename ImplicitG", "float alpha = params.alpha; typename ImplicitG" | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need more comments in this file, in orde to easy to maintain and update for others
单元测试在python/paddle/fluid/tests/unittests/ir/inference/test_cutlass_conv2d_fusion_op.py中。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
后续此类代码,需要更详细注释,写清楚使用限制等。
7e93dbc
to
06b647e
Compare
ok |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
后续TODO:
group>1 情况;
padding_algorithm非EXPLICIT支持;
PR types
Others
PR changes
Others
Describe