c++visual-studiosycldpc++

SYCL program working using VS Debugger but not when running the .exe


I am trying to build and run a simple SYCL program from this book. Here it is:

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

const std::string secret {
    "Ifmmp-!xpsme\"\012J(n!tpssz-!Ebwf/!"
    "J(n!bgsbje!J!dbo(u!ep!uibu/!.!IBM\01"
};
const auto sz = secret.size();

int main(int argc, char* argv[]) {
    queue Q;

    char* result = malloc_shared<char>(sz, Q);
    std::memcpy(result, secret.data(), sz);

    Q.parallel_for(sz, [=](auto& i) {
        result[i] -= 1;
        }).wait();

    std::cout << result <<  "\n";

    return 0;
}

I am using Visual Studio 2019 and I am compilating with Intel oneAPI DPC++ 2022. If I run the Visual Studio Debugger, everything is working, I am obtaining as output: "Hello World! I'm sorry, Dave. I'm afraid i can't do that. - HAL"

But if I am executing the .exe file that I just have built from the command prompt, nothing is happening... The program is executing itself, nothing is given as output, and I receive no error either. I tried to put some printf everywhere to see where to problem could come from. If I put a printf right just after "queue Q;" I wouldn't be able to see it when I run the .exe file. From what I have read the problem comes from the initialization of my object Q. I replaced "queue Q;" by "queue Q(default_selector{});" but it didn't solve the problem.


EDIT : I have simply reduced the code to the following:

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

int main(int argc, char* argv[]) {
    std::cout << "Beginning of the program.\n";
    
    queue Q; // The problem appears to come from this line

    std::cout << "End of the program.\n";
    system("pause");
    return 0;
}

Here is the output when I am launching the program in the Visual Studio Debugger:

> Beginning of the program.
> End of the program.
>
> Sortie de C:\Users\...\test.exe (processus 8108). Code : 0.
> Press any key to continue . . .

Here is the output when I am calling the .exe from the command prompt:

> C:\Users\...\Release>test.exe
> Beginning of the program.
>
> C:\Users\...\Release>

I have noticed that during the short time when the program is running in the command prompt (something like one second), I saw that the program Windows Problem Reporting ran in the Task Manager. Than it vanished as soon as the program apparently finished to compute.


EDIT 2 : Here is what happens if I am looking for the device used. With the following code:

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

int main(int argc, char* argv[]) {
    default_selector device_selector;
    std::cout << "default_selector has been defined.\n";

    auto defaultQueue = queue(device_selector);
    std::cout << "default_queue has been defined.\n";
    std::cout << "Running on " << defaultQueue.get_device().get_info<info::device::name>() << "\n";

    system("pause");
    return 0;
}

I get this output from the Visual Studio debugger:

> Beginning of the program...
> default_selector has been defined.
> default queue has been defined.
> Running on      Intel(R) Core(TM) i5-3337U CPU @ 1.80GHz
> Press any key to continue...

And this when I am executing the .exe from the commande prompt (doing this in administrator or not doesn't change anything):

> C:\Users\...\Release>test.exe
> Beginning of the program...
> default_selector has been defined.
>
> C:\Users\...\Release>

Solution

  • The answer has been brought by the Intel Developer Software Forums.

    Although the compiler has been well installed on my machine, the oneAPI environment had not be configured yet. This is why it couldn't work when running the .exe in the Windows command prompt.

    I had to run the batch file setvars.bat that was at the adress C:\Program Files (x86)\intel\oneAPI then it worked!