0

What is the correct way to create a 2D std::vector buffer in SYCL? I have a template function which receives arguments as shown below:

template <typename T>
void MatrixMulParallelNaive(queue& q, 
    std::vector<std::vector<T>>& a,
    std::vector<std::vector<T>>& b,
    std::vector<std::vector<T>>& c){ 
    
    // Is this a correct way?
    buffer<T, 2> a_buf(a.data(), range<2>{a.size(), a[0].size()})
    buffer<T, 2> b_buf(b.data(), range<2>{b.size(), b[0].size()})
    buffer<T, 2> c_buf(c.data(), range<2>{c.size(), c[0].size()})
    
    /* ... */
}

a, b and c are 2D std::vectors

I have been able to implement buffers for 2D C-style arrays, but I've tried multiple docs and answers, but none seem to match this specific usecase.

Karan Shah
  • 417
  • 6
  • 21

1 Answers1

1

No. vector<vector<T>> doesn't create a contiguous block of memory. You need to use vector<T> and interpret it as a two dimensional block of data.

ALX23z
  • 4,456
  • 1
  • 11
  • 18
  • Do you mean I flatten the 2D vector and access as a linear block of memory? – Karan Shah Oct 18 '20 at 06:15
  • @KaranShan yeah. `data(x,y) := vec[x+y*cols]`. You should also checkout what happens with the stride. Normally images and the like have height, width, and stride as parameters and thus I believe `buffer` should have one as well. – ALX23z Oct 18 '20 at 06:58