oneDPL
oneDPL copied to clipboard
[BUG] oneapi::dpl::reduce_by_key cannot produce expected output
Hi oneDPL experts,
The oneapi::dpl::reduce_by_key cannot produce expected output when the key elements are all zero. However, change the key elements to be one can get rid of the bug. Bug can be reproduced with Intel oneAPI 2022.0.2 with VS2019 Could you please take a look? Thanks
#define ONEDPL_USE_DPCPP_BACKEND 1
#include <oneapi/dpl/execution>
#include <oneapi/dpl/algorithm>
#include <oneapi/dpl/iterator>
#include <CL/sycl.hpp>
#include <iostream>
int main() {
auto policy = oneapi::dpl::execution::dpcpp_default;
sycl::usm_allocator<int, sycl::usm::alloc::shared> alloc(policy.queue());
std::vector<int, decltype(alloc)> keys({ 0,0,0 }, alloc); // this won't produce output
// std::vector<int, decltype(alloc)> keys({ 1,1,1 }, alloc); // this line is fine
std::vector<int, decltype(alloc)> values({ 1,2,3 }, alloc);
std::vector<int, decltype(alloc)> output_keys(keys.size(), alloc);
std::vector<int, decltype(alloc)> output_values(values.size(), alloc);
// keys: [0,0,0]
// values: [1,2,3]
// expected output_keys: [0]
// expected output_values: [1+2+3=6]
auto new_end = oneapi::dpl::reduce_by_key(policy,
keys.begin(), keys.end(),
values.begin(),
output_keys.begin(),
output_values.begin(),
std::equal_to<int>(),
std::plus<int>());
size_t size = oneapi::dpl::distance(output_keys.begin(), new_end.first);
for (size_t i = 0; i < size; i++) {
std::cout << "output_keys[" << i << "] = " << output_keys[i] << std::endl;
std::cout << "output_values[" << i << "] = " << output_values[i] << std::endl;
}
return 0;
}
Thanks, Lilo
Thank you for reporting, we will take a look.
The root cause found and fixed. Fix will be available in the next oneDPL release.
Confirmed the bug has been fixed and verified with oneAPI 2023.1.0.
Fine! Thank you, @lilohuang!