oneDPL icon indicating copy to clipboard operation
oneDPL copied to clipboard

[BUG] oneapi::dpl::reduce_by_key cannot produce expected output

Open lilohuang opened this issue 2 years ago • 2 comments

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

lilohuang avatar Mar 30 '22 02:03 lilohuang

Thank you for reporting, we will take a look.

SergeyKopienko avatar Mar 30 '22 10:03 SergeyKopienko

The root cause found and fixed. Fix will be available in the next oneDPL release.

SergeyKopienko avatar Jul 27 '22 12:07 SergeyKopienko

Confirmed the bug has been fixed and verified with oneAPI 2023.1.0.

lilohuang avatar Apr 18 '23 13:04 lilohuang

Fine! Thank you, @lilohuang!

SergeyKopienko avatar Apr 18 '23 13:04 SergeyKopienko