oneDPL icon indicating copy to clipboard operation
oneDPL copied to clipboard

How to construct sycl::stream within DPL lambda body for debugging purpose?

Open lilohuang opened this issue 2 years ago • 3 comments

As we all know, https://developer.codeplay.com/products/computecpp/ce/guides/sycl-guide/debugging demonstrates how to construct a sycl::stream for printing to standard output from device code. However, I have no idea how to obtain the handler to construct the sycl::stream. Is it a known limitation of DPL? BTW, I'm a CUDA programmer for many years, and evaluating the benefit/limitation of oneAPI (DPC++, DPL) for HPC purpose. Thank you so much.

   sycl::queue q(sycl::gpu_selector{});
   oneapi::dpl::for_each(oneapi::dpl::execution::make_device_policy(q),
      oneapi::dpl::counting_iterator<size_t>(0),
      oneapi::dpl::counting_iterator<size_t>(32),
      [](size_t i) {
         // How to obtain cgh within lambda body for debugging purpose??
         // sycl::stream out(1024, 256, cgh); 
      });

lilohuang avatar Feb 21 '22 09:02 lilohuang

Hi, @lilohuang. Yes, it is a limitation. oneDPL does not provide access to the command group handlers used by the algorithms and thus sycl::stream cannot be applied.

I am investigating if there are alternative approaches for printing from within kernels.

Have you tried using Intel® Distribution for GDB? The approach of debugging is different from one you asked about, but it may be useful too.

dmitriy-sobolev avatar Feb 25 '22 17:02 dmitriy-sobolev

@dmitriy-sobolev thanks for your quick response, using debugger (e.g. intel gdb, cuda-gdb, etc.) requires shipping source code to customer side so it won't fit my need. My current alternative solution is writing debug data to an array manually within the lambda body, and then dump the array separately. BTW, thrust::for_each within lambda function can easily achieve debugging through printf() in the lambda body on a CUDA device. Looking forward to seeing DPL to support sycl::stream or the similar feature. I will leave this ticket open.

lilohuang avatar Feb 25 '22 22:02 lilohuang

You could use sycl::ext::oneapi::experimental::printf of course, e.g., https://github.com/kokkos/kokkos/blob/63ceaca62813248e4b2eae3fab742b3028206168/core/src/setup/Kokkos_Setup_SYCL.hpp#L59-L65.

masterleinad avatar Jul 21 '22 13:07 masterleinad

Hi @masterleinad ,

Using sycl::ext::oneapi::experimental::printf() perfectly meets my needs.

Thanks, Lilo

lilohuang avatar Apr 12 '23 06:04 lilohuang