3

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)?

Mehran Khazaeizadeh
  • 1,021
  • 1
  • 7
  • 13

1 Answers1

2

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 
Umar Arshad
  • 970
  • 1
  • 9
  • 22
  • 1
    Hi again. I did what you said, but now I've a new problem: I created my array using af::constant, then I did what you said, now when I print my modified array it's still 0 (it changed just one time in debug mode, but most of the time it didn't. – Mehran Khazaeizadeh Aug 24 '22 at 08:21
  • 1
    Can you send me a code snippet? I think you will need to create a new StackOverflow question or go to the ArrayFire slack channel and ask your question there. – Umar Arshad Sep 01 '22 at 16:38
  • 1
    Thanks. I'll create a new question in here. – Mehran Khazaeizadeh Sep 01 '22 at 19:45