syclacademy icon indicating copy to clipboard operation
syclacademy copied to clipboard

Code in the slides does not compile in the new version

Open pLopezRamos opened this issue 1 year ago • 1 comments
trafficstars

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 avatar Dec 05 '23 13:12 pLopezRamos

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

pLopezRamos avatar Dec 05 '23 14:12 pLopezRamos