<?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:Multi-dimensional data to USM Allocator class in Intel® oneAPI DPC++/C++ Compiler</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Multi-dimensional-data-to-USM-Allocator-class/m-p/1195255#M610</link>
    <description>&lt;P&gt;Hi Suraj,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your syntax of vector allocation is correct. In your code(attached) you are trying to free a double-pointer which is not allocated by any of the SYCL allocation function so there will not be any SYCL context associated with the pointer. This is the reason for the error.&lt;/P&gt;
&lt;P&gt;You can directly clear the vector of array instead of freeing the pointer to the vector.&lt;/P&gt;
&lt;P&gt;Please find the below code for more details.&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;#include &amp;lt;CL/sycl.hpp&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;array&amp;gt;

using namespace sycl;
static const int N = 5;

int main(){

  gpu_selector device_selector;

  queue q(device_selector);

  std::cout &amp;lt;&amp;lt; "Device: " &amp;lt;&amp;lt; q.get_device().get_info&amp;lt;info::device::name&amp;gt;() &amp;lt;&amp;lt; std::endl;

  auto ctx = q.get_context();
  usm_allocator&amp;lt;std::array&amp;lt;double,3&amp;gt;, usm::alloc::shared&amp;gt; alloc(q.get_context(), q.get_device());
  std::vector&amp;lt;std::array&amp;lt;double,3&amp;gt;,decltype(alloc) &amp;gt; arrVec(N,alloc);

  //std::array&amp;lt;std::vector&amp;lt;double&amp;gt;,3&amp;gt; arrVec({std::vector&amp;lt;double&amp;gt;(5,alloc),std::vector&amp;lt;double&amp;gt;(11), std::vector&amp;lt;double&amp;gt;(12)});

  for(int i=0; i&amp;lt;N; i++)
    for(int j=0; j&amp;lt;3; j++)
      arrVec[i][j] = (i+1)*10 + j + 1;

  double** ptr0 = (double**)(&amp;amp;arrVec[0][0]);


  {
   q.submit([&amp;amp;](handler &amp;amp;h) {
       h.parallel_for(range&amp;lt;2&amp;gt;(N,3), [=] (id&amp;lt;2&amp;gt; i){
           // ptr[i] *= ptr1[i];
           ptr0[i[0]][i[1]] += 1;
         });
       }).wait_and_throw();
  }


  std::cout&amp;lt;&amp;lt;"O/P"&amp;lt;&amp;lt;std::endl;
  for(int i=0; i&amp;lt;N; i++)
    std::cout &amp;lt;&amp;lt; arrVec[i][0] &amp;lt;&amp;lt;" "&amp;lt;&amp;lt; arrVec[i][1] &amp;lt;&amp;lt; std::endl;

  arrVec.clear();

  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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warm Regards,&lt;/P&gt;
&lt;P&gt;Abhishek&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jul 2020 08:29:00 GMT</pubDate>
    <dc:creator>AbhishekD_Intel</dc:creator>
    <dc:date>2020-07-28T08:29:00Z</dc:date>
    <item>
      <title>Multi-dimensional data to USM Allocator class</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Multi-dimensional-data-to-USM-Allocator-class/m-p/1195011#M608</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am trying to pass a vector of array to the USM allocator class and am trying to follow the syntax given in one of the webinars which goes like:&lt;BR /&gt;usm_allocator&amp;lt;int, usm::alloc::shared&amp;gt; alloc(q.get_context(), q.get_device());&lt;BR /&gt;std::vector&amp;lt;int, decltype(alloc)&amp;gt; v(size, initial value, alloc);&lt;/P&gt;
&lt;P&gt;I have attached the code I am trying this in.&amp;nbsp; I am getting the output but also an error as follows:&lt;/P&gt;
&lt;P&gt;Device: Intel(R) Gen9&lt;BR /&gt;terminate called after throwing an instance of 'cl::sycl::runtime_error'&lt;BR /&gt;what(): Native API failed. Native API returns: -30 (CL_INVALID_VALUE) -30 (CL_INVALID_VALUE)&lt;BR /&gt;Aborted (core dumped)&lt;/P&gt;
&lt;P&gt;System spec: Ubuntu 18.04.4 LTS,&amp;nbsp;Intel® HD Graphics 630 (Kaby Lake GT2)&lt;BR /&gt;oneAPI version beta 07, running on default L0 BE&lt;/P&gt;
&lt;P&gt;Please kindly advise on the error and syntax I have used for the vector of array passed to USM alloc class.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jul 2020 15:28:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Multi-dimensional-data-to-USM-Allocator-class/m-p/1195011#M608</guid>
      <dc:creator>Suraj</dc:creator>
      <dc:date>2020-07-27T15:28:06Z</dc:date>
    </item>
    <item>
      <title>Re:Multi-dimensional data to USM Allocator class</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Multi-dimensional-data-to-USM-Allocator-class/m-p/1195255#M610</link>
      <description>&lt;P&gt;Hi Suraj,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your syntax of vector allocation is correct. In your code(attached) you are trying to free a double-pointer which is not allocated by any of the SYCL allocation function so there will not be any SYCL context associated with the pointer. This is the reason for the error.&lt;/P&gt;
&lt;P&gt;You can directly clear the vector of array instead of freeing the pointer to the vector.&lt;/P&gt;
&lt;P&gt;Please find the below code for more details.&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;#include &amp;lt;CL/sycl.hpp&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;array&amp;gt;

using namespace sycl;
static const int N = 5;

int main(){

  gpu_selector device_selector;

  queue q(device_selector);

  std::cout &amp;lt;&amp;lt; "Device: " &amp;lt;&amp;lt; q.get_device().get_info&amp;lt;info::device::name&amp;gt;() &amp;lt;&amp;lt; std::endl;

  auto ctx = q.get_context();
  usm_allocator&amp;lt;std::array&amp;lt;double,3&amp;gt;, usm::alloc::shared&amp;gt; alloc(q.get_context(), q.get_device());
  std::vector&amp;lt;std::array&amp;lt;double,3&amp;gt;,decltype(alloc) &amp;gt; arrVec(N,alloc);

  //std::array&amp;lt;std::vector&amp;lt;double&amp;gt;,3&amp;gt; arrVec({std::vector&amp;lt;double&amp;gt;(5,alloc),std::vector&amp;lt;double&amp;gt;(11), std::vector&amp;lt;double&amp;gt;(12)});

  for(int i=0; i&amp;lt;N; i++)
    for(int j=0; j&amp;lt;3; j++)
      arrVec[i][j] = (i+1)*10 + j + 1;

  double** ptr0 = (double**)(&amp;amp;arrVec[0][0]);


  {
   q.submit([&amp;amp;](handler &amp;amp;h) {
       h.parallel_for(range&amp;lt;2&amp;gt;(N,3), [=] (id&amp;lt;2&amp;gt; i){
           // ptr[i] *= ptr1[i];
           ptr0[i[0]][i[1]] += 1;
         });
       }).wait_and_throw();
  }


  std::cout&amp;lt;&amp;lt;"O/P"&amp;lt;&amp;lt;std::endl;
  for(int i=0; i&amp;lt;N; i++)
    std::cout &amp;lt;&amp;lt; arrVec[i][0] &amp;lt;&amp;lt;" "&amp;lt;&amp;lt; arrVec[i][1] &amp;lt;&amp;lt; std::endl;

  arrVec.clear();

  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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warm Regards,&lt;/P&gt;
&lt;P&gt;Abhishek&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 08:29:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Multi-dimensional-data-to-USM-Allocator-class/m-p/1195255#M610</guid>
      <dc:creator>AbhishekD_Intel</dc:creator>
      <dc:date>2020-07-28T08:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Re:Multi-dimensional data to USM Allocator class</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Multi-dimensional-data-to-USM-Allocator-class/m-p/1195264#M611</link>
      <description>&lt;P&gt;Thank you very much. I understand. Silly mistake on my part. The issue is resolved for me.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 08:58:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Multi-dimensional-data-to-USM-Allocator-class/m-p/1195264#M611</guid>
      <dc:creator>Suraj</dc:creator>
      <dc:date>2020-07-28T08:58:11Z</dc:date>
    </item>
    <item>
      <title>Re:Multi-dimensional data to USM Allocator class</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Multi-dimensional-data-to-USM-Allocator-class/m-p/1195527#M615</link>
      <description>&lt;P&gt;Hi Suraj,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thank you for the confirmation, please post a new thread if you have any other issues.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Warm Regards,&lt;/P&gt;&lt;P&gt;Abhishek&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 29 Jul 2020 05:33:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Multi-dimensional-data-to-USM-Allocator-class/m-p/1195527#M615</guid>
      <dc:creator>AbhishekD_Intel</dc:creator>
      <dc:date>2020-07-29T05:33:36Z</dc:date>
    </item>
  </channel>
</rss>

