mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-25 19:48:11 +00:00
### Description This PR is a preview of cherry-picks for ort-web to `rel-1.17.3` based on `rel-1.17.2`. <details> <summary>Changes of ort-web to cherry-pick</summary> The following commits are from main branch. `o` stands for pick, and `x` stands for skip. ``` o2e0a388c36[js/webgpu] Add HardSigmoid support (#19215) od226e40856[js/webgpu] set query type in onRunStart (#19202) o61610ff986[js/webgpu] Add FusedConv clip test case (#18900) oa33b5bd1fa[JS/WebGPU] Added Uniforms to SkipLayerNorm. (#18788) o591f90c0b9[js/webgpu] Fix issue of timestamp query (#19258) o7252c6e747[WebNN EP] Support WebNN async API with Asyncify (#19145) o5b06505073[js/webgpu] Fix Tanh explosion (#19201) o656ca66186[js/webgpu] Support uniforms for conv, conv transpose, conv grouped (#18753) oa3f0e2422b[js/webgpu] Support f16 uniform (#19098) o9e69606360fix f16 for attention, enable slice and flatten for more types (#19262) o624b4e2063[js/webgpu] Remove enableShapesUniforms (#19279) o90883a366a[js/webgpu] Add hardSigmoid activation for fusedConv (#19233) o85cef0af8c[js/webgpu] Support capture and replay for jsep (#18989) od73131cf0f[js/webgpu] Use DataType as uniform cpu type (#19281) odd1f6ccc45[js/webgpu] resolve codescan alert (#19343) o3a2ab1963a[js/webgpu] Refactor createTensorShapeVariables (#18883) oefc17e79de[js/webgpu] Fix the undefined push error (#19366) x50806a7dd5[js/web] support external data in npm test (#19377) occbe264a39[js/webgpu] Add LeakyRelu activation for fusedConv (#19369) o5ff27ef02a[js/webgpu] support customop FastGelu (#19392) x03be65e064[js/web] fix types exports in package.json (#19458) o06269a3952[js/webgpu] allow uint8 tensors for webgpu (#19545) odfeda9019c[JS/WebGPU] Add MatMulNBits (#19446) o1b48054e1b[js/webgpu] Create Split indices helpers by rank, not by shape (#19554) o3fe2c137ee[js] small fix to workaround formatter (#19400) x70567a4b3a[js/web] use ApiTensor insteadof onnxjs Tensor in TensorResultValidator (#19358) o6e04e36e3f[js/common] upgrade tsc in common from 4.9.5 to 5.2.2 (#19317) o58f4921686[js] changes to allow Float16Array if any polyfill is available (#19305) o57d6819212[js/web] Fix fused-conv is not included in npm test (#19581) oebd220b073Misspelling in README.md (#19433) o38c3432393Bump ip from 1.1.8 to 1.1.9 in /js/react_native (#19582) ofe82fccf1a[js/webgpu] Fix Conv2DTransposeMatMul f16 compilation failure (#19596) o76a2a487a1Bump ip from 1.1.8 to 1.1.9 in /js/react_native/e2e (#19583) o29b1106033[node] Switch to setImmediate to avoid starving the Node.js event loop (#19610) oae3d73c981[JS/WebGPU] Fix Split and Where to handle corner cases. (#19613) oaec2389ad0[js/webgpu] allows a ProgramInfo's RunData to use zero sized output (#19614) obb43a0f133[js/webgpu] minor fixes to make tinyllama work (#19564) o0edb035808[js/web] fix suite test list for zero sized tensor (#19638) o3cb81cdde2[js/common] move 'env.wasm.trace' to 'env.trace' (#19617) oe30618d055[js/webgpu] use Headless for webgpu test by default (#19702) of06164ef8b[js/web] transfer input buffer back to caller thread (#19677) xa788514027[js/web] dump debug logs for karma for diagnose purpose (#19785) o24b72d2613[JS/WebGPU] Preserve zero size input tensor dims. (#19737) o4538d31a8b[js/webgpu] expose a few properties in WebGPU API (#19857) o53de2d8cb0[js/webgpu] Enable GroupedConvVectorize path (#19791) oed250b88c3[JS/WebGPU] Optimize MatMulNBits (#19852) xe771a763c3[js/test] align web test runner flags with ort.env (#19790) o79e50aeef3[js/web] rewrite backend resolve to allow multiple EPs (#19735) oacb0df2280Fix #19931 broken Get Started link of "ONNX Runtime JavaScript API" page (#19932) ob29849a287[js/common] fix typedoc warnings (#19933) oafdab62f53Bump follow-redirects from 1.15.4 to 1.15.6 in /js/web (#19949) o28ad6c3955Bump follow-redirects from 1.15.4 to 1.15.6 in /js/node (#19951) o7e0d424934accumulate in fp32 for Reduce* (#19868) o4c6a6a37f7[js/webgpu] Fix NAN caused by un-initialized buffer in instance-norm (#19387) o01c7aaf6aa[js/webgpu] allow setting env.webgpu.adapter (#19940) oc45cff60cf[js/webgpu] fix maxpool / fp16 (#19981) ``` </details> <details> <summary>Cherry-pick commandlines</summary> ```sh git cherry-pick2e0a388c36git cherry-pickd226e40856git cherry-pick61610ff986git cherry-picka33b5bd1fagit cherry-pick591f90c0b9git cherry-pick7252c6e747git cherry-pick5b06505073git cherry-pick656ca66186git cherry-picka3f0e2422bgit cherry-pick9e69606360git cherry-pick624b4e2063git cherry-pick90883a366agit cherry-pick85cef0af8c#<<<<< Note: conflicts git cherry-pickd73131cf0fgit cherry-pickdd1f6ccc45git cherry-pick3a2ab1963agit cherry-pickefc17e79degit cherry-pickccbe264a39git cherry-pick5ff27ef02agit cherry-pick06269a3952git cherry-pickdfeda9019cgit cherry-pick1b48054e1bgit cherry-pick3fe2c137eegit cherry-pick6e04e36e3fgit cherry-pick58f4921686git cherry-pick57d6819212git cherry-pickebd220b073git cherry-pick38c3432393git cherry-pickfe82fccf1agit cherry-pick76a2a487a1git cherry-pick29b1106033git cherry-pickae3d73c981git cherry-pickaec2389ad0git cherry-pickbb43a0f133git cherry-pick0edb035808git cherry-pick3cb81cdde2git cherry-picke30618d055git cherry-pickf06164ef8bgit cherry-pick24b72d2613git cherry-pick4538d31a8bgit cherry-pick53de2d8cb0git cherry-picked250b88c3git cherry-pick79e50aeef3git cherry-pickacb0df2280git cherry-pickb29849a287git cherry-pickafdab62f53git cherry-pick28ad6c3955git cherry-pick7e0d424934git cherry-pick4c6a6a37f7git cherry-pick01c7aaf6aagit cherry-pickc45cff60cf``` </details> <details> <summary>Cherry-pick conflicts</summary> -85cef0af8c#18989 this change is for enabling graph capture feature for JSEP, and it is done after ROCM EP enabled graph capture feature. However, the ROCM EP graph capture feature is not cherry-picked in rel-1.17.2. </details> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Jiajia Qin <jiajia.qin@intel.com> Co-authored-by: Xu Xing <xing.xu@intel.com> Co-authored-by: satyajandhyala <satya.k.jandhyala@gmail.com> Co-authored-by: Yang Gu <yang.gu@intel.com> Co-authored-by: Wanming Lin <wanming.lin@intel.com> Co-authored-by: Jiajie Hu <jiajie.hu@intel.com> Co-authored-by: Guenther Schmuelling <guschmue@microsoft.com> Co-authored-by: Matttttt <18152455+martholomew@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Segev Finer <segev208@gmail.com> Co-authored-by: Belem Zhang <belem.zhang@intel.com>
313 lines
14 KiB
TypeScript
313 lines
14 KiB
TypeScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
import {TensorView} from '../../tensor-view';
|
|
import {PoolConvUtil} from '../../util';
|
|
import {AttributeWithCacheKey} from '../attribute-with-cache-key';
|
|
import {ComputeContext} from '../types';
|
|
|
|
import {createConv2DMatMulProgramInfo} from './3rd-party/conv2d_mm_webgpu';
|
|
import {createMatmulProgramInfo} from './3rd-party/matmul_packed_webgpu';
|
|
import {createGroupedConvProgramInfo, createGroupedConvVectorizeProgramInfo} from './conv-grouped';
|
|
import {InternalActivationAttributes, parseInternalActivationAttributes} from './fuse-utils';
|
|
import {createNaiveMatmulProgramInfo} from './matmul';
|
|
import {createTransposeProgramInfo} from './transpose';
|
|
|
|
export const calculateOutputShape =
|
|
(inputShape: readonly number[], kernelShape: readonly number[], dilations: readonly number[],
|
|
adjustPads: readonly number[], strides: readonly number[], isChannelLast: boolean): number[] => {
|
|
const batchSize = inputShape[0];
|
|
const inputSpatialShape = inputShape.slice(isChannelLast ? 1 : 2, isChannelLast ? 3 : 4);
|
|
const spatialRank = inputSpatialShape.length;
|
|
const outChannels = kernelShape[0];
|
|
const kernelSpatialShape = kernelShape.slice(2);
|
|
const dilatedKernelShape = kernelSpatialShape.map((v, i) => v + (v - 1) * (dilations[i] - 1));
|
|
const inputSpatialShapeWithPad = inputSpatialShape.map((v, i) => v + adjustPads[i] + adjustPads[i + spatialRank]);
|
|
const outputShape =
|
|
inputSpatialShapeWithPad.map((v, i) => Math.floor((v - dilatedKernelShape[i] + strides[i]) / strides[i]));
|
|
outputShape.splice(0, 0, batchSize);
|
|
outputShape.splice(isChannelLast ? 3 : 1, 0, outChannels);
|
|
return outputShape;
|
|
};
|
|
|
|
export interface ConvAttributes extends InternalActivationAttributes, AttributeWithCacheKey {
|
|
readonly autoPad: string;
|
|
readonly dilations: readonly number[];
|
|
readonly format: 'NHWC'|'NCHW';
|
|
readonly group: number;
|
|
readonly kernelShape: readonly number[];
|
|
readonly pads: readonly number[];
|
|
readonly strides: readonly number[];
|
|
readonly wIsConst: boolean;
|
|
}
|
|
|
|
// for transposing weight tensor from [M, C/group, KH, KW] to [KH, KW, C/group, M]
|
|
const weightTransposeAttribute = [2, 3, 1, 0];
|
|
|
|
const validateInputs = (inputs: readonly TensorView[], attributes: ConvAttributes): void => {
|
|
// Refer to the below link for all input checks
|
|
// https://github.com/onnx/onnx/blob/master/docs/Operators.md#Conv
|
|
if (!inputs || (inputs.length !== 2 && inputs.length !== 3)) {
|
|
throw new Error('Conv requires 2 or 3 inputs');
|
|
}
|
|
|
|
// TODO : Need to add support for multi-dimensional conv
|
|
if (inputs[0].dims.length !== 4 && inputs[0].dims.length !== 3) {
|
|
throw new Error('currently only support conv 1D and 2D');
|
|
}
|
|
|
|
if (inputs[0].dims.length !== inputs[1].dims.length) {
|
|
throw new Error('filter does not have same dimension as input');
|
|
}
|
|
|
|
// FILTER_IN_CHANNEL should be equal to DATA_CHANNEL
|
|
const dataChannel = inputs[0].dims[attributes.format === 'NHWC' ? inputs[0].dims.length - 1 : 1];
|
|
const filterInChannel = inputs[1].dims[1] * attributes.group;
|
|
if (dataChannel !== filterInChannel) {
|
|
throw new Error('FILTER_IN_CHANNEL should be equal to DATA_CHANNEL');
|
|
}
|
|
|
|
// if bias is provided it should be 1D and the number of elements should be equal to the number of feature maps
|
|
if (inputs.length === 3 && (inputs[2].dims.length !== 1 || inputs[1].dims[0] !== inputs[2].dims[0])) {
|
|
throw new Error('invalid bias');
|
|
}
|
|
|
|
const spatialRank = inputs[0].dims.length - 2;
|
|
// wrong dilations dimension
|
|
if (attributes.dilations.length !== spatialRank) {
|
|
throw new Error(`dilations should be ${spatialRank}D`);
|
|
}
|
|
|
|
// Wrong strides dimension
|
|
if (attributes.strides.length !== spatialRank) {
|
|
throw new Error(`strides should be ${spatialRank}D`);
|
|
}
|
|
|
|
// Wrong pads dimension
|
|
if (attributes.pads.length !== spatialRank * 2) {
|
|
throw new Error(`pads should be ${spatialRank * 2}D`);
|
|
}
|
|
|
|
// if kernelShape is specified, it's data length must be 2 less than dims length of the weights tensor
|
|
// (the first 2 dims are batch_size and channels)
|
|
if (attributes.kernelShape.length !== 0 && attributes.kernelShape.length !== inputs[1].dims.length - 2) {
|
|
throw new Error('invalid kernel shape');
|
|
}
|
|
};
|
|
|
|
const getAdjustedConvAttributes = <T extends ConvAttributes>(attributes: T, inputs: readonly TensorView[]): T => {
|
|
const kernelShape = attributes.kernelShape.slice();
|
|
// if kernelShape is not specified in the attributes of this op, infer it from the weight tensor dims
|
|
for (let i = 2; i < inputs[1].dims.length; ++i) {
|
|
if (kernelShape[i - 2] === 0) {
|
|
kernelShape[i - 2] = inputs[1].dims[i];
|
|
}
|
|
}
|
|
const pads = attributes.pads.slice();
|
|
PoolConvUtil.adjustPadsBasedOnAutoPad(
|
|
inputs[0].dims, attributes.strides, attributes.dilations, kernelShape, pads, attributes.format === 'NHWC',
|
|
attributes.autoPad);
|
|
|
|
// always return a new object so does not modify the original attributes
|
|
const newAttributes: T = Object.assign({}, attributes);
|
|
Object.assign(newAttributes, {kernelShape, pads});
|
|
return newAttributes;
|
|
};
|
|
|
|
export const parseConvAttributes = (attributes: Record<string, unknown>): ConvAttributes => {
|
|
const activationAttributes = parseInternalActivationAttributes(attributes);
|
|
// TODO : Make this generic enough to compute default attributes for multi-dimensional conv
|
|
const format = attributes.format as 'NHWC' | 'NCHW';
|
|
const autoPad = ['NOTSET', 'VALID', 'SAME_UPPER', 'SAME_LOWER'][attributes.auto_pad as number];
|
|
const dilations = attributes.dilations as [number, number];
|
|
const group = attributes.group as number;
|
|
const kernelShape = attributes.kernel_shape as [number, number];
|
|
const pads = attributes.pads as [number, number, number, number];
|
|
const strides = attributes.strides as [number, number];
|
|
const wIsConst = (attributes.w_is_const as () => boolean)();
|
|
|
|
return {
|
|
autoPad,
|
|
format,
|
|
dilations,
|
|
group,
|
|
kernelShape,
|
|
pads,
|
|
strides,
|
|
wIsConst,
|
|
...activationAttributes,
|
|
cacheKey: `${attributes.format};${activationAttributes.activation};`
|
|
};
|
|
};
|
|
|
|
const conv2d = (context: ComputeContext, inputs: readonly TensorView[], attributes: ConvAttributes): void => {
|
|
const adjustedAttributes = getAdjustedConvAttributes(attributes, inputs);
|
|
|
|
// check attributes
|
|
|
|
// const hasPreluActivationWeights = false; /* TODO: add support for prelu activation weights */
|
|
const isChannelsLast = attributes.format === 'NHWC';
|
|
if (attributes.group !== 1) {
|
|
// NVIDIA GPU with ampere architecture fails with below 2 cases, but we couldn't repro them with any other
|
|
// GPUs. So just disable vectorize on NVIDIA ampere to ensure always correct outputs.
|
|
// [webgpu]Conv - conv - vectorize group - B
|
|
// [webgpu]Conv - conv - vectorize group - D
|
|
const enableGroupedConvVectorize = !context.adapterInfo.isArchitecture('ampere');
|
|
if (enableGroupedConvVectorize && isChannelsLast && inputs[1].dims[0] === attributes.group &&
|
|
inputs[1].dims[1] === 1 && attributes.dilations[0] === 1 && attributes.dilations[1] === 1) {
|
|
const outputShape = calculateOutputShape(
|
|
inputs[0].dims, inputs[1].dims, attributes.dilations, adjustedAttributes.pads, attributes.strides,
|
|
isChannelsLast);
|
|
const transposedWeight = (context.kernelCustomData.wT as TensorView | undefined) ??
|
|
context.compute(
|
|
createTransposeProgramInfo(inputs[1], weightTransposeAttribute),
|
|
{inputs: [1], outputs: [attributes.wIsConst ? -2 : -1]})[0];
|
|
if (attributes.wIsConst && !context.kernelCustomData.wT) {
|
|
context.kernelCustomData.wT = transposedWeight;
|
|
}
|
|
const convInputs = [inputs[0], transposedWeight];
|
|
if (inputs.length === 3) {
|
|
convInputs.push(inputs[2]);
|
|
}
|
|
context.compute(
|
|
createGroupedConvVectorizeProgramInfo(convInputs, adjustedAttributes, outputShape), {inputs: convInputs});
|
|
} else {
|
|
context.compute(createGroupedConvProgramInfo(inputs, adjustedAttributes));
|
|
}
|
|
return;
|
|
}
|
|
|
|
const hasBias = inputs.length === 3;
|
|
const inputHeight = inputs[0].dims[isChannelsLast ? 1 : 2];
|
|
const inputWidth = inputs[0].dims[isChannelsLast ? 2 : 3];
|
|
const inputChannels = inputs[0].dims[isChannelsLast ? 3 : 1];
|
|
const weightHeight = inputs[1].dims[2];
|
|
const weightWidth = inputs[1].dims[3];
|
|
|
|
const outputShape = calculateOutputShape(
|
|
inputs[0].dims, inputs[1].dims, attributes.dilations, adjustedAttributes.pads, attributes.strides,
|
|
isChannelsLast);
|
|
const outHeight = outputShape[isChannelsLast ? 1 : 2];
|
|
const outWidth = outputShape[isChannelsLast ? 2 : 3];
|
|
const outChannels = outputShape[isChannelsLast ? 3 : 1];
|
|
|
|
const sameSize = isChannelsLast && weightHeight === inputHeight && weightWidth === inputWidth &&
|
|
attributes.pads[0] === 0 && attributes.pads[1] === 0;
|
|
if (sameSize ||
|
|
(weightHeight === 1 && weightWidth === 1 && attributes.dilations[0] === 1 && attributes.dilations[1] === 1 &&
|
|
attributes.strides[0] === 1 && attributes.strides[1] === 1 && attributes.pads[0] === 0 &&
|
|
attributes.pads[1] === 0)) {
|
|
// conv2dByMatMul
|
|
const batch = outputShape[0];
|
|
let xReshaped, wReshaped, matmulOutputShape;
|
|
const matmulInputs = [];
|
|
if (isChannelsLast) {
|
|
const transposedWeight = (context.kernelCustomData.wT as TensorView | undefined) ??
|
|
context.compute(
|
|
createTransposeProgramInfo(inputs[1], weightTransposeAttribute),
|
|
{inputs: [1], outputs: [attributes.wIsConst ? -2 : -1]})[0];
|
|
if (attributes.wIsConst && !context.kernelCustomData.wT) {
|
|
context.kernelCustomData.wT = transposedWeight;
|
|
}
|
|
if (sameSize) {
|
|
const sharedDim = inputHeight * inputWidth * inputChannels;
|
|
xReshaped = inputs[0].reshape([1, batch, sharedDim]);
|
|
wReshaped = transposedWeight.reshape([1, sharedDim, outChannels]);
|
|
matmulOutputShape = [1, batch, outChannels];
|
|
} else {
|
|
xReshaped = inputs[0].reshape([batch, inputHeight * inputWidth, inputChannels]);
|
|
wReshaped = transposedWeight.reshape([1, inputChannels, outChannels]);
|
|
matmulOutputShape = [batch, outHeight * outWidth, outChannels];
|
|
}
|
|
matmulInputs.push(xReshaped);
|
|
matmulInputs.push(wReshaped);
|
|
} else {
|
|
xReshaped = inputs[0].reshape([batch, inputChannels, inputHeight * inputWidth]);
|
|
wReshaped = inputs[1].reshape([1, outChannels, inputChannels]);
|
|
matmulOutputShape = [batch, outChannels, outHeight * outWidth];
|
|
matmulInputs.push(wReshaped);
|
|
matmulInputs.push(xReshaped);
|
|
}
|
|
if (hasBias) {
|
|
matmulInputs.push(inputs[2]);
|
|
}
|
|
const N = matmulOutputShape[2];
|
|
const K = matmulInputs[0].dims[matmulInputs[0].dims.length - 1];
|
|
// Tune the threshold.
|
|
if (N < 8 && K < 8) {
|
|
context.compute(
|
|
createNaiveMatmulProgramInfo(
|
|
matmulInputs, adjustedAttributes, outputShape, matmulOutputShape, isChannelsLast),
|
|
{inputs: matmulInputs});
|
|
} else {
|
|
context.compute(
|
|
createMatmulProgramInfo(matmulInputs, adjustedAttributes, outputShape, matmulOutputShape, isChannelsLast),
|
|
{inputs: matmulInputs});
|
|
}
|
|
return;
|
|
}
|
|
|
|
// TODO: implement conv2dWithIm2Col()
|
|
|
|
const sequentialAccessByThreads = /* backend.adapterInfo.isIntel() */ true;
|
|
|
|
// STEP.1: transpose weight
|
|
const transposedWeight = (context.kernelCustomData.wT as TensorView | undefined) ??
|
|
context.compute(
|
|
createTransposeProgramInfo(inputs[1], weightTransposeAttribute),
|
|
{inputs: [1], outputs: [attributes.wIsConst ? -2 : -1]})[0];
|
|
if (attributes.wIsConst && !context.kernelCustomData.wT) {
|
|
context.kernelCustomData.wT = transposedWeight;
|
|
}
|
|
|
|
// STEP.2: prepare reshaped inputs
|
|
const convInputs = [inputs[0], transposedWeight];
|
|
if (hasBias) {
|
|
convInputs.push(inputs[2]);
|
|
}
|
|
|
|
// STEP.3: compute matmul
|
|
const dimAOuter = isChannelsLast ? outHeight * outWidth : outChannels;
|
|
const dimBOuter = isChannelsLast ? outChannels : outHeight * outWidth;
|
|
const dimInner = weightHeight * weightWidth * inputChannels;
|
|
context.compute(
|
|
createConv2DMatMulProgramInfo(
|
|
convInputs, adjustedAttributes, outputShape, dimAOuter, dimBOuter, dimInner, hasBias,
|
|
sequentialAccessByThreads),
|
|
{inputs: convInputs});
|
|
};
|
|
|
|
const conv1d = (context: ComputeContext, attributes: ConvAttributes): void => {
|
|
// extend the input to 2D by adding H dimension
|
|
const isChannelLast = attributes.format === 'NHWC';
|
|
const inputs = [
|
|
context.inputs[0].reshape(
|
|
isChannelLast ?
|
|
// [N, W, C] -> [N, H=1, W, C]
|
|
[context.inputs[0].dims[0], 1, context.inputs[0].dims[1], context.inputs[0].dims[2]] :
|
|
// [N, C, W] -> [N, C, H=1, W]
|
|
[context.inputs[0].dims[0], context.inputs[0].dims[1], 1, context.inputs[0].dims[2]]),
|
|
//[FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, kW] -> [FILTER_OUT_CHANNEL, FILTER_IN_CHANNEL, kH=1, kW]
|
|
context.inputs[1].reshape([context.inputs[1].dims[0], context.inputs[1].dims[1], 1, context.inputs[1].dims[2]])
|
|
];
|
|
if (context.inputs.length === 3) {
|
|
inputs.push(context.inputs[2]);
|
|
}
|
|
const pads = [0, attributes.pads[0], 0, attributes.pads[1]];
|
|
const strides = [1].concat(attributes.strides);
|
|
const dilations = [1].concat(attributes.dilations);
|
|
const kernelShape = [1].concat(attributes.kernelShape);
|
|
const adjustedAttributes = getAdjustedConvAttributes({...attributes, pads, strides, dilations, kernelShape}, inputs);
|
|
context.compute(createGroupedConvProgramInfo(
|
|
inputs, adjustedAttributes,
|
|
outputShape => isChannelLast ? [outputShape[0], outputShape[2], outputShape[3]] : []));
|
|
};
|
|
|
|
export const conv = (context: ComputeContext, attributes: ConvAttributes): void => {
|
|
validateInputs(context.inputs, attributes); // currently will fail if not conv1D/2D
|
|
if (context.inputs[0].dims.length === 3) {
|
|
conv1d(context, attributes);
|
|
} else {
|
|
conv2d(context, context.inputs, attributes);
|
|
}
|
|
};
|