<?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: About SYCL_EXTERNAL issue when separating defitions from declaration of a class in Intel® oneAPI DPC++/C++ Compiler</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/About-SYCL-EXTERNAL-issue-when-separating-defitions-from/m-p/1460853#M2866</link>
    <description>&lt;P&gt;Thanks so much,&amp;nbsp;&lt;SPAN&gt;Shaik!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; I tried your code and it works.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The reason I got stuck here is because I always think "extern" can only be used for a variable or a function, instead of a class member function....&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I know that my question is very fundamental and is probably not worth for you spending time to provide an answer : )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Anyway, really thanks!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PC&lt;/SPAN&gt;&lt;/P&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;</description>
    <pubDate>Thu, 02 Mar 2023 00:30:19 GMT</pubDate>
    <dc:creator>PC-1</dc:creator>
    <dc:date>2023-03-02T00:30:19Z</dc:date>
    <item>
      <title>About SYCL_EXTERNAL issue when separating defitions from declaration of a class</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/About-SYCL-EXTERNAL-issue-when-separating-defitions-from/m-p/1459441#M2855</link>
      <description>&lt;P&gt;I previously posted a similar question but not really get a solution. Suppose I need to call a function object and its member function in a kernel:&lt;/P&gt;
&lt;P&gt;____________________&lt;/P&gt;
&lt;P&gt;Q.submit([&amp;amp;](sycl::handler&amp;amp; h) { &lt;BR /&gt;&lt;BR /&gt;sycl::accessor A(B, h);&lt;BR /&gt;h.parallel_for(size, [=](auto&amp;amp; idx) {&lt;BR /&gt;my_class&amp;amp; mc_ref =A[idx];&lt;BR /&gt;mc_ref.update();&amp;nbsp; &amp;nbsp; &amp;nbsp; //call member function of my_class&lt;BR /&gt;}&lt;BR /&gt;);&lt;BR /&gt;});&lt;/P&gt;
&lt;P&gt;________&lt;/P&gt;
&lt;P&gt;According to SYCL specifications, I need to define "my_class" and corresponding member function "my_class::update()" in one header, like&lt;/P&gt;
&lt;P&gt;in "my_class.h"_____________&lt;/P&gt;
&lt;P&gt;class my_class{&lt;/P&gt;
&lt;P&gt;.....&lt;/P&gt;
&lt;P&gt;void update()&amp;nbsp; { .... ;&amp;nbsp; return; }&lt;/P&gt;
&lt;P&gt;.....&lt;/P&gt;
&lt;P&gt;};&lt;/P&gt;
&lt;P&gt;________________&lt;/P&gt;
&lt;P&gt;Hoever,&amp;nbsp; if I separate definition from class declaration, like&lt;/P&gt;
&lt;P&gt;in "my_class.h"_____________&lt;/P&gt;
&lt;P&gt;class my_class{&lt;/P&gt;
&lt;P&gt;.....&lt;/P&gt;
&lt;P&gt;void update() ;&lt;/P&gt;
&lt;P&gt;.....&lt;/P&gt;
&lt;P&gt;};&lt;/P&gt;
&lt;P&gt;in "my_class.cpp"_____________&lt;/P&gt;
&lt;P&gt;void&amp;nbsp;my_class::update() { ... ; return;}&lt;/P&gt;
&lt;P&gt;___________________________&lt;/P&gt;
&lt;P&gt;It would generate compiler error : SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute, since the member function is now defined under a different translation unit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is that if there is anyway, or how can I declare "SYCL_EXTERNAL" in this situation so that I can separate class definiton from declaration ??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to do this because my code is a little compilcated, and in "my_class" there would be another class objects. (I usually manage data and abstration by C++ class).&lt;/P&gt;
&lt;P&gt;If I put all defitions of member functions in one header file, it would be more than 5k lines... which I think is a little crazy and hard to read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could anyone provide me an example or some suggestions on how to organize my program in this case?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks so much!&lt;/P&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;&amp;nbsp;&lt;/P&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;__________&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 09:32:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/About-SYCL-EXTERNAL-issue-when-separating-defitions-from/m-p/1459441#M2855</guid>
      <dc:creator>PC-1</dc:creator>
      <dc:date>2023-02-26T09:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: About SYCL_EXTERNAL issue when separating defitions from declaration of a class</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/About-SYCL-EXTERNAL-issue-when-separating-defitions-from/m-p/1460201#M2864</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for posting in Intel Communities.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&lt;EM&gt;My questi&lt;/EM&gt;&lt;EM style="background-color: var(--slds-g-color-neutral-base-100, var(--lwc-colorbackgroundinput,#ffffff)); color: var(--slds-g-color-neutral-base-30, var(--lwc-colortextweak,#444444));"&gt;on is that if there is anyway, or how can I declare "SYCL_EXTERNAL" in this situation so that I can separate class definiton from declaration ??&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, you can provide function declaration in a class and it's definition in another file but as per SYCL specifications, the function will come under different translation unit. Please make sure to include "SYCL_EXTERNAL" before function declaration in your header file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please go through the modified code files to understand it better.&lt;/P&gt;
&lt;P&gt;main.cpp&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#include "my_class1.h"

int main()
{
size_t N = 4;

sycl::buffer&amp;lt;int&amp;gt; B(N);
{
sycl::host_accessor a(B, sycl::write_only);
for (int i = 0; i &amp;lt; N; i++) {
a[i] = i;
}
}

queue Q;
Q.submit([&amp;amp;](sycl::handler&amp;amp; h) {
sycl::accessor A(B, h);
h.parallel_for(N, [=](item&amp;lt;1&amp;gt; i) {
my_class mc_ref;
mc_ref.update(A, i);      //call member function of my_class
});
});

host_accessor h{B};
for(int i=0;i&amp;lt;N;i++)
std::cout&amp;lt;&amp;lt;h[i]&amp;lt;&amp;lt;" ";
return 0;
}&lt;/LI-CODE&gt;
&lt;P&gt;my_class.cpp&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#include "my_class1.h"


//Methods
void my_class::update(cl::sycl::accessor&amp;lt;int, 1, cl::sycl::access::mode::read_write&amp;gt; A, cl::sycl::item&amp;lt;1&amp;gt; i)
{
	int idx=i.get_id();
	A[idx]=A[idx]+1;
}
&lt;/LI-CODE&gt;
&lt;P&gt;my_class1.h&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;#pragma once
#include&amp;lt;iostream&amp;gt;
#include&amp;lt;CL/sycl.hpp&amp;gt;
using namespace sycl;

class my_class{

public:

//extern 
SYCL_EXTERNAL void update(cl::sycl::accessor&amp;lt;int, 1, cl::sycl::access::mode::read_write&amp;gt; A, cl::sycl::item&amp;lt;1&amp;gt; i);
};&lt;/LI-CODE&gt;
&lt;P&gt;Hope this resolves your issue, if you still face any issues please share the sample reproducer code with us.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; regards,&lt;/P&gt;
&lt;P&gt;Shaik Rabiya&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 16:01:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/About-SYCL-EXTERNAL-issue-when-separating-defitions-from/m-p/1460201#M2864</guid>
      <dc:creator>RabiyaSK_Intel</dc:creator>
      <dc:date>2023-02-28T16:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: About SYCL_EXTERNAL issue when separating defitions from declaration of a class</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/About-SYCL-EXTERNAL-issue-when-separating-defitions-from/m-p/1460853#M2866</link>
      <description>&lt;P&gt;Thanks so much,&amp;nbsp;&lt;SPAN&gt;Shaik!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; I tried your code and it works.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The reason I got stuck here is because I always think "extern" can only be used for a variable or a function, instead of a class member function....&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I know that my question is very fundamental and is probably not worth for you spending time to provide an answer : )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Anyway, really thanks!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PC&lt;/SPAN&gt;&lt;/P&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;</description>
      <pubDate>Thu, 02 Mar 2023 00:30:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/About-SYCL-EXTERNAL-issue-when-separating-defitions-from/m-p/1460853#M2866</guid>
      <dc:creator>PC-1</dc:creator>
      <dc:date>2023-03-02T00:30:19Z</dc:date>
    </item>
    <item>
      <title>Re:About SYCL_EXTERNAL issue when separating defitions from declaration of a class</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/About-SYCL-EXTERNAL-issue-when-separating-defitions-from/m-p/1461006#M2870</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.&amp;nbsp;&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;Shaik Rabiya&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 02 Mar 2023 10:31:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/About-SYCL-EXTERNAL-issue-when-separating-defitions-from/m-p/1461006#M2870</guid>
      <dc:creator>RabiyaSK_Intel</dc:creator>
      <dc:date>2023-03-02T10:31:14Z</dc:date>
    </item>
  </channel>
</rss>

