Support for using existing chunks of memory

Issue #16 closed
Alex Shtof created an issue

Description

In many applications users have existing arrays in memory, which were not constructed by Blaze. Currently, Blaze does offer the functionality to conveniently copy these arrays into vectors and matrices. However, given that these arrays match the expectations of the Blaze algorithms in terms of alignment and strides, it would be more efficient to use them directly. Thus Blaze should provide an API for constructing vectors and matrices, which represent those memory chunks and thus enable to perform linear algebra computation on them as if they were constructed by Blaze.

Conceptual Example

double* vecarray = new double[size];

// Instantiate a vector to represent the vector array of double precision elements.
// The constructor will check if the alignment of data matches the requirements.
// Note that the vector will NOT take ownership of the memory resource!
blaze::CustomVector<double,blaze::columnVector> x( vecarray, size );

double* matarray = new double[rows*columns];

// Instantiate a matrix to represent the matrix array of double precision elements.
// The constructor will check that the beginning of each row is properly aligned according to the requirements.
// Note that the matrix will NOT take ownership of the memory resource!
blaze::CustomMatrix<double,blaze::rowMajor> A( matarray, rows, columns );

blaze::DynamicVector<double,columnVector> y;
y = A * x;

Tasks

  • design an API to allow to use chunks of memory as native Blaze vectors and matrices
  • implement the necessary functionality
  • provide a full documentation of the feature
  • ensure compatibility with all existing vector and matrix classes
  • ensure compatibility with all existing vector and matrix expressions
  • guarantee maximum performance for all operations
  • add the necessary number of test cases for the entire functionality

Comments (2)

  1. Klaus Iglberger

    We have accepted your proposal. I have adapted the description a little and added a conceptual example that gives an idea of our understanding. Please comment if this represents your idea of the feature.

    In the original description, you mentioned that "The data may be represented using different storage orders and strides for each dimension". We are not exactly sure what you mean with "strides for each dimension. We would expect that each row/column has the same number of (padding) elements. Could you please comment on that?

    It is important to note that Blaze expects a specific alignment of the data, which for instance includes padding in each row/column. If this is not given then the existing algorithms would not work. Thus the API would have to make sure that the data is properly aligned and cannot accept arbitrary chunks of data. Is this restriction acceptable from your point of view?

  2. Log in to comment