1

I'm learning the oneapi and I get wrong results when i try to do an exclusive_scan when I use the dpcpp parallel version.

It always assumes the first element to be zero.

Code:

#include <CL/sycl.hpp>
#include <oneapi/dpl/execution>
#include <oneapi/dpl/numeric>
#include <oneapi/dpl/iterator>
#include <iostream>
#include <vector>



int main(){
    sycl::queue Q(sycl::cpu_selector{});

    const u_int32_t n   = 100;
    
    std::vector<u_int32_t> data(n,1);
    
    {    
        sycl::buffer b_data(data);
        auto policy = oneapi::dpl::execution::make_device_policy<class mypolicy>(Q);
        oneapi::dpl::exclusive_scan(
            policy,
            oneapi::dpl::begin(b_data),
            oneapi::dpl::end(b_data),
            oneapi::dpl::begin(b_data),
            0);
    }
    
    for(auto i=0; i<10 ; i++){
        std::cout << data[i] << std::endl;
    }
}

Output:

0
0
1
2
3
4
5
6
7
8

Expected output:

0
1
2
3
4
5
6
7
8
9

Build command: dpcpp -Wall main.cpp -o main

1 Answers1

1

This is a known limitation as mentioned in the below link: https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-library-guide/top/intel-oneapi-dpc-library-onedpl-overview.html

It is recommended to use initial value as 1 instead of 0 for unary operations.

oneapi::dpl::exclusive_scan(
        policy,
        oneapi::dpl::begin(b_data),
        oneapi::dpl::end(b_data),
        oneapi::dpl::begin(b_data),
        1);

Thanks & Regards, Hemanth.

HemanthCH
  • 3
  • 7