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

Add cinn_instruction_run_op for launching execution of a cinn instruction #39435

Merged
merged 11 commits into from
Feb 15, 2022

Conversation

CtfGo
Copy link
Contributor

@CtfGo CtfGo commented Feb 9, 2022

PR types

Performance optimization

PR changes

OPs

Describe

  1. add a new operator cinn_instruction_run_op: detail explanation of this operator can refer to the comments in its OpMaker.
  2. upgrade the organization structure of the cache in CinnCompiler: add a index->cached object map as the real storage of all CinnCompiledObjects and the old two cache maps save their indexes as value, and add a new interface GetCompiledObject for getting the cached result by a index.
  3. add a new reverse name map cinn variable name -> paddle variable name in CinnLaunchContext, which is generated by the current map paddle variable name -> cinn variable name that is also extended to include the internal variables(the map only include external variables originally).
  4. add a new interface GetCinnBufferOfVar in CinnLaunchContext for getting the cinn_buffer_t object of a specified variable.

@paddle-bot-old
Copy link

paddle-bot-old bot commented Feb 9, 2022

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Comment on lines 8 to 9
#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)
Copy link
Contributor

@wzzju wzzju Feb 10, 2022

Choose a reason for hiding this comment

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

如果这两句无用请直接删除,请不要在此注释。

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

res, paddle2cinn_varmap_.end(),
platform::errors::InvalidArgument(
"Variable(%s) not found in compilation result", paddle_var_name));
auto it = name2argument_.find(res->second);
Copy link
Contributor

Choose a reason for hiding this comment

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

请在注释中注明name2argument_中的key使用的是cinn var的名字。

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

这儿是否可能返回为空指针或者野指针啊?特别是在多线程环境下?建议加个PADDLE_ENFORCE_NE

Copy link
Contributor Author

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);
Copy link
Contributor

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)(如果有这个接口)?

Copy link
Contributor Author

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()));
Copy link
Contributor

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*类型的么?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

裸指针,是。cinn 会根据实际数据类型读取

Copy link
Contributor

@thisjiang thisjiang left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@wzzju wzzju left a comment

Choose a reason for hiding this comment

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

LGTM

@CtfGo CtfGo merged commit 9d0baea into PaddlePaddle:develop Feb 15, 2022
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