diff --git a/metal/paddle-mobile/paddle-mobile/Src/Framework/Texture.swift b/metal/paddle-mobile/paddle-mobile/Src/Framework/Texture.swift index c99b545f396ad2dd721c5e01a217517223fbbe12..63250fa085c07848848c60256a78f105df9d2ea6 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Framework/Texture.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Framework/Texture.swift @@ -71,6 +71,7 @@ extension InputTexture { public class Texture: Tensorial { public var dim: Dim public var tensorDim: Dim + public var useMPS = false /// tensor dim pad to four public var padToFourDim: Dim @@ -135,14 +136,22 @@ public class Texture: Tensorial { } if computePrecision == .Float16 { - if tensorDim[1] == 1 { - tmpTextureDes.pixelFormat = .r16Float + if useMPS { + if tensorDim[1] == 1 { + tmpTextureDes.pixelFormat = .r16Float + } else { + tmpTextureDes.pixelFormat = .rgba16Float + } } else { tmpTextureDes.pixelFormat = .rgba16Float } } else if computePrecision == .Float32 { - if tensorDim[1] == 1 { - tmpTextureDes.pixelFormat = .r32Float + if useMPS { + if tensorDim[1] == 1 { + tmpTextureDes.pixelFormat = .r32Float + } else { + tmpTextureDes.pixelFormat = .rgba32Float + } } else { tmpTextureDes.pixelFormat = .rgba32Float } diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift index e4fa5b1d67ad0ffc88bfe934cc24d3cb9f14e869..0e893d35e6475d967f3de883b2236b687bacd776 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift @@ -112,8 +112,14 @@ class ConvAddKernel: Kernel, Computable { var shouldUseMPS = false let functionName = type(of: self).kernelFunctionName(param: param, useAggressiveOptimization: initContext.useAggresiveOptimization) if #available(iOS 11.0, *), (initContext.useMPS || initContext.useAggresiveOptimization) { - if (param.input.tensorDim[1] == 1 || param.input.tensorDim[1] > 4) && (param.output.tensorDim[1] == 1 || param.output.tensorDim[1] > 4) { - shouldUseMPS = true + if initContext.useAggresiveOptimization { + if (param.input.tensorDim[1] == 1 || param.input.tensorDim[1] > 4) && (param.output.tensorDim[1] == 1 || param.output.tensorDim[1] > 4) { + shouldUseMPS = true + } + } else { + if param.input.tensorDim[1] > 4 && param.output.tensorDim[1] > 4 { + shouldUseMPS = true + } } } if type(of: self).isWinoGrad(functionName: functionName) { @@ -166,6 +172,8 @@ class ConvAddKernel: Kernel, Computable { let isDepthWise = param.filter.tensorDim[1] == 1 && param.filter.tensorDim[0] == param.input.tensorDim[1] if #available(iOS 11.0, *) { + param.input.useMPS = true + param.output.useMPS = true let desc: MPSCNNConvolutionDescriptor = isDepthWise ? MPSCNNDepthWiseConvolutionDescriptor(kernelWidth: param.filter.tensorDim[3], kernelHeight: param.filter.tensorDim[2],