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 149956653b91a54cfefc23b8e24b4d5ae8306ee1..d3f8d02b819c66738ad8f7181ee5db44e02be2c0 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 ae3449205e0bcf373a6237567c52c775b28cc7f1..54a5e465fd9e4e8840def865ae492157182b0973 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 220b0cea798ec89b8a2042f9d12679b7746be024..57b4f8201778d92d79f12c2fc6b43949660c8bcb 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 1b42ba0a4b561efc5322516f586906d34ad28e7a..35cd09eb49cde78a958ab019e69b03d4dfe35d0d 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 0b9ee0a679eae75ae173637bf968b616863f6ba6..a0c7ec68647b2e15b43b5e6ccd18d620cfed89dc 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 35fffb52ec2364adda2c9a9cd70b7d7ff3cf6f2e..3af3a75a64fa64b5cc482c24925c762cec38a925 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 23ad7113971de3d0843abe17accfe3d67f0caaa9..6128aa87768aaefddb782cf29ce0056a67284b37 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 701bb37bf2442ff30f372d420670ca6f4f7fc85e..21a9f4385d7205c02414634e042c1e958d1ab120 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 0b6b17205f7450f29f6d5428272e0ca40af4673a..fa86c463e62e6e4dda5150885788b175f9be7b5a 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 790b961480982157da2ba4737442285c3676a2ef..c437d284ccff5fd76d4bda26bc011083a8aeb998 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 298f2ce420a2285d0365abea47b524119c138c6c..b1121875c8071f6f5e16ce1c0be94bcba6b4627e 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 cc1ed05e121524fec9ff35ce1df3d2c54b4a8c88..72195a22ea5fdde4f8c813c5c4863a9b9850e7f2 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 f16344e5005fd678e07a0bf2dc7e115cb5d469a9..a2f4104b9bf3d42b1c9aba06278b314409088d69 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 0af90e411b9d1c7f7d2bebd990de24839ecd58c4..37a847b7501ee93c2a9296957725a15594d8801f 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 904e04c468e8b85c2b5d4c01ea828c10444c4692..7e53ea8d1cdd211fa377acb0438b17697685a78b 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 e44a49d9004ea9260ff32881b810fbd294d00d29..51703c3e6fd07d6031bda497cf04e79dfc9aa1fe 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 442d1af9ea4629e56979ad970dfbaf85f497d3b6..0ca6325922b4d1da2b3e1772503616482f6831d4 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 a8034c681fd8677138fec6fc818be73f3fd8411e..e526bf05db4e54cd48a3728b47d2ae31042e3499 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 e7865045e5485721c5c4137fa8a8be0e7b8680e4..f22a0026d3a941942feffe5781958727f4f76601 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 311967c22cf0918e7cde986e72834a244516f85c..dd08da27ace558fad3405067b67002343f2c55a9 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 7b9958a0666b619de46ee15935233a45e81585dd..c24441f7f34956629774cab951819d89c09a1c41 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 dc3205622484d43b86bd0371043ead45df87534a..03cbeb8187377bd4974d2d6c6d95a693c07b41c0 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 1a973c51ef32e85d699b39eae55ce7afbc06c720..adbad35b4755f0c093a8f9c49f4c879a91265f8e 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 2d402ae4316d50cf47e648ac9485bac75f47161e..93ddb53bc92cf96447aee39a6b9762b42ef79b26 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 8322263e7c6e558d2e05493dc619c6ebe29fe2e7..57269354a11a8006b34eacb17b560f587d8c259f 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 4686501fddda1cfe7e15680af6b3984381d842cb..49e146b688e626e87d6641e6271e20b6109cc98e 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 ef3bc21316126c6902eb5086c2aaf79743aac4f7..dd3f50c5d41685d043e07c522879f79cff08b76a 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 cd5307b5840b2cb756d132f3e60c21b7fe86f484..73a278e3c72460398c2aa17f39d67a7b7a37338d 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 bd853f6c0f5b209da21f9965b30726d0703f11df..bcf0ba994ca48b6af18533f36718c1d458239e8e 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 bab3d8dce740291138a4f328907d521bf132e2bf..0d9510d2b0353890c517c6ece71b60635a10eaf0 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 671c2f33faa29620cf423166b0f6f71849a66e67..e9a5a395aed840d37e29ea1dec16b34085d80624 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 b98299085167f7cb5dbf090d7cc48f6e779a2294..f5d100494835a6980a3604914010797b1d6c0198 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 0e2005b024b94a28d4476624e507b10cc9d88f72..ee2b4ad7e52646d4b415bcd6123dd78cdebece26 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 c8a65190851c7af154dc6c1f61cbde05db243632..8a217eacb11cdc3732540d576f62b91835221450 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 8f295672c19991897d85ffb6622dfb840d0c0b50..94ece69eebdcab2faca3d287a770a16439843d4f 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 195366c79668f7553848f969be03fbddb36d7905..803b2f593ccd3c8afffe4d6219be5314f950f254 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 b2dd3064469ef465f785c8e7d5153abce9d687a3..c89900a84e4df1c2b4873c96f2260a62e20b7d4a 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 0ff0b57f6c8497cf916804b152fbd57a301c6a5c..ca6cae65c8fcac12ed29cd46775edeb2f43a3f8c 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 b770ae0d74c88440fc14d6643e86e31e4f9984a7..65f01645d0c997323c1bd53498b68fddea1d98d6 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 1b054cb9cab80c0cb053e2cdbf8d0af6779ee477..3535ae1868ecde2ac2794b542dbefdd72b198e2c 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 415ec94b517405ad15f331bd3fcebf8414fbf754..9fa519a7eb80928919048e4d67c09456a87ab86f 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 7ff040219e9d5277f6becbbaf353386008863c97..fff6dd4726b16fd258df8ba1469d4889900a9970 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 f1753d0a09294e82eae5c01c23d4fe1c7b220c8d..33ee422c3add3ca00f9d88736427873d41b6d702 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 2a87d4362f51a237f5d8620116cdc6c17c7d059c..8d4bed8674db48f3b73d86b25a6ea787b216c02a 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 cf83c2e750aaf8c3c9dfd27c096970b84be217d7..34c45cb06171ee37b292597240ca748e57d78137 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 616fcc1f2d61c4ffba9baa2c7183a5b172fb7b2e..8164a98efab614e4241576f27071021c51d282e4 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 5956806001e8ec3cfb33c6d13095f0e11aa9420d..7e9f129a015c1859c0fb848815eb2c8f5d4eebc0 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 4f59bf9971704b26ba360cefac3fc50558db3d0e..d3350a4225ecaf273a716a99334a2b46317d61e5 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 37878f26d08ed79e8bfa7c8a1e2e800c8775ff53..2e7a4c38566ff3bd9da1ea79345cf015cbd17cbe 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 053cb827e3c9d37253b487bddea43ee520aca308..906dc0fcfe650a57e6e9d66d6f17c0bf44e15294 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 cb8ef81de3176ac7fcf3e3f43a6c023a2e09eb18..009062c889a303da31835ffcfa57811ebcd3cb85 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 06ff7d39902602dbb6bf3639192a12a582ef9550..e4fe6fdf8c056689b7e529f6fa1ccce5a75d146d 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 954eff9a568ec7e7a816aa508d3f0415c5857503..0613e4952dacba2b336d017b9010cfa855f41dfb 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 7e9105ae57ed59ceab3ace5c64cdfd97ba029a1f..5edf80332abf81772192218c96e524ab4a05d91a 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 1d2b80cae412ce34415f6c678f0912bbf29e1bb2..a4f250a175c85c99437e2ad00d511c90507ba2d6 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 b4f3281425474eba90cbb3ac6e262cf06f3eeb2d..bccb37c47d820fe010bb4780885875bb886ae24d 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 d15e37296290980a3a7092b7e52a82d33e1044a9..eaaffa7bfe8a07df4a1da2ebd5ca10b8d373f1e3 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 58b3db8d8666fd4321eb5554541dca66cf5b6397..022d31df8f569a1a055c580f3ae02b48ed43ff24 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 92947dc27845986c43d099f58c147c1f4c86a4ef..a2f87758348ed0b692937e9f7222f19c3550ac97 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 b438b3c46cf061d48837646d1678c150223c4673..c8dcf4e023fdebd7a817bb3b56343f3af8483fdd 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 8b212f3b1d0ea616881eef3f35dc4bc1eb2f02f2..8fed29aeddf126ebbe7986a9db4fba0a0d405738 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 09a6b027e38b640e355357f244f0e6150e0d95d5..429e82a49350b42791296330b418c2126b0605e8 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 80774f22a9fa27fa97165636b3792785d3146add..6af9490766ba9d2e50ac715ac6a510e207329116 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 a286114b3ff02365ce5ce51a841d85955996110b..8a782f694b58cfe99146a8f7df2f1b8c0b5079be 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 417344f1da60f160b7727872355652821e4cdb61..acff1c95eaf421acd46293048c43d18456c45439 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 e71a62b682bd40bdb3f910aafb2d11f2fe439df0..7b9fbf412ff2216195f764f32cd757516604052d 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 fd358a67aee6e9403d7d8cb5ca3d1c11e5e1f5cb..c3a1d37f52286ee21355e308705b07a119c5a1b0 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 f13bf201956f04ee0a41124bf8556c1d6f31e410..cf56f9590c2ddbfa5b5d190bb71a094239d06311 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 4d5cb9b0beff3a657c5a72fe00ef6f9e9140cc58..d6f4aa4784dd7886b7ee9698abf7dca8b66137c0 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 c05c08066797d8d5c7855d8294ad7f703e85e582..458bbef54fb3136e8b9144e387e8c359873f93d7 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 e4248b64098bd7939f09577566021c1756c05085..aaf1da12382072efacfbb2dd91755b8d4f36f639 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,