MCPcopy Create free account
hub / github.com/apache/tvm / copyFromRawBytes

Method copyFromRawBytes

web/src/runtime.ts:650–666  ·  view source on GitHub ↗

* Copy data from raw bytes. * @param data Uint8Array of bytes. * @returns this

(data: Uint8Array)

Source from the content-addressed store, hash-verified

648 * @returns this
649 */
650 copyFromRawBytes(data: Uint8Array): this {
651 // short cut for gpu copy
652 if (this.device.deviceType === DeviceStrToEnum.webgpu) {
653 this.lib.webGPUContext?.copyRawBytesToBuffer(data, this.getDataPtr(), 0, data.length);
654 return this;
655 }
656 // CPU copy
657 const size = this.shape.reduce((a, b) => {
658 return a * b;
659 }, 1);
660 const nbytes = this.dlDataType.numStorageBytes() * size;
661 if (nbytes != data.length) {
662 throw new Error("Expect the data's length equals nbytes=" + nbytes);
663 }
664 this.ctx.tensorCopyFromJSBytes(this, data);
665 return this;
666 }
667 /**
668 * Return a copied Uint8Array of the raw bytes in the Tensor.
669 * @returns The result array.

Callers 1

copyFromMethod · 0.95

Calls 4

getDataPtrMethod · 0.95
copyRawBytesToBufferMethod · 0.80
reduceMethod · 0.80
numStorageBytesMethod · 0.80

Tested by

no test coverage detected