<!--
{
  "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/bindAndWriteData(_:to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "ML Compute"
    ],
    "preciseIdentifier" : "c:objc(cs)MLCTensor(im)bindAndWriteData:toDevice:"
  },
  "title" : "bindAndWriteData(_:to:)"
}
-->

# bindAndWriteData(_:to:)

Associates the given data to the tensor, and if the device is a GPU, also copies the data to the device memory.

```
func bindAndWriteData(_ data: MLCTensorData, to device: MLCDevice) -> Bool
```

## Parameters

`data`

The data you want to associate with the tensor.

`device`

The compute device.

## Return Value

`true` if the framework successfully associated the data with the tensor and copied it to the device; otherwise, `false`.

## Discussion

The caller must guarantee the lifetime of the underlying memory of `data` for the lifetime of the tensor.

Only use this method to update device memory for tensors that are typically layer parameters, such as weights and bias for convolution layers, or beta and gamma for normalization layers. A typical use case might be implementing your own optimizer and needing to update the device memory data for these tensors.

For input tensors, use [`bindAndWriteData(_:forInputs:to:batchSize:synchronous:)`](/documentation/MLCompute/MLCGraph/bindAndWriteData(_:forInputs:to:batchSize:synchronous:)).

---

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)