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

Code in the slides does not compile in the new version #323

Open
pLopezRamos opened this issue Dec 5, 2023 · 1 comment
Open

Code in the slides does not compile in the new version #323

pLopezRamos opened this issue Dec 5, 2023 · 1 comment

Comments

@pLopezRamos
Copy link

Hi,

The code presented in the slides, at least in the case of exercise 4, seems to be written for version 1.2.1 and fails to compile in the newer versions of the compiler. I think it may be a good idea to either state in the slides that the code is for version 1.2.1 or upgrade the slides.

Salu2,
Pablo

@pLopezRamos
Copy link
Author

pLopezRamos commented Dec 5, 2023

Hi again,

The code I was looking at did not compile because a single_task was being called with parameters for a parallel_for. There are warnings regarding the use of a deprecated device selector followed by errors related to the single_task issue. My mistake was not looking in detail at the errors being generated, assuming a compiler version problem.

This is a version of the code that compiles without errors or warnings:

#include <sycl/sycl.hpp>

class add;

using namespace sycl;

int main() {
std::vector dA{ 7, 5, 16, 8 }, dB{ 8, 16, 5, 7 }, dO{ 0, 0, 0, 0 };
try{

  queue gpuQueue(gpu_selector_v, [=](exception_list eL) {
        for (auto e : eL) { std::rethrow_exception(e); }
        });

  buffer bufA{dA};
  buffer bufB{dB};
  buffer bufO{dO};

  gpuQueue.submit([&](handler &cgh) {
        auto inA = accessor{bufA, cgh, read_only};
        auto inB = accessor{bufB, cgh, read_only};
        auto out = accessor{bufO, cgh, write_only};
        cgh.parallel_for(range{bufO.size()}, [=](id<1> i) { out[i] = inA[i] + inB[i];});
        });

  gpuQueue.throw_asynchronous();

} catch (...) { /* handle errors */ }
}

Hope it helps and sorry for the mishap.

Salu2,
Pablo

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

No branches or pull requests

1 participant