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*

Compile error

Darius_Nicholas
New Contributor I
5,003 Views

OS: Windows

IDE: Visual Studio 2022

I compile a oneapi code on Visual studio, and it compiles with errors.

This is my code.联想截图_20230807151059.png

compile errors:

联想截图_20230807151225.png

Trouble you again, thank you!

0 Kudos
1 Solution
Darius_Nicholas
New Contributor I
3,853 Views

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.

View solution in original post

0 Kudos
17 Replies
NoorjahanSk_Intel
Moderator
4,943 Views

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:

NoorjahanSk_Intel_0-1691582145934.png

Intel OneAPI Command prompt:

NoorjahanSk_Intel_1-1691582167176.png

 

Thanks & Regards,

Noorjahan.

 

 

0 Kudos
Darius_Nicholas
New Contributor I
4,923 Views

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?

联想截图_20230810094731.png

Exception:

联想截图_20230810095033.png

I'm sorry to bother you again. Thank you!

0 Kudos
Darius_Nicholas
New Contributor I
4,860 Views

I have a new problem! I'm sorry to trouble you again. Can you help me solve it? Thank you!

0 Kudos
NoorjahanSk_Intel
Moderator
4,838 Views

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:

NoorjahanSk_Intel_0-1697015514340.png

 

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.

 

0 Kudos
Darius_Nicholas
New Contributor I
4,823 Views

I have tried it before, but failed!

OS: Windows 11

IDE: Visual Studio 2022

I'm sorry to bother you again. Thank you!

0 Kudos
NoorjahanSk_Intel
Moderator
4,807 Views

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:

NoorjahanSk_Intel_0-1692353895850.png

 

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.

https://www.intel.com/content/www/us/en/developer/articles/reference-implementation/intel-compilers-compatibility-with-microsoft-visual-studio-and-xcode.html

 

Thanks & Regards,

Noorjahan

 

0 Kudos
NoorjahanSk_Intel
Moderator
4,748 Views

Hi,


We haven't heard back from you. Could you please provide an update on your issue?


Thanks & Regards,

Noorjahan.


0 Kudos
Darius_Nicholas
New Contributor I
4,741 Views

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:

Darius_Nicholas_0-1692950494564.png

This is mine:

Darius_Nicholas_1-1692950550421.png

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!

 

0 Kudos
Darius_Nicholas
New Contributor I
4,657 Views

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:

Darius_Nicholas_1-1693377234060.png

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!

 

 

0 Kudos
Darius_Nicholas
New Contributor I
4,568 Views

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!

 

0 Kudos
NoorjahanSk_Intel
Moderator
4,556 Views

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:

NoorjahanSk_Intel_0-1693909742302.png

 

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.

 

0 Kudos
Darius_Nicholas
New Contributor I
4,548 Views

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

Darius_Nicholas_0-1693992508638.png

This exception can be observed on both UHD730 and UHD630 integrated graphics.

0 Kudos
NoorjahanSk_Intel
Moderator
4,120 Views

Hi,


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


Thanks & Regards,

Noorjahan.


0 Kudos
NoorjahanSk_Intel
Moderator
3,922 Views

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.


0 Kudos
NoorjahanSk_Intel
Moderator
3,859 Views

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.


0 Kudos
Darius_Nicholas
New Contributor I
3,854 Views

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.

0 Kudos
NoorjahanSk_Intel
Moderator
3,840 Views

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.


0 Kudos
Reply