提交 1435d179 编写于 作者: Z zhaocai 提交者: jackzhang235

(feat): add copytocpu & copyfromcpu for mlu

上级 0c0d3b1e
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
#include "lite/api/paddle_api.h" #include "lite/api/paddle_api.h"
#include "lite/core/context.h" #include "lite/core/context.h"
#include "lite/core/device_info.h" #include "lite/core/device_info.h"
#include "lite/core/target_wrapper.h" #include "lite/core/target_wrapper.h"
...@@ -22,6 +23,10 @@ ...@@ -22,6 +23,10 @@
#include "lite/backends/cuda/target_wrapper.h" #include "lite/backends/cuda/target_wrapper.h"
#endif #endif
#ifdef LITE_WITH_MLU
#include "lite/backends/mlu/target_wrapper.h"
#endif
namespace paddle { namespace paddle {
namespace lite_api { namespace lite_api {
...@@ -97,6 +102,13 @@ void Tensor::CopyFromCpu(const T *src_data) { ...@@ -97,6 +102,13 @@ void Tensor::CopyFromCpu(const T *src_data) {
data, src_data, num * sizeof(T), lite::IoDirection::HtoD); data, src_data, num * sizeof(T), lite::IoDirection::HtoD);
#else #else
LOG(FATAL) << "Please compile the lib with CUDA."; LOG(FATAL) << "Please compile the lib with CUDA.";
#endif
} else if (type == TargetType::kMLU) {
#ifdef LITE_WITH_MLU
lite::TargetWrapperMlu::MemcpySync(
data, src_data, num * sizeof(T), lite::IoDirection::HtoD);
#else
LOG(FATAL) << "Please compile the lib with MLU.";
#endif #endif
} else { } else {
LOG(FATAL) << "The CopyFromCpu interface just support kHost, kARM, kCUDA"; LOG(FATAL) << "The CopyFromCpu interface just support kHost, kARM, kCUDA";
...@@ -117,6 +129,13 @@ void Tensor::CopyToCpu(T *data) const { ...@@ -117,6 +129,13 @@ void Tensor::CopyToCpu(T *data) const {
data, src_data, num * sizeof(T), lite::IoDirection::DtoH); data, src_data, num * sizeof(T), lite::IoDirection::DtoH);
#else #else
LOG(FATAL) << "Please compile the lib with CUDA."; LOG(FATAL) << "Please compile the lib with CUDA.";
#endif
} else if (type == TargetType::kMLU) {
#ifdef LITE_WITH_MLU
lite::TargetWrapperMlu::MemcpySync(
data, src_data, num * sizeof(T), lite::IoDirection::DtoH);
#else
LOG(FATAL) << "Please compile the lib with MLU.";
#endif #endif
} else { } else {
LOG(FATAL) << "The CopyToCpu interface just support kHost, kARM, kCUDA"; LOG(FATAL) << "The CopyToCpu interface just support kHost, kARM, kCUDA";
...@@ -138,6 +157,11 @@ template void Tensor::CopyFromCpu<int64_t, TargetType::kCUDA>(const int64_t *); ...@@ -138,6 +157,11 @@ template void Tensor::CopyFromCpu<int64_t, TargetType::kCUDA>(const int64_t *);
template void Tensor::CopyFromCpu<float, TargetType::kCUDA>(const float *); template void Tensor::CopyFromCpu<float, TargetType::kCUDA>(const float *);
template void Tensor::CopyFromCpu<int8_t, TargetType::kCUDA>(const int8_t *); template void Tensor::CopyFromCpu<int8_t, TargetType::kCUDA>(const int8_t *);
template void Tensor::CopyFromCpu<int, TargetType::kMLU>(const int *);
template void Tensor::CopyFromCpu<int64_t, TargetType::kMLU>(const int64_t *);
template void Tensor::CopyFromCpu<float, TargetType::kMLU>(const float *);
template void Tensor::CopyFromCpu<int8_t, TargetType::kMLU>(const int8_t *);
template void Tensor::CopyToCpu(float *) const; template void Tensor::CopyToCpu(float *) const;
template void Tensor::CopyToCpu(int *) const; template void Tensor::CopyToCpu(int *) const;
template void Tensor::CopyToCpu(int8_t *) const; template void Tensor::CopyToCpu(int8_t *) const;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册