Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

fix memory corruption in gluoncv ssd training #13727

Merged
merged 1 commit into from
Jan 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/operator/contrib/bounding_box-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ void BipartiteMatchingForward(const nnvm::NodeAttrs& attrs,
.get_with_shape<xpu, 2, DType>(Shape2(batch_size, col), s);
Shape<1> sort_index_shape = Shape1(dshape.Size());
index_t workspace_size = sort_index_shape.Size();
workspace_size += ((sort_index_shape.Size() * sizeof(int32_t) - 1) / sizeof(DType)) * 2;
workspace_size += (sort_index_shape.Size() * 2 * sizeof(int32_t) - 1) / sizeof(DType) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for my naive understanding. But, I do not understand why +1? And this mean, we will have one extra size in the workspace always?

Copy link
Member Author

@arcadiaphy arcadiaphy Dec 27, 2018

Choose a reason for hiding this comment

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

Yes, we will have extra size sometimes when we need to hold int32_t data in DType workspace, and the calculation assures that only the smallest needed space is allocated.

if workspace = (N * sizeof(int32_t) - 1) / sizeof(DType) + 1,
then workspace * sizeof(DType) >= N * sizeof(int32_t) - 1 - (sizeof(DType) - 1) + sizeof(DType)
                                = N * sizeof(int32_t)

Actually, L426 has already calculated correctly.

Tensor<xpu, 1, DType> workspace = ctx.requested[0]
.get_space_typed<xpu, 1, DType>(Shape1(workspace_size), s);
Tensor<xpu, 1, DType> scores_copy(workspace.dptr_,
Expand Down