<?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 Implementing multiple functions in kernel in Intel® oneAPI DPC++/C++ Compiler</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Implementing-multiple-functions-in-kernel/m-p/1369146#M1966</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Shown below is my DPC++ code.&lt;BR /&gt;I want to call the function Add within the kernel scope. I want the function add to be implemented by the kernel and not by the host. Is it doable using dpc++.&lt;BR /&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#include &amp;lt;iostream&amp;gt;&lt;BR /&gt;#include&amp;lt;vector&amp;gt;&lt;BR /&gt;#include&amp;lt;random&amp;gt;&lt;BR /&gt;#include&amp;lt;omp.h&amp;gt;&lt;BR /&gt;#include&amp;lt;chrono&amp;gt;&lt;BR /&gt;#include &amp;lt;CL/sycl.hpp&amp;gt;&lt;BR /&gt;#include &amp;lt;ext/intel/fpga_extensions.hpp&amp;gt;&lt;BR /&gt;using namespace std;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;void Oneapi_Fpga()&lt;BR /&gt;{&lt;BR /&gt;vector&amp;lt;float&amp;gt;testData(10);&lt;BR /&gt;vector&amp;lt;float&amp;gt;filterCoeff(5);&lt;BR /&gt;int convLen = testData.size() + filterCoeff.size() - 1;&lt;BR /&gt;vector&amp;lt;float&amp;gt;convSeq(convLen);&lt;BR /&gt;&lt;BR /&gt;std::random_device rand;&lt;BR /&gt;std::mt19937 generator(rand());&lt;BR /&gt;std::normal_distribution&amp;lt;float&amp;gt; ndist{ 0.0f, 1.0f };&lt;BR /&gt;for (int i = 0; i &amp;lt; testData.size(); i++)&lt;BR /&gt;{&lt;BR /&gt;testData[i] = ndist(generator);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;std::random_device randi;&lt;BR /&gt;std::mt19937 generatorr(randi());&lt;BR /&gt;std::normal_distribution&amp;lt;float&amp;gt; ndisti{ 0.0f, 1.0f };&lt;BR /&gt;for (int i = 0; i &amp;lt; filterCoeff.size(); i++)&lt;BR /&gt;{&lt;BR /&gt;filterCoeff[i] = ndisti(generator);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;int lenA = 10;&lt;BR /&gt;int lenB = 5;&lt;BR /&gt;int nconv;&lt;/P&gt;
&lt;P&gt;std::chrono::high_resolution_clock::time_point t6, t7;&lt;BR /&gt;std::chrono::duration&amp;lt;double, std::milli&amp;gt; accum3;&lt;/P&gt;
&lt;P&gt;accum3 = std::chrono::milliseconds(0);&lt;/P&gt;
&lt;P&gt;nconv = lenA + lenB - 1;&lt;BR /&gt;vector&amp;lt;float&amp;gt;C(nconv);&lt;BR /&gt;&lt;BR /&gt;//*********************************************************&lt;BR /&gt;// FPGA oneapi implementation&lt;BR /&gt;//*********************************************************&lt;BR /&gt;sycl::buffer testBuff(testData);&lt;BR /&gt;sycl::buffer filterBuff(filterCoeff);&lt;BR /&gt;sycl::buffer convBuff(C);&lt;BR /&gt;sycl::ext::intel::fpga_emulator_selector d_selector;&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;cl::sycl::queue Q(d_selector);&lt;BR /&gt;t6 = std::chrono::high_resolution_clock::now();&lt;BR /&gt;Q.submit([&amp;amp;](sycl::handler&amp;amp; h)&lt;BR /&gt;{&lt;BR /&gt;sycl::accessor testAccess(testBuff, h, sycl::read_only);&lt;BR /&gt;sycl::accessor filterAccess(filterBuff, h, sycl::read_only);&lt;BR /&gt;sycl::accessor cAccess(convBuff, h, sycl::read_write);&lt;BR /&gt;h.single_task([=]() {&lt;/P&gt;
&lt;P&gt;for (int i = 0; i &amp;lt; nconv; i++)&lt;BR /&gt;{&lt;BR /&gt;int i1 = i;&lt;BR /&gt;float tmp = 0.0;&lt;BR /&gt;for (int j = 0; j &amp;lt; lenB; j++)&lt;BR /&gt;{&lt;BR /&gt;if (i1 &amp;gt;= 0 &amp;amp;&amp;amp; i1 &amp;lt; lenA)&lt;BR /&gt;tmp = tmp + (testAccess[i1] * filterAccess[j]);&lt;/P&gt;
&lt;P&gt;i1 = i1 - 1;&lt;BR /&gt;cAccess[i] = tmp;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;STRONG&gt;Add(cAccess);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // function should be implemented by kernel&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;});&lt;BR /&gt;});&lt;BR /&gt;t7 = std::chrono::high_resolution_clock::now();&lt;BR /&gt;Q.wait_and_throw();&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;catch (sycl::exception const&amp;amp; e)&lt;BR /&gt;{&lt;BR /&gt;std::cout &amp;lt;&amp;lt; "Caught a SYCL host exception:\n" &amp;lt;&amp;lt; e.what() &amp;lt;&amp;lt; "\n";&lt;BR /&gt;}&lt;BR /&gt;sycl::host_accessor cHost(convBuff);&lt;BR /&gt;//*********************************************************&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;accum3 = t7 - t6;&lt;/P&gt;
&lt;P&gt;cout &amp;lt;&amp;lt; "time taken by FPGA oneapi implementation is" &amp;lt;&amp;lt; accum3.count() &amp;lt;&amp;lt; endl;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;}&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;for(int i=0;i&amp;lt;1000000;i++)&lt;BR /&gt;{&lt;BR /&gt;Oneapi_Fpga();&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;std::cout &amp;lt;&amp;lt; "success\n";&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Mar 2022 02:55:24 GMT</pubDate>
    <dc:creator>student4</dc:creator>
    <dc:date>2022-03-16T02:55:24Z</dc:date>
    <item>
      <title>Implementing multiple functions in kernel</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Implementing-multiple-functions-in-kernel/m-p/1369146#M1966</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Shown below is my DPC++ code.&lt;BR /&gt;I want to call the function Add within the kernel scope. I want the function add to be implemented by the kernel and not by the host. Is it doable using dpc++.&lt;BR /&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#include &amp;lt;iostream&amp;gt;&lt;BR /&gt;#include&amp;lt;vector&amp;gt;&lt;BR /&gt;#include&amp;lt;random&amp;gt;&lt;BR /&gt;#include&amp;lt;omp.h&amp;gt;&lt;BR /&gt;#include&amp;lt;chrono&amp;gt;&lt;BR /&gt;#include &amp;lt;CL/sycl.hpp&amp;gt;&lt;BR /&gt;#include &amp;lt;ext/intel/fpga_extensions.hpp&amp;gt;&lt;BR /&gt;using namespace std;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;void Oneapi_Fpga()&lt;BR /&gt;{&lt;BR /&gt;vector&amp;lt;float&amp;gt;testData(10);&lt;BR /&gt;vector&amp;lt;float&amp;gt;filterCoeff(5);&lt;BR /&gt;int convLen = testData.size() + filterCoeff.size() - 1;&lt;BR /&gt;vector&amp;lt;float&amp;gt;convSeq(convLen);&lt;BR /&gt;&lt;BR /&gt;std::random_device rand;&lt;BR /&gt;std::mt19937 generator(rand());&lt;BR /&gt;std::normal_distribution&amp;lt;float&amp;gt; ndist{ 0.0f, 1.0f };&lt;BR /&gt;for (int i = 0; i &amp;lt; testData.size(); i++)&lt;BR /&gt;{&lt;BR /&gt;testData[i] = ndist(generator);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;std::random_device randi;&lt;BR /&gt;std::mt19937 generatorr(randi());&lt;BR /&gt;std::normal_distribution&amp;lt;float&amp;gt; ndisti{ 0.0f, 1.0f };&lt;BR /&gt;for (int i = 0; i &amp;lt; filterCoeff.size(); i++)&lt;BR /&gt;{&lt;BR /&gt;filterCoeff[i] = ndisti(generator);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;int lenA = 10;&lt;BR /&gt;int lenB = 5;&lt;BR /&gt;int nconv;&lt;/P&gt;
&lt;P&gt;std::chrono::high_resolution_clock::time_point t6, t7;&lt;BR /&gt;std::chrono::duration&amp;lt;double, std::milli&amp;gt; accum3;&lt;/P&gt;
&lt;P&gt;accum3 = std::chrono::milliseconds(0);&lt;/P&gt;
&lt;P&gt;nconv = lenA + lenB - 1;&lt;BR /&gt;vector&amp;lt;float&amp;gt;C(nconv);&lt;BR /&gt;&lt;BR /&gt;//*********************************************************&lt;BR /&gt;// FPGA oneapi implementation&lt;BR /&gt;//*********************************************************&lt;BR /&gt;sycl::buffer testBuff(testData);&lt;BR /&gt;sycl::buffer filterBuff(filterCoeff);&lt;BR /&gt;sycl::buffer convBuff(C);&lt;BR /&gt;sycl::ext::intel::fpga_emulator_selector d_selector;&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;cl::sycl::queue Q(d_selector);&lt;BR /&gt;t6 = std::chrono::high_resolution_clock::now();&lt;BR /&gt;Q.submit([&amp;amp;](sycl::handler&amp;amp; h)&lt;BR /&gt;{&lt;BR /&gt;sycl::accessor testAccess(testBuff, h, sycl::read_only);&lt;BR /&gt;sycl::accessor filterAccess(filterBuff, h, sycl::read_only);&lt;BR /&gt;sycl::accessor cAccess(convBuff, h, sycl::read_write);&lt;BR /&gt;h.single_task([=]() {&lt;/P&gt;
&lt;P&gt;for (int i = 0; i &amp;lt; nconv; i++)&lt;BR /&gt;{&lt;BR /&gt;int i1 = i;&lt;BR /&gt;float tmp = 0.0;&lt;BR /&gt;for (int j = 0; j &amp;lt; lenB; j++)&lt;BR /&gt;{&lt;BR /&gt;if (i1 &amp;gt;= 0 &amp;amp;&amp;amp; i1 &amp;lt; lenA)&lt;BR /&gt;tmp = tmp + (testAccess[i1] * filterAccess[j]);&lt;/P&gt;
&lt;P&gt;i1 = i1 - 1;&lt;BR /&gt;cAccess[i] = tmp;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;STRONG&gt;Add(cAccess);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // function should be implemented by kernel&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;});&lt;BR /&gt;});&lt;BR /&gt;t7 = std::chrono::high_resolution_clock::now();&lt;BR /&gt;Q.wait_and_throw();&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;catch (sycl::exception const&amp;amp; e)&lt;BR /&gt;{&lt;BR /&gt;std::cout &amp;lt;&amp;lt; "Caught a SYCL host exception:\n" &amp;lt;&amp;lt; e.what() &amp;lt;&amp;lt; "\n";&lt;BR /&gt;}&lt;BR /&gt;sycl::host_accessor cHost(convBuff);&lt;BR /&gt;//*********************************************************&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;accum3 = t7 - t6;&lt;/P&gt;
&lt;P&gt;cout &amp;lt;&amp;lt; "time taken by FPGA oneapi implementation is" &amp;lt;&amp;lt; accum3.count() &amp;lt;&amp;lt; endl;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;}&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;for(int i=0;i&amp;lt;1000000;i++)&lt;BR /&gt;{&lt;BR /&gt;Oneapi_Fpga();&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;std::cout &amp;lt;&amp;lt; "success\n";&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2022 02:55:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Implementing-multiple-functions-in-kernel/m-p/1369146#M1966</guid>
      <dc:creator>student4</dc:creator>
      <dc:date>2022-03-16T02:55:24Z</dc:date>
    </item>
    <item>
      <title>Re:Implementing multiple functions in kernel</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Implementing-multiple-functions-in-kernel/m-p/1369649#M1972</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks for reaching out to us.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;We are working on your issue. We will get back to you soon.&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;Noorjahan.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Mar 2022 11:00:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Implementing-multiple-functions-in-kernel/m-p/1369649#M1972</guid>
      <dc:creator>NoorjahanSk_Intel</dc:creator>
      <dc:date>2022-03-17T11:00:57Z</dc:date>
    </item>
    <item>
      <title>Re:Implementing multiple functions in kernel</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Implementing-multiple-functions-in-kernel/m-p/1386675#M2192</link>
      <description>&lt;P&gt;I assume you are looking for something like (see also &lt;A href="https://oneapi-src.github.io/DPCPP_Reference/model/kernel-programming-model.html" target="_blank"&gt;https://oneapi-src.github.io/DPCPP_Reference/model/kernel-programming-model.html&lt;/A&gt;&lt;LI-EMOJI id="lia_disappointed-face" title=":disappointed_face:"&gt;&lt;/LI-EMOJI&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;void Add( sycl::accessor&amp;lt;float, 1, sycl::access::mode::read_write&amp;gt; cAccess ){&lt;/P&gt;&lt;P&gt;&amp;nbsp;  int nconv = cAccess.size();&lt;/P&gt;&lt;P&gt;&amp;nbsp;  for (int i = 0; i &amp;lt; nconv; i++){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;    cAccess[i] *= nconv;&lt;/P&gt;&lt;P&gt;&amp;nbsp;  }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 23 May 2022 19:07:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Implementing-multiple-functions-in-kernel/m-p/1386675#M2192</guid>
      <dc:creator>Klaus-Dieter_O_Intel</dc:creator>
      <dc:date>2022-05-23T19:07:20Z</dc:date>
    </item>
  </channel>
</rss>

