From c7bbfb33ad816762f00e19f5076b1d6fed105b2d Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Fri, 8 Jun 2018 10:39:44 +0800 Subject: [PATCH] Fix a GPU bug --- paddle/fluid/operators/crop_op.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/operators/crop_op.h b/paddle/fluid/operators/crop_op.h index d8e9f086cc9..91cfbbda735 100644 --- a/paddle/fluid/operators/crop_op.h +++ b/paddle/fluid/operators/crop_op.h @@ -39,11 +39,16 @@ static std::vector GetOffsets(const framework::ExecutionContext& ctx) { PADDLE_ENFORCE_EQ( rank, offsets_tensor->dims()[0], "Offsets size should be equal to dimension size of input tensor."); - const int* offsets_data = offsets_tensor->data(); - res.resize(rank); - for (size_t i = 0; i < rank; ++i) { - res[i] = offsets_data[i]; + const int* offsets_data; + framework::Tensor cpu_tmp_tensor; + if (platform::is_cpu_place(offsets_tensor->place())) { + offsets_data = offsets_tensor->data(); + } else { + framework::TensorCopySync(*offsets_tensor, platform::CPUPlace(), + &cpu_tmp_tensor); + offsets_data = cpu_tmp_tensor.data(); } + res = std::vector(offsets_data, offsets_data + rank); } else { res = ctx.Attr>("offsets"); PADDLE_ENFORCE_EQ( -- GitLab