[js/webgpu] allow uint8 tensors for webgpu (#19545)

### Description
allow uint8 tensors for webgpu
This commit is contained in:
Yulong Wang 2024-02-16 18:28:27 -08:00 committed by GitHub
parent 4874a41008
commit 06269a3952
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 4 additions and 3 deletions

View file

@ -103,7 +103,7 @@ export class Tensor implements TensorInterface {
}
case 'gpu-buffer': {
if ((type !== 'float32' && type !== 'float16' && type !== 'int32' && type !== 'int64' && type !== 'uint32' &&
type !== 'bool')) {
type !== 'uint8' && type !== 'bool')) {
throw new TypeError(`unsupported type "${type}" to create tensor from gpu buffer`);
}
this.gpuBufferData = arg0.gpuBuffer;

View file

@ -135,7 +135,7 @@ export declare namespace Tensor {
/**
* supported data types for constructing a tensor from a WebGPU buffer
*/
export type GpuBufferDataTypes = 'float32'|'float16'|'int32'|'int64'|'uint32'|'bool';
export type GpuBufferDataTypes = 'float32'|'float16'|'int32'|'int64'|'uint32'|'uint8'|'bool';
/**
* represent where the tensor data is stored

View file

@ -169,7 +169,8 @@ export const logLevelStringToEnum = (logLevel?: 'verbose'|'info'|'warning'|'erro
* Check whether the given tensor type is supported by GPU buffer
*/
export const isGpuBufferSupportedType = (type: Tensor.Type): type is Tensor.GpuBufferDataTypes => type === 'float32' ||
type === 'int32' || type === 'int64' || type === 'bool' || type === 'float16' || type === 'uint32';
type === 'float16' || type === 'int32' || type === 'int64' || type === 'uint32' || type === 'uint8' ||
type === 'bool';
/**
* Map string data location to integer value