Skip to content

Commit c7bbfb3

Browse files
committed
Fix a GPU bug
1 parent 24649a7 commit c7bbfb3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

paddle/fluid/operators/crop_op.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@ static std::vector<int> GetOffsets(const framework::ExecutionContext& ctx) {
3939
PADDLE_ENFORCE_EQ(
4040
rank, offsets_tensor->dims()[0],
4141
"Offsets size should be equal to dimension size of input tensor.");
42-
const int* offsets_data = offsets_tensor->data<int>();
43-
res.resize(rank);
44-
for (size_t i = 0; i < rank; ++i) {
45-
res[i] = offsets_data[i];
42+
const int* offsets_data;
43+
framework::Tensor cpu_tmp_tensor;
44+
if (platform::is_cpu_place(offsets_tensor->place())) {
45+
offsets_data = offsets_tensor->data<int>();
46+
} else {
47+
framework::TensorCopySync(*offsets_tensor, platform::CPUPlace(),
48+
&cpu_tmp_tensor);
49+
offsets_data = cpu_tmp_tensor.data<int>();
4650
}
51+
res = std::vector<int>(offsets_data, offsets_data + rank);
4752
} else {
4853
res = ctx.Attr<std::vector<int>>("offsets");
4954
PADDLE_ENFORCE_EQ(

0 commit comments

Comments
 (0)