<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute in Intel® oneAPI DPC++/C++ Compiler</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/SYCL-kernel-cannot-call-an-undefined-function-without-SYCL/m-p/1382886#M2118</link>
    <description>&lt;P&gt;I am not calling the function inside the kernel, actually, the problem lies in the way I am doing the parallelism in parallel_for:&lt;/P&gt;
&lt;P&gt;so it works normally if I do this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;h.parallel_for(num_items, [=](auto i) {
  
        for (int j = 0; j &amp;lt;(const int) a[i].size(); ++j) {
            dif[i] += a[i];
        }
        });&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but when I try to take the values in the second dimension like this:&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;h.parallel_for(num_items, [=](auto i) {
  
        for (int j = 0; j &amp;lt;(const int) a[i].size(); ++j) {
            dif[i] += a[i][j] ;
        }
        });&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;It gives an error.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please see the previous full code, I don't know if I defined the buffers and accessors correctly.&lt;/P&gt;
&lt;P&gt;I tried to do the solution you provided, but it gave me many errors more than before, so it is not working, unfortunately.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 May 2022 15:07:10 GMT</pubDate>
    <dc:creator>amaltaha</dc:creator>
    <dc:date>2022-05-09T15:07:10Z</dc:date>
    <item>
      <title>SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/SYCL-kernel-cannot-call-an-undefined-function-without-SYCL/m-p/1382710#M2114</link>
      <description>&lt;DIV class="votecell post-layout--left"&gt;
&lt;DIV class="js-voting-container d-flex jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="72166136"&gt;
&lt;DIV class="js-vote-count flex--item d-flex fd-column ai-center fc-black-500 fs-title" data-value="0"&gt;&lt;SPAN&gt;I am trying to calculate the euclidean distance for KNN but in parallel using dpc++. the training dataset contains 5 features and 1600 rows, while I want to calculate the distance between the current test point and each training point on the grid in parallel, but I keep getting an error regarding sycl kernal. code for the function:&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="postcell post-layout--right"&gt;
&lt;DIV class="s-prose js-post-body"&gt;&lt;LI-CODE lang="cpp"&gt;std::vector&amp;lt;double&amp;gt; distance_calculation_FPGA(queue&amp;amp; q,const std::vector&amp;lt;std::vector&amp;lt;double&amp;gt;&amp;gt;&amp;amp; dataset,const std::vector&amp;lt;double&amp;gt;&amp;amp; curr_test) {
range&amp;lt;1&amp;gt; num_items{ dataset.size()};
std::vector&amp;lt;double&amp;gt;res;


res.resize(dataset.size());
buffer dataset_buf(dataset);
buffer curr_test_buf(curr_test);
buffer res_buf(res.data(), num_items);

q.submit([&amp;amp;](handler&amp;amp; h) {
    accessor a(dataset_buf, h, read_only);
    accessor b(curr_test_buf, h, read_only);

    accessor dif(res_buf, h, write_only, no_init);

   h.parallel_for(num_items, [=](auto i) {
  
        for (int j = 0; j &amp;lt;(const int) a[i].size(); ++j) {
            dif[i] += (a[i][j] - b[j]) * (a[i][j] - b[j]) ;
        }
        });
 });
for (int i = 0; i &amp;lt; res.size(); ++i) {
    std::cout &amp;lt;&amp;lt; res[i] &amp;lt;&amp;lt; std::endl;
} 
//old distance calculation (serial)
//for (int i = 0; i &amp;lt; dataset.size(); ++i) {
 //   double dis = 0;
   // for (int j = 0; j &amp;lt; dataset[i].size(); ++j) {
     //   dis += (curr_test[j] - dataset[i][j]) * (curr_test[j] - dataset[i][j]);
    //}
    //res.push_back(dis);
//}

return res;
}&lt;/LI-CODE&gt;
&lt;P&gt;the error I am receiving:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;SYCL kernel cannot call a variadic function

SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Would be extremely grateful for any help!&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 09 May 2022 15:07:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/SYCL-kernel-cannot-call-an-undefined-function-without-SYCL/m-p/1382710#M2114</guid>
      <dc:creator>amaltaha</dc:creator>
      <dc:date>2022-05-09T15:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/SYCL-kernel-cannot-call-an-undefined-function-without-SYCL/m-p/1382827#M2116</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for posting in Intel Communities.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We assume that you are using the following scenario:&lt;/P&gt;
&lt;P&gt;Trying to launch the distance_calculation_FPGA() function inside an SYCL kernel and printing its return value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To resolve your issue, you can use the below workaround:&lt;/P&gt;
&lt;P&gt;1. Create a header file (example: Header.h) and declare the function as "SYCL_EXTERNAL"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#include&amp;lt;CL/sycl.hpp&amp;gt;
extern SYCL_EXTERNAL std::vector&amp;lt;double&amp;gt; distance_calculation_FPGA(queue&amp;amp; q,const std::vector&amp;lt;std::vector&amp;lt;double&amp;gt;&amp;gt;&amp;amp; dataset,const std::vector&amp;lt;double&amp;gt;&amp;amp; curr_test);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Now include the header file in your source code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#include &amp;lt;CL/sycl.hpp&amp;gt;
#include "Header.h"
std::vector&amp;lt;double&amp;gt; distance_calculation_FPGA(queue&amp;amp; q,const std::vector&amp;lt;std::vector&amp;lt;double&amp;gt;&amp;gt;&amp;amp; dataset,const std::vector&amp;lt;double&amp;gt;&amp;amp; curr_test){

}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Try to recompile and run your program.&lt;/P&gt;
&lt;P&gt;If this resolves your issue, make sure to accept this as a solution. This would help others with a similar issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you still face any issues, then please provide us with the complete sample reproducer code and steps to reproduce your issue from our end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;
&lt;P&gt;Santosh&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2022 10:42:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/SYCL-kernel-cannot-call-an-undefined-function-without-SYCL/m-p/1382827#M2116</guid>
      <dc:creator>SantoshY_Intel</dc:creator>
      <dc:date>2022-05-09T10:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/SYCL-kernel-cannot-call-an-undefined-function-without-SYCL/m-p/1382886#M2118</link>
      <description>&lt;P&gt;I am not calling the function inside the kernel, actually, the problem lies in the way I am doing the parallelism in parallel_for:&lt;/P&gt;
&lt;P&gt;so it works normally if I do this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;h.parallel_for(num_items, [=](auto i) {
  
        for (int j = 0; j &amp;lt;(const int) a[i].size(); ++j) {
            dif[i] += a[i];
        }
        });&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but when I try to take the values in the second dimension like this:&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;h.parallel_for(num_items, [=](auto i) {
  
        for (int j = 0; j &amp;lt;(const int) a[i].size(); ++j) {
            dif[i] += a[i][j] ;
        }
        });&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;It gives an error.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please see the previous full code, I don't know if I defined the buffers and accessors correctly.&lt;/P&gt;
&lt;P&gt;I tried to do the solution you provided, but it gave me many errors more than before, so it is not working, unfortunately.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2022 15:07:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/SYCL-kernel-cannot-call-an-undefined-function-without-SYCL/m-p/1382886#M2118</guid>
      <dc:creator>amaltaha</dc:creator>
      <dc:date>2022-05-09T15:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/SYCL-kernel-cannot-call-an-undefined-function-without-SYCL/m-p/1383752#M2130</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We tried running your code by creating dummy 'dataset' and 'curr_test' variables. We were able to run the program successfully as shown in the below screenshot.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="SantoshY_Intel_0-1652344669271.png" style="width: 400px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/29380i22653CA2A7AB1CBD/image-size/medium?v=v2&amp;amp;px=400&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="SantoshY_Intel_0-1652344669271.png" alt="SantoshY_Intel_0-1652344669271.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please refer to the complete code attached below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#include &amp;lt;CL/sycl.hpp&amp;gt;
#include &amp;lt;iostream&amp;gt;
using namespace sycl;

std::vector&amp;lt;double&amp;gt; distance_calculation_FPGA(queue&amp;amp; q,const std::vector&amp;lt;std::vector&amp;lt;double&amp;gt;&amp;gt;&amp;amp; dataset,const std::vector&amp;lt;double&amp;gt;&amp;amp; curr_test) 
{
    range&amp;lt;1&amp;gt; num_items{ dataset.size()};
    std::vector&amp;lt;double&amp;gt;res;

    res.resize(dataset.size());
    buffer dataset_buf(dataset);
    buffer curr_test_buf(curr_test);
    buffer res_buf(res.data(), num_items);

    q.submit([&amp;amp;](handler&amp;amp; h) {
    accessor a(dataset_buf, h, read_only);
    accessor b(curr_test_buf, h, read_only);

    accessor dif(res_buf, h, write_only, no_init);

    h.parallel_for(num_items, [=](auto i) {

        for (int j = 0; j &amp;lt;(const int) a[i].size(); ++j) {
//           dif[i] += (a[i][j] - b[j]) * (a[i][j] - b[j]) ;
	     dif[i]+=a[i][j];          
        }
        });
    });
    q.wait(); //We have added this line of code for synchronization.
    for (int i : res) { 
        std::cout &amp;lt;&amp;lt;i&amp;lt;&amp;lt; std::endl;
    } 
    return res;
    }


int main(){

	std::vector&amp;lt;std::vector&amp;lt;double&amp;gt;&amp;gt; dataset;
	for(int i=0;i&amp;lt;5;i++)
	{
		std::vector&amp;lt;double&amp;gt; d;

		for(int j=0;j&amp;lt;1600;j++)
		{
			d.push_back((double)j);
		}
		dataset.push_back(d);
	}

	std::vector&amp;lt;double&amp;gt; curr_test;
	for(int i=0;i&amp;lt;1600;i++)
	{
		curr_test.push_back((double)i);
	}
    queue q;
    std::cout &amp;lt;&amp;lt; "Running on "&amp;lt;&amp;lt; 
    q.get_device().get_info&amp;lt;sycl::info::device::name&amp;gt;()&amp;lt;&amp;lt; std::endl; 
    //print the device name as a test to check the parallelisation

    distance_calculation_FPGA(q,dataset,curr_test);

    return 0;
    }
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;
&lt;P&gt;Santosh&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 08:49:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/SYCL-kernel-cannot-call-an-undefined-function-without-SYCL/m-p/1383752#M2130</guid>
      <dc:creator>SantoshY_Intel</dc:creator>
      <dc:date>2022-05-12T08:49:42Z</dc:date>
    </item>
    <item>
      <title>Re: SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/SYCL-kernel-cannot-call-an-undefined-function-without-SYCL/m-p/1383944#M2139</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;BR /&gt;Thank you so much for the support, actually I am using Microsoft Visual Studio 2022 to run OneAPI compiler for dpc++. I tried to run your code in it but it gave me the same exact error. But I tried to run in on the cloud like the screenshot, and it worked normally.&amp;nbsp; Very Glad I was able to run it on the cloud though thank you so much.&lt;BR /&gt;I solved the problem in Visual Studio by making a one-dimensional vector&amp;lt;double&amp;gt; instead of vector&amp;lt;vector&amp;lt;double&amp;gt;&amp;gt; and accessed the elements I wanted by x + y * col.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really appreciate the very professional efforts and support from you.&lt;/P&gt;
&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 21:53:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/SYCL-kernel-cannot-call-an-undefined-function-without-SYCL/m-p/1383944#M2139</guid>
      <dc:creator>amaltaha</dc:creator>
      <dc:date>2022-05-12T21:53:32Z</dc:date>
    </item>
    <item>
      <title>Re:SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/SYCL-kernel-cannot-call-an-undefined-function-without-SYCL/m-p/1384080#M2143</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;&lt;P&gt;Santosh&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 13 May 2022 08:03:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/SYCL-kernel-cannot-call-an-undefined-function-without-SYCL/m-p/1384080#M2143</guid>
      <dc:creator>SantoshY_Intel</dc:creator>
      <dc:date>2022-05-13T08:03:27Z</dc:date>
    </item>
  </channel>
</rss>

