-
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
Add copy from tensor #34406
Add copy from tensor #34406
Conversation
… add_copy_from_tensor
Thanks for your contribution! |
… add_copy_from_tensor
… add_copy_from_tensor
… add_copy_from_tensor
const std::string& name, PlaceType place, void* p_scope); | ||
|
||
private: | ||
static void CopyTensorImp(Tensor& dst, const Tensor& src, void* exec_stream, |
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.
Imp -> Impl
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
std::vector<float> input(in_num, 1.0); | ||
|
||
auto input_names = predictor->GetInputNames(); | ||
auto input_t = predictor->GetInputHandle(input_names[0]); |
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.
input_tensor
_t
后缀一般表示 type,比如 value_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.
done
@@ -185,7 +187,8 @@ void Tensor::CopyFromCpu(const T *data) { | |||
} | |||
|
|||
template <typename T> | |||
void Tensor::CopyToCpu(T *data) { | |||
void Tensor::CopyToCpuImp(T *data, void *exec_stream, CallbackFunc cb, |
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.
全局, Imp -> Impl
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
|
||
using paddle::PaddleDType; | ||
|
||
std::unique_ptr<Tensor> TensorUtils::CreateInferTensorForTest( |
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.
用于单测的,最好单独拆出去,用 WITH_TESTING 宏隔开
这个会进到最终生产环境的库里面吧?
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,thanks
@@ -0,0 +1,325 @@ | |||
/* Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. | |||
|
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.
文件名 copy_tensor,两个单词
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.
这是个单测?
文件名也需要加 _tester
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
最好把用例,功能在 PR 描述里面也加下 |
paddle/fluid/inference/tests/api/paddle_infer_api_copytensor.cc
Outdated
Show resolved
Hide resolved
paddle/fluid/inference/tests/api/paddle_infer_api_copytensor.cc
Outdated
Show resolved
Hide resolved
paddle/fluid/inference/tests/api/paddle_infer_api_copytensor.cc
Outdated
Show resolved
Hide resolved
paddle/fluid/inference/tests/api/paddle_infer_api_copytensor.cc
Outdated
Show resolved
Hide resolved
paddle/fluid/inference/tests/api/paddle_infer_api_copytensor.cc
Outdated
Show resolved
Hide resolved
done |
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 for 'set_tests_properties(paddle_infer_api_copy_tensor_tester PROPERTIES TIMEOUT 30) '
This reverts commit ac33c0c.
…dle#35173)" This reverts commit 32c1ec4.
PR types
Others
PR changes
APIs
Describe
add copy_from_tensor api for inference tensor
一、python增加同步copy_tensor的api,使用示例
二、C++增加paddle_infer::Tensor::CopyToCpuAsync接口(当前只支持GPU到CPU的异步拷贝,此时不能使用Host申请的内存,需要使用cuda的pinned memory,可以使用提供的工具函数申请和释放 CudaMallocPinnedMemory()/CudaFreePinnedMemory()),示例如下
三、增加C++ tensor拷贝函数
异步使用方式参考Tensor.CopyToCpuAsync()
测试代码参考 paddle/fluid/inference/tests/api/paddle_infer_api_copy_tensor_tester.cc