Skip to content

[DPC++] reduction error using a vector type #3121

@zjin-lcf

Description

@zjin-lcf

The reproducer is listed below. A comment is added to the line of issue which causes build errors. Thank you.

#include <CL/sycl.hpp>
#include <iostream>
#include <random>

using namespace sycl;
using namespace sycl::ONEAPI;

int main() {
  constexpr size_t N = 16;
  constexpr size_t L = 4;

  queue Q;
  float* data = malloc_shared<float>(N, Q);
  float* data2 = malloc_shared<float>(N, Q);

  float2* res = malloc_shared<float2>(1, Q);
  std::generate(data, data + N, std::mt19937{});
  std::generate(data2, data2 + N, std::mt19937{});

  float2 identity = {0.f, 0.f};
  *res = identity;
  auto red = reduction(res, identity, std::plus<float2>());
  Q.submit([&](handler& h) {
     h.parallel_for(nd_range<1>{N, L}, red, [=](nd_item<1> item, auto& res) {
       int i = item.get_global_id(0);
       res += {data[i], data2[i]};   //  res.combine({data[i], data2[i]});  is successful 
     });
   }).wait();

  std::cout << "sum value = " << res->x() << " " << res->y() << "\n";

  free(res, Q);
  free(data, Q);
  free(data2, Q);
  return 0
}

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions