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
func bindAndWriteData(_ data: MLCTensorData, to device: MLCDevice) -> BoolParameters
- 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:).