arrayfire

Is it possible to access arrayfire's data memory using CPU backend without data copy?


I wanna use arrayfire in CPU mode (mkl) only to be able to access data without transmission, as it may happen for GPU data.

Is there a way to have direct access to arrayfire's data memory (only CPU blackened will be used)?


Solution

  • You can access the data of an af::array object by calling the device() member function. This will give you direct access to the data unless it is being referenced by another af::array or it is a sub-array/view into another array. In those cases the data will be copied.

    Example:

    array data = randu(10);
    float* data_ptr = data.device<float>();
    
    data_ptr[5] = 1337;
    data.unlock();
    af_print(data);
    
    #+RESULTS:
    data
    [10 1 1 1]
        0.6010 
        0.0278 
        0.9806 
        0.2126 
        0.0655 
     1337.0000 
        0.2864 
        0.3410 
        0.7509 
        0.4105