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*
724 Discussions

Something went wrong when trying SYCL reduction variables with oneAPI

JamesFBM
Beginner
1,053 Views

Hi, I'm new to SYCL and am trying to run an example about reduction variables from the SYCL Specification with oneAPI 2023.0.0. I revise the code a little and the final version is shown as follows:

 

#include <iostream>
#include <sycl/sycl.hpp>
#include <numeric>

using namespace sycl;

int main() {
	buffer<int> valuesBuf{ 1024 };
	{
		host_accessor a{ valuesBuf };
        // std::iota(a.begin(), a.end(), 0);
        std::iota(&(a[0]), &(a[1023]), 0);
	}

	int sumResult = 0;
	buffer<int> sumBuf{ &sumResult, 1 };
	int maxResult = 0;
	buffer<int> maxBuf{ &maxResult, 1 };

	queue myQueue;

	myQueue.submit([&](handler& cgh) {
		auto inputValues = valuesBuf.get_access<access_mode::read>(cgh);
	auto sumReduction = reduction(sumBuf, cgh, plus<>());
	auto maxReduction = reduction(maxBuf, cgh, maximum<>());

    /*
	 cgh.parallel_for(range<1> {2048, 1024}, sumReduction, maxReduction,
		[=](nd_item<1> it, auto& sum, auto& max) {
			sum += inputValues[it.get_local_id()];
			max.combine(inputValues[it.get_global_id()]);
		});
    */

    cgh.parallel_for(nd_range<1> {2048, 1024}, sumReduction, maxReduction,
		[=](nd_item<1> it, auto& sum, auto& max) {
			sum += inputValues[it.get_local_id()];
	        max.combine(inputValues[it.get_local_id()]);
		});
    });

	// assert(maxBuf.get_host_access()[0] == 1023 && sumBuf.get_host_access()[0] == 523776);
    std::cout << maxBuf.get_host_access()[0] << std::endl;
    std::cout << sumBuf.get_host_access()[0] << std::endl;
}

 

However, there is still something wrong with it which I cannot figure out the reasons. The problems are:

  1. The code can be successfully compiled in cmd with command

    icpx -fsycl src.cpp -o o.exe​
    while when compiled in Visual Studio 2022 with Intel(R) oneAPI DPC++ Compiler, it fails and pops out the error
    SYCL kernel cannot call a variadic function
    SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute
    I have seen a similar problem in Re: SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute - Intel Communities  and Re: SYCL kernel cannot call an undefined function without SYCL_EXTERNAL attribute - Intel Communities and believe that Line 38 function
    max.combine(inputValues[it.get_local_id()]);​
    triggers the compilation error, but cannot find a suitable solution to it.
  2.  The program compiled with icpx in cmd does not work as expected. The program typically prints out nothing and exits with a meaningless value. The results are shown below:
    C:\Users\a1595\Desktop\dr\c>icpx -fsycl c.cpp -o c.exe
    
    C:\Users\a1595\Desktop\dr\c>c.exe
    
    C:\Users\a1595\Desktop\dr\c>echo %ERRORLEVEL%
    -1073740791​
    A similar result also occurs in Visual Studio 2022 environment and I have no idea about it.

I am looking forward to any help. Thanks a lot.

0 Kudos
1 Reply
AishwaryaCV_Intel
Moderator
1,033 Views

Hi,


Thank you for posting in intel communities.


Since this is a duplicate thread of <https://community.intel.com/t5/Intel-oneAPI-Data-Parallel-C/problems-about-SYCL-reduction-variables-using-oneAPI/m-p/1454057#M2774>, we will no longer monitor this thread. We will continue addressing this issue in the other thread.


Thanks And Regards,

Aishwarya


0 Kudos
Reply