提交 e2e2614d 编写于 作者: J Jiaying Zhao 提交者: GitHub

Merge branch 'develop' into develop

......@@ -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 = "<group>"; };
FC9797C621D609FB00F2FD90 /* synset.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = synset.txt; sourceTree = "<group>"; };
FC9797CE21D6506F00F2FD90 /* mingren.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = mingren.jpg; sourceTree = "<group>"; };
FCAFD8492231614200496A36 /* yolo_16_param */ = {isa = PBXFileReference; lastKnownFileType = file; path = yolo_16_param; sourceTree = "<group>"; };
FCAFD84A2231614200496A36 /* yolo_16_model */ = {isa = PBXFileReference; lastKnownFileType = file; path = yolo_16_model; sourceTree = "<group>"; };
FCBCCC542122EF5400D94F7E /* MetalHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MetalHelper.swift; sourceTree = "<group>"; };
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 = "<group>"; };
FCCED60421D7646E00BE8D5F /* test_image_super */ = {isa = PBXFileReference; lastKnownFileType = file; path = test_image_super; sourceTree = "<group>"; };
......@@ -263,6 +267,7 @@
FC704C1B21D237FC00F98BAB /* vision_model */ = {
isa = PBXGroup;
children = (
FCAFD8482231614200496A36 /* yolo_16 */,
FC704C1C21D237FC00F98BAB /* mobilenet */,
FC704C1F21D237FC00F98BAB /* yolo */,
);
......@@ -322,6 +327,15 @@
path = mobilenet;
sourceTree = "<group>";
};
FCAFD8482231614200496A36 /* yolo_16 */ = {
isa = PBXGroup;
children = (
FCAFD8492231614200496A36 /* yolo_16_param */,
FCAFD84A2231614200496A36 /* yolo_16_model */,
);
path = yolo_16;
sourceTree = "<group>";
};
/* 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 */,
......
......@@ -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 {
......
......@@ -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
......
......@@ -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
......
......@@ -34,7 +34,7 @@ import Foundation
@objc public class Runner: NSObject {
var program: Program?
var executor: Executor<Float32>?
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<Float32>.init()
var loader: Loaderable
switch net.paramPrecision {
case .Float16:
loader = Loader<Float16>.init()
case .Float32:
loader = Loader<Float32>.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<Float32>.init(inDevice: inDevice, inQueue: inQueue, inProgram: program!, initContext: initContext)
switch net.paramPrecision {
case .Float16:
executor = try Executor<Float16>.init(inDevice: inDevice, inQueue: inQueue, inProgram: program!, initContext: initContext)
case .Float32:
executor = try Executor<Float32>.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 " )
......
......@@ -254,7 +254,7 @@ extension MTLDevice {
return tensor
}
func tensor2texture<P>(value: [P], dim: [Int], transpose: [Int] = [0, 1, 2, 3], inComputePrecision: ComputePrecision = .Float32) -> MTLTexture {
func tensor2texture<P>(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 })
}
......
......@@ -14,7 +14,7 @@
import Foundation
func writeToLibrary<P: PrecisionType>(fileName: String, array: [P]) {
func writeToLibrary<P: PrecisionProtocol>(fileName: String, array: [P]) {
let libraryPath = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true).last ?! " library path get error "
let filePath = libraryPath + "/" + fileName
let fileManager = FileManager.init()
......
......@@ -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<P: PrecisionType>(_ inP: P)
init<P: PrecisionProtocol>(_ 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<P>(_ inP: P) where P : PrecisionType {
public static func initializeValue() -> Int16 {
return 0
}
public init<P>(_ 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<P>(_ 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<P>(_ 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
}
......
......@@ -41,7 +41,12 @@ var isTest = false
}
public class Executor<P: PrecisionType> {
protocol Executorable {
func predict(input: MTLTexture, dim: Dim, completionHandle: @escaping ([GPUResultHolder]) -> Void, preProcessKernle: CusomKernel?, except: Int) throws
func clear()
}
public class Executor<P: PrecisionProtocol>: Executorable{
var ops: [Runable & InferShaperable] = []
var preInputDim: Dim = Dim.init(inDim: [])
let program: Program
......
......@@ -15,7 +15,12 @@
import Foundation
//import SwiftProtobuf
public class Loader<P: PrecisionType> {
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<P: PrecisionProtocol>: Loaderable{
class ParaLoader {
let file: UnsafeMutablePointer<FILE>
let fileSize: Int
......@@ -143,7 +148,7 @@ public class Loader<P: PrecisionType> {
}
}
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<P: PrecisionType> {
}
}
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 !")
}
......
......@@ -28,7 +28,7 @@ extension Tensorial {
}
}
class DataConverter<P: PrecisionType> {
class DataConverter<P: PrecisionProtocol> {
func convert(from: UnsafeMutablePointer<P>, to: UnsafeMutablePointer<P>, fromDim: Dim) {
fatalError(" need imp")
}
......@@ -40,7 +40,7 @@ class DataConverter<P: PrecisionType> {
/// [ outputChannels ][ inputChannels ][ kernelHeight ][ kernelWidth ] ->
/// [ outputChannels ][ kernelHeight ][ kernelWidth ][ inputChannels ]
class MPSPointerConverter<P: PrecisionType>: DataConverter<P>{
class MPSPointerConverter<P: PrecisionProtocol>: DataConverter<P>{
/// [ outputChannels ][ inputChannels ][ kernelHeight ][ kernelWidth ] ->
/// [ outputChannels ][ kernelHeight ][ kernelWidth ][ inputChannels ]
......@@ -81,7 +81,7 @@ class MPSPointerConverter<P: PrecisionType>: DataConverter<P>{
}
}
class Tensor<P: PrecisionType>: Tensorial {
class Tensor<P: PrecisionProtocol>: Tensorial {
var data: Data
var dim: Dim
......@@ -169,14 +169,15 @@ class Tensor<P: PrecisionType>: 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<P>.allocate(capacity: numel())
let n = dim[0]
......@@ -193,12 +194,8 @@ class Tensor<P: PrecisionType>: Tensorial {
data = Data.init(inCount: data.count, inPointer: transposePointer)
}
guard let floatPointer = data.pointer as? UnsafeMutablePointer<Float32> else {
fatalError(" not support yet ")
}
let precisionSize: Int
switch precision {
switch computePrecision {
case .Float32:
precisionSize = 4
case .Float16:
......@@ -213,44 +210,58 @@ class Tensor<P: PrecisionType>: 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<P>.stride)
switch P.precisionType {
case .Float16:
float32ToFloat16(input: floatPointer, output: buffer.contents(), count: count)
buffer?.contents().copyMemory(from: data.pointer, byteCount: count * MemoryLayout<P>.stride)
case .Float32:
switch computePrecision {
case .Float32:
buffer?.contents().copyMemory(from: data.pointer, byteCount: count * MemoryLayout<P>.stride)
case .Float16:
float32ToFloat16(input: data.pointer as! UnsafeMutablePointer<Float32>, 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<P>.stride)
switch P.precisionType {
case .Float16:
float32ToFloat16(input: floatPointer, output: buffer.contents(), count: numel())
buffer?.contents().copyMemory(from: data.pointer, byteCount: numel() * MemoryLayout<P>.stride)
case .Float32:
switch computePrecision {
case .Float32:
buffer?.contents().copyMemory(from: data.pointer, byteCount: numel() * MemoryLayout<P>.stride)
case .Float16:
float32ToFloat16(input: data.pointer as! UnsafeMutablePointer<Float32>, output: buffer.contents(), count: numel())
}
}
} else {
buffer = device.makeBuffer(length: count * precisionSize)
let convertedPointer = UnsafeMutablePointer<Float32>.allocate(capacity: count)
var tmpPointer = floatPointer
let convertedPointer = UnsafeMutablePointer<P>.allocate(capacity: count)
var tmpPointer = data.pointer
var dstPtr = convertedPointer
for _ in 0..<dim[0] * dim[1] * dim[2] {
for j in 0..<paddedC {
if j < C {
dstPtr[j] = tmpPointer[j]
} else {
dstPtr[j] = 0
dstPtr[j] = P.initializeValue()
}
}
tmpPointer += C
dstPtr += paddedC
}
switch precision {
case .Float32:
buffer?.contents().copyMemory(from: convertedPointer, byteCount: count * MemoryLayout<P>.stride)
switch P.precisionType {
case .Float16:
float32ToFloat16(input: convertedPointer, output: buffer.contents(), count: count)
buffer?.contents().copyMemory(from: convertedPointer, byteCount: count * MemoryLayout<P>.stride)
case .Float32:
switch computePrecision {
case .Float32:
buffer?.contents().copyMemory(from: convertedPointer, byteCount: count * MemoryLayout<P>.stride)
case .Float16:
float32ToFloat16(input: convertedPointer as! UnsafeMutablePointer<Float32>, output: buffer.contents(), count: count)
}
}
convertedPointer.deinitialize(count: count)
convertedPointer.deallocate()
}
......@@ -261,36 +272,46 @@ class Tensor<P: PrecisionType>: 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<P>.stride)
switch P.precisionType {
case .Float16:
float32ToFloat16(input: floatPointer, output: buffer.contents(), count: count)
buffer?.contents().copyMemory(from: data.pointer, byteCount: count * MemoryLayout<P>.stride)
case .Float32:
switch computePrecision {
case .Float32:
buffer?.contents().copyMemory(from: data.pointer, byteCount: count * MemoryLayout<P>.stride)
case .Float16:
float32ToFloat16(input: data.pointer as! UnsafeMutablePointer<Float32>, output: buffer.contents(), count: count)
}
}
} else if C == 1 {
fatalError(" not support ")
} else {
buffer = device.makeBuffer(length: count * precisionSize)
let convertedPointer = UnsafeMutablePointer<Float32>.allocate(capacity: count)
var tmpPointer = floatPointer
let convertedPointer = UnsafeMutablePointer<P>.allocate(capacity: count)
var tmpPointer = data.pointer
var dstPtr = convertedPointer
for _ in 0..<dim[0] * dim[1] * dim[2] {
for j in 0..<paddedC {
if j < C {
dstPtr[j] = tmpPointer[j]
} else {
dstPtr[j] = 0
dstPtr[j] = P.initializeValue()
}
}
tmpPointer += C
dstPtr += paddedC
}
switch precision {
case .Float32:
switch P.precisionType {
case .Float16: // 模型精度为 32 位
buffer?.contents().copyMemory(from: convertedPointer, byteCount: count * MemoryLayout<P>.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<P>.stride)
case .Float16:
float32ToFloat16(input: convertedPointer as! UnsafeMutablePointer<Float32>, output: buffer.contents(), count: count)
}
}
convertedPointer.deinitialize(count: count)
convertedPointer.deallocate()
......@@ -299,11 +320,17 @@ class Tensor<P: PrecisionType>: 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<P>.stride)
switch P.precisionType {
case .Float16:
float32ToFloat16(input: floatPointer, output: buffer.contents(), count: num)
buffer?.contents().copyMemory(from: data.pointer, byteCount: num * MemoryLayout<P>.stride)
case .Float32:
switch computePrecision {
case .Float32:
buffer?.contents().copyMemory(from: data.pointer, byteCount: num * MemoryLayout<P>.stride)
case .Float16:
float32ToFloat16(input: data.pointer as! UnsafeMutablePointer<Float32>, 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..<buffer.length/MemoryLayout<P>.size {
str += " \(buffer.contents().assumingMemoryBound(to: P.self)[i])"
}
......
......@@ -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
}
......
......@@ -15,7 +15,7 @@
import Foundation
fileprivate var singletons : [String : Any] = [:]
class OpCreator<P: PrecisionType> {
class OpCreator<P: PrecisionProtocol> {
static var shared : OpCreator<P> {
let key = String(describing: P.self)
if let singleton = singletons[key] {
......
......@@ -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<VarType: Variant>(key: String, map: [String : [String]], from: Scope) throws -> VarType
static func inputX<VarType: Variant>(inputs: [String : [String]], from: Scope) throws -> VarType
......
......@@ -15,7 +15,7 @@
import Foundation
import Metal
class BatchNormParam<P: PrecisionType>: OpParam {
class BatchNormParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -44,7 +44,7 @@ class BatchNormParam<P: PrecisionType>: OpParam {
let momentum: Float
}
class BatchNormOp<P: PrecisionType>: Operator<BatchNormKernel<P>, BatchNormParam<P>>, Runable, Creator, InferShaperable{
class BatchNormOp<P: PrecisionProtocol>: Operator<BatchNormKernel<P>, BatchNormParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = BatchNormOp<P>
func inferShape() {
......
......@@ -15,7 +15,7 @@
import Foundation
import Metal
class BilinearInterpParam<P: PrecisionType>: OpParam {
class BilinearInterpParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -36,7 +36,7 @@ class BilinearInterpParam<P: PrecisionType>: OpParam {
let out_w: Int
}
class BilinearInterpOp<P: PrecisionType>: Operator<BilinearInterpKernel<P>, BilinearInterpParam<P>>, Runable, Creator, InferShaperable{
class BilinearInterpOp<P: PrecisionProtocol>: Operator<BilinearInterpKernel<P>, BilinearInterpParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = BilinearInterpOp<P>
......
......@@ -14,7 +14,7 @@
import Foundation
class BoxcoderParam<P: PrecisionType>: OpParam {
class BoxcoderParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -45,7 +45,7 @@ class BoxcoderParam<P: PrecisionType>: OpParam {
let boxNormalized: Bool
}
class BoxcoderOp<P: PrecisionType>: Operator<BoxcoderKernel<P>, BoxcoderParam<P>>, Runable, Creator, InferShaperable{
class BoxcoderOp<P: PrecisionProtocol>: Operator<BoxcoderKernel<P>, BoxcoderParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = BoxcoderOp<P>
......
......@@ -14,7 +14,7 @@
import Foundation
class ConcatParam<P: PrecisionType>: OpParam {
class ConcatParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -46,7 +46,7 @@ class ConcatParam<P: PrecisionType>: OpParam {
let axis: Int
}
class ConcatOp<P: PrecisionType>: Operator<ConcatKernel<P>, ConcatParam<P>>, Runable, Creator, InferShaperable{
class ConcatOp<P: PrecisionProtocol>: Operator<ConcatKernel<P>, ConcatParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = ConcatOp<P>
......
......@@ -15,7 +15,7 @@
import Foundation
import Metal
class ConvAddAddPreluParam<P: PrecisionType>: OpParam {
class ConvAddAddPreluParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -46,7 +46,7 @@ class ConvAddAddPreluParam<P: PrecisionType>: OpParam {
let groups: Int
}
class ConvAddAddPreluOp<P: PrecisionType>: Operator<ConvAddAddPreluKernel<P>, ConvAddAddPreluParam<P>>, Runable, Creator, InferShaperable, Fusion{
class ConvAddAddPreluOp<P: PrecisionProtocol>: Operator<ConvAddAddPreluKernel<P>, ConvAddAddPreluParam<P>>, Runable, Creator, InferShaperable, Fusion{
typealias OpType = ConvAddAddPreluOp<P>
static func fusionNode() -> Node {
......
......@@ -15,7 +15,7 @@
import Foundation
class ConvAddBatchNormReluParam<P: PrecisionType>: OpParam {
class ConvAddBatchNormReluParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -59,7 +59,7 @@ class ConvAddBatchNormReluParam<P: PrecisionType>: OpParam {
let groups: Int
}
class ConvAddBatchNormReluOp<P: PrecisionType>: Operator<ConvAddBatchNormReluKernel<P>, ConvAddBatchNormReluParam<P>>, Runable, Creator, InferShaperable, Fusion{
class ConvAddBatchNormReluOp<P: PrecisionProtocol>: Operator<ConvAddBatchNormReluKernel<P>, ConvAddBatchNormReluParam<P>>, Runable, Creator, InferShaperable, Fusion{
typealias OpType = ConvAddBatchNormReluOp<P>
......
......@@ -14,7 +14,7 @@
import Foundation
class ConvAddParam<P: PrecisionType>: OpParam {
class ConvAddParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -43,7 +43,7 @@ class ConvAddParam<P: PrecisionType>: OpParam {
let groups: Int
}
class ConvAddOp<P: PrecisionType>: Operator<ConvAddKernel<P>, ConvAddParam<P>>, Runable, Creator, InferShaperable, Fusion{
class ConvAddOp<P: PrecisionProtocol>: Operator<ConvAddKernel<P>, ConvAddParam<P>>, Runable, Creator, InferShaperable, Fusion{
typealias OpType = ConvAddOp<P>
static func fusionNode() -> Node {
......
......@@ -14,7 +14,7 @@
import Foundation
class ConvAddPreluParam<P: PrecisionType>: OpParam {
class ConvAddPreluParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -45,7 +45,7 @@ class ConvAddPreluParam<P: PrecisionType>: OpParam {
let groups: Int
}
class ConvAddPreluOp<P: PrecisionType>: Operator<ConvAddPreluKernel<P>, ConvAddPreluParam<P>>, Runable, Creator, InferShaperable, Fusion{
class ConvAddPreluOp<P: PrecisionProtocol>: Operator<ConvAddPreluKernel<P>, ConvAddPreluParam<P>>, Runable, Creator, InferShaperable, Fusion{
typealias OpType = ConvAddPreluOp<P>
static func fusionNode() -> Node {
......
......@@ -14,7 +14,7 @@
import Foundation
class ConvBNReluParam<P: PrecisionType>: OpParam {
class ConvBNReluParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -53,7 +53,7 @@ class ConvBNReluParam<P: PrecisionType>: OpParam {
let groups: Int
}
class ConvBNReluOp<P: PrecisionType>: Operator<ConvBNReluKernel<P>, ConvBNReluParam<P>>, Runable, Creator, InferShaperable, Fusion{
class ConvBNReluOp<P: PrecisionProtocol>: Operator<ConvBNReluKernel<P>, ConvBNReluParam<P>>, Runable, Creator, InferShaperable, Fusion{
typealias OpType = ConvBNReluOp<P>
func inputs() -> [Variant] {
......
......@@ -14,7 +14,7 @@
import Foundation
class ConvParam<P: PrecisionType>: OpParam {
class ConvParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -40,7 +40,7 @@ class ConvParam<P: PrecisionType>: OpParam {
let groups: Int
}
class ConvOp<P: PrecisionType>: Operator<ConvKernel<P>, ConvParam<P>>, Runable, Creator, InferShaperable {
class ConvOp<P: PrecisionProtocol>: Operator<ConvKernel<P>, ConvParam<P>>, Runable, Creator, InferShaperable {
typealias OpType = ConvOp<P>
func inferShape() {
......
......@@ -14,7 +14,7 @@
import Foundation
class ConvTransposeParam<P: PrecisionType>: ConvParam<P> {
class ConvTransposeParam<P: PrecisionProtocol>: ConvParam<P> {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -25,7 +25,7 @@ class ConvTransposeParam<P: PrecisionType>: ConvParam<P> {
}
}
class ConvTransposeOp<P: PrecisionType>: Operator<ConvTransposeKernel<P>, ConvTransposeParam<P>>, Runable, Creator, InferShaperable{
class ConvTransposeOp<P: PrecisionProtocol>: Operator<ConvTransposeKernel<P>, ConvTransposeParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = ConvTransposeOp<P>
......
......@@ -14,7 +14,7 @@
import Foundation
class DepthConvOp<P: PrecisionType>: Operator<ConvKernel<P>, ConvParam<P>>, Runable, Creator, InferShaperable {
class DepthConvOp<P: PrecisionProtocol>: Operator<ConvKernel<P>, ConvParam<P>>, Runable, Creator, InferShaperable {
typealias OpType = DepthConvOp<P>
......
......@@ -14,7 +14,7 @@
import Foundation
class DwConvBNReluOp<P: PrecisionType>: Operator<ConvBNReluKernel<P>, ConvBNReluParam<P>>, Runable, Creator, InferShaperable, Fusion{
class DwConvBNReluOp<P: PrecisionProtocol>: Operator<ConvBNReluKernel<P>, ConvBNReluParam<P>>, Runable, Creator, InferShaperable, Fusion{
typealias OpType = ConvBNReluOp<P>
func inferShape() {
......
......@@ -15,7 +15,7 @@
import Foundation
import Metal
class ElementwiseAddParam<P: PrecisionType>: OpParam {
class ElementwiseAddParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -61,7 +61,7 @@ class ElementwiseAddParam<P: PrecisionType>: OpParam {
var axis: Int
}
class ElementwiseAddOp<P: PrecisionType>: Operator<ElementwiseAddKernel<P>, ElementwiseAddParam<P>>, Runable, Creator, InferShaperable{
class ElementwiseAddOp<P: PrecisionProtocol>: Operator<ElementwiseAddKernel<P>, ElementwiseAddParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = ElementwiseAddOp<P>
func inferShape() {
......
......@@ -15,7 +15,7 @@
import Foundation
import Metal
class ElementwiseAddPreluParam<P: PrecisionType>: OpParam {
class ElementwiseAddPreluParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -65,7 +65,7 @@ class ElementwiseAddPreluParam<P: PrecisionType>: OpParam {
var axis: Int
}
class ElementwiseAddPreluOp<P: PrecisionType>: Operator<ElementwiseAddPreluKernel<P>, ElementwiseAddPreluParam<P>>, Runable, Creator, InferShaperable, Fusion{
class ElementwiseAddPreluOp<P: PrecisionProtocol>: Operator<ElementwiseAddPreluKernel<P>, ElementwiseAddPreluParam<P>>, Runable, Creator, InferShaperable, Fusion{
static func fusionNode() -> Node {
let beginNode = Node.init(inType: gElementwiseAddType)
_ = beginNode
......
......@@ -16,7 +16,7 @@ import Foundation
import MetalKit
import CoreMedia
class FeedParam<P: PrecisionType>: OpParam{
class FeedParam<P: PrecisionProtocol>: OpParam{
var output: Texture
var input: InputTexture {
return scope.input() as! InputTexture
......@@ -35,7 +35,7 @@ class FeedParam<P: PrecisionType>: OpParam{
//typealias ParamPrecisionType = P
}
class FeedOp<P: PrecisionType>: Operator<Texture2DTo2DArrayKernel<P>, FeedParam<P>>, Runable, Creator, InferShaperable {
class FeedOp<P: PrecisionProtocol>: Operator<Texture2DTo2DArrayKernel<P>, FeedParam<P>>, Runable, Creator, InferShaperable {
typealias OpType = FeedOp<P>
func inferShape() {
......
......@@ -15,7 +15,7 @@
import Foundation
import Metal
class FetchParam<P: PrecisionType>: OpParam{
class FetchParam<P: PrecisionProtocol>: OpParam{
var output: FetchHolder
let input: Texture
let scope: Scope
......@@ -33,7 +33,7 @@ class FetchParam<P: PrecisionType>: OpParam{
//typealias ParamPrecisionType = P
}
class FetchOp<P: PrecisionType>: Operator< FetchKernel<P>, FetchParam<P>>, Runable, Creator, InferShaperable {
class FetchOp<P: PrecisionProtocol>: Operator< FetchKernel<P>, FetchParam<P>>, Runable, Creator, InferShaperable {
typealias OpType = FetchOp<P>
......
......@@ -14,7 +14,7 @@
import Foundation
class FlattenParam<P: PrecisionType>: OpParam {
class FlattenParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -31,7 +31,7 @@ class FlattenParam<P: PrecisionType>: OpParam {
}
class FlattenOp<P: PrecisionType>: Operator<FlattenKernel<P>, FlattenParam<P>>, Runable, Creator, InferShaperable{
class FlattenOp<P: PrecisionProtocol>: Operator<FlattenKernel<P>, FlattenParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = FlattenOp<P>
......
......@@ -14,7 +14,7 @@
import Foundation
class BatchNormKernel<P: PrecisionType>: Kernel, Computable {
class BatchNormKernel<P: PrecisionProtocol>: Kernel, Computable {
required init(device: MTLDevice, param: BatchNormParam<P>, initContext: InitContext) {
let count = param.variance.dim.numel()
let varianceP = param.variance.data.pointer
......
......@@ -19,7 +19,7 @@ struct BilinearInterpMetalParam {
var ratio_w: Float32
}
class BilinearInterpKernel<P: PrecisionType>: Kernel, Computable{
class BilinearInterpKernel<P: PrecisionProtocol>: Kernel, Computable{
func compute(commandBuffer: MTLCommandBuffer, param: BilinearInterpParam<P>) throws {
guard let encoder = commandBuffer.makeComputeCommandEncoder() else {
throw PaddleMobileError.predictError(message: " encode is nil")
......
......@@ -17,7 +17,7 @@ import Foundation
struct BoxcoderMetalParam {
}
class BoxcoderKernel<P: PrecisionType>: Kernel, Computable{
class BoxcoderKernel<P: PrecisionProtocol>: Kernel, Computable{
func compute(commandBuffer: MTLCommandBuffer, param: BoxcoderParam<P>) throws {
guard let encoder = commandBuffer.makeComputeCommandEncoder() else {
throw PaddleMobileError.predictError(message: " encode is nil")
......
......@@ -31,7 +31,7 @@ struct ConcatMetalParam {
var vdim: (Int32, Int32, Int32, Int32, Int32, Int32) = (0, 0, 0, 0, 0, 0)
}
class ConcatKernel<P: PrecisionType>: Kernel, Computable{
class ConcatKernel<P: PrecisionProtocol>: Kernel, Computable{
var v = "normal"
var pm = ConcatMetalParam.init()
func compute(commandBuffer: MTLCommandBuffer, param: ConcatParam<P>) throws {
......
......@@ -14,7 +14,7 @@
import Foundation
class ConvAddAddPreluKernel<P: PrecisionType>: Kernel, Computable {
class ConvAddAddPreluKernel<P: PrecisionProtocol>: Kernel, Computable {
var metalParam: MetalConvParam!
required init(device: MTLDevice, param: ConvAddAddPreluParam<P>, initContext: InitContext) {
param.output.initTexture(device: device, inTranspose: [0, 2, 3, 1], computePrecision: GlobalConfig.shared.computePrecision)
......
......@@ -36,7 +36,7 @@ struct ConvAddBatchNormReluTestParam: TestParam {
}
}
class ConvAddBatchNormReluKernel<P: PrecisionType>: Kernel, Computable, Testable {
class ConvAddBatchNormReluKernel<P: PrecisionProtocol>: 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)
......
......@@ -27,7 +27,7 @@ func getUniqueKey() -> String {
return UUID.init().uuidString
}
class ConvAddKernel<P: PrecisionType>: Kernel, Computable {
class ConvAddKernel<P: PrecisionProtocol>: Kernel, Computable {
var metalParam: MetalConvParam!
let identifyingKey: String = getUniqueKey()
......
......@@ -14,7 +14,7 @@
import Foundation
class ConvAddPreluKernel<P: PrecisionType>: Kernel, Computable {
class ConvAddPreluKernel<P: PrecisionProtocol>: Kernel, Computable {
var metalParam: MetalConvParam!
required init(device: MTLDevice, param: ConvAddPreluParam<P>, initContext: InitContext) {
param.output.initTexture(device: device, inTranspose: [0, 2, 3, 1], computePrecision: GlobalConfig.shared.computePrecision)
......
......@@ -37,7 +37,7 @@ struct ConvBNReluTestParam: TestParam {
}
}
class ConvBNReluKernel<P: PrecisionType>: Kernel, Computable, Testable {
class ConvBNReluKernel<P: PrecisionProtocol>: 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)
......
......@@ -24,10 +24,10 @@ public struct MetalConvParam {
let dilationY: UInt16
}
class ConvKernel<P: PrecisionType>: Kernel, Computable {
class ConvKernel<P: PrecisionProtocol>: Kernel, Computable {
var metalParam: MetalConvParam!
required init(device: MTLDevice, param: ConvParam<P>, 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 {
......
......@@ -28,7 +28,7 @@ struct MetalConvTransposeParam {
let dilationY: UInt16;
}
class ConvTransposeKernel<P: PrecisionType>: Kernel, Computable{
class ConvTransposeKernel<P: PrecisionProtocol>: Kernel, Computable{
var metalParam: MetalConvTransposeParam!
required init(device: MTLDevice, param: ConvTransposeParam<P>, initContext: InitContext) {
param.output.initTexture(device: device, inTranspose: param.input.transpose, computePrecision: GlobalConfig.shared.computePrecision)
......
......@@ -24,7 +24,7 @@ struct ElementwiseAddMetalParam {
var ytrans: (Int32, Int32, Int32, Int32) = (0, 1, 2, 3)
}
class ElementwiseAddKernel<P: PrecisionType>: Kernel, Computable {
class ElementwiseAddKernel<P: PrecisionProtocol>: Kernel, Computable {
var metalParam: ElementwiseAddMetalParam
required init(device: MTLDevice, param: ElementwiseAddParam<P>, initContext: InitContext) {
param.output.initTexture(device: device, inTranspose: param.inputX.transpose, computePrecision: GlobalConfig.shared.computePrecision)
......
......@@ -15,7 +15,7 @@
import Foundation
class ElementwiseAddPreluKernel<P: PrecisionType>: Kernel, Computable {
class ElementwiseAddPreluKernel<P: PrecisionProtocol>: Kernel, Computable {
var metalParam: ElementwiseAddMetalParam
required init(device: MTLDevice, param: ElementwiseAddPreluParam<P>, initContext: InitContext) {
param.output.initTexture(device: device, inTranspose: param.inputX.transpose, computePrecision: GlobalConfig.shared.computePrecision)
......
......@@ -14,7 +14,7 @@
import Foundation
class FetchKernel<P: PrecisionType>: Kernel, Computable {
class FetchKernel<P: PrecisionProtocol>: Kernel, Computable {
required init(device: MTLDevice, param: FetchParam<P>, initContext: InitContext) {
param.output.initBuffer(device: device)
......
......@@ -22,7 +22,7 @@ struct FlattenMetalParam {
}
class FlattenKernel<P: PrecisionType>: Kernel, Computable{
class FlattenKernel<P: PrecisionProtocol>: Kernel, Computable{
var metalParam: FlattenMetalParam
......
......@@ -14,7 +14,7 @@
import Foundation
class MulticlassNMSKernel<P: PrecisionType>: Kernel, Computable{
class MulticlassNMSKernel<P: PrecisionProtocol>: Kernel, Computable{
let pipline1: MTLComputePipelineState
required init(device: MTLDevice, param: MulticlassNMSParam<P>, initContext: InitContext) {
......
......@@ -24,7 +24,7 @@ struct PoolMetalParam {
let poolType: Int32
}
class PoolKernel<P: PrecisionType>: Kernel, Computable{
class PoolKernel<P: PrecisionProtocol>: Kernel, Computable{
var metalParam: PoolMetalParam
required init(device: MTLDevice, param: PoolParam<P>, initContext: InitContext) {
param.output.initTexture(device: device, inTranspose: param.input.transpose, computePrecision: GlobalConfig.shared.computePrecision)
......
......@@ -14,7 +14,7 @@
import Foundation
class PreluKernel<P: PrecisionType>: Kernel, Computable{
class PreluKernel<P: PrecisionProtocol>: Kernel, Computable{
required init(device: MTLDevice, param: PreluParam<P>, initContext: InitContext) {
param.alpha.initBuffer(device: device, precision: GlobalConfig.shared.computePrecision)
param.output.initTexture(device: device, inTranspose: param.input.transpose, computePrecision: GlobalConfig.shared.computePrecision)
......
......@@ -29,7 +29,7 @@ struct PriorBoxMetalParam {
let maxSizeSize: uint
}
class PriorBoxKernel<P: PrecisionType>: Kernel, Computable{
class PriorBoxKernel<P: PrecisionProtocol>: Kernel, Computable{
var metalParam: PriorBoxMetalParam!
required init(device: MTLDevice, param: PriorBoxParam<P>, initContext: InitContext) {
......
......@@ -14,7 +14,7 @@
import Foundation
class ReluKernel<P: PrecisionType>: Kernel, Computable{
class ReluKernel<P: PrecisionProtocol>: Kernel, Computable{
func compute(commandBuffer: MTLCommandBuffer, param: ReluParam<P>) throws {
guard let encoder = commandBuffer.makeComputeCommandEncoder() else {
throw PaddleMobileError.predictError(message: " encode is nil")
......
......@@ -27,7 +27,7 @@ struct ReshapeTestParam: TestParam {
let param: ReshapeMetalParam
}
class ReshapeKernel<P: PrecisionType>: Kernel, Computable{
class ReshapeKernel<P: PrecisionProtocol>: Kernel, Computable{
var metalParam: ReshapeMetalParam
......
......@@ -19,7 +19,7 @@ struct ResizeBilinearMetalParam {
var ratio_w: Float32
}
class ResizeBilinearKernel<P: PrecisionType>: Kernel, Computable{
class ResizeBilinearKernel<P: PrecisionProtocol>: Kernel, Computable{
required init(device: MTLDevice, param: ResizeBilinearParam<P>, initContext: InitContext) {
param.output.initTexture(device: device, inTranspose: param.input.transpose, computePrecision: GlobalConfig.shared.computePrecision)
if GlobalConfig.shared.computePrecision == .Float32 {
......
......@@ -18,7 +18,7 @@ import Foundation
struct ShapeMetalParam {
}
class ShapeKernel<P: PrecisionType>: Kernel, Computable{
class ShapeKernel<P: PrecisionProtocol>: Kernel, Computable{
func compute(commandBuffer: MTLCommandBuffer, param: ShapeParam<P>) throws {
// print("shape compute")
// guard let encoder = commandBuffer.makeComputeCommandEncoder() else {
......
......@@ -19,7 +19,7 @@ struct SoftmaxMetalParam {
let K: Int32
}
class SoftmaxKernel<P: PrecisionType>: Kernel, Computable{
class SoftmaxKernel<P: PrecisionProtocol>: Kernel, Computable{
var metalParam: SoftmaxMetalParam
required init(device: MTLDevice, param: SoftmaxParam<P>, initContext: InitContext) {
......
......@@ -22,7 +22,7 @@ struct SplitMetalParam {
var vdim: (Int32, Int32, Int32, Int32) = (0, 0, 0, 0)
}
class SplitKernel<P: PrecisionType>: Kernel, Computable{
class SplitKernel<P: PrecisionProtocol>: Kernel, Computable{
var smp: SplitMetalParam
func compute(commandBuffer: MTLCommandBuffer, param: SplitParam<P>) throws {
guard let encoder = commandBuffer.makeComputeCommandEncoder() else {
......
......@@ -22,7 +22,7 @@ struct Texture2DTo2DArrayParam {
let expectDim: Dim
}
class Texture2DTo2DArrayKernel<P: PrecisionType>: Kernel, Computable{
class Texture2DTo2DArrayKernel<P: PrecisionProtocol>: Kernel, Computable{
func compute(commandBuffer: MTLCommandBuffer, param: FeedParam<P>) throws {
guard let encoder = commandBuffer.makeComputeCommandEncoder() else {
throw PaddleMobileError.predictError(message: " encode is nil")
......
......@@ -20,7 +20,7 @@ struct TransposeMetalParam {
var axis: (Int32, Int32, Int32, Int32) = (0, 1, 2, 3)
}
class TransposeKernel<P: PrecisionType>: Kernel, Computable {
class TransposeKernel<P: PrecisionProtocol>: Kernel, Computable {
var metalParam: TransposeMetalParam = TransposeMetalParam.init()
required init(device: MTLDevice, param: TransposeParam<P>, initContext: InitContext) {
param.output.initTexture(device: device, computePrecision: GlobalConfig.shared.computePrecision)
......
......@@ -14,7 +14,7 @@
import Foundation
class MulticlassNMSParam<P: PrecisionType>: OpParam {
class MulticlassNMSParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -36,7 +36,7 @@ class MulticlassNMSParam<P: PrecisionType>: OpParam {
var output: Texture
}
class MulticlassNMSOp<P: PrecisionType>: Operator<MulticlassNMSKernel<P>, MulticlassNMSParam<P>>, Runable, Creator, InferShaperable{
class MulticlassNMSOp<P: PrecisionProtocol>: Operator<MulticlassNMSKernel<P>, MulticlassNMSParam<P>>, 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<P: PrecisionType>: Operator<MulticlassNMSKernel<P>, Multic
func computeMiddleResult(device: MTLDevice, buffer: MTLCommandBuffer) {
do {
try kernel.compute(commandBuffer: buffer, param: para)
} catch let _ {
fatalError()
} catch let error {
fatalError("\(error)")
}
}
......
......@@ -14,7 +14,7 @@
import Foundation
class PoolParam<P: PrecisionType>: OpParam {
class PoolParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -42,7 +42,7 @@ class PoolParam<P: PrecisionType>: OpParam {
var globalPooling: Bool
}
class PoolOp<P: PrecisionType>: Operator<PoolKernel<P>, PoolParam<P>>, Runable, Creator, InferShaperable{
class PoolOp<P: PrecisionProtocol>: Operator<PoolKernel<P>, PoolParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = PoolOp<P>
......
......@@ -14,7 +14,7 @@
import Foundation
class PreluParam<P: PrecisionType>: OpParam {
class PreluParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -32,7 +32,7 @@ class PreluParam<P: PrecisionType>: OpParam {
var output: Texture
}
class PreluOp<P: PrecisionType>: Operator<PreluKernel<P>, PreluParam<P>>, Runable, Creator, InferShaperable{
class PreluOp<P: PrecisionProtocol>: Operator<PreluKernel<P>, PreluParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = PreluOp<P>
......
......@@ -14,7 +14,7 @@
import Foundation
class PriorBoxParam<P: PrecisionType>: OpParam {
class PriorBoxParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -59,7 +59,7 @@ class PriorBoxParam<P: PrecisionType>: OpParam {
let outputVariances: Texture
}
class PriorBoxOp<P: PrecisionType>: Operator<PriorBoxKernel<P>, PriorBoxParam<P>>, Runable, Creator, InferShaperable{
class PriorBoxOp<P: PrecisionProtocol>: Operator<PriorBoxKernel<P>, PriorBoxParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = PriorBoxOp<P>
......
......@@ -15,7 +15,7 @@
import Foundation
class ReluParam<P: PrecisionType>: OpParam {
class ReluParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -29,7 +29,7 @@ class ReluParam<P: PrecisionType>: OpParam {
var output: Texture
}
class ReluOp<P: PrecisionType>: Operator<ReluKernel<P>, ReluParam<P>>, Runable, Creator, InferShaperable{
class ReluOp<P: PrecisionProtocol>: Operator<ReluKernel<P>, ReluParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = ReluOp<P>
......
......@@ -15,7 +15,7 @@
import Foundation
import Metal
class ReshapeParam<P: PrecisionType>: OpParam {
class ReshapeParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -53,7 +53,7 @@ class ReshapeParam<P: PrecisionType>: OpParam {
var output: Texture
}
class ReshapeOp<P: PrecisionType>: Operator<ReshapeKernel<P>, ReshapeParam<P>>, Runable, Creator, InferShaperable{
class ReshapeOp<P: PrecisionProtocol>: Operator<ReshapeKernel<P>, ReshapeParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = ReshapeOp<P>
......
......@@ -14,7 +14,7 @@
import Foundation
class ResizeBilinearParam<P: PrecisionType>: OpParam {
class ResizeBilinearParam<P: PrecisionProtocol>: OpParam {
typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -35,7 +35,7 @@ class ResizeBilinearParam<P: PrecisionType>: OpParam {
let out_w: Int32
}
class ResizeBilinearOp<P: PrecisionType>: Operator<ResizeBilinearKernel<P>, ResizeBilinearParam<P>>, Runable, Creator, InferShaperable{
class ResizeBilinearOp<P: PrecisionProtocol>: Operator<ResizeBilinearKernel<P>, ResizeBilinearParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = ResizeBilinearOp<P>
......
......@@ -14,7 +14,7 @@
import Foundation
class ShapeParam<P: PrecisionType>: OpParam {
class ShapeParam<P: PrecisionProtocol>: OpParam {
// typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -28,7 +28,7 @@ class ShapeParam<P: PrecisionType>: OpParam {
let input: Texture
}
class ShapeOp<P: PrecisionType>: Operator<ShapeKernel<P>, ShapeParam<P>>, Runable, Creator, InferShaperable{
class ShapeOp<P: PrecisionProtocol>: Operator<ShapeKernel<P>, ShapeParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = ShapeOp<P>
......
......@@ -15,7 +15,7 @@
import Foundation
import Metal
class SoftmaxParam<P: PrecisionType>: OpParam {
class SoftmaxParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -36,7 +36,7 @@ class SoftmaxParam<P: PrecisionType>: OpParam {
var output: Texture
}
class SoftmaxOp<P: PrecisionType>: Operator<SoftmaxKernel<P>, SoftmaxParam<P>>, Runable, Creator, InferShaperable{
class SoftmaxOp<P: PrecisionProtocol>: Operator<SoftmaxKernel<P>, SoftmaxParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = SoftmaxOp<P>
func inferShape() {
......
......@@ -14,7 +14,7 @@
import Foundation
class SplitParam<P: PrecisionType>: OpParam {
class SplitParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -47,7 +47,7 @@ class SplitParam<P: PrecisionType>: OpParam {
var sections: [Int32] = []
}
class SplitOp<P: PrecisionType>: Operator<SplitKernel<P>, SplitParam<P>>, Runable, Creator, InferShaperable{
class SplitOp<P: PrecisionProtocol>: Operator<SplitKernel<P>, SplitParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = SplitOp<P>
......
......@@ -15,7 +15,7 @@
import Foundation
import Metal
class TransposeParam<P: PrecisionType>: OpParam {
class TransposeParam<P: PrecisionProtocol>: OpParam {
//typealias ParamPrecisionType = P
required init(opDesc: PMOpDesc, inScope: Scope) throws {
do {
......@@ -31,7 +31,7 @@ class TransposeParam<P: PrecisionType>: OpParam {
let axis: [Int32]
}
class TransposeOp<P: PrecisionType>: Operator<TransposeKernel<P>, TransposeParam<P>>, Runable, Creator, InferShaperable{
class TransposeOp<P: PrecisionProtocol>: Operator<TransposeKernel<P>, TransposeParam<P>>, Runable, Creator, InferShaperable{
typealias OpType = TransposeOp<P>
......
......@@ -181,7 +181,7 @@ extension Node: Equatable {
}
class ProgramOptimize<P: PrecisionType> {
class ProgramOptimize<P: PrecisionProtocol> {
// register fusion
let fusionOps: [Fusion.Type] = [ConvAddBatchNormReluOp<P>.self,
// ConvAddAddPreluOp<P>.self,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册