Skip to content
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
20 changes: 11 additions & 9 deletions onnxruntime/core/providers/cpu/tensor/gather.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ Status GatherCopyData(const Tensor* indices_tensor, const uint8_t* src_base, uin
}
}

auto lambda = [&](int64_t index) {
int64_t batch = index / N;
int64_t i = index % N;
auto lambda = [&](ptrdiff_t index) {
const int64_t batch = static_cast<int64_t>(index / N);
const int64_t i = static_cast<int64_t>(index % N);

const int64_t src_offset_batch = batch * data_batch_bytes;
const int64_t dst_offset_batch = batch * gathered_batch_bytes;
Expand All @@ -120,12 +120,14 @@ Status GatherCopyData(const Tensor* indices_tensor, const uint8_t* src_base, uin
memcpy(dst_base + dst_offset, src_base + src_offset, narrow<size_t>(block_size));
}
};
concurrency::ThreadPool::TryParallelFor(tp, SafeInt<ptrdiff_t>(M) * N, static_cast<double>(block_size),
[&lambda](ptrdiff_t first, ptrdiff_t last) {
for (int index = static_cast<int>(first), end = static_cast<int>(last); index < end; ++index) {
lambda(index);
}
});

concurrency::ThreadPool::TryParallelFor(
tp, SafeInt<ptrdiff_t>(M) * N, static_cast<double>(block_size),
[&lambda](ptrdiff_t first, ptrdiff_t last) {
for (ptrdiff_t index = first; index < last; ++index) {
lambda(index);
}
});

return Status::OK();
}
Expand Down
Loading