---
title: "bindAndWriteData(_:to:)"
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/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.

## Declaration

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

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

## Discussion

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:).

## See Also

### Managing Tensor Data

- [synchronizeData()](mlcompute/mlctensor/synchronizedata().md)
- [synchronizeOptimizerData()](mlcompute/mlctensor/synchronizeoptimizerdata().md)
- [copyDataFromDeviceMemory(toBytes:length:synchronizeWithDevice:)](mlcompute/mlctensor/copydatafromdevicememory(tobytes:length:synchronizewithdevice:).md)
- [bindOptimizerData(_:deviceData:)](mlcompute/mlctensor/bindoptimizerdata(_:devicedata:).md)
