<!--
{
  "availability" : [
    "iOS: 14.0.0 - 17.4.0",
    "iPadOS: 14.0.0 - 17.4.0",
    "macCatalyst: 14.0.0 - 17.4.0",
    "macOS: 11.0.0 - 14.3.0",
    "tvOS: 14.0.0 - 17.4.0"
  ],
  "documentType" : "symbol",
  "framework" : "MLCompute",
  "identifier" : "/documentation/MLCompute/MLCTensor/copyDataFromDeviceMemory(toBytes:length:synchronizeWithDevice:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "ML Compute"
    ],
    "preciseIdentifier" : "c:objc(cs)MLCTensor(im)copyDataFromDeviceMemoryToBytes:length:synchronizeWithDevice:"
  },
  "title" : "copyDataFromDeviceMemory(toBytes:length:synchronizeWithDevice:)"
}
-->

# copyDataFromDeviceMemory(toBytes:length:synchronizeWithDevice:)

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

```
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

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

## 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`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)