- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OS: Windows
IDE: Visual Studio 2022
I compile a oneapi code on Visual studio, and it compiles with errors.
This is my code.
compile errors:
Trouble you again, thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
terribly sorry! I already know the solution to the problem. I defined M_PI in the header file, and it is of double data type, so the data type returned by the cos function in hanning is also double, so the function cannot run. The new graphics card does not support the double data type. We said this before. Sorry to have delayed you for so long. The problem I encountered has always been that the graphics card does not support the double data type, but I did not pay attention to the definition and cos function in the header file. Really sorry.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for posting in Intel Communities.
We have tried your code by adding a main function and it is working as expected without any errors in Visual studio 2022 Release mode and in oneAPI command prompt.
Please find the below full code:
#include <vector>
#include <iostream>
#include <CL/sycl.hpp>
std::vector<std::vector<double>> filter2d(const std::vector<double>& b, double a, const std::vector<std::vector<double>>& x) {
int rows = x.size();
int cols = x[0].size();
std::vector<std::vector<double>> y(x.size(), std::vector<double>(x[0].size()));
auto z = b.size();
sycl::queue q(sycl::cpu_selector_v);
sycl::buffer b_buffer(b);
sycl::buffer y_buffer(y);
sycl::buffer x_buffer(x);
q.submit([&](sycl::handler& h) {
sycl::accessor x_acc(x_buffer, h, sycl::read_only);
sycl::accessor b_acc(b_buffer, h, sycl::read_only);
sycl::accessor y_acc(y_buffer, h, sycl::write_only, sycl::no_init);
h.parallel_for(sycl::range<2>(rows, cols), [=](sycl::item<2> idx) {
int i = idx[0];
int j = idx[1];
y_acc[i][j] = 0.0;
for (int k = 0; k < z; k++) {
if (i - k >= 0) {
y_acc[i][j] += b_acc[k] * x_acc[i - k][j];
}
}
y_acc[i][j] /= a;
});
});
q.wait();
return y;
}
int main()
{
std::vector<double> b = { 1.0, 2.0, 1.0 };
double a = 1.0;
std::vector<std::vector<double>> x = {
{ 1.0, 2.0, 3.0 },
{ 4.0, 5.0, 6.0 },
{ 7.0, 8.0, 9.0 }
};
std::vector<std::vector<double>> y = filter2d(b, a, x);
for (const auto& row : y) {
for (const auto& val : row) {
std::cout << val << " ";
}
std::cout << "\n";
}
return 0;
}
Please refer to below screenshots for more details:
Visual studio:
Intel OneAPI Command prompt:
Thanks & Regards,
Noorjahan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! When I switch to release mode, it runs successfully. I'm sorry to bother you again. I have another question. When I specify the GPU as the selector, it runs with an exception, why, and how to solve it?
Exception:
I'm sorry to bother you again. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a new problem! I'm sorry to trouble you again. Can you help me solve it? Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Please find the below modified code that works with GPU & CPU selector.
#include <vector>
#include <iostream>
#include <CL/sycl.hpp>
using namespace sycl;
std::vector<std::vector<double>> filter2d(const std::vector<double>& b, double a, const std::vector<std::vector<double>>& x) {
int rows = x.size();
int cols = x[0].size();
std::vector<std::vector<double>> y(x.size(), std::vector<double>(x[0].size()));
auto z = b.size();
std::vector<double> flat_y(rows * cols);
std::vector<double> flat_x(rows * cols);
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
flat_x[i * cols + j] = x[i][j];
}
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
flat_y[i * cols + j] = y[i][j];
}
}
sycl::buffer<double,1> b_buffer(b.data(),range<1> (rows));
sycl::buffer<double,2> x_buffer(flat_x.data(),range<2> (rows,cols));
sycl::buffer<double,2> y_buffer(flat_y.data(),range<2> (rows,cols));
sycl::queue q(sycl::gpu_selector_v);
std::cout<<"Device name: "<< q.get_device().get_info<sycl::info::device::name>();
q.submit([&](sycl::handler& h) {
sycl::accessor x_acc(x_buffer,h);
sycl:: accessor y_acc(y_buffer,h);
sycl::accessor b_acc(b_buffer,h);
auto out = sycl::stream(512, 256, h);
h.parallel_for(sycl::range{static_cast<size_t>(rows),static_cast<size_t>(cols)}, [=](sycl::id<2> idx) {
int i = idx[0];
int j = idx[1];
y_acc[i][j] = 0.0;
for (int k = 0; k < z; k++)
{
if (i - k >= 0)
{
y_acc[i][j] = y_acc[i][j] + b_acc[k] * x_acc[(i - k)][j];
}
}
y_acc[i][j] = y_acc[i][j] / a;
});
}).wait();
sycl::host_accessor y_h(y_buffer);
for(int i=0;i<rows;i++){
for(int j=0;j<cols;j++){
y[i][j]=y_h[i][j];
}
}
return y;
}
int main()
{
std::vector<double> b = { 1.0, 2.0, 1.0 };
double a = 1.0;
std::vector<std::vector<double>> x = {
{ 1.0, 2.0, 3.0 },
{ 4.0, 5.0, 6.0 },
{ 7.0, 8.0, 9.0 }
};
auto y = filter2d(b, a, x);
std::cout<< "\n";
for (const auto& row : y) {
for (const auto& val : row) {
std::cout << val << " ";
}
std::cout << "\n";
}
return 0;
}
Please refer to below screenshot for more details:
Please let us know if you still face any issues.
>>I have a new problem!
Could you please elaborate about your new problem?
Thanks & Regards,
Noorjahan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have tried it before, but failed!
OS: Windows 11
IDE: Visual Studio 2022
I'm sorry to bother you again. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We have tried on Windows 11, visual studio 2022 (17.6.2) with Intel oneAPI 2023.2 and did not observe any issues at our end.
Please find the below screenshot:
Please find the attached complete VS project for more details.
Please check whether you are using a supported version of Visual Studio. If not please try it on the supported version and let us know if you still face any issues.
Thanks & Regards,
Noorjahan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We haven't heard back from you. Could you please provide an update on your issue?
Thanks & Regards,
Noorjahan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry for taking so long to reply to you! I've tried the code you've given, unfortunately I'm getting the same error as my code was running before. I don't know how to solve this problem.
This is yours:
This is mine:
The version of Visual Studio: Visual Studio(2022) 17.6.4
OS: Windows 11
The version of oneAPI:2023.2.0
Trouble you again ! I'm sorry! Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, I just noticed that I forgot to turn on the integrated graphics mode of the laptop, which is why the above error occurs. However, the previous error still occurs, the code you gave and the code I wrote have the same error.
Errors:
Another problem is that the code you gave can run on the UHD630 integrated graphics card, but it cannot run on the UHD730 integrated graphics card, and the above error will appear. Excuse me, what is this question? Sorry to bother you, thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Noorjahan:
I have found the cause of the above problem. The reason is that the new graphics card does not support the double data type. When I change double to float, the code can run. Thank you very much!
However, I now encounter a new problem. When the vector is two-dimensional, the code can run. When the vector is one-dimensional, he code will throw an exception.
Attached is my code!The function func_apod can run successfully, but the function hanning cannot. It's hard for me to find the reason for the exception! So I want your help! I am sorry for disturbing you! Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
>> I have found the cause of the above problem
Glad to know that you resolves your issue.
We have tried your code at our end and we observed that the code includes a file (#include"functions.h") which is not attached along with your code.
Please refer to the below screenshot for more details on the error we observed at our end:
Could you please share us the complete code files(.h) so that we can try it from our side?
Also please share the error log/ Exception you have observed.
Also please let us know whether you observe this exception on both UHD730 and UHD630 integrated graphics.
Thanks & Regards,
Noorjahan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, it was my mistake. header files can be ignored. You can comment out #include "functions.h". This does not affect code execution.
As for M_PI, it is directly defined as 3.1415926.
code: const float M_PI=3.1415926
This exception can be observed on both UHD730 and UHD630 integrated graphics.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We are working on your issue. We will get back to you soon.
Thanks & Regards,
Noorjahan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We have reported this issue to the concerned development team. They are looking into your issue. We will get back to you soon.
Thanks & Regards,
Noorjahan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for your patiecnce.
>> I now encounter a new problem. When the vector is two-dimensional, the code can run. When the vector is one-dimensional, he code will throw an exception.
Could you please provide working code when vector is two dimensional so that we can investigate more on this issue?
>>The function func_apod can run successfully, but the function hanning cannot.
Also please let us know what do you mean here by func_apod running successfully but not hanning?
Thanks & Regards,
Noorjahan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
terribly sorry! I already know the solution to the problem. I defined M_PI in the header file, and it is of double data type, so the data type returned by the cos function in hanning is also double, so the function cannot run. The new graphics card does not support the double data type. We said this before. Sorry to have delayed you for so long. The problem I encountered has always been that the graphics card does not support the double data type, but I did not pay attention to the definition and cos function in the header file. Really sorry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thank you for sharing the solution with us.
Glad to know that your issue is resolved. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.
Thanks & Regards,
Noorjahan.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page