1

This question might be trivial, unfortunately I haven't found the answer I was looking for.

I used dpct migration tool to port some cuda code to Intel DPC++ and then I further optimized everything I needed and eventually got rid of everything related to dpct expect the super handy

dpct::get_current_device();

which basically solves all the previous pain I had to put compile options to select the appropriate device and control them with Makefiles and so on.

Is there any way to do this without using dpct ? I had a look at how dpct does this (here) but it looks pretty non-straightforward and it relies on other internal functions.

Is there any way to avoid this ?

Elle
  • 305
  • 2
  • 10

1 Answers1

1

I'm not totally clear from your question whether you want to 1) grab a handle to your device or 2) select a device on which to run stuff, so I'll try to answer both. Note that dpct::get_current_device() isn't actually selecting a device, it's just returning the device which you have already selected earlier in your program.

  1. Typically when using SYCL we start with a sycl::queue, which we use to submit kernels, memory copy operations etc. From a sycl::queue you can access your device with:
sycl::device d = q.get_device();
  1. But it seems like you may instead be asking for the simplest way to select a device. In this case, the simplest approach is to construct your queue with one of SYCL's provided device selectors:
sycl::queue q{sycl::gpu_selector()};
sycl::queue q{sycl::cpu_selector()};
sycl::queue q{sycl::default_selector()};

Note that the last option (sycl::default_selector()) is probably what dpct is currently doing for you.

Joe Todd
  • 814
  • 6
  • 13
  • You're right, it was in fact doing `sycl::default_selector{}`. Your clarification helped me a lot, thanks! – Elle Jun 25 '22 at 16:06