From c3c6cbd3ee3fbcca486565fd46f8e92c956dde88 Mon Sep 17 00:00:00 2001 From: Yanzhan Yang Date: Fri, 10 May 2019 20:01:39 +0800 Subject: [PATCH] change pixelFormat only when useAggressiveOptimization is set (#1614) --- .../paddle-mobile/Src/Framework/Texture.swift | 17 +++++++++++++---- .../Src/Operators/Kernels/ConvAddKernel.swift | 12 ++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/metal/paddle-mobile/paddle-mobile/Src/Framework/Texture.swift b/metal/paddle-mobile/paddle-mobile/Src/Framework/Texture.swift index c99b545f39..63250fa085 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 e4fa5b1d67..0e893d35e6 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], -- GitLab