license import { backend_util , DepthwiseConv2dNative , DepthwiseConv2dNativeAttrs , DepthwiseConv2dNativeInputs , env , KernelConfig , KernelFunc , util } from '@tensorflow/tfjs-core' ; import { MathBackendWebGL } from '../backend_webgl' ; import { DepthwiseConv2DProgram } from '../conv_gpu_depthwise' ; import { DepthwiseConvPacked2DProgram } from '../conv_packed_gpu_depthwise' ; export function depthwiseConv2dNative ( args ) { const { inputs , backend , attrs } = args ; const { x , filter } = inputs ; const { strides , pad , dilations , dimRoundingMode } = attrs ; let $dilations = dilations ; if ( $dilations == null ) { $dilations = [ 1 , 1 ] ; } util . assert ( backend_util . eitherStridesOrDilationsAreOne ( strides , $dilations ) , ( ) => 'Error in depthwiseConv2d: Either strides or dilations must be ' + `1. Got strides ${ strides } and dilations '${ $dilations }'` ) ; const convInfo = backend_util . computeConv2DInfo ( x . shape as [ number , number , number , number ] , filter . shape as [ number , number , number , number ] , strides , $dilations , pad , dimRoundingMode , true ) ; let program ; if ( env ( ) . getBool ( 'WEBGL_PACK_DEPTHWISECONV' ) && convInfo . strideWidth <= 2 && convInfo . outChannels / convInfo . inChannels === 1 ) { program = new DepthwiseConvPacked2DProgram ( convInfo ) ; } else { program = new DepthwiseConv2DProgram ( convInfo ) ; } const customValues = [ [ convInfo . padInfo . top , convInfo . padInfo . left ] , [ convInfo . strideHeight , convInfo . strideWidth ] , [ convInfo . dilationHeight , convInfo . dilationWidth ] , [ convInfo . inHeight , convInfo . inWidth ] ] ; return backend . runWebGLProgram ( program , [ x , filter ] , 'float32' , customValues ) ; } export const depthwiseConv2dNativeConfig = { kernelName : DepthwiseConv2dNative , backendName : 'webgl' , kernelFunc : depthwiseConv2dNative as { } as KernelFunc , } ;