没有sycl_external属性,SYCL内核无法调用未定义的函数

发布于 2025-01-27 02:50:35 字数 1499 浏览 4 评论 0原文

我正在尝试计算KNN的欧几里得距离,但使用DPC ++并行。训练数据集包含5个功能和1600行,而我想并行计算当前测试点和每个训练点之间的距离,但是我一直在遇到有关SYCL内核的错误。 函数的代码:

代码

std::vector<double> distance_calculation_FPGA(queue& q,const std::vector<std::vector<double>>& dataset,const std::vector<double>& curr_test) {
range<1> num_items{ dataset.size()};
std::vector<double>res;


res.resize(dataset.size());
buffer dataset_buf(dataset);
buffer curr_test_buf(curr_test);
buffer res_buf(res.data(), num_items);

q.submit([&](handler& h) {
    accessor a(dataset_buf, h, read_only);
    accessor b(curr_test_buf, h, read_only);

    accessor dif(res_buf, h, write_only, no_init);

   h.parallel_for(num_items, [=](auto i) {
  
        for (int j = 0; j <(const int) a[i].size(); ++j) {
            dif[i] += (a[i][j] - b[j]) * (a[i][j] - b[j]) ;
        }
        });
 });
for (int i = 0; i < res.size(); ++i) {
    std::cout << res[i] << std::endl;
} 
//old distance calculation (serial)
//for (int i = 0; i < dataset.size(); ++i) {
 //   double dis = 0;
   // for (int j = 0; j < dataset[i].size(); ++j) {
     //   dis += (curr_test[j] - dataset[i][j]) * (curr_test[j] - dataset[i][j]);
    //}
    //res.push_back(dis);
//}

return res;

}

我收到的错误:

SYCL kernel cannot call a variadic function

SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute

非常感谢任何帮助!

谢谢

I am trying to calculate the euclidean distance for KNN but in parallel using dpc++. the training dataset contains 5 features and 1600 rows, while I want to calculate the distance between the current test point and each training point on the grid in parallel, but I keep getting an error regarding sycl kernal.
code for the function:

code

std::vector<double> distance_calculation_FPGA(queue& q,const std::vector<std::vector<double>>& dataset,const std::vector<double>& curr_test) {
range<1> num_items{ dataset.size()};
std::vector<double>res;


res.resize(dataset.size());
buffer dataset_buf(dataset);
buffer curr_test_buf(curr_test);
buffer res_buf(res.data(), num_items);

q.submit([&](handler& h) {
    accessor a(dataset_buf, h, read_only);
    accessor b(curr_test_buf, h, read_only);

    accessor dif(res_buf, h, write_only, no_init);

   h.parallel_for(num_items, [=](auto i) {
  
        for (int j = 0; j <(const int) a[i].size(); ++j) {
            dif[i] += (a[i][j] - b[j]) * (a[i][j] - b[j]) ;
        }
        });
 });
for (int i = 0; i < res.size(); ++i) {
    std::cout << res[i] << std::endl;
} 
//old distance calculation (serial)
//for (int i = 0; i < dataset.size(); ++i) {
 //   double dis = 0;
   // for (int j = 0; j < dataset[i].size(); ++j) {
     //   dis += (curr_test[j] - dataset[i][j]) * (curr_test[j] - dataset[i][j]);
    //}
    //res.push_back(dis);
//}

return res;

}

the error I am receiving:

SYCL kernel cannot call a variadic function

SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute

Would be extremely grateful for any help!

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽手叙旧 2025-02-03 02:50:35

我们尝试通过创建虚拟“数据集”和“ Curr_test”变量来运行您的代码。我们能够成功运行该程序。请参阅此线程

请参阅下面附加的完整代码。

#include <CL/sycl.hpp>
#include <iostream> 
using namespace sycl;

std::vector<double> distance_calculation_FPGA(queue& q,const std::vector<std::vector<double>>& dataset,const std::vector<double>& curr_test) 
{
range<1> num_items{ dataset.size()};
std::vector<double>res;

res.resize(dataset.size());
buffer dataset_buf(dataset);
buffer curr_test_buf(curr_test);
buffer res_buf(res.data(), num_items);

q.submit([&](handler& h) {
accessor a(dataset_buf, h, read_only);
accessor b(curr_test_buf, h, read_only);

accessor dif(res_buf, h, write_only, no_init);

h.parallel_for(num_items, [=](auto i) {

    for (int j = 0; j <(const int) a[i].size(); ++j) {
//           dif[i] += (a[i][j] - b[j]) * (a[i][j] - b[j]) ;
         dif[i]+=a[i][j];          
        }
        });
    });
    q.wait(); //We have added this line of code for synchronization.
    for (int i : res) { 
        std::cout <<i<< std::endl;
    } 
    return res;
    }


int main(){
std::vector<std::vector<double>> dataset;
for(int i=0;i<5;i++)
{
    std::vector<double> d;

    for(int j=0;j<1600;j++)
    {
        d.push_back((double)j);
    }
    dataset.push_back(d);
}

std::vector<double> curr_test;
for(int i=0;i<1600;i++)
{
    curr_test.push_back((double)i);
}
queue q;
std::cout << "Running on "<< 
q.get_device().get_info<sycl::info::device::name>()<< std::endl; 
//print the device name as a test to check the parallelisation

distance_calculation_FPGA(q,dataset,curr_test);

return 0;
}

We tried running your code by creating dummy 'dataset' and 'curr_test' variables. We were able to run the program successfully. Please refer this thread

Please refer to the complete code attached below.

#include <CL/sycl.hpp>
#include <iostream> 
using namespace sycl;

std::vector<double> distance_calculation_FPGA(queue& q,const std::vector<std::vector<double>>& dataset,const std::vector<double>& curr_test) 
{
range<1> num_items{ dataset.size()};
std::vector<double>res;

res.resize(dataset.size());
buffer dataset_buf(dataset);
buffer curr_test_buf(curr_test);
buffer res_buf(res.data(), num_items);

q.submit([&](handler& h) {
accessor a(dataset_buf, h, read_only);
accessor b(curr_test_buf, h, read_only);

accessor dif(res_buf, h, write_only, no_init);

h.parallel_for(num_items, [=](auto i) {

    for (int j = 0; j <(const int) a[i].size(); ++j) {
//           dif[i] += (a[i][j] - b[j]) * (a[i][j] - b[j]) ;
         dif[i]+=a[i][j];          
        }
        });
    });
    q.wait(); //We have added this line of code for synchronization.
    for (int i : res) { 
        std::cout <<i<< std::endl;
    } 
    return res;
    }


int main(){
std::vector<std::vector<double>> dataset;
for(int i=0;i<5;i++)
{
    std::vector<double> d;

    for(int j=0;j<1600;j++)
    {
        d.push_back((double)j);
    }
    dataset.push_back(d);
}

std::vector<double> curr_test;
for(int i=0;i<1600;i++)
{
    curr_test.push_back((double)i);
}
queue q;
std::cout << "Running on "<< 
q.get_device().get_info<sycl::info::device::name>()<< std::endl; 
//print the device name as a test to check the parallelisation

distance_calculation_FPGA(q,dataset,curr_test);

return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文