- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am using DPC++ to accelerate knn algorithm on FPGA device. The following code is the code I wrote for the euclidean distance. The problem is that the fpga_emulation works very well with no problems while running it on fpga hardware (Intel Arria 10 OneAPI) gives -nan for all values in the resulting buffer, which means something got wrong in the parallel_for lioop. But I can't find anything wrong about it and the emulation worked.
I am using Intel Devcloud platform.
std::vector<double> distance_calculation_FPGA(queue& q, const std::vector<std::vector<double>>& dataset, const std::vector<double>& curr_test) { std::cout<<"convert 2D to 1D"<<std::endl; std::vector<double>linear_dataset; for (int i = 0; i < dataset.size(); ++i) { for (int j = 0; j < dataset[i].size(); ++j) { linear_dataset.push_back(dataset[i][j]); } } std::cout<<"buffering"<<std::endl; range<1> num_items{dataset.size()}; std::vector<double>res; //std::cout << "im in" << std::endl; res.resize(dataset.size()); buffer dataset_buf(linear_dataset); buffer curr_test_buf(curr_test); buffer res_buf(res.data(), num_items); std::cout<<"submit a job"<<std::endl; auto start = std::chrono::high_resolution_clock::now(); { 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 < 5; ++j) { dif[i] += (b[j] - a[i * 5 + j]) * (b[j] - a[i * 5 + j]); } // out << "i : " << i << " i[0]: " << i[0] << " b: " << b[0] << cl::sycl::endl; }); }).wait(); } auto finish = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> elapsed = finish - start; std::cout << "Elapsed time: " << elapsed.count() << " s\n"; /* 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; }
results with fpga_emulation: ./knn.fpga_emu
results for fpga hardware: ./knn.fpga
Thank you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Aik Eu,
Thank you for your reply, I removed the no_init from the accessor and is now working correctly as expected.
this line:
accessor dif(res_buf, h, write_only, no_init);
became this:
accessor dif(res_buf, h, write_only);
Thank you!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi amaltaha,
May I know which reference example that you build to run your project?
I not sure the project you used may not considered some of the changes required for the hardware nodes to run. Therefore you might get different results when running on hardware as compared to emulation.
I think will be better to leverage on a working reference example project to build your own project.
Thanks.
Regards,
Aik Eu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Aik Eu,
Thank you for your reply, I removed the no_init from the accessor and is now working correctly as expected.
this line:
accessor dif(res_buf, h, write_only, no_init);
became this:
accessor dif(res_buf, h, write_only);
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page