GPU Compute Software
Ask questions about Intel® Graphics Compute software technologies, such as OpenCL* GPU driver and oneAPI Level Zero
355 Discussions

[hellow world sycl program] runtime call abort() while call sycl::handler::parallel_for

gamma-coco
Novice
3 714 Visites

It should be a stupid problem. Can any one please tell me what was happened .

 

The following is the problem code:

 

#include <sycl/sycl.hpp>
#include <vector>
#include <iostream>
#include <string>
#if FPGA_HARDWARE || FPGA_EMULATOR || FPGA_SIMULATOR
#include <sycl/ext/intel/fpga_extensions.hpp>
#endif

void exception_handler(sycl::exception_list exceptions) {
		for (std::exception_ptr const& e : exceptions) {
			try {
				std::rethrow_exception(e);
			}
			catch (sycl::exception const& e) {
				std::wcout << L"Caught asynchronous SYCL exception: ";
				std::cout << e.what() << std::endl;
			}
		}
}

int wmain(int argc, char* argv[]) {
	constexpr size_t dataSize = 10000;

	std::vector<int> hostData;
	hostData.resize(dataSize);

	sycl::queue commandQueue(sycl::gpu_selector_v);
	std::cout << "run in device: " << commandQueue.get_device().get_info<sycl::info::device::name>() << std::endl;

	{
		sycl::range<1> dataRange(dataSize);

		sycl::buffer<int, 1> dataBuffer(hostData.data(), hostData.size());

		commandQueue.submit([&](sycl::handler& handle) {
			sycl::accessor<int, 1, sycl::access::mode::write, sycl::access::target::device> dataAccesor(dataBuffer, handle, sycl::write_only, sycl::no_init);
			handle.parallel_for(dataRange, [=](auto index) {
				dataAccesor[index] = (double)index;
			});
			});
	}

	return 0;
}

 

 

0 Compliments
1 Solution
gamma-coco
Novice
3 616 Visites

Thanks all,

I name the Kernal and now it worked without conclude to a function. That final code is:

#include <sycl/sycl.hpp>
#include <vector>
#include <iostream>
#include <string>
#if FPGA_HARDWARE || FPGA_EMULATOR || FPGA_SIMULATOR
#include <sycl/ext/intel/fpga_extensions.hpp>
#endif

constexpr int dataSize = 1000;

void exception_handler(sycl::exception_list exceptions) {
		for (std::exception_ptr const& e : exceptions) {
			try {
				std::rethrow_exception(e);
			}
			catch (sycl::exception const& e) {
				std::wcout << L"Caught asynchronous SYCL exception: ";
				std::cout << e.what() << std::endl;
			}
		}
}

int wmain(int argc, wchar_t* argv[]) {
    auto selector = sycl::default_selector_v;
    std::vector<float> dataSet_1;
	dataSet_1.resize(dataSize);

    try {
        sycl::queue commandQueue(sycl::gpu_selector_v, exception_handler);

        std::cout << "Running on device: "
            << commandQueue.get_device().get_info<sycl::info::device::name>() << std::endl;
        std::cout << "Vector size: " << dataSet_1.size() << std::endl;

		{
			sycl::range<1> num_items{ dataSet_1.size() };

			sycl::buffer<float, 1> sum_buf(dataSet_1.data(), num_items);

			commandQueue.submit([&](sycl::handler& h) {
				sycl::accessor<float, 1, sycl::access::mode::write> accessBuffer(sum_buf, h, sycl::write_only, sycl::no_init);

				h.parallel_for<class MyKernal>(num_items, [=](sycl::id<1> i) {
					accessBuffer[i] = 0.01F * (float)i;
					});
				});
		}

		// Wait until compute tasks on GPU done
		commandQueue.wait();

		sycl::buffer<float> bufferA(dataSet_1);
		sycl::host_accessor readAccessor(bufferA, sycl::read_only);
		for (auto item : readAccessor) {
			std::cout << item << std::endl;
		}
    }
    catch (sycl::exception const& e) {
        std::cout << "An exception is caught: " << e.what() <<std::endl;
        std::terminate();
    }

	return 0;
}

The point is I must name the kernal.

Voir la solution dans l'envoi d'origine

0 Compliments
7 Réponses
Ben_A_Intel
Employé
3 695 Visites

Hello!  A good first thing to check is: do you have a supported GPU?  Because you're specifically requesting a GPU queue...

sycl::queue commandQueue(sycl::gpu_selector_v);

... if you don't have a GPU you'll get an exception when you try to use it.

If you aren't sure, can you please include your output if you run sycl-ls?

A few other helpful things to know would be: How are you compiling your program?  What OS and what compiler version are you using?  Is there any other information included in the abort() message?

gamma-coco
Novice
3 626 Visites

Thank @Ben_A_Intel for quick response.

I have a GPU, it is the result of sycl-ls

C:\Program Files (x86)\Intel\oneAPI>sycl-ls
[opencl:acc:0] Intel(R) FPGA Emulation Platform for OpenCL(TM), Intel(R) FPGA Emulation Device 1.2 [2023.16.6.0.28_042959]
[opencl:cpu:1] Intel(R) OpenCL, Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz 3.0 [2023.16.6.0.28_042959]
[opencl:gpu:2] Intel(R) OpenCL Graphics, Intel(R) Arc(TM) A770 Graphics 3.0 [31.0.101.4669]
[ext_oneapi_level_zero:gpu:0] Intel(R) Level-Zero, Intel(R) Arc(TM) A770 Graphics 1.3 [1.3.26771]

C:\Program Files (x86)\Intel\oneAPI>

I use visual studio 2022 & DPC++ in windows.

The abort() occurs by memory access exception:

Unhandled exception at 0x00007FF8DAB24C3C in SyclRun.exe: Microsoft C++ exception: sycl::_V1::runtime_error at memory location 0x00000094D2739570.

if I comment out the "handle.parallel_for()" statement:

	{
		sycl::range<1> dataRange(dataSize);

		sycl::buffer<int, 1> dataBuffer(hostData.data(), hostData.size());

		commandQueue.submit([&](sycl::handler& handle) {
			sycl::accessor<int, 1, sycl::access::mode::write, sycl::access::target::device> dataAccesor(dataBuffer, handle, sycl::write_only, sycl::no_init);
			//handle.parallel_for(dataRange, [=](auto index) {
			//	dataAccesor[index] = index;
			//});
			});
	}

the program exit normally.

0 Compliments
gamma-coco
Novice
3 617 Visites

I did the following 2 changes and it works:

1.) use float instead of double in Kenerl function

    ** It seems Intel A770 GPU don't support FP64

2.) conclude the submit call to a seperate function.

   ** If I don't do it, it failed with "No kernel named was found -46 (PI_ERROR_INVALID_KERNEL_NAME)"

 

The worked code is:

#include <sycl/sycl.hpp>
#include <vector>
#include <iostream>
#include <string>
#if FPGA_HARDWARE || FPGA_EMULATOR || FPGA_SIMULATOR
#include <sycl/ext/intel/fpga_extensions.hpp>
#endif

constexpr int dataSize = 1000;

void vectorInitialize(sycl::queue& commandQueue, std::vector<float>& dataSet) {
	sycl::range<1> num_items{ dataSet.size() };

	sycl::buffer<float, 1> sum_buf(dataSet.data(), num_items);

	commandQueue.submit([&](sycl::handler& h) {

	sycl::accessor<float, 1, sycl::access::mode::write> accessBuffer(sum_buf, h, sycl::write_only, sycl::no_init);

	h.parallel_for(num_items, [=](sycl::id<1> i) {
		accessBuffer[i] = 0.01F * (float)i;
		});
		});
}

void exception_handler(sycl::exception_list exceptions) {
		for (std::exception_ptr const& e : exceptions) {
			try {
				std::rethrow_exception(e);
			}
			catch (sycl::exception const& e) {
				std::wcout << L"Caught asynchronous SYCL exception: ";
				std::cout << e.what() << std::endl;
			}
		}
}

int wmain(int argc, wchar_t* argv[]) {
    auto selector = sycl::default_selector_v;
    std::vector<float> dataSet_1;
	dataSet_1.resize(dataSize);

    try {
        sycl::queue commandQueue(sycl::gpu_selector_v, exception_handler);

        std::cout << "Running on device: "
            << commandQueue.get_device().get_info<sycl::info::device::name>() << std::endl;
        std::cout << "Vector size: " << dataSet_1.size() << std::endl;

		vectorInitialize(commandQueue, dataSet_1);

		// Wait until compute tasks on GPU done
		commandQueue.wait();

		sycl::buffer<float> bufferA(dataSet_1);
		sycl::host_accessor readAccessor(bufferA, sycl::read_only);
		for (auto item : readAccessor) {
			std::cout << item << std::endl;
		}
    }
    catch (sycl::exception const& e) {
        std::cout << "An exception is caught: " << e.what() <<std::endl;
        std::terminate();
    }

	return 0;
}

 

Thanks for @Ben_A_Intel  for your help.

Now the new question is why I must conclude the vectorInitialize to a function.

0 Compliments
gamma-coco
Novice
3 617 Visites

Thanks all,

I name the Kernal and now it worked without conclude to a function. That final code is:

#include <sycl/sycl.hpp>
#include <vector>
#include <iostream>
#include <string>
#if FPGA_HARDWARE || FPGA_EMULATOR || FPGA_SIMULATOR
#include <sycl/ext/intel/fpga_extensions.hpp>
#endif

constexpr int dataSize = 1000;

void exception_handler(sycl::exception_list exceptions) {
		for (std::exception_ptr const& e : exceptions) {
			try {
				std::rethrow_exception(e);
			}
			catch (sycl::exception const& e) {
				std::wcout << L"Caught asynchronous SYCL exception: ";
				std::cout << e.what() << std::endl;
			}
		}
}

int wmain(int argc, wchar_t* argv[]) {
    auto selector = sycl::default_selector_v;
    std::vector<float> dataSet_1;
	dataSet_1.resize(dataSize);

    try {
        sycl::queue commandQueue(sycl::gpu_selector_v, exception_handler);

        std::cout << "Running on device: "
            << commandQueue.get_device().get_info<sycl::info::device::name>() << std::endl;
        std::cout << "Vector size: " << dataSet_1.size() << std::endl;

		{
			sycl::range<1> num_items{ dataSet_1.size() };

			sycl::buffer<float, 1> sum_buf(dataSet_1.data(), num_items);

			commandQueue.submit([&](sycl::handler& h) {
				sycl::accessor<float, 1, sycl::access::mode::write> accessBuffer(sum_buf, h, sycl::write_only, sycl::no_init);

				h.parallel_for<class MyKernal>(num_items, [=](sycl::id<1> i) {
					accessBuffer[i] = 0.01F * (float)i;
					});
				});
		}

		// Wait until compute tasks on GPU done
		commandQueue.wait();

		sycl::buffer<float> bufferA(dataSet_1);
		sycl::host_accessor readAccessor(bufferA, sycl::read_only);
		for (auto item : readAccessor) {
			std::cout << item << std::endl;
		}
    }
    catch (sycl::exception const& e) {
        std::cout << "An exception is caught: " << e.what() <<std::endl;
        std::terminate();
    }

	return 0;
}

The point is I must name the kernal.

0 Compliments
SeshaP_Intel
Modérateur
3 535 Visites

Hi,


We can see that your issue got resolved. Could you please confirm whether we can close this thread from our end?


Thanks and Regards,

Pendyala Sesha Srinivas


0 Compliments
gamma-coco
Novice
3 524 Visites

dear @SeshaP_Intel ,

Thank you for reply.

Yes, this issue can be closed.

 

Thanks & regards,

Gamma

0 Compliments
SeshaP_Intel
Modérateur
3 517 Visites

Hi,


Thanks for the confirmation. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.


Thanks and Regards,

Pendyala Sesha Srinivas


0 Compliments
Répondre