Intel® oneAPI Data Parallel C++
Support for Intel® oneAPI DPC++ Compiler, Intel® oneAPI DPC++ Library, Intel ICX Compiler , Intel® DPC++ Compatibility Tool, and GDB*
581 Discussions

Unable to declare vector inside SYCL_EXTERNAL function

student4
Beginner
902 Views

Hi,

I have a Main file containing Main.cpp
and Library.dll file containing the following
Sample1.h and Sample1.cpp
Sample2.h and Sample2.cpp
The Main.cpp invokes the Library.dll.

 

Main.cpp
#include <CL/sycl.hpp>
#include <vector>
#include <iostream>
#include <ext/intel/fpga_extensions.hpp>
#include<complex>
#include "../Library/Sample1.h"
#include "../Library/Sample2.h"
void test()
{
sycl::ext::intel::fpga_emulator_selector d_selector;
sycl::queue q(d_selector);
Sample1 obj1;
obj1.func1(q);
}


//************************************
// Demonstrate vector add both in sequential on CPU and in parallel on device.
//************************************
int main(int argc, char* argv[]) {
test();
return 0;
}

Sample1.h
#pragma once
#include <CL/sycl.hpp>
#include <vector>
#include <iostream>
#include<complex>
#include <ext/intel/fpga_extensions.hpp>

class _declspec(dllexport)Sample1
{


public:
Sample1();
~Sample1();


void func1(sycl::queue& q);

};

Sample1.cpp
#include "Sample1.h"
#include "Sample2.h"

Sample1::Sample1()
{

}

Sample1::~Sample1()
{

}

 

void Sample1::func1(sycl::queue& q)
{

try
{

q.submit([&](sycl::handler& h)
{

h.parallel_for(sycl::range{ 4, 2 }, [=](sycl::id<2> idx) {
Sample2 obj;
obj.func2();
});
});

q.wait_and_throw();
}


catch (sycl::exception const& e)
{
std::cout << "Caught a SYCL host exception:\n" << e.what() << "\n";
}


}

Sample2.h
#pragma once
#include <CL/sycl.hpp>
#include <vector>
#include <iostream>
#include <ext/intel/fpga_extensions.hpp>
#include<complex>
class _declspec(dllexport)Sample2
{
public:

SYCL_EXTERNAL Sample2();
SYCL_EXTERNAL ~Sample2();


SYCL_EXTERNAL float func2();

};

Sample2.cpp
#include "Sample2.h"

 

Sample2::Sample2()
{

}

Sample2::~Sample2()
{

}

 

float Sample2::func2()
{
std::vector<std::complex<float>>S(3);
return 0.1f;
}

I have declared the complex float vector S. When I build this program, it throws an erro showing: SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute
I would appreciate your help on this problem.
Thank you.

0 Kudos
1 Solution
HemanthCH_Intel
Moderator
844 Views

Hi,

 

Thank you for posting in Intel Communities.

 

From the above sample reproducer code, please remove the vector declaration from "float Sample2::func2()" function, because the vector allocates memory dynamically which is not supported inside the kernel.

For more information, please refer to this link:https://link.springer.com/content/pdf/10.1007%2F978-1-4842-5574-2.pdf  DataParallel C++ book[page no:14]

 

Thanks & Regards,

Hemanth.

 

View solution in original post

0 Kudos
3 Replies
HemanthCH_Intel
Moderator
845 Views

Hi,

 

Thank you for posting in Intel Communities.

 

From the above sample reproducer code, please remove the vector declaration from "float Sample2::func2()" function, because the vector allocates memory dynamically which is not supported inside the kernel.

For more information, please refer to this link:https://link.springer.com/content/pdf/10.1007%2F978-1-4842-5574-2.pdf  DataParallel C++ book[page no:14]

 

Thanks & Regards,

Hemanth.

 

0 Kudos
student4
Beginner
790 Views

Thanks for the clarification.

0 Kudos
HemanthCH_Intel
Moderator
730 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,

Hemanth.


0 Kudos
Reply