From 477e3710ccdd2c450a667c757d287353717331f0 Mon Sep 17 00:00:00 2001 From: liuruilong Date: Thu, 7 Mar 2019 23:11:44 +0800 Subject: [PATCH] support 16bit params --- .../project.pbxproj | 16 +++ .../paddle-mobile-demo/Net/YoloNet.swift | 7 +- .../paddle-mobile/API/GlobalConfig.swift | 4 +- .../paddle-mobile/paddle-mobile/API/Net.swift | 3 + .../paddle-mobile/API/Runner.swift | 20 ++- .../Src/Common/MetalExtension.swift | 2 +- .../paddle-mobile/Src/Common/Tools.swift | 2 +- .../paddle-mobile/Src/Common/Types.swift | 107 ++++------------ .../Src/Framework/Executor.swift | 7 +- .../paddle-mobile/Src/Framework/Loader.swift | 11 +- .../paddle-mobile/Src/Framework/Tensor.swift | 115 +++++++++++------- .../paddle-mobile/Src/Framework/Texture.swift | 4 +- .../Src/Operators/Base/OpCreator.swift | 2 +- .../Src/Operators/Base/OpParam.swift | 2 +- .../Src/Operators/BatchNormOp.swift | 4 +- .../Src/Operators/BilinearInterpOp.swift | 4 +- .../Src/Operators/BoxcoderOp.swift | 4 +- .../Src/Operators/ConcatOp.swift | 4 +- .../Src/Operators/ConvAddAddPreluOp.swift | 4 +- .../Operators/ConvAddBatchNormReluOp.swift | 4 +- .../Src/Operators/ConvAddOp.swift | 4 +- .../Src/Operators/ConvAddPreluOp.swift | 4 +- .../Src/Operators/ConvBNReluOp.swift | 4 +- .../paddle-mobile/Src/Operators/ConvOp.swift | 4 +- .../Src/Operators/ConvTransposeOp.swift | 4 +- .../Src/Operators/DepthwiseConvOp.swift | 2 +- .../Src/Operators/DwConvBNReluOp.swift | 2 +- .../Src/Operators/ElementwiseAddOp.swift | 4 +- .../Src/Operators/ElementwiseAddPreluOp.swift | 4 +- .../paddle-mobile/Src/Operators/FeedOp.swift | 4 +- .../paddle-mobile/Src/Operators/FetchOp.swift | 4 +- .../Src/Operators/FlattenOp.swift | 4 +- .../Operators/Kernels/BatchNormKernel.swift | 2 +- .../Kernels/BilinearInterpKernel.swift | 2 +- .../Operators/Kernels/BoxcoderKernel.swift | 2 +- .../Src/Operators/Kernels/ConcatKernel.swift | 2 +- .../Kernels/ConvAddAddPreluKernel.swift | 2 +- .../Kernels/ConvAddBatchNormReluKernel.swift | 2 +- .../Src/Operators/Kernels/ConvAddKernel.swift | 2 +- .../Kernels/ConvAddPreluKernel.swift | 2 +- .../Operators/Kernels/ConvBNReluKernel.swift | 2 +- .../Src/Operators/Kernels/ConvKernel.swift | 4 +- .../Kernels/ConvTransposeKernel.swift | 2 +- .../Kernels/ElementwiseAddKernel.swift | 2 +- .../Kernels/ElementwiseAddPreluKernel.swift | 2 +- .../Src/Operators/Kernels/FetchKernel.swift | 2 +- .../Src/Operators/Kernels/FlattenKernel.swift | 2 +- .../Kernels/MulticlassNMSKernel.swift | 2 +- .../Src/Operators/Kernels/PoolKernel.swift | 2 +- .../Src/Operators/Kernels/PreluKernel.swift | 2 +- .../Operators/Kernels/PriorBoxKernel.swift | 2 +- .../Src/Operators/Kernels/ReluKernel.swift | 2 +- .../Src/Operators/Kernels/ReshapeKernel.swift | 2 +- .../Kernels/ResizeBilinearKernel.swift | 2 +- .../Src/Operators/Kernels/ShapeKernel.swift | 2 +- .../Src/Operators/Kernels/SoftmaxKernel.swift | 2 +- .../Src/Operators/Kernels/SplitKernel.swift | 2 +- .../Kernels/Texture2DTo2DArrayKernel.swift | 2 +- .../Operators/Kernels/TransposeKernel.swift | 2 +- .../Src/Operators/MulticlassNMSOp.swift | 8 +- .../paddle-mobile/Src/Operators/PoolOp.swift | 4 +- .../paddle-mobile/Src/Operators/PreluOp.swift | 4 +- .../Src/Operators/PriorBoxOp.swift | 4 +- .../paddle-mobile/Src/Operators/ReluOp.swift | 4 +- .../Src/Operators/ReshapeOp.swift | 4 +- .../Src/Operators/ResizeBilinearOp.swift | 4 +- .../paddle-mobile/Src/Operators/ShapeOp.swift | 4 +- .../Src/Operators/SoftmaxOp.swift | 4 +- .../paddle-mobile/Src/Operators/SplitOp.swift | 4 +- .../Src/Operators/TransposeOp.swift | 4 +- .../Src/Program/ProgramOptimize.swift | 2 +- 71 files changed, 245 insertions(+), 231 deletions(-) diff --git a/metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj b/metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj index 149956653b..d3f8d02b81 100644 --- a/metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj +++ b/metal/paddle-mobile-demo/paddle-mobile-demo.xcodeproj/project.pbxproj @@ -44,6 +44,8 @@ FC9797C321D608E000F2FD90 /* mobilenet_params in Resources */ = {isa = PBXBuildFile; fileRef = FC9797C121D608DF00F2FD90 /* mobilenet_params */; }; FC9797C721D609FB00F2FD90 /* synset.txt in Resources */ = {isa = PBXBuildFile; fileRef = FC9797C621D609FB00F2FD90 /* synset.txt */; }; FC9797CF21D6506F00F2FD90 /* mingren.jpg in Resources */ = {isa = PBXBuildFile; fileRef = FC9797CE21D6506F00F2FD90 /* mingren.jpg */; }; + FCAFD84B2231614200496A36 /* yolo_16_param in Resources */ = {isa = PBXBuildFile; fileRef = FCAFD8492231614200496A36 /* yolo_16_param */; }; + FCAFD84C2231614200496A36 /* yolo_16_model in Resources */ = {isa = PBXBuildFile; fileRef = FCAFD84A2231614200496A36 /* yolo_16_model */; }; FCBCCC552122EF5500D94F7E /* MetalHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCBCCC542122EF5400D94F7E /* MetalHelper.swift */; }; FCC15E15221E716500DC3CB2 /* paddle-mobile-metallib.metallib in Resources */ = {isa = PBXBuildFile; fileRef = FCC15E14221E716400DC3CB2 /* paddle-mobile-metallib.metallib */; }; FCCED60521D7646E00BE8D5F /* test_image_super in Resources */ = {isa = PBXBuildFile; fileRef = FCCED60421D7646E00BE8D5F /* test_image_super */; }; @@ -114,6 +116,8 @@ FC9797C121D608DF00F2FD90 /* mobilenet_params */ = {isa = PBXFileReference; lastKnownFileType = file; path = mobilenet_params; sourceTree = ""; }; FC9797C621D609FB00F2FD90 /* synset.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = synset.txt; sourceTree = ""; }; FC9797CE21D6506F00F2FD90 /* mingren.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = mingren.jpg; sourceTree = ""; }; + FCAFD8492231614200496A36 /* yolo_16_param */ = {isa = PBXFileReference; lastKnownFileType = file; path = yolo_16_param; sourceTree = ""; }; + FCAFD84A2231614200496A36 /* yolo_16_model */ = {isa = PBXFileReference; lastKnownFileType = file; path = yolo_16_model; sourceTree = ""; }; FCBCCC542122EF5400D94F7E /* MetalHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalHelper.swift; sourceTree = ""; }; FCC15E14221E716400DC3CB2 /* paddle-mobile-metallib.metallib */ = {isa = PBXFileReference; lastKnownFileType = "archive.metal-library"; name = "paddle-mobile-metallib.metallib"; path = "../../../../Library/Developer/Xcode/DerivedData/paddle-mobile-hdsimtkoxoondndnjczkbkchcwyh/Build/Products/Release-iphoneos/paddle-mobile-metallib.metallib"; sourceTree = ""; }; FCCED60421D7646E00BE8D5F /* test_image_super */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_image_super; sourceTree = ""; }; @@ -263,6 +267,7 @@ FC704C1B21D237FC00F98BAB /* vision_model */ = { isa = PBXGroup; children = ( + FCAFD8482231614200496A36 /* yolo_16 */, FC704C1C21D237FC00F98BAB /* mobilenet */, FC704C1F21D237FC00F98BAB /* yolo */, ); @@ -322,6 +327,15 @@ path = mobilenet; sourceTree = ""; }; + FCAFD8482231614200496A36 /* yolo_16 */ = { + isa = PBXGroup; + children = ( + FCAFD8492231614200496A36 /* yolo_16_param */, + FCAFD84A2231614200496A36 /* yolo_16_model */, + ); + path = yolo_16; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -388,6 +402,7 @@ FC039B8C20E11C560081E9F8 /* LaunchScreen.storyboard in Resources */, FC9797CF21D6506F00F2FD90 /* mingren.jpg in Resources */, FC704C2221D237FC00F98BAB /* combined_mobilenet_params in Resources */, + FCAFD84B2231614200496A36 /* yolo_16_param in Resources */, FC704C1921D2375300F98BAB /* super_params in Resources */, FC2BFCBE21DF15D900C262B2 /* 123.jpg in Resources */, FC039B8920E11C560081E9F8 /* Assets.xcassets in Resources */, @@ -397,6 +412,7 @@ FC704C1A21D2375300F98BAB /* super_model in Resources */, FC039B8720E11C550081E9F8 /* Main.storyboard in Resources */, FC9797C221D608E000F2FD90 /* mobilenet_model in Resources */, + FCAFD84C2231614200496A36 /* yolo_16_model in Resources */, FC2BFCC021DF279900C262B2 /* classify-img-output.png in Resources */, FC203FB221CBFDBA00B37166 /* test.jpg in Resources */, FCC15E15221E716500DC3CB2 /* paddle-mobile-metallib.metallib in Resources */, diff --git a/metal/paddle-mobile-demo/paddle-mobile-demo/Net/YoloNet.swift b/metal/paddle-mobile-demo/paddle-mobile-demo/Net/YoloNet.swift index ae3449205e..54a5e465fd 100644 --- a/metal/paddle-mobile-demo/paddle-mobile-demo/Net/YoloNet.swift +++ b/metal/paddle-mobile-demo/paddle-mobile-demo/Net/YoloNet.swift @@ -20,12 +20,13 @@ public class YoloNet: Net { @objc public override init(device: MTLDevice) { super.init(device: device) except = 0 - modelPath = Bundle.main.path(forResource: "yolo_model", ofType: nil) ?! "model null" - paramPath = Bundle.main.path(forResource: "yolo_params", ofType: nil) ?! "para null" + modelPath = Bundle.main.path(forResource: "yolo_16_model", ofType: nil) ?! "model null" + paramPath = Bundle.main.path(forResource: "yolo_16_param", ofType: nil) ?! "para null" inputDim = Dim.init(inDim: [1, 416, 416, 3]) metalLoadMode = .LoadMetalInCustomMetalLib metalLibPath = Bundle.main.path(forResource: "paddle-mobile-metallib", ofType: "metallib") - useMPS = true + useMPS = false + paramPrecision = .Float16 } override public func resultStr(res: [ResultHolder]) -> String { diff --git a/metal/paddle-mobile/paddle-mobile/API/GlobalConfig.swift b/metal/paddle-mobile/paddle-mobile/API/GlobalConfig.swift index 220b0cea79..57b4f82017 100644 --- a/metal/paddle-mobile/paddle-mobile/API/GlobalConfig.swift +++ b/metal/paddle-mobile/paddle-mobile/API/GlobalConfig.swift @@ -21,7 +21,7 @@ import Foundation LoadMetalInCustomMetalLib = 3 // 使用 metal 库文件 } -@objc public enum ComputePrecision: Int { +@objc public enum Precision: Int { case Float32 = 1, Float16 = 2 @@ -33,7 +33,7 @@ import Foundation @objc public static let shared: GlobalConfig = GlobalConfig.init() /// 运算精度, runner 生命周期中不可变 - @objc public var computePrecision: ComputePrecision = .Float16 + @objc public var computePrecision: Precision = .Float16 /// 是否开启 log @objc public var debug: Bool = false diff --git a/metal/paddle-mobile/paddle-mobile/API/Net.swift b/metal/paddle-mobile/paddle-mobile/API/Net.swift index 1b42ba0a4b..35cd09eb49 100644 --- a/metal/paddle-mobile/paddle-mobile/API/Net.swift +++ b/metal/paddle-mobile/paddle-mobile/API/Net.swift @@ -59,6 +59,9 @@ import Foundation /// 是否使用 MetalPerformanceShaders 进行运算 @objc public var useMPS: Bool = false + /// 模型精度 - 当使用模型精度为 Float 16 时 不要开启 useMPS, 暂不支持 + @objc public var paramPrecision: Precision = .Float32 + @objc public init(device: MTLDevice, inParamPointer: UnsafeMutableRawPointer, inParamSize:Int, inModelPointer: UnsafeMutableRawPointer, inModelSize: Int) { self.paramPointer = inParamPointer self.paramSize = inParamSize diff --git a/metal/paddle-mobile/paddle-mobile/API/Runner.swift b/metal/paddle-mobile/paddle-mobile/API/Runner.swift index 0b9ee0a679..a0c7ec6864 100644 --- a/metal/paddle-mobile/paddle-mobile/API/Runner.swift +++ b/metal/paddle-mobile/paddle-mobile/API/Runner.swift @@ -34,7 +34,7 @@ import Foundation @objc public class Runner: NSObject { var program: Program? - var executor: Executor? + var executor: Executorable? var queue: MTLCommandQueue? var textureLoader: MTKTextureLoader? public let net: Net @@ -68,7 +68,14 @@ import Foundation print(" paddle mobile gpu load error, need MTLCommandQueue") return false } - let loader = Loader.init() + var loader: Loaderable + switch net.paramPrecision { + case .Float16: + loader = Loader.init() + case .Float32: + loader = Loader.init() + } + do { if let inParamPointer = net.paramPointer, let inModelPointer = net.modelPointer { @@ -89,7 +96,13 @@ import Foundation initContext.metalLibPath = net.metalLibPath initContext.useMPS = net.useMPS - executor = try Executor.init(inDevice: inDevice, inQueue: inQueue, inProgram: program!, initContext: initContext) + switch net.paramPrecision { + case .Float16: + executor = try Executor.init(inDevice: inDevice, inQueue: inQueue, inProgram: program!, initContext: initContext) + case .Float32: + executor = try Executor.init(inDevice: inDevice, inQueue: inQueue, inProgram: program!, initContext: initContext) + } + net.updateProgram(program: program!) } catch let error { print(error) @@ -105,6 +118,7 @@ import Foundation /// - completion: 结果回调, 当 success 为 true 时 result 不为 nil @objc public func predict(texture: MTLTexture, completion: @escaping ( _ success: Bool, _ result: [ResultHolder]?) -> Void) { do { + try self.executor?.predict(input: texture, dim: self.net.inputDim, completionHandle: { [weak self] (res) in guard let SSelf = self else { fatalError( " self nil " ) diff --git a/metal/paddle-mobile/paddle-mobile/Src/Common/MetalExtension.swift b/metal/paddle-mobile/paddle-mobile/Src/Common/MetalExtension.swift index 35fffb52ec..3af3a75a64 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Common/MetalExtension.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Common/MetalExtension.swift @@ -254,7 +254,7 @@ extension MTLDevice { return tensor } - func tensor2texture

(value: [P], dim: [Int], transpose: [Int] = [0, 1, 2, 3], inComputePrecision: ComputePrecision = .Float32) -> MTLTexture { + func tensor2texture

(value: [P], dim: [Int], transpose: [Int] = [0, 1, 2, 3], inComputePrecision: Precision = .Float32) -> MTLTexture { if value.count > 0 { assert(value.count == dim.reduce(1) { $0 * $1 }) } diff --git a/metal/paddle-mobile/paddle-mobile/Src/Common/Tools.swift b/metal/paddle-mobile/paddle-mobile/Src/Common/Tools.swift index 23ad711397..6128aa8776 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Common/Tools.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Common/Tools.swift @@ -14,7 +14,7 @@ import Foundation -func writeToLibrary(fileName: String, array: [P]) { +func writeToLibrary(fileName: String, array: [P]) { let libraryPath = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true).last ?! " library path get error " let filePath = libraryPath + "/" + fileName let fileManager = FileManager.init() diff --git a/metal/paddle-mobile/paddle-mobile/Src/Common/Types.swift b/metal/paddle-mobile/paddle-mobile/Src/Common/Types.swift index 701bb37bf2..21a9f4385d 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Common/Types.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Common/Types.swift @@ -20,20 +20,28 @@ public protocol SummableMultipliable: Equatable { static func *(lhs: Self, rhs: Self) -> Self static func -(lhs: Self, rhs: Self) -> Self } -public protocol PrecisionType: SummableMultipliable{ + +public protocol PrecisionProtocol: SummableMultipliable{ init(inFloat: Float32) init(inFloat16: Float16) - init(_ inP: P) + init(_ inP: P) static var bitSize: UInt { get } + static func initializeValue() -> Self + static var precisionType: Precision { get } } public typealias Float16 = Int16 -extension Float16: PrecisionType { - public static func * (prefix: Float16, postfix: Float16) { - return prefix * postfix +extension Float16: PrecisionProtocol { + + public static var precisionType: Precision { + return .Float16 } - public init

(_ inP: P) where P : PrecisionType { + public static func initializeValue() -> Int16 { + return 0 + } + + public init

(_ inP: P) where P : PrecisionProtocol { if P.bitSize == Float32.bitSize { self = Float16(inFloat: inP as! Float32) } else if P.bitSize == Float16.bitSize { @@ -55,8 +63,17 @@ extension Float16: PrecisionType { } } -extension Float32: PrecisionType { - public init

(_ inP: P) where P : PrecisionType { +extension Float32: PrecisionProtocol { + + public static var precisionType: Precision { + return .Float32 + } + + public static func initializeValue() -> Float { + return 0.0 + } + + public init

(_ inP: P) where P : PrecisionProtocol { if P.bitSize == Float32.bitSize { self = inP as! Float32 } else if P.bitSize == Float16.bitSize { @@ -116,80 +133,6 @@ struct DataLayout { return layoutWithDim.count } - var N: Int? { - get { - for layoutDim in layoutWithDim { - if layoutDim.0 == .N { - return layoutDim.1 - } - } - return nil - } - set { - var newN = (Layout.N, newValue) - if let index = layoutWithDim.index(where: { (layout: Layout, dim: Int) -> Bool in - return layout == .N - }) { - fatalError() - } - } - } - var C: Int? { - get { - for layoutDim in layoutWithDim { - if layoutDim.0 == .C { - return layoutDim.1 - } - } - return nil - } - set { - var newN = (Layout.C, newValue) - if let index = layoutWithDim.index(where: { (layout: Layout, dim: Int) -> Bool in - return layout == .N - }) { - fatalError() - } - } - } - var H: Int? { - get { - for layoutDim in layoutWithDim { - if layoutDim.0 == .H { - return layoutDim.1 - } - } - return nil - } - set { - var newN = (Layout.H, newValue) - if let index = layoutWithDim.index(where: { (layout: Layout, dim: Int) -> Bool in - return layout == .H - }) { - fatalError() - } - } - } - var W: Int? { - get { - for layoutDim in layoutWithDim { - if layoutDim.0 == .W { - return layoutDim.1 - } - } - return nil - } - set { - var newN = (Layout.W, newValue) - if let index = layoutWithDim.index(where: { (layout: Layout, dim: Int) -> Bool in - return layout == .W - }) { - fatalError() - } - } - } - - init(_ inLayout: [(Layout, Int)]) { layoutWithDim = inLayout } diff --git a/metal/paddle-mobile/paddle-mobile/Src/Framework/Executor.swift b/metal/paddle-mobile/paddle-mobile/Src/Framework/Executor.swift index 0b6b17205f..fa86c463e6 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Framework/Executor.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Framework/Executor.swift @@ -41,7 +41,12 @@ var isTest = false } -public class Executor { +protocol Executorable { + func predict(input: MTLTexture, dim: Dim, completionHandle: @escaping ([GPUResultHolder]) -> Void, preProcessKernle: CusomKernel?, except: Int) throws + func clear() +} + +public class Executor: Executorable{ var ops: [Runable & InferShaperable] = [] var preInputDim: Dim = Dim.init(inDim: []) let program: Program diff --git a/metal/paddle-mobile/paddle-mobile/Src/Framework/Loader.swift b/metal/paddle-mobile/paddle-mobile/Src/Framework/Loader.swift index 790b961480..c437d284cc 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Framework/Loader.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Framework/Loader.swift @@ -15,7 +15,12 @@ import Foundation //import SwiftProtobuf -public class Loader { +protocol Loaderable { + func load(device:MTLDevice, paramPointer: UnsafeMutableRawPointer, paramSize:Int, modePointer: UnsafeMutableRawPointer, modelSize: Int) throws -> Program + func load(device: MTLDevice, modelPath: String, paraPath: String) throws -> Program +} + +public class Loader: Loaderable{ class ParaLoader { let file: UnsafeMutablePointer let fileSize: Int @@ -143,7 +148,7 @@ public class Loader { } } public init(){} - func loadModelandParam(_ device:MTLDevice,_ modelData:Data, _ paraLoaderPointer:ParaLoaderWithPointer?, _ paraLoader:ParaLoader?) throws -> Program { + private func loadModelandParam(_ device:MTLDevice,_ modelData:Data, _ paraLoaderPointer:ParaLoaderWithPointer?, _ paraLoader:ParaLoader?) throws -> Program { do { /// swift protobuf serialized Data to instance class // let protoProgram = try PaddleMobile_Framework_Proto_ProgramDesc.init( @@ -248,7 +253,7 @@ public class Loader { } } - public func load(device: MTLDevice, modelPath: String, paraPath: String) throws -> Program{ + public func load(device: MTLDevice, modelPath: String, paraPath: String) throws -> Program { guard let modelData = try? Data.init(contentsOf: URL.init(fileURLWithPath: modelPath)) else { throw PaddleMobileError.loaderError(message: "load " + modelPath + " failed !") } diff --git a/metal/paddle-mobile/paddle-mobile/Src/Framework/Tensor.swift b/metal/paddle-mobile/paddle-mobile/Src/Framework/Tensor.swift index 298f2ce420..b1121875c8 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Framework/Tensor.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Framework/Tensor.swift @@ -28,7 +28,7 @@ extension Tensorial { } } -class DataConverter { +class DataConverter { func convert(from: UnsafeMutablePointer

, to: UnsafeMutablePointer

, fromDim: Dim) { fatalError(" need imp") } @@ -40,7 +40,7 @@ class DataConverter { /// [ outputChannels ][ inputChannels ][ kernelHeight ][ kernelWidth ] -> /// [ outputChannels ][ kernelHeight ][ kernelWidth ][ inputChannels ] -class MPSPointerConverter: DataConverter

{ +class MPSPointerConverter: DataConverter

{ /// [ outputChannels ][ inputChannels ][ kernelHeight ][ kernelWidth ] -> /// [ outputChannels ][ kernelHeight ][ kernelWidth ][ inputChannels ] @@ -81,7 +81,7 @@ class MPSPointerConverter: DataConverter

{ } } -class Tensor: Tensorial { +class Tensor: Tensorial { var data: Data var dim: Dim @@ -169,14 +169,15 @@ class Tensor: Tensorial { layout = to } - - - func initBuffer(device: MTLDevice, precision: ComputePrecision = .Float16, padWhenOneC: Bool = false, convertToNHWC: Bool = true, withTranspose: Bool = false) { + func initBuffer(device: MTLDevice, precision computePrecision: Precision = .Float16, padWhenOneC: Bool = false, convertToNHWC: Bool = true, withTranspose: Bool = false) { if convertToNHWC { - // print(layout) convert(to: DataLayout.NHWC()) } + if P.precisionType == .Float16 && computePrecision == .Float32{ + fatalError(" 不支持: 16位模型不能按照 32 位进行运算") + } + if withTranspose { let transposePointer = UnsafeMutablePointer

.allocate(capacity: numel()) let n = dim[0] @@ -193,12 +194,8 @@ class Tensor: Tensorial { data = Data.init(inCount: data.count, inPointer: transposePointer) } - guard let floatPointer = data.pointer as? UnsafeMutablePointer else { - fatalError(" not support yet ") - } - let precisionSize: Int - switch precision { + switch computePrecision { case .Float32: precisionSize = 4 case .Float16: @@ -213,44 +210,58 @@ class Tensor: Tensorial { let count = paddedC * dim[0] * dim[1] * dim[2] if C == paddedC { buffer = device.makeBuffer(length: count * precisionSize) - switch precision { - case .Float32: - buffer?.contents().copyMemory(from: data.pointer, byteCount: count * MemoryLayout

.stride) + switch P.precisionType { case .Float16: - float32ToFloat16(input: floatPointer, output: buffer.contents(), count: count) + buffer?.contents().copyMemory(from: data.pointer, byteCount: count * MemoryLayout

.stride) + case .Float32: + switch computePrecision { + case .Float32: + buffer?.contents().copyMemory(from: data.pointer, byteCount: count * MemoryLayout

.stride) + case .Float16: + float32ToFloat16(input: data.pointer as! UnsafeMutablePointer, output: buffer.contents(), count: count) + } } } else if C == 1 && !padWhenOneC { buffer = device.makeBuffer(length: numel() * precisionSize) - switch precision { - case .Float32: - buffer?.contents().copyMemory(from: data.pointer, byteCount: numel() * MemoryLayout

.stride) + switch P.precisionType { case .Float16: - float32ToFloat16(input: floatPointer, output: buffer.contents(), count: numel()) + buffer?.contents().copyMemory(from: data.pointer, byteCount: numel() * MemoryLayout

.stride) + case .Float32: + switch computePrecision { + case .Float32: + buffer?.contents().copyMemory(from: data.pointer, byteCount: numel() * MemoryLayout

.stride) + case .Float16: + float32ToFloat16(input: data.pointer as! UnsafeMutablePointer, output: buffer.contents(), count: numel()) + } } } else { buffer = device.makeBuffer(length: count * precisionSize) - let convertedPointer = UnsafeMutablePointer.allocate(capacity: count) - var tmpPointer = floatPointer + let convertedPointer = UnsafeMutablePointer

.allocate(capacity: count) + var tmpPointer = data.pointer var dstPtr = convertedPointer for _ in 0...stride) + switch P.precisionType { case .Float16: - float32ToFloat16(input: convertedPointer, output: buffer.contents(), count: count) + buffer?.contents().copyMemory(from: convertedPointer, byteCount: count * MemoryLayout

.stride) + case .Float32: + switch computePrecision { + case .Float32: + buffer?.contents().copyMemory(from: convertedPointer, byteCount: count * MemoryLayout

.stride) + case .Float16: + float32ToFloat16(input: convertedPointer as! UnsafeMutablePointer, output: buffer.contents(), count: count) + } } - convertedPointer.deinitialize(count: count) convertedPointer.deallocate() } @@ -261,36 +272,46 @@ class Tensor: Tensorial { let count = paddedC * dim[0] * dim[1] * dim[2] if C == paddedC { buffer = device.makeBuffer(length: count * precisionSize) - switch precision { - case .Float32: - buffer?.contents().copyMemory(from: data.pointer, byteCount: count * MemoryLayout

.stride) + switch P.precisionType { case .Float16: - float32ToFloat16(input: floatPointer, output: buffer.contents(), count: count) + buffer?.contents().copyMemory(from: data.pointer, byteCount: count * MemoryLayout

.stride) + case .Float32: + switch computePrecision { + case .Float32: + buffer?.contents().copyMemory(from: data.pointer, byteCount: count * MemoryLayout

.stride) + case .Float16: + float32ToFloat16(input: data.pointer as! UnsafeMutablePointer, output: buffer.contents(), count: count) + } } } else if C == 1 { fatalError(" not support ") } else { buffer = device.makeBuffer(length: count * precisionSize) - let convertedPointer = UnsafeMutablePointer.allocate(capacity: count) - var tmpPointer = floatPointer + let convertedPointer = UnsafeMutablePointer

.allocate(capacity: count) + var tmpPointer = data.pointer var dstPtr = convertedPointer for _ in 0...stride) - case .Float16: - float32ToFloat16(input: convertedPointer, output: buffer.contents(), count: count) + case .Float32: // 模型精度为 16 位 + switch computePrecision { + case .Float32: + buffer?.contents().copyMemory(from: convertedPointer, byteCount: count * MemoryLayout

.stride) + case .Float16: + float32ToFloat16(input: convertedPointer as! UnsafeMutablePointer, output: buffer.contents(), count: count) + } } convertedPointer.deinitialize(count: count) convertedPointer.deallocate() @@ -299,11 +320,17 @@ class Tensor: Tensorial { } else if dim.cout() == 1 { let num = ((numel() + 3) / 4) * 4 buffer = device.makeBuffer(length: num * precisionSize) - switch precision { - case .Float32: - buffer?.contents().copyMemory(from: data.pointer, byteCount: num * MemoryLayout

.stride) + + switch P.precisionType { case .Float16: - float32ToFloat16(input: floatPointer, output: buffer.contents(), count: num) + buffer?.contents().copyMemory(from: data.pointer, byteCount: num * MemoryLayout

.stride) + case .Float32: + switch computePrecision { + case .Float32: + buffer?.contents().copyMemory(from: data.pointer, byteCount: num * MemoryLayout

.stride) + case .Float16: + float32ToFloat16(input: data.pointer as! UnsafeMutablePointer, output: buffer.contents(), count: num) + } } } else { fatalError(" not support !") @@ -404,7 +431,7 @@ extension Tensor { var debugDescription: String { var str = "dim: \(dim) \n" - str += "MTLBuffer: \(self.buffer) \n" + str += "MTLBuffer: \(self.buffer.description) \n" for i in 0...size { str += " \(buffer.contents().assumingMemoryBound(to: P.self)[i])" } diff --git a/metal/paddle-mobile/paddle-mobile/Src/Framework/Texture.swift b/metal/paddle-mobile/paddle-mobile/Src/Framework/Texture.swift index cc1ed05e12..72195a22ea 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Framework/Texture.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Framework/Texture.swift @@ -96,7 +96,7 @@ public class Texture: Tensorial { return metalTexture.realNHWC(dim: (n: padToFourDim[0], h: padToFourDim[1], w: padToFourDim[2], c: padToFourDim[3])) } - public func initTexture(device: MTLDevice, inTranspose: [Int] = [0, 1, 2, 3], computePrecision: ComputePrecision = .Float16) { + public func initTexture(device: MTLDevice, inTranspose: [Int] = [0, 1, 2, 3], computePrecision: Precision = .Float16) { transpose = inTranspose for i in 0..<(4 - tensorDim.cout()) { if i != inTranspose[i] { @@ -196,7 +196,7 @@ extension Texture { public var debugDescription: String{ var str = "" str += "Dim: \(dim) \n value:[ " - str += "\(metalTexture)" + str += "\(metalTexture.description)" str += " ]" return str } diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Base/OpCreator.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Base/OpCreator.swift index f16344e500..a2f4104b9b 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Base/OpCreator.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Base/OpCreator.swift @@ -15,7 +15,7 @@ import Foundation fileprivate var singletons : [String : Any] = [:] -class OpCreator { +class OpCreator { static var shared : OpCreator

{ let key = String(describing: P.self) if let singleton = singletons[key] { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Base/OpParam.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Base/OpParam.swift index 0af90e411b..37a847b750 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Base/OpParam.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Base/OpParam.swift @@ -26,7 +26,7 @@ protocol OpParam { var output: OutputType { get set } func outputDesc() -> String - //associatedtype ParamPrecisionType: PrecisionType + //associatedtype ParamPrecisionType: PrecisionProtocol init(opDesc: PMOpDesc, inScope: Scope) throws static func getFirstTensor(key: String, map: [String : [String]], from: Scope) throws -> VarType static func inputX(inputs: [String : [String]], from: Scope) throws -> VarType diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/BatchNormOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/BatchNormOp.swift index 904e04c468..7e53ea8d1c 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/BatchNormOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/BatchNormOp.swift @@ -15,7 +15,7 @@ import Foundation import Metal -class BatchNormParam: OpParam { +class BatchNormParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -44,7 +44,7 @@ class BatchNormParam: OpParam { let momentum: Float } -class BatchNormOp: Operator, BatchNormParam

>, Runable, Creator, InferShaperable{ +class BatchNormOp: Operator, BatchNormParam

>, Runable, Creator, InferShaperable{ typealias OpType = BatchNormOp

func inferShape() { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/BilinearInterpOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/BilinearInterpOp.swift index e44a49d900..51703c3e6f 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/BilinearInterpOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/BilinearInterpOp.swift @@ -15,7 +15,7 @@ import Foundation import Metal -class BilinearInterpParam: OpParam { +class BilinearInterpParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -36,7 +36,7 @@ class BilinearInterpParam: OpParam { let out_w: Int } -class BilinearInterpOp: Operator, BilinearInterpParam

>, Runable, Creator, InferShaperable{ +class BilinearInterpOp: Operator, BilinearInterpParam

>, Runable, Creator, InferShaperable{ typealias OpType = BilinearInterpOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/BoxcoderOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/BoxcoderOp.swift index 442d1af9ea..0ca6325922 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/BoxcoderOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/BoxcoderOp.swift @@ -14,7 +14,7 @@ import Foundation -class BoxcoderParam: OpParam { +class BoxcoderParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -45,7 +45,7 @@ class BoxcoderParam: OpParam { let boxNormalized: Bool } -class BoxcoderOp: Operator, BoxcoderParam

>, Runable, Creator, InferShaperable{ +class BoxcoderOp: Operator, BoxcoderParam

>, Runable, Creator, InferShaperable{ typealias OpType = BoxcoderOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConcatOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConcatOp.swift index a8034c681f..e526bf05db 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConcatOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConcatOp.swift @@ -14,7 +14,7 @@ import Foundation -class ConcatParam: OpParam { +class ConcatParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -46,7 +46,7 @@ class ConcatParam: OpParam { let axis: Int } -class ConcatOp: Operator, ConcatParam

>, Runable, Creator, InferShaperable{ +class ConcatOp: Operator, ConcatParam

>, Runable, Creator, InferShaperable{ typealias OpType = ConcatOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddAddPreluOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddAddPreluOp.swift index e7865045e5..f22a0026d3 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddAddPreluOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddAddPreluOp.swift @@ -15,7 +15,7 @@ import Foundation import Metal -class ConvAddAddPreluParam: OpParam { +class ConvAddAddPreluParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -46,7 +46,7 @@ class ConvAddAddPreluParam: OpParam { let groups: Int } -class ConvAddAddPreluOp: Operator, ConvAddAddPreluParam

>, Runable, Creator, InferShaperable, Fusion{ +class ConvAddAddPreluOp: Operator, ConvAddAddPreluParam

>, Runable, Creator, InferShaperable, Fusion{ typealias OpType = ConvAddAddPreluOp

static func fusionNode() -> Node { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddBatchNormReluOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddBatchNormReluOp.swift index 311967c22c..dd08da27ac 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddBatchNormReluOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddBatchNormReluOp.swift @@ -15,7 +15,7 @@ import Foundation -class ConvAddBatchNormReluParam: OpParam { +class ConvAddBatchNormReluParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -59,7 +59,7 @@ class ConvAddBatchNormReluParam: OpParam { let groups: Int } -class ConvAddBatchNormReluOp: Operator, ConvAddBatchNormReluParam

>, Runable, Creator, InferShaperable, Fusion{ +class ConvAddBatchNormReluOp: Operator, ConvAddBatchNormReluParam

>, Runable, Creator, InferShaperable, Fusion{ typealias OpType = ConvAddBatchNormReluOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddOp.swift index 7b9958a066..c24441f7f3 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddOp.swift @@ -14,7 +14,7 @@ import Foundation -class ConvAddParam: OpParam { +class ConvAddParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -43,7 +43,7 @@ class ConvAddParam: OpParam { let groups: Int } -class ConvAddOp: Operator, ConvAddParam

>, Runable, Creator, InferShaperable, Fusion{ +class ConvAddOp: Operator, ConvAddParam

>, Runable, Creator, InferShaperable, Fusion{ typealias OpType = ConvAddOp

static func fusionNode() -> Node { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddPreluOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddPreluOp.swift index dc32056224..03cbeb8187 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddPreluOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvAddPreluOp.swift @@ -14,7 +14,7 @@ import Foundation -class ConvAddPreluParam: OpParam { +class ConvAddPreluParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -45,7 +45,7 @@ class ConvAddPreluParam: OpParam { let groups: Int } -class ConvAddPreluOp: Operator, ConvAddPreluParam

>, Runable, Creator, InferShaperable, Fusion{ +class ConvAddPreluOp: Operator, ConvAddPreluParam

>, Runable, Creator, InferShaperable, Fusion{ typealias OpType = ConvAddPreluOp

static func fusionNode() -> Node { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvBNReluOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvBNReluOp.swift index 1a973c51ef..adbad35b47 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvBNReluOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvBNReluOp.swift @@ -14,7 +14,7 @@ import Foundation -class ConvBNReluParam: OpParam { +class ConvBNReluParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -53,7 +53,7 @@ class ConvBNReluParam: OpParam { let groups: Int } -class ConvBNReluOp: Operator, ConvBNReluParam

>, Runable, Creator, InferShaperable, Fusion{ +class ConvBNReluOp: Operator, ConvBNReluParam

>, Runable, Creator, InferShaperable, Fusion{ typealias OpType = ConvBNReluOp

func inputs() -> [Variant] { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvOp.swift index 2d402ae431..93ddb53bc9 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvOp.swift @@ -14,7 +14,7 @@ import Foundation -class ConvParam: OpParam { +class ConvParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -40,7 +40,7 @@ class ConvParam: OpParam { let groups: Int } -class ConvOp: Operator, ConvParam

>, Runable, Creator, InferShaperable { +class ConvOp: Operator, ConvParam

>, Runable, Creator, InferShaperable { typealias OpType = ConvOp

func inferShape() { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvTransposeOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvTransposeOp.swift index 8322263e7c..57269354a1 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvTransposeOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ConvTransposeOp.swift @@ -14,7 +14,7 @@ import Foundation -class ConvTransposeParam: ConvParam

{ +class ConvTransposeParam: ConvParam

{ //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -25,7 +25,7 @@ class ConvTransposeParam: ConvParam

{ } } -class ConvTransposeOp: Operator, ConvTransposeParam

>, Runable, Creator, InferShaperable{ +class ConvTransposeOp: Operator, ConvTransposeParam

>, Runable, Creator, InferShaperable{ typealias OpType = ConvTransposeOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/DepthwiseConvOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/DepthwiseConvOp.swift index 4686501fdd..49e146b688 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/DepthwiseConvOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/DepthwiseConvOp.swift @@ -14,7 +14,7 @@ import Foundation -class DepthConvOp: Operator, ConvParam

>, Runable, Creator, InferShaperable { +class DepthConvOp: Operator, ConvParam

>, Runable, Creator, InferShaperable { typealias OpType = DepthConvOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/DwConvBNReluOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/DwConvBNReluOp.swift index ef3bc21316..dd3f50c5d4 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/DwConvBNReluOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/DwConvBNReluOp.swift @@ -14,7 +14,7 @@ import Foundation -class DwConvBNReluOp: Operator, ConvBNReluParam

>, Runable, Creator, InferShaperable, Fusion{ +class DwConvBNReluOp: Operator, ConvBNReluParam

>, Runable, Creator, InferShaperable, Fusion{ typealias OpType = ConvBNReluOp

func inferShape() { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ElementwiseAddOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ElementwiseAddOp.swift index cd5307b584..73a278e3c7 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ElementwiseAddOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ElementwiseAddOp.swift @@ -15,7 +15,7 @@ import Foundation import Metal -class ElementwiseAddParam: OpParam { +class ElementwiseAddParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -61,7 +61,7 @@ class ElementwiseAddParam: OpParam { var axis: Int } -class ElementwiseAddOp: Operator, ElementwiseAddParam

>, Runable, Creator, InferShaperable{ +class ElementwiseAddOp: Operator, ElementwiseAddParam

>, Runable, Creator, InferShaperable{ typealias OpType = ElementwiseAddOp

func inferShape() { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ElementwiseAddPreluOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ElementwiseAddPreluOp.swift index bd853f6c0f..bcf0ba994c 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ElementwiseAddPreluOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ElementwiseAddPreluOp.swift @@ -15,7 +15,7 @@ import Foundation import Metal -class ElementwiseAddPreluParam: OpParam { +class ElementwiseAddPreluParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -65,7 +65,7 @@ class ElementwiseAddPreluParam: OpParam { var axis: Int } -class ElementwiseAddPreluOp: Operator, ElementwiseAddPreluParam

>, Runable, Creator, InferShaperable, Fusion{ +class ElementwiseAddPreluOp: Operator, ElementwiseAddPreluParam

>, Runable, Creator, InferShaperable, Fusion{ static func fusionNode() -> Node { let beginNode = Node.init(inType: gElementwiseAddType) _ = beginNode diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/FeedOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/FeedOp.swift index bab3d8dce7..0d9510d2b0 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/FeedOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/FeedOp.swift @@ -16,7 +16,7 @@ import Foundation import MetalKit import CoreMedia -class FeedParam: OpParam{ +class FeedParam: OpParam{ var output: Texture var input: InputTexture { return scope.input() as! InputTexture @@ -35,7 +35,7 @@ class FeedParam: OpParam{ //typealias ParamPrecisionType = P } -class FeedOp: Operator, FeedParam

>, Runable, Creator, InferShaperable { +class FeedOp: Operator, FeedParam

>, Runable, Creator, InferShaperable { typealias OpType = FeedOp

func inferShape() { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/FetchOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/FetchOp.swift index 671c2f33fa..e9a5a395ae 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/FetchOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/FetchOp.swift @@ -15,7 +15,7 @@ import Foundation import Metal -class FetchParam: OpParam{ +class FetchParam: OpParam{ var output: FetchHolder let input: Texture let scope: Scope @@ -33,7 +33,7 @@ class FetchParam: OpParam{ //typealias ParamPrecisionType = P } -class FetchOp: Operator< FetchKernel

, FetchParam

>, Runable, Creator, InferShaperable { +class FetchOp: Operator< FetchKernel

, FetchParam

>, Runable, Creator, InferShaperable { typealias OpType = FetchOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/FlattenOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/FlattenOp.swift index b982990851..f5d1004948 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/FlattenOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/FlattenOp.swift @@ -14,7 +14,7 @@ import Foundation -class FlattenParam: OpParam { +class FlattenParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -31,7 +31,7 @@ class FlattenParam: OpParam { } -class FlattenOp: Operator, FlattenParam

>, Runable, Creator, InferShaperable{ +class FlattenOp: Operator, FlattenParam

>, Runable, Creator, InferShaperable{ typealias OpType = FlattenOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BatchNormKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BatchNormKernel.swift index 0e2005b024..ee2b4ad7e5 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BatchNormKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BatchNormKernel.swift @@ -14,7 +14,7 @@ import Foundation -class BatchNormKernel: Kernel, Computable { +class BatchNormKernel: Kernel, Computable { required init(device: MTLDevice, param: BatchNormParam

, initContext: InitContext) { let count = param.variance.dim.numel() let varianceP = param.variance.data.pointer diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BilinearInterpKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BilinearInterpKernel.swift index c8a6519085..8a217eacb1 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BilinearInterpKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BilinearInterpKernel.swift @@ -19,7 +19,7 @@ struct BilinearInterpMetalParam { var ratio_w: Float32 } -class BilinearInterpKernel: Kernel, Computable{ +class BilinearInterpKernel: Kernel, Computable{ func compute(commandBuffer: MTLCommandBuffer, param: BilinearInterpParam

) throws { guard let encoder = commandBuffer.makeComputeCommandEncoder() else { throw PaddleMobileError.predictError(message: " encode is nil") diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BoxcoderKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BoxcoderKernel.swift index 8f295672c1..94ece69eeb 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BoxcoderKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/BoxcoderKernel.swift @@ -17,7 +17,7 @@ import Foundation struct BoxcoderMetalParam { } -class BoxcoderKernel: Kernel, Computable{ +class BoxcoderKernel: Kernel, Computable{ func compute(commandBuffer: MTLCommandBuffer, param: BoxcoderParam

) throws { guard let encoder = commandBuffer.makeComputeCommandEncoder() else { throw PaddleMobileError.predictError(message: " encode is nil") diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConcatKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConcatKernel.swift index 195366c796..803b2f593c 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConcatKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConcatKernel.swift @@ -31,7 +31,7 @@ struct ConcatMetalParam { var vdim: (Int32, Int32, Int32, Int32, Int32, Int32) = (0, 0, 0, 0, 0, 0) } -class ConcatKernel: Kernel, Computable{ +class ConcatKernel: Kernel, Computable{ var v = "normal" var pm = ConcatMetalParam.init() func compute(commandBuffer: MTLCommandBuffer, param: ConcatParam

) throws { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddAddPreluKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddAddPreluKernel.swift index b2dd306446..c89900a84e 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddAddPreluKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddAddPreluKernel.swift @@ -14,7 +14,7 @@ import Foundation -class ConvAddAddPreluKernel: Kernel, Computable { +class ConvAddAddPreluKernel: Kernel, Computable { var metalParam: MetalConvParam! required init(device: MTLDevice, param: ConvAddAddPreluParam

, initContext: InitContext) { param.output.initTexture(device: device, inTranspose: [0, 2, 3, 1], computePrecision: GlobalConfig.shared.computePrecision) diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddBatchNormReluKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddBatchNormReluKernel.swift index 0ff0b57f6c..ca6cae65c8 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddBatchNormReluKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddBatchNormReluKernel.swift @@ -36,7 +36,7 @@ struct ConvAddBatchNormReluTestParam: TestParam { } } -class ConvAddBatchNormReluKernel: Kernel, Computable, Testable { +class ConvAddBatchNormReluKernel: Kernel, Computable, Testable { required init(device: MTLDevice, testParam: ConvAddBatchNormReluTestParam, initContext: InitContext) { if testParam.filterSize.width == 1 && testParam.filterSize.height == 1 { super.init(device: device, inFunctionName: "conv_add_batch_norm_relu_1x1", initContext: initContext) 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 b770ae0d74..65f01645d0 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddKernel.swift @@ -27,7 +27,7 @@ func getUniqueKey() -> String { return UUID.init().uuidString } -class ConvAddKernel: Kernel, Computable { +class ConvAddKernel: Kernel, Computable { var metalParam: MetalConvParam! let identifyingKey: String = getUniqueKey() diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddPreluKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddPreluKernel.swift index 1b054cb9ca..3535ae1868 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddPreluKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvAddPreluKernel.swift @@ -14,7 +14,7 @@ import Foundation -class ConvAddPreluKernel: Kernel, Computable { +class ConvAddPreluKernel: Kernel, Computable { var metalParam: MetalConvParam! required init(device: MTLDevice, param: ConvAddPreluParam

, initContext: InitContext) { param.output.initTexture(device: device, inTranspose: [0, 2, 3, 1], computePrecision: GlobalConfig.shared.computePrecision) diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvBNReluKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvBNReluKernel.swift index 415ec94b51..9fa519a7eb 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvBNReluKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvBNReluKernel.swift @@ -37,7 +37,7 @@ struct ConvBNReluTestParam: TestParam { } } -class ConvBNReluKernel: Kernel, Computable, Testable { +class ConvBNReluKernel: Kernel, Computable, Testable { required init(device: MTLDevice, testParam: ConvBNReluTestParam, initContext: InitContext) { if testParam.filterSize.width == 1 && testParam.filterSize.height == 1 { super.init(device: device, inFunctionName: "conv_batch_norm_relu_1x1", initContext: initContext) diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvKernel.swift index 7ff040219e..fff6dd4726 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvKernel.swift @@ -24,10 +24,10 @@ public struct MetalConvParam { let dilationY: UInt16 } -class ConvKernel: Kernel, Computable { +class ConvKernel: Kernel, Computable { var metalParam: MetalConvParam! required init(device: MTLDevice, param: ConvParam

, initContext: InitContext) { - param.filter.initBuffer(device: device, precision: ComputePrecision.Float32) + param.filter.initBuffer(device: device, precision: Precision.Float32) if param.filter.width == 1 && param.filter.height == 1 { super.init(device: device, inFunctionName: "conv_1x1", initContext: initContext) } else if param.filter.channel == 1 { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvTransposeKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvTransposeKernel.swift index f1753d0a09..33ee422c3a 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvTransposeKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ConvTransposeKernel.swift @@ -28,7 +28,7 @@ struct MetalConvTransposeParam { let dilationY: UInt16; } -class ConvTransposeKernel: Kernel, Computable{ +class ConvTransposeKernel: Kernel, Computable{ var metalParam: MetalConvTransposeParam! required init(device: MTLDevice, param: ConvTransposeParam

, initContext: InitContext) { param.output.initTexture(device: device, inTranspose: param.input.transpose, computePrecision: GlobalConfig.shared.computePrecision) diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ElementwiseAddKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ElementwiseAddKernel.swift index 2a87d4362f..8d4bed8674 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ElementwiseAddKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ElementwiseAddKernel.swift @@ -24,7 +24,7 @@ struct ElementwiseAddMetalParam { var ytrans: (Int32, Int32, Int32, Int32) = (0, 1, 2, 3) } -class ElementwiseAddKernel: Kernel, Computable { +class ElementwiseAddKernel: Kernel, Computable { var metalParam: ElementwiseAddMetalParam required init(device: MTLDevice, param: ElementwiseAddParam

, initContext: InitContext) { param.output.initTexture(device: device, inTranspose: param.inputX.transpose, computePrecision: GlobalConfig.shared.computePrecision) diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ElementwiseAddPreluKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ElementwiseAddPreluKernel.swift index cf83c2e750..34c45cb061 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ElementwiseAddPreluKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ElementwiseAddPreluKernel.swift @@ -15,7 +15,7 @@ import Foundation -class ElementwiseAddPreluKernel: Kernel, Computable { +class ElementwiseAddPreluKernel: Kernel, Computable { var metalParam: ElementwiseAddMetalParam required init(device: MTLDevice, param: ElementwiseAddPreluParam

, initContext: InitContext) { param.output.initTexture(device: device, inTranspose: param.inputX.transpose, computePrecision: GlobalConfig.shared.computePrecision) diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/FetchKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/FetchKernel.swift index 616fcc1f2d..8164a98efa 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/FetchKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/FetchKernel.swift @@ -14,7 +14,7 @@ import Foundation -class FetchKernel: Kernel, Computable { +class FetchKernel: Kernel, Computable { required init(device: MTLDevice, param: FetchParam

, initContext: InitContext) { param.output.initBuffer(device: device) diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/FlattenKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/FlattenKernel.swift index 5956806001..7e9f129a01 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/FlattenKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/FlattenKernel.swift @@ -22,7 +22,7 @@ struct FlattenMetalParam { } -class FlattenKernel: Kernel, Computable{ +class FlattenKernel: Kernel, Computable{ var metalParam: FlattenMetalParam diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/MulticlassNMSKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/MulticlassNMSKernel.swift index 4f59bf9971..d3350a4225 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/MulticlassNMSKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/MulticlassNMSKernel.swift @@ -14,7 +14,7 @@ import Foundation -class MulticlassNMSKernel: Kernel, Computable{ +class MulticlassNMSKernel: Kernel, Computable{ let pipline1: MTLComputePipelineState required init(device: MTLDevice, param: MulticlassNMSParam

, initContext: InitContext) { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PoolKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PoolKernel.swift index 37878f26d0..2e7a4c3856 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PoolKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PoolKernel.swift @@ -24,7 +24,7 @@ struct PoolMetalParam { let poolType: Int32 } -class PoolKernel: Kernel, Computable{ +class PoolKernel: Kernel, Computable{ var metalParam: PoolMetalParam required init(device: MTLDevice, param: PoolParam

, initContext: InitContext) { param.output.initTexture(device: device, inTranspose: param.input.transpose, computePrecision: GlobalConfig.shared.computePrecision) diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PreluKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PreluKernel.swift index 053cb827e3..906dc0fcfe 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PreluKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PreluKernel.swift @@ -14,7 +14,7 @@ import Foundation -class PreluKernel: Kernel, Computable{ +class PreluKernel: Kernel, Computable{ required init(device: MTLDevice, param: PreluParam

, initContext: InitContext) { param.alpha.initBuffer(device: device, precision: GlobalConfig.shared.computePrecision) param.output.initTexture(device: device, inTranspose: param.input.transpose, computePrecision: GlobalConfig.shared.computePrecision) diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PriorBoxKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PriorBoxKernel.swift index cb8ef81de3..009062c889 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PriorBoxKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/PriorBoxKernel.swift @@ -29,7 +29,7 @@ struct PriorBoxMetalParam { let maxSizeSize: uint } -class PriorBoxKernel: Kernel, Computable{ +class PriorBoxKernel: Kernel, Computable{ var metalParam: PriorBoxMetalParam! required init(device: MTLDevice, param: PriorBoxParam

, initContext: InitContext) { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ReluKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ReluKernel.swift index 06ff7d3990..e4fe6fdf8c 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ReluKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ReluKernel.swift @@ -14,7 +14,7 @@ import Foundation -class ReluKernel: Kernel, Computable{ +class ReluKernel: Kernel, Computable{ func compute(commandBuffer: MTLCommandBuffer, param: ReluParam

) throws { guard let encoder = commandBuffer.makeComputeCommandEncoder() else { throw PaddleMobileError.predictError(message: " encode is nil") diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ReshapeKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ReshapeKernel.swift index 954eff9a56..0613e4952d 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ReshapeKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ReshapeKernel.swift @@ -27,7 +27,7 @@ struct ReshapeTestParam: TestParam { let param: ReshapeMetalParam } -class ReshapeKernel: Kernel, Computable{ +class ReshapeKernel: Kernel, Computable{ var metalParam: ReshapeMetalParam diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ResizeBilinearKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ResizeBilinearKernel.swift index 7e9105ae57..5edf80332a 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ResizeBilinearKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ResizeBilinearKernel.swift @@ -19,7 +19,7 @@ struct ResizeBilinearMetalParam { var ratio_w: Float32 } -class ResizeBilinearKernel: Kernel, Computable{ +class ResizeBilinearKernel: Kernel, Computable{ required init(device: MTLDevice, param: ResizeBilinearParam

, initContext: InitContext) { param.output.initTexture(device: device, inTranspose: param.input.transpose, computePrecision: GlobalConfig.shared.computePrecision) if GlobalConfig.shared.computePrecision == .Float32 { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ShapeKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ShapeKernel.swift index 1d2b80cae4..a4f250a175 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ShapeKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/ShapeKernel.swift @@ -18,7 +18,7 @@ import Foundation struct ShapeMetalParam { } -class ShapeKernel: Kernel, Computable{ +class ShapeKernel: Kernel, Computable{ func compute(commandBuffer: MTLCommandBuffer, param: ShapeParam

) throws { // print("shape compute") // guard let encoder = commandBuffer.makeComputeCommandEncoder() else { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SoftmaxKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SoftmaxKernel.swift index b4f3281425..bccb37c47d 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SoftmaxKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SoftmaxKernel.swift @@ -19,7 +19,7 @@ struct SoftmaxMetalParam { let K: Int32 } -class SoftmaxKernel: Kernel, Computable{ +class SoftmaxKernel: Kernel, Computable{ var metalParam: SoftmaxMetalParam required init(device: MTLDevice, param: SoftmaxParam

, initContext: InitContext) { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SplitKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SplitKernel.swift index d15e372962..eaaffa7bfe 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SplitKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/SplitKernel.swift @@ -22,7 +22,7 @@ struct SplitMetalParam { var vdim: (Int32, Int32, Int32, Int32) = (0, 0, 0, 0) } -class SplitKernel: Kernel, Computable{ +class SplitKernel: Kernel, Computable{ var smp: SplitMetalParam func compute(commandBuffer: MTLCommandBuffer, param: SplitParam

) throws { guard let encoder = commandBuffer.makeComputeCommandEncoder() else { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/Texture2DTo2DArrayKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/Texture2DTo2DArrayKernel.swift index 58b3db8d86..022d31df8f 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/Texture2DTo2DArrayKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/Texture2DTo2DArrayKernel.swift @@ -22,7 +22,7 @@ struct Texture2DTo2DArrayParam { let expectDim: Dim } -class Texture2DTo2DArrayKernel: Kernel, Computable{ +class Texture2DTo2DArrayKernel: Kernel, Computable{ func compute(commandBuffer: MTLCommandBuffer, param: FeedParam

) throws { guard let encoder = commandBuffer.makeComputeCommandEncoder() else { throw PaddleMobileError.predictError(message: " encode is nil") diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/TransposeKernel.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/TransposeKernel.swift index 92947dc278..a2f8775834 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/TransposeKernel.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/Kernels/TransposeKernel.swift @@ -20,7 +20,7 @@ struct TransposeMetalParam { var axis: (Int32, Int32, Int32, Int32) = (0, 1, 2, 3) } -class TransposeKernel: Kernel, Computable { +class TransposeKernel: Kernel, Computable { var metalParam: TransposeMetalParam = TransposeMetalParam.init() required init(device: MTLDevice, param: TransposeParam

, initContext: InitContext) { param.output.initTexture(device: device, computePrecision: GlobalConfig.shared.computePrecision) diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/MulticlassNMSOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/MulticlassNMSOp.swift index b438b3c46c..c8dcf4e023 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/MulticlassNMSOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/MulticlassNMSOp.swift @@ -14,7 +14,7 @@ import Foundation -class MulticlassNMSParam: OpParam { +class MulticlassNMSParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -36,7 +36,7 @@ class MulticlassNMSParam: OpParam { var output: Texture } -class MulticlassNMSOp: Operator, MulticlassNMSParam

>, Runable, Creator, InferShaperable{ +class MulticlassNMSOp: Operator, MulticlassNMSParam

>, Runable, Creator, InferShaperable{ func inputVariant() -> [String : [MTLBuffer]] { guard let scoreBuffer = para.middleOutput.resultBuffer, let bboxBuffer = para.middleOutput.resultBuffer else { @@ -48,8 +48,8 @@ class MulticlassNMSOp: Operator, Multic func computeMiddleResult(device: MTLDevice, buffer: MTLCommandBuffer) { do { try kernel.compute(commandBuffer: buffer, param: para) - } catch let _ { - fatalError() + } catch let error { + fatalError("\(error)") } } diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/PoolOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/PoolOp.swift index 8b212f3b1d..8fed29aedd 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/PoolOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/PoolOp.swift @@ -14,7 +14,7 @@ import Foundation -class PoolParam: OpParam { +class PoolParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -42,7 +42,7 @@ class PoolParam: OpParam { var globalPooling: Bool } -class PoolOp: Operator, PoolParam

>, Runable, Creator, InferShaperable{ +class PoolOp: Operator, PoolParam

>, Runable, Creator, InferShaperable{ typealias OpType = PoolOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/PreluOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/PreluOp.swift index 09a6b027e3..429e82a493 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/PreluOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/PreluOp.swift @@ -14,7 +14,7 @@ import Foundation -class PreluParam: OpParam { +class PreluParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -32,7 +32,7 @@ class PreluParam: OpParam { var output: Texture } -class PreluOp: Operator, PreluParam

>, Runable, Creator, InferShaperable{ +class PreluOp: Operator, PreluParam

>, Runable, Creator, InferShaperable{ typealias OpType = PreluOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/PriorBoxOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/PriorBoxOp.swift index 80774f22a9..6af9490766 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/PriorBoxOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/PriorBoxOp.swift @@ -14,7 +14,7 @@ import Foundation -class PriorBoxParam: OpParam { +class PriorBoxParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -59,7 +59,7 @@ class PriorBoxParam: OpParam { let outputVariances: Texture } -class PriorBoxOp: Operator, PriorBoxParam

>, Runable, Creator, InferShaperable{ +class PriorBoxOp: Operator, PriorBoxParam

>, Runable, Creator, InferShaperable{ typealias OpType = PriorBoxOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ReluOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ReluOp.swift index a286114b3f..8a782f694b 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ReluOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ReluOp.swift @@ -15,7 +15,7 @@ import Foundation -class ReluParam: OpParam { +class ReluParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -29,7 +29,7 @@ class ReluParam: OpParam { var output: Texture } -class ReluOp: Operator, ReluParam

>, Runable, Creator, InferShaperable{ +class ReluOp: Operator, ReluParam

>, Runable, Creator, InferShaperable{ typealias OpType = ReluOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ReshapeOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ReshapeOp.swift index 417344f1da..acff1c95ea 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ReshapeOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ReshapeOp.swift @@ -15,7 +15,7 @@ import Foundation import Metal -class ReshapeParam: OpParam { +class ReshapeParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -53,7 +53,7 @@ class ReshapeParam: OpParam { var output: Texture } -class ReshapeOp: Operator, ReshapeParam

>, Runable, Creator, InferShaperable{ +class ReshapeOp: Operator, ReshapeParam

>, Runable, Creator, InferShaperable{ typealias OpType = ReshapeOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ResizeBilinearOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ResizeBilinearOp.swift index e71a62b682..7b9fbf412f 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ResizeBilinearOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ResizeBilinearOp.swift @@ -14,7 +14,7 @@ import Foundation -class ResizeBilinearParam: OpParam { +class ResizeBilinearParam: OpParam { typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -35,7 +35,7 @@ class ResizeBilinearParam: OpParam { let out_w: Int32 } -class ResizeBilinearOp: Operator, ResizeBilinearParam

>, Runable, Creator, InferShaperable{ +class ResizeBilinearOp: Operator, ResizeBilinearParam

>, Runable, Creator, InferShaperable{ typealias OpType = ResizeBilinearOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/ShapeOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/ShapeOp.swift index fd358a67ae..c3a1d37f52 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/ShapeOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/ShapeOp.swift @@ -14,7 +14,7 @@ import Foundation -class ShapeParam: OpParam { +class ShapeParam: OpParam { // typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -28,7 +28,7 @@ class ShapeParam: OpParam { let input: Texture } -class ShapeOp: Operator, ShapeParam

>, Runable, Creator, InferShaperable{ +class ShapeOp: Operator, ShapeParam

>, Runable, Creator, InferShaperable{ typealias OpType = ShapeOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/SoftmaxOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/SoftmaxOp.swift index f13bf20195..cf56f9590c 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/SoftmaxOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/SoftmaxOp.swift @@ -15,7 +15,7 @@ import Foundation import Metal -class SoftmaxParam: OpParam { +class SoftmaxParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -36,7 +36,7 @@ class SoftmaxParam: OpParam { var output: Texture } -class SoftmaxOp: Operator, SoftmaxParam

>, Runable, Creator, InferShaperable{ +class SoftmaxOp: Operator, SoftmaxParam

>, Runable, Creator, InferShaperable{ typealias OpType = SoftmaxOp

func inferShape() { diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/SplitOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/SplitOp.swift index 4d5cb9b0be..d6f4aa4784 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/SplitOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/SplitOp.swift @@ -14,7 +14,7 @@ import Foundation -class SplitParam: OpParam { +class SplitParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -47,7 +47,7 @@ class SplitParam: OpParam { var sections: [Int32] = [] } -class SplitOp: Operator, SplitParam

>, Runable, Creator, InferShaperable{ +class SplitOp: Operator, SplitParam

>, Runable, Creator, InferShaperable{ typealias OpType = SplitOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Operators/TransposeOp.swift b/metal/paddle-mobile/paddle-mobile/Src/Operators/TransposeOp.swift index c05c080667..458bbef54f 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Operators/TransposeOp.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Operators/TransposeOp.swift @@ -15,7 +15,7 @@ import Foundation import Metal -class TransposeParam: OpParam { +class TransposeParam: OpParam { //typealias ParamPrecisionType = P required init(opDesc: PMOpDesc, inScope: Scope) throws { do { @@ -31,7 +31,7 @@ class TransposeParam: OpParam { let axis: [Int32] } -class TransposeOp: Operator, TransposeParam

>, Runable, Creator, InferShaperable{ +class TransposeOp: Operator, TransposeParam

>, Runable, Creator, InferShaperable{ typealias OpType = TransposeOp

diff --git a/metal/paddle-mobile/paddle-mobile/Src/Program/ProgramOptimize.swift b/metal/paddle-mobile/paddle-mobile/Src/Program/ProgramOptimize.swift index e4248b6409..aaf1da1238 100644 --- a/metal/paddle-mobile/paddle-mobile/Src/Program/ProgramOptimize.swift +++ b/metal/paddle-mobile/paddle-mobile/Src/Program/ProgramOptimize.swift @@ -181,7 +181,7 @@ extension Node: Equatable { } -class ProgramOptimize { +class ProgramOptimize { // register fusion let fusionOps: [Fusion.Type] = [ConvAddBatchNormReluOp

.self, // ConvAddAddPreluOp

.self, -- GitLab