-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Add cinn_instruction_run_op for launching execution of a cinn instruction #39435
Conversation
Thanks for your contribution! |
… add_cinn_run_op
… add_cinn_run_op
… add_cinn_run_op
#op_library(cinn_launch_op SRCS cinn_launch_op.cc cinn_launch_op.cu.cc DEPS string_helper cinn cinn_compiler cinn_op_helper cinn_launch_context) | ||
#op_library(cinn_instruction_run_op SRCS cinn_instruction_run_op.cc cinn_instruction_run_op.cu.cc DEPS string_helper cinn cinn_compiler cinn_op_helper cinn_launch_context) |
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.
done
res, paddle2cinn_varmap_.end(), | ||
platform::errors::InvalidArgument( | ||
"Variable(%s) not found in compilation result", paddle_var_name)); | ||
auto it = name2argument_.find(res->second); |
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.
请在注释中注明name2argument_
中的key使用的是cinn var
的名字。
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.
已在头文件声明处添加注释
compiled_object.launch_context.get(); | ||
auto share_argument_buffer_fn = [launch_context, | ||
&ctx](const std::string& var_name) { | ||
cinn_buffer_t* buffer = launch_context->GetCinnBufferOfVar(var_name); |
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_ENFORCE_NE
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.
GetCinnBufferOfVar函数中有 ENFORCE 判断,若是变量名不存在会报错
auto share_argument_buffer_fn = [launch_context, | ||
&ctx](const std::string& var_name) { | ||
cinn_buffer_t* buffer = launch_context->GetCinnBufferOfVar(var_name); | ||
framework::Variable* var = ctx.scope().GetVar(var_name); |
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.
同理,这儿要不先判断下ctx.scope().HasVar(var_name)
(如果有这个接口)?
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.
scope.GetVar 函数中有 ENFORCE 判断
framework::Variable* var = ctx.scope().GetVar(var_name); | ||
auto* tensor = var->template GetMutable<framework::LoDTensor>(); | ||
buffer->memory = | ||
reinterpret_cast<uint8_t*>(tensor->mutable_data<T>(ctx.GetPlace())); |
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.
这儿为啥要转为uint8_t*
啊?CINN的buffer指针都是uint8_t*
类型的么?
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.
裸指针,是。cinn 会根据实际数据类型读取
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
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
PR types
Performance optimization
PR changes
OPs
Describe
cinn_instruction_run_op
: detail explanation of this operator can refer to the comments in its OpMaker.CinnCompiler
: add aindex->cached object
map as the real storage of allCinnCompiledObjects
and the old two cache maps save their indexes as value, and add a new interfaceGetCompiledObject
for getting the cached result by a index.cinn variable name -> paddle variable name
inCinnLaunchContext
, which is generated by the current mappaddle variable name -> cinn variable name
that is also extended to include the internal variables(the map only include external variables originally).GetCinnBufferOfVar
inCinnLaunchContext
for getting thecinn_buffer_t
object of a specified variable.