Intel® oneAPI DPC++/C++ Compiler
Talk to fellow users of Intel® oneAPI DPC++/C++ Compiler and companion tools like Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and Intel® Distribution for GDB*

Implementing multiple functions in kernel

student4
Beginner
646 Views

Hi,

 

Shown below is my DPC++ code.
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++.
Thank you.

 

 

#include <iostream>
#include<vector>
#include<random>
#include<omp.h>
#include<chrono>
#include <CL/sycl.hpp>
#include <ext/intel/fpga_extensions.hpp>
using namespace std;

 

void Oneapi_Fpga()
{
vector<float>testData(10);
vector<float>filterCoeff(5);
int convLen = testData.size() + filterCoeff.size() - 1;
vector<float>convSeq(convLen);

std::random_device rand;
std::mt19937 generator(rand());
std::normal_distribution<float> ndist{ 0.0f, 1.0f };
for (int i = 0; i < testData.size(); i++)
{
testData[i] = ndist(generator);
}

std::random_device randi;
std::mt19937 generatorr(randi());
std::normal_distribution<float> ndisti{ 0.0f, 1.0f };
for (int i = 0; i < filterCoeff.size(); i++)
{
filterCoeff[i] = ndisti(generator);
}


int lenA = 10;
int lenB = 5;
int nconv;

std::chrono::high_resolution_clock::time_point t6, t7;
std::chrono::duration<double, std::milli> accum3;

accum3 = std::chrono::milliseconds(0);

nconv = lenA + lenB - 1;
vector<float>C(nconv);

//*********************************************************
// FPGA oneapi implementation
//*********************************************************
sycl::buffer testBuff(testData);
sycl::buffer filterBuff(filterCoeff);
sycl::buffer convBuff(C);
sycl::ext::intel::fpga_emulator_selector d_selector;
try
{
cl::sycl::queue Q(d_selector);
t6 = std::chrono::high_resolution_clock::now();
Q.submit([&](sycl::handler& h)
{
sycl::accessor testAccess(testBuff, h, sycl::read_only);
sycl::accessor filterAccess(filterBuff, h, sycl::read_only);
sycl::accessor cAccess(convBuff, h, sycl::read_write);
h.single_task([=]() {

for (int i = 0; i < nconv; i++)
{
int i1 = i;
float tmp = 0.0;
for (int j = 0; j < lenB; j++)
{
if (i1 >= 0 && i1 < lenA)
tmp = tmp + (testAccess[i1] * filterAccess[j]);

i1 = i1 - 1;
cAccess[i] = tmp;

}
}
Add(cAccess);        // function should be implemented by kernel

});
});
t7 = std::chrono::high_resolution_clock::now();
Q.wait_and_throw();
}

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




accum3 = t7 - t6;

cout << "time taken by FPGA oneapi implementation is" << accum3.count() << endl;


}
int main()
{
for(int i=0;i<1000000;i++)
{
Oneapi_Fpga();
}

std::cout << "success\n";
}

 

0 Kudos
2 Replies
NoorjahanSk_Intel
Moderator
560 Views

Hi,


Thanks for reaching out to us.


We are working on your issue. We will get back to you soon.


Thanks & Regards,

Noorjahan.


0 Kudos
Klaus-Dieter_O_Intel
463 Views

I assume you are looking for something like (see also https://oneapi-src.github.io/DPCPP_Reference/model/kernel-programming-model.html


void Add( sycl::accessor<float, 1, sycl::access::mode::read_write> cAccess ){

  int nconv = cAccess.size();

  for (int i = 0; i < nconv; i++){

   cAccess[i] *= nconv;

  }

}



0 Kudos
Reply