Intel® oneAPI DPC++/C++ Compiler
Talk to fellow users of Intel® oneAPI DPC++/C++ Compiler and companion tools like Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and Intel® Distribution for GDB*
719 Discussions

std::set does not working in for_parallel()

tgave
Beginner
1,977 Views

While working using sycl I found something weird.
I started by using an unordered_set in my for_parallel() and everything worked perfectly, however I ended up having to ordered my set, so I thought that I would have just to replace all my 'unordered_set' by 'set' but it resulted in a  way too hard to understand by me error (cf error.txt).
After fooling around to understand a bit more the problem, I found out that It is impossible (at least for me) to manipulate set in a for_parallel() (ex iteration in a foreach or pass it as a parameter in a function) and I couldn't find anywhere on the internet someone having the same problem as me. The answer might be written in a documentation but I didn't find anything.

The test code I wrote : test_set.cpp, test_unordered_set.cpp. The only difference in those two is that set is replaced by ordered_set.(I had to comment to be able to attach them)


So I only wanted to know why it is possible to use unordered_set in for_parallel() but not a set.

 

Thank you for your answer.

Labels (1)
0 Kudos
1 Solution
SantoshY_Intel
Moderator
1,932 Views

Hi,


Thank you for posting in Intel Communities.


According to SYCL specifications(https://www.khronos.org/registry/SYCL/specs/sycl-1.2.1.pdf)[page no-257], recursion is not allowed in a SYCL kernel or any code called from the kernel.


"set" internally uses a BST(Binary Search Tree) whereas "unordered_set" internally uses a hash table.

Since BST uses recursive calls for traversals, we are getting an error: "SYCL kernel cannot call a recursive function".


As SYCL doesn't allow us to use recursive calls inside a SYCL kernel, we can't use sets inside a SYCL kernel.


Thanks & Regards,

Santosh







View solution in original post

0 Kudos
2 Replies
SantoshY_Intel
Moderator
1,933 Views

Hi,


Thank you for posting in Intel Communities.


According to SYCL specifications(https://www.khronos.org/registry/SYCL/specs/sycl-1.2.1.pdf)[page no-257], recursion is not allowed in a SYCL kernel or any code called from the kernel.


"set" internally uses a BST(Binary Search Tree) whereas "unordered_set" internally uses a hash table.

Since BST uses recursive calls for traversals, we are getting an error: "SYCL kernel cannot call a recursive function".


As SYCL doesn't allow us to use recursive calls inside a SYCL kernel, we can't use sets inside a SYCL kernel.


Thanks & Regards,

Santosh







0 Kudos
SantoshY_Intel
Moderator
1,916 Views

Hi,


Thanks for accepting our solution. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.


Thanks & Regards,

Santosh



0 Kudos
Reply