Community
cancel
Showing results for 
Search instead for 
Did you mean: 
CFR
Beginner
367 Views

sycl::stream causing segfault?

Jump to solution

Given the following (example) source...

 

#include <CL/sycl.hpp>
namespace sycl = cl::sycl;
const int Nproc = 6;
int
main(int argc, char *argv[])
{
    sycl::device dev = sycl::cpu_selector().select_device();
    sycl::queue q(dev);
    q.submit([&](sycl::handler& cgh) {
      sycl::stream sout {1024, 1024, cgh};
      sout << "Kernel" << sycl::endl;
      cgh.parallel_for<class kernelCPU>(
          sycl::range<1> {Nproc},
          [=] (sycl::item<1> item) {
              int idx = item.get_linear_id();
              sout << idx << sycl::endl;
              }
          );
      }
      );
}

 

... built/run as follows...

 

user@t570:~/OneAPI/SYCL$ dpcpp --version
Intel(R) oneAPI DPC++ Compiler 2021.1-beta07 (2020.5.0.0604)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/opt/inteloneapi/compiler/latest/linux/bin
user@t570:~/OneAPI/SYCL$ make bug4
dpcpp -O3 -g -mavx2 -o bug4 bug4.cpp -lOpenCL -lsycl
user@t570:~/OneAPI/SYCL$ ./bug4
PLEASE submit a bug report to https://software.intel.com/en-us/support/priority-support and include the crash backtrace.
Segmentation fault (core dumped)

 

The offending line is the "sout << "Kernel" << sycl::endl;".  Comment that out and the fault disappears.

I'm not sure if this is a dpc++ bug, or a "me" bug, but it said to report it so...  (fyi I don't have priority support so I'm doing it here).

0 Kudos
1 Solution
GouthamK_Intel
Moderator
358 Views

Hi,


As we discussed in your previous thread (https://community.intel.com/t5/Intel-oneAPI-Data-Parallel-C/std-ostream-lt-lt-vec-lt-T-length-gt-not...). 


The stream class is designed to use only within kernels in order to stream from the kernel back to the host CPU for printing via stdout.


The stream instance is constructed in host within the command group scope and takes maximum buffer size, maximum stream size, and command group handler instance as parameters.


cl::sycl::stream sout(<max_buffer_size>, <max_stream_size>, <cgh>); 


maximum buffer size = the overall character stream that can be output in characters (a character is of size sizeof(char) bytes) during kernel invocation (the aggregate of outputs from all work items).

maximum stream size = this specifies the maximum size of the character stream (number of characters) that can be output within a work item before a flush must be performed (maximum number of characters that can be used in a single statement on the stream).


When strings are stream to the object within a kernel, the contents are stored on an internal cl_mem object until the kernel finishes execution. The output is then output to stdout when the stream object is destroyed by the runtime.


In the sample code provided by you, as sout<< () is getting invoked outside the kernel (parallel_for), it is causing the segmentation fault error. Whereas for the sout<<() which was invoked inside the kernel you don't see any issues.


Please let us know if the above information helped you.



Regards

Goutham


View solution in original post

4 Replies
GouthamK_Intel
Moderator
359 Views

Hi,


As we discussed in your previous thread (https://community.intel.com/t5/Intel-oneAPI-Data-Parallel-C/std-ostream-lt-lt-vec-lt-T-length-gt-not...). 


The stream class is designed to use only within kernels in order to stream from the kernel back to the host CPU for printing via stdout.


The stream instance is constructed in host within the command group scope and takes maximum buffer size, maximum stream size, and command group handler instance as parameters.


cl::sycl::stream sout(<max_buffer_size>, <max_stream_size>, <cgh>); 


maximum buffer size = the overall character stream that can be output in characters (a character is of size sizeof(char) bytes) during kernel invocation (the aggregate of outputs from all work items).

maximum stream size = this specifies the maximum size of the character stream (number of characters) that can be output within a work item before a flush must be performed (maximum number of characters that can be used in a single statement on the stream).


When strings are stream to the object within a kernel, the contents are stored on an internal cl_mem object until the kernel finishes execution. The output is then output to stdout when the stream object is destroyed by the runtime.


In the sample code provided by you, as sout<< () is getting invoked outside the kernel (parallel_for), it is causing the segmentation fault error. Whereas for the sout<<() which was invoked inside the kernel you don't see any issues.


Please let us know if the above information helped you.



Regards

Goutham


View solution in original post

GouthamK_Intel
Moderator
325 Views

Hi,


Could you please confirm if your issue is resolved?


Regards

Goutham


CFR
Beginner
308 Views

I understand my error.  Thanks.

 

GouthamK_Intel
Moderator
296 Views

Hi,

Thanks for the confirmation.!

This issue has been resolved and we will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.


Have a Good day.!


Thanks & Regards

Goutham


Reply