---
title: "copyDataFromDeviceMemory(toBytes:length:synchronizeWithDevice:)"
framework: ML Compute
role: symbol
role_heading: Instance Method
platforms: [iOS 14.0+, iPadOS 14.0+, Mac Catalyst 14.0+, macOS 11.0+, tvOS 14.0+]
path: "mlcompute/mlctensor/copydatafromdevicememory(tobytes:length:synchronizewithdevice:)"
---

# copyDataFromDeviceMemory(toBytes:length:synchronizeWithDevice:)

Copies tensor data from device memory to user-specified memory.

## Declaration

```swift
func copyDataFromDeviceMemory(toBytes bytes: UnsafeMutableRawPointer, length: Int, synchronizeWithDevice: Bool) -> Bool
```

## Parameters

- `bytes`: The data to copy.
- `length`: The number of bytes you specify for the framework to copy.
- `synchronizeWithDevice`: A Boolean that indicates whether you choose to synchronize device memory if the device is a GPU.

## Return Value

Return Value true if successful; otherwise, false if the framework failed to copy or synchronize.

## Discussion

Discussion When the device is a GPU, you may need to synchronize the device memory, that is, set synchronizeWithDevice to true. The framework ignores synchronizeWithDevice when the device is the CPU. important: Only call this method once the graph, with which you used this tensor, finishes execution. Otherwise the results in device memory may not be up to date. When the device is a GPU, you must set synchronizeWithDevice to false when you call this method in a completion handler. If you specified a tensor for the outputs of a graph using addOutputs, set synchronizeWithDevice to false.

## See Also

### Managing Tensor Data

- [synchronizeData()](mlcompute/mlctensor/synchronizedata().md)
- [synchronizeOptimizerData()](mlcompute/mlctensor/synchronizeoptimizerdata().md)
- [bindAndWriteData(_:to:)](mlcompute/mlctensor/bindandwritedata(_:to:).md)
- [bindOptimizerData(_:deviceData:)](mlcompute/mlctensor/bindoptimizerdata(_:devicedata:).md)
