How to set the size of SyncCopyFromCPU(const mx_float *data, size_t size)

I have a question is that, when I use the fucn. of SyncCopyFromCPU(const mx_float *data, size_t size), I don’t konw how to set the size is the have the most performance. What effects the ‘size’?

Does anyone konws how to set the parameter ‘size’ for SyncCopyFromCPU which will gain the best performance.

Hey @gao,
you should exactly allocate as much memory as you need for your specific NDArray.
Here is a short example:

  Context global_ctx = Context::cpu();  // or  Context::gpu();
  Shape input_shape(3, 224, 224);  // e.g. default ImageNet size
  std::vector<float> array;  // alternatively you can also use a float array
  // ... fill your data here
  NDArray image_data = NDArray(input_shape, global_ctx, false);
  image_data.SyncCopyFromCPU(, input_shape.Size());
1 Like