refactor(op): polish generate_proposals_op

Polish styles in generate_proposals_op.

1. inline lambda functions rathar than use std::function to save var.
2. add `static inline` to template functions .cc
   * Make them static to prevent generating symbols.
   * Make them inline to give compiler a hit inline them as possible.
   * Not if the function is not static, they cannot be inlined since the
     symbols should be exported.
3. add `static` to global functions in .cc
   * Make them static to prevent generating symbols.
4. Use Vector<uint64> instead manually manange storage between devices.
5. Prefer to use platform::ForRange, so we can optimize `ForRange` by
   just changing `for_range.h` if it is needed.
6. Do not change shape of inputs

test=develop
release/1.1
Yu Yang 7 years ago
parent 7a5f3f750b
commit 593ad763cd

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -39,11 +39,9 @@ void CPUGather(const platform::DeviceContext& ctx, const Tensor& src,
PADDLE_ENFORCE(platform::is_cpu_place(ctx.GetPlace())); PADDLE_ENFORCE(platform::is_cpu_place(ctx.GetPlace()));
// check index of shape 1-D // check index of shape 1-D
PADDLE_ENFORCE(index.dims().size() == 1); PADDLE_ENFORCE(index.dims().size() == 1);
int index_size = index.dims()[0]; int64_t index_size = index.dims()[0];
auto src_dims = src.dims(); auto src_dims = src.dims();
framework::DDim output_dims(src_dims);
output_dims[0] = index_size;
const T* p_src = src.data<T>(); const T* p_src = src.data<T>();
const int* p_index = index.data<int>(); const int* p_index = index.data<int>();
@ -55,7 +53,7 @@ void CPUGather(const platform::DeviceContext& ctx, const Tensor& src,
const size_t slice_bytes = slice_size * sizeof(T); const size_t slice_bytes = slice_size * sizeof(T);
for (int i = 0; i < index_size; ++i) { for (int64_t i = 0; i < index_size; ++i) {
int index_ = p_index[i]; int index_ = p_index[i];
memcpy(p_output + i * slice_size, p_src + index_ * slice_size, slice_bytes); memcpy(p_output + i * slice_size, p_src + index_ * slice_size, slice_bytes);
} }

Loading…
Cancel
Save