| 32 | |
| 33 | template<typename T> |
| 34 | void copyData(T *to, const Array<T> &from) { |
| 35 | if (from.elements() == 0) { return; } |
| 36 | |
| 37 | from.eval(); |
| 38 | // Ensure all operations on 'from' are complete before copying data to host. |
| 39 | getQueue().sync(); |
| 40 | if (from.isLinear()) { |
| 41 | // FIXME: Check for errors / exceptions |
| 42 | memcpy(to, from.get(), from.elements() * sizeof(T)); |
| 43 | } else { |
| 44 | dim4 ostrides = calcStrides(from.dims()); |
| 45 | kernel::stridedCopy<T>(to, ostrides, from.get(), from.dims(), |
| 46 | from.strides(), from.ndims() - 1); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | template<typename T> |
| 51 | Array<T> copyArray(const Array<T> &A) { |