Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example from 4.12.1. Defining kernels as named function objects is misleading #198

Open
keryell opened this issue Nov 5, 2021 · 1 comment · May be fixed by #719
Open

Example from 4.12.1. Defining kernels as named function objects is misleading #198

keryell opened this issue Nov 5, 2021 · 1 comment · May be fixed by #719

Comments

@keryell
Copy link
Member

keryell commented Nov 5, 2021

The example

 class RandomFiller {
 public:
  RandomFiller(accessor<int> ptr)
      : ptr_ { ptr } {
    std::random_device hwRand;
    std::uniform_int_distribution<> r { 1, 100 };
    randomNum_ = r(hwRand);
  }
  void operator()(item<1> item) const { ptr_[item.get_id()] = get_random(); }
  int get_random() { return randomNum_; }

 private:
  accessor<int> ptr_;
  int randomNum_;
};

void workFunction(buffer<int, 1>& b, queue& q, const range<1> r) {
    myQueue.submit([&](handler& cgh) {
      accessor ptr { buf, cgh };
      RandomFiller filler { ptr };

      cgh.parallel_for(r, filler);
    });
}

is kind of misleading because of the useless call to get_random() instead of returning directly randomNum_, which might suggest with the call operator that a different random number is used for each work-item.

@fraggamuffin
Copy link

simplify with direct member

@Pennycook Pennycook linked a pull request Feb 12, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants