none
Templates with parallel_for_each and kernel RRS feed

  • Question

  • If I create an 'array' then it becomes an array only in GPU. And for that I have to pass a reference in the pfe.

    For example, below is an example before template creation and you can see that I am passing the reference of 'array' in parallel_for_each.

    float data[100];
    float out[100]; 
    
    extern<1> ext(100);
    
    array<float> input(ext, data); 
    array_view<float> output(ext, out);
     
    parallel_for_each(ext, [=, &input](index<1> idx) restrict(amp) <-- I am passing the reference of 'input' array
    { 
        output[idx] = input[idx]; 
    }); 
    
    output.synchronize();

    What happens to that passing reference in pfe if I create a template? Do I need that passing reference in the template as well?

    float data[100];
    float out[100]; 
    
    extern<1> ext(100);
    
    array<float> input(ext, data); 
    array_view<float> output(ext, out);
    
    
    xparallel_for_each(data.size(), [=, &input](int idx) restrict(amp)  <-- I am passing the reference of 'input' array
    {
        output[idx] = input[idx];
    });
    
    
    template <typename Kernel>
    void xparallel_for_each(int ext_size, Kernel kernel)
    {
         auto krn = [=, &input] (index<1> idx) restrict(amp)  <--- do I need to pass the 'input' array reference here?
         {
    	kernel(idx[0]);
         };
    	
         concurrency::parallel_for_each(extent<1>(ext_size), krn);
    }


    Wednesday, September 10, 2014 4:54 PM

All replies