Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js/webgpu] Enable GroupedConvVectorize path #19791

Merged
merged 6 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use interface in types.ts and restrict strings of architecture and ve…
…ndor
  • Loading branch information
gyagp committed Mar 11, 2024
commit d4e26d155c668b67a8a0b9412cab35caac1182fc
23 changes: 8 additions & 15 deletions js/web/lib/wasm/jsep/backend-webgpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {createView, TensorView} from './tensor-view';
import {createGpuDataManager, downloadGpuData, GpuDataManager} from './webgpu/gpu-data-manager';
import {RunFunction, WEBGPU_OP_RESOLVE_RULES} from './webgpu/op-resolve-rules';
import {ProgramManager} from './webgpu/program-manager';
import {ComputeContext, GpuData, ProgramInfo, ProgramInputTensorInfoDependency, SessionState, TimestampQuery} from './webgpu/types';
import {AdapterInfo, ComputeContext, GpuArchitecture, GpuData, GpuVendor, ProgramInfo, ProgramInputTensorInfoDependency, SessionState, TimestampQuery} from './webgpu/types';

interface CommandInfo {
readonly kernelId: number;
Expand Down Expand Up @@ -94,13 +94,9 @@ const getProgramInfoUniqueKey =
return key;
};


/**
* this class is designed for info and related helper functions of the GPU adapter in use
*/
export class AdapterInfo {
private architecture: string;
private vendor: string;
class AdapterInfoImpl implements AdapterInfo {
readonly architecture: string;
gyagp marked this conversation as resolved.
Show resolved Hide resolved
readonly vendor: string;

constructor(adapterInfo: GPUAdapterInfo) {
if (adapterInfo) {
Expand All @@ -109,16 +105,14 @@ export class AdapterInfo {
}
}

// architecture could be ampere, gen12-lp, etc.
isArchitecture(architecture: string): boolean {
isArchitecture(architecture: GpuArchitecture): boolean {
if (typeof this.architecture === 'undefined') {
return false;
}
return this.architecture === architecture;
}

// vendor could be amd, intel, nvidia, etc.
isVendor(vendor: string): boolean {
isVendor(vendor: GpuVendor): boolean {
if (typeof this.vendor === 'undefined') {
return false;
}
Expand All @@ -131,7 +125,7 @@ export class AdapterInfo {
* the first parameter so that it is stored for future use.
*/
export class WebGpuBackend {
adapterInfo: AdapterInfo;
adapterInfo: AdapterInfoImpl;
device: GPUDevice;
/**
* an instance of GpuDataManager to manage a GpuDataId -> GpuBuffer mapping
Expand Down Expand Up @@ -245,8 +239,7 @@ export class WebGpuBackend {
}

this.device = await adapter.requestDevice(deviceDescriptor);
const adapterInfo = await adapter.requestAdapterInfo();
this.adapterInfo = new AdapterInfo(adapterInfo);
this.adapterInfo = new AdapterInfoImpl(await adapter.requestAdapterInfo());
this.gpuDataManager = createGpuDataManager(this);
this.programManager = new ProgramManager(this);
this.kernels = new Map();
Expand Down
4 changes: 2 additions & 2 deletions js/web/lib/wasm/jsep/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {Env} from 'onnxruntime-common';
import {OrtWasmModule} from '../binding/ort-wasm';
import {DataType, getTensorElementSize} from '../wasm-common';

import {AdapterInfo, WebGpuBackend} from './backend-webgpu';
import {WebGpuBackend} from './backend-webgpu';
import {LOG_DEBUG} from './log';
import {TensorView} from './tensor-view';
import {ShapeUtil} from './util';
import {ComputeContext, ComputeContextInputsOutputsMapping, ProgramInfo} from './webgpu/types';
import {AdapterInfo, ComputeContext, ComputeContextInputsOutputsMapping, ProgramInfo} from './webgpu/types';

/* eslint-disable no-bitwise */

Expand Down
5 changes: 3 additions & 2 deletions js/web/lib/wasm/jsep/webgpu/ops/conv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ const conv2d = (context: ComputeContext, inputs: readonly TensorView[], attribut
// const hasPreluActivationWeights = false; /* TODO: add support for prelu activation weights */
const isChannelsLast = attributes.format === 'NHWC';
if (attributes.group !== 1) {
// One CI with NVIDIA GPU (ampere architecutre) fails with below 2 cases, but we couldn't repro them with any other GPUs, including NVIDIA ones.
// One CI with NVIDIA GPU (ampere architecutre) fails with below 2 cases, but we couldn't repro them with any other
// GPUs, including NVIDIA ones.
// [webgpu]Conv - conv - vectorize group - B
// [webgpu]Conv - conv - vectorize group - D
// Disable vectorize on NVIDIA ampere to make bots happy. BTW, no obvious perf gain with vectorize is seen on NVIDIA GPUs.
// Disable vectorize on NVIDIA ampere to make bots happy.
fs-eire marked this conversation as resolved.
Show resolved Hide resolved
const enableGroupedConvVectorize = context.adapterInfo.isArchitecture('ampere') ? false : true;
gyagp marked this conversation as resolved.
Show resolved Hide resolved
if (enableGroupedConvVectorize && isChannelsLast && inputs[1].dims[0] === attributes.group &&
inputs[1].dims[1] === 1 && attributes.dilations[0] === 1 && attributes.dilations[1] === 1) {
Expand Down
11 changes: 10 additions & 1 deletion js/web/lib/wasm/jsep/webgpu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

import {DataType} from '../../wasm-common';
import {AdapterInfo} from '../backend-webgpu'
import {TensorView} from '../tensor-view';

import {ShaderHelper} from './ops/common';
Expand All @@ -16,6 +15,16 @@ export enum GpuDataType {
}
export type GpuDataId = number;

export type GpuArchitecture = 'ampere';
export type GpuVendor = 'amd'|'intel'|'nvidia';
export interface AdapterInfo {
readonly architecture: string;
readonly vendor: string;
gyagp marked this conversation as resolved.
Show resolved Hide resolved

isArchitecture: (architecture: GpuArchitecture) => boolean;
isVendor: (vendor: GpuVendor) => boolean;
}

export interface GpuData {
type: GpuDataType;
id: GpuDataId;
Expand Down