onnxruntime/js/web/lib/wasm/jsep/tensor-view.ts
xhcao 3bfb5e4f62
[js/webgpu] support float16 for Clip (#21584)
### Description
<!-- Describe your changes. -->



### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
2024-08-28 13:19:20 -07:00

60 lines
1.4 KiB
TypeScript

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { Tensor } from 'onnxruntime-common';
import { tensorTypeToTypedArrayConstructor } from '../wasm-common';
export const createView = (
dataBuffer: ArrayBuffer,
type: Tensor.Type,
):
| Int32Array
| Uint32Array
| BigInt64Array
| BigUint64Array
| Uint8Array
| Float32Array
| Float64Array
| Int8Array
| Int16Array
| Uint16Array => new (tensorTypeToTypedArrayConstructor(type))(dataBuffer);
/**
* a TensorView does not own the data.
*/
export interface TensorView {
readonly data: number;
readonly dataType: number;
readonly dims: readonly number[];
/**
* get a Float16Array data view of the tensor data. tensor data must be on CPU.
*/
getUint16Array(): Uint16Array;
/**
* get a Float32Array data view of the tensor data. tensor data must be on CPU.
*/
getFloat32Array(): Float32Array;
/**
* get a BigInt64Array data view of the tensor data. tensor data must be on CPU.
*/
getBigInt64Array(): BigInt64Array;
/**
* get a Int32Array data view of the tensor data. tensor data must be on CPU.
*/
getInt32Array(): Int32Array;
/**
* get a Uint16Array data view of the tensor data. tensor data must be on CPU.
*/
getUint16Array(): Uint16Array;
/**
* create a new tensor view with the same data but different dimensions.
*/
reshape(newDims: readonly number[]): TensorView;
}