提交 2aecd77e 编写于 作者: H hjchen2

Merge branch 'dev-latest' of https://github.com/hjchen2/paddle-mobile into dev-latest

...@@ -93,3 +93,6 @@ metal/paddle-mobile/paddle-mobile/CPU/libpaddle-mobile.a ...@@ -93,3 +93,6 @@ metal/paddle-mobile/paddle-mobile/CPU/libpaddle-mobile.a
*.xcuserdatad/ *.xcuserdatad/
*/xcuserdata/ */xcuserdata/
/venv/ /venv/
metal/paddle-mobile-demo/paddle-mobile-demo/images
metal/paddle-mobile-demo/paddle-mobile-demo/models
...@@ -17,7 +17,7 @@ import MetalKit ...@@ -17,7 +17,7 @@ import MetalKit
import Foundation import Foundation
import paddle_mobile import paddle_mobile
class MetalHelper { public class MetalHelper {
let device: MTLDevice let device: MTLDevice
let queue: MTLCommandQueue let queue: MTLCommandQueue
let textureLoader: MTKTextureLoader let textureLoader: MTKTextureLoader
......
...@@ -23,23 +23,23 @@ let threadSupport: [(Platform, String)] = [(.GPU, "GPU"), (.CPU, "CPU")] ...@@ -23,23 +23,23 @@ let threadSupport: [(Platform, String)] = [(.GPU, "GPU"), (.CPU, "CPU")]
//.mobilenet_ssd : Runner.init(inNet: MobileNet_ssd_hand.init(device: MetalHelper.shared.device), commandQueue: MetalHelper.shared.queue, inPlatform: platform), //.mobilenet_ssd : Runner.init(inNet: MobileNet_ssd_hand.init(device: MetalHelper.shared.device), commandQueue: MetalHelper.shared.queue, inPlatform: platform),
let modelHelperMap: [SupportModel : Runner] = [ let modelHelperMap: [SupportModel : Runner] = [
.genet : Runner.init(inNet: Genet.init(device: MetalHelper.shared.device), commandQueue: MetalHelper.shared.queue, inPlatform: platform), .yolo : Runner.init(inNet: YoloNet.init(device: MetalHelper.shared.device), commandQueue: MetalHelper.shared.queue, inPlatform: platform),
.mobilenet_ssd_ar : Runner.init(inNet: MobileNet_ssd_AR.init(device: MetalHelper.shared.device), commandQueue: MetalHelper.shared.queue, inPlatform: platform)] .mobilenet_combined : Runner.init(inNet: MobileNetCombined.init(device: MetalHelper.shared.device), commandQueue: MetalHelper.shared.queue, inPlatform: platform)]
//, .genet : Genet.init() //, .genet : Genet.init()
//let modelHelperMap: [SupportModel : Net] = [.mobilenet : MobileNet.init(), .mobilenet_ssd : MobileNet_ssd_hand.init()] //let modelHelperMap: [SupportModel : Net] = [.mobilenet : MobileNet.init(), .mobilenet_ssd : MobileNet_ssd_hand.init()]
let netSupport: [SupportModel : Net] = [.genet : Genet.init(device: MetalHelper.shared.device), .mobilenet_ssd_ar : MobileNet_ssd_AR.init(device: MetalHelper.shared.device)] let netSupport: [SupportModel : Net] = [.yolo : YoloNet.init(device: MetalHelper.shared.device), .mobilenet_combined : MobileNetCombined.init(device: MetalHelper.shared.device)]
enum SupportModel: String{ enum SupportModel: String{
// case mobilenet = "mobilenet" // case mobilenet = "mobilenet"
// case mobilenet_ssd = "mobilenetssd" // case mobilenet_ssd = "mobilenetssd"
case genet = "genet" case yolo = "yolo"
case mobilenet_ssd_ar = "mobilenetssd_ar" case mobilenet_combined = "mobilenet_combined"
static func supportedModels() -> [SupportModel] { static func supportedModels() -> [SupportModel] {
// .mobilenet, // .mobilenet,
// .mobilenet_ssd, // .mobilenet_ssd,
return [.genet, .mobilenet_ssd_ar] return [.yolo, .mobilenet_combined]
} }
} }
...@@ -98,7 +98,7 @@ class ViewController: UIViewController { ...@@ -98,7 +98,7 @@ class ViewController: UIViewController {
} }
@IBAction func predictAct(_ sender: Any) { @IBAction func predictAct(_ sender: Any) {
let max = 50 let max = 1
switch platform { switch platform {
case .GPU: case .GPU:
guard let inTexture = toPredictTexture else { guard let inTexture = toPredictTexture else {
...@@ -106,11 +106,11 @@ class ViewController: UIViewController { ...@@ -106,11 +106,11 @@ class ViewController: UIViewController {
return return
} }
for _ in 0..<10{ // for _ in 0..<1{
runner.predict(texture: inTexture) { (success, resultHolder) in // runner.predict(texture: inTexture) { (success, resultHolder) in
resultHolder?.releasePointer() // resultHolder?.releasePointer()
} // }
} // }
let startDate = Date.init() let startDate = Date.init()
for i in 0..<max { for i in 0..<max {
......
...@@ -29,6 +29,11 @@ ...@@ -29,6 +29,11 @@
4AF9287921341661005B6C3A /* Softmax.metal in Sources */ = {isa = PBXBuildFile; fileRef = 4AF9287821341661005B6C3A /* Softmax.metal */; }; 4AF9287921341661005B6C3A /* Softmax.metal in Sources */ = {isa = PBXBuildFile; fileRef = 4AF9287821341661005B6C3A /* Softmax.metal */; };
4AF928822135673D005B6C3A /* ConcatKernel.metal in Sources */ = {isa = PBXBuildFile; fileRef = 4AF928812135673D005B6C3A /* ConcatKernel.metal */; }; 4AF928822135673D005B6C3A /* ConcatKernel.metal in Sources */ = {isa = PBXBuildFile; fileRef = 4AF928812135673D005B6C3A /* ConcatKernel.metal */; };
4AF9288421357BE3005B6C3A /* Elementwise.metal in Sources */ = {isa = PBXBuildFile; fileRef = 4AF9288321357BE3005B6C3A /* Elementwise.metal */; }; 4AF9288421357BE3005B6C3A /* Elementwise.metal in Sources */ = {isa = PBXBuildFile; fileRef = 4AF9288321357BE3005B6C3A /* Elementwise.metal */; };
C28FDF8421B7858F0054EFAC /* MobileNetCombined.swift in Sources */ = {isa = PBXBuildFile; fileRef = C28FDF8221B7858F0054EFAC /* MobileNetCombined.swift */; };
C28FDF8521B7858F0054EFAC /* YoloNet.swift in Sources */ = {isa = PBXBuildFile; fileRef = C28FDF8321B7858F0054EFAC /* YoloNet.swift */; };
C28FE02F21BA68C00054EFAC /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C28FE02C21BA68C00054EFAC /* Metal.framework */; };
C28FE03021BA68C00054EFAC /* MetalPerformanceShaders.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C28FE02D21BA68C00054EFAC /* MetalPerformanceShaders.framework */; };
C28FE03121BA68C00054EFAC /* MetalKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C28FE02E21BA68C00054EFAC /* MetalKit.framework */; };
D3831F70E7E0B565B9AC22DA /* Pods_paddle_mobile.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD2E06330A1E7129C918DB46 /* Pods_paddle_mobile.framework */; }; D3831F70E7E0B565B9AC22DA /* Pods_paddle_mobile.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD2E06330A1E7129C918DB46 /* Pods_paddle_mobile.framework */; };
FC0226562138F33800F395E2 /* TransposeKernel.metal in Sources */ = {isa = PBXBuildFile; fileRef = FC0226552138F33800F395E2 /* TransposeKernel.metal */; }; FC0226562138F33800F395E2 /* TransposeKernel.metal in Sources */ = {isa = PBXBuildFile; fileRef = FC0226552138F33800F395E2 /* TransposeKernel.metal */; };
FC0226582138F38D00F395E2 /* PoolKernel.metal in Sources */ = {isa = PBXBuildFile; fileRef = FC0226572138F38D00F395E2 /* PoolKernel.metal */; }; FC0226582138F38D00F395E2 /* PoolKernel.metal in Sources */ = {isa = PBXBuildFile; fileRef = FC0226572138F38D00F395E2 /* PoolKernel.metal */; };
...@@ -72,7 +77,6 @@ ...@@ -72,7 +77,6 @@
FC4FD9752140E1DE0073E130 /* PaddleMobile.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC4FD9742140E1DE0073E130 /* PaddleMobile.swift */; }; FC4FD9752140E1DE0073E130 /* PaddleMobile.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC4FD9742140E1DE0073E130 /* PaddleMobile.swift */; };
FC4FD9792140E4980073E130 /* PaddleMobileCPU.h in Headers */ = {isa = PBXBuildFile; fileRef = FC4FD9772140E4980073E130 /* PaddleMobileCPU.h */; settings = {ATTRIBUTES = (Public, ); }; }; FC4FD9792140E4980073E130 /* PaddleMobileCPU.h in Headers */ = {isa = PBXBuildFile; fileRef = FC4FD9772140E4980073E130 /* PaddleMobileCPU.h */; settings = {ATTRIBUTES = (Public, ); }; };
FC4FD97A2140E4980073E130 /* libpaddle-mobile.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FC4FD9782140E4980073E130 /* libpaddle-mobile.a */; }; FC4FD97A2140E4980073E130 /* libpaddle-mobile.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FC4FD9782140E4980073E130 /* libpaddle-mobile.a */; };
FC4FD97E2140F2C30073E130 /* libstdc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = FC4FD97D2140F2C30073E130 /* libstdc++.tbd */; };
FC5163F620EF556E00636C28 /* Texture2DTo2DArrayKernel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC5163F520EF556E00636C28 /* Texture2DTo2DArrayKernel.swift */; }; FC5163F620EF556E00636C28 /* Texture2DTo2DArrayKernel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC5163F520EF556E00636C28 /* Texture2DTo2DArrayKernel.swift */; };
FC60DB8920E9AAA500FF203F /* MetalExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC60DB8820E9AAA500FF203F /* MetalExtension.swift */; }; FC60DB8920E9AAA500FF203F /* MetalExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC60DB8820E9AAA500FF203F /* MetalExtension.swift */; };
FC803BBF214CB65A0094B8E5 /* ConvAddPreluOp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC803BBE214CB65A0094B8E5 /* ConvAddPreluOp.swift */; }; FC803BBF214CB65A0094B8E5 /* ConvAddPreluOp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC803BBE214CB65A0094B8E5 /* ConvAddPreluOp.swift */; };
...@@ -160,6 +164,11 @@ ...@@ -160,6 +164,11 @@
4AF9287821341661005B6C3A /* Softmax.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Softmax.metal; sourceTree = "<group>"; }; 4AF9287821341661005B6C3A /* Softmax.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Softmax.metal; sourceTree = "<group>"; };
4AF928812135673D005B6C3A /* ConcatKernel.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = ConcatKernel.metal; sourceTree = "<group>"; }; 4AF928812135673D005B6C3A /* ConcatKernel.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = ConcatKernel.metal; sourceTree = "<group>"; };
4AF9288321357BE3005B6C3A /* Elementwise.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Elementwise.metal; sourceTree = "<group>"; }; 4AF9288321357BE3005B6C3A /* Elementwise.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = Elementwise.metal; sourceTree = "<group>"; };
C28FDF8221B7858F0054EFAC /* MobileNetCombined.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MobileNetCombined.swift; sourceTree = "<group>"; };
C28FDF8321B7858F0054EFAC /* YoloNet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YoloNet.swift; sourceTree = "<group>"; };
C28FE02C21BA68C00054EFAC /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; };
C28FE02D21BA68C00054EFAC /* MetalPerformanceShaders.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MetalPerformanceShaders.framework; path = System/Library/Frameworks/MetalPerformanceShaders.framework; sourceTree = SDKROOT; };
C28FE02E21BA68C00054EFAC /* MetalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MetalKit.framework; path = System/Library/Frameworks/MetalKit.framework; sourceTree = SDKROOT; };
CDF58151D902A1CBAE56A0C2 /* Pods-paddle-mobile.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-paddle-mobile.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-paddle-mobile/Pods-paddle-mobile.debug.xcconfig"; sourceTree = "<group>"; }; CDF58151D902A1CBAE56A0C2 /* Pods-paddle-mobile.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-paddle-mobile.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-paddle-mobile/Pods-paddle-mobile.debug.xcconfig"; sourceTree = "<group>"; };
DD2E06330A1E7129C918DB46 /* Pods_paddle_mobile.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_paddle_mobile.framework; sourceTree = BUILT_PRODUCTS_DIR; }; DD2E06330A1E7129C918DB46 /* Pods_paddle_mobile.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_paddle_mobile.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E2A7957C92EDA5C3BEC0FFC2 /* Pods-paddle-mobile.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-paddle-mobile.release.xcconfig"; path = "../Pods/Target Support Files/Pods-paddle-mobile/Pods-paddle-mobile.release.xcconfig"; sourceTree = "<group>"; }; E2A7957C92EDA5C3BEC0FFC2 /* Pods-paddle-mobile.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-paddle-mobile.release.xcconfig"; path = "../Pods/Target Support Files/Pods-paddle-mobile/Pods-paddle-mobile.release.xcconfig"; sourceTree = "<group>"; };
...@@ -277,7 +286,9 @@ ...@@ -277,7 +286,9 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
FC4FD97E2140F2C30073E130 /* libstdc++.tbd in Frameworks */, C28FE02F21BA68C00054EFAC /* Metal.framework in Frameworks */,
C28FE03021BA68C00054EFAC /* MetalPerformanceShaders.framework in Frameworks */,
C28FE03121BA68C00054EFAC /* MetalKit.framework in Frameworks */,
D3831F70E7E0B565B9AC22DA /* Pods_paddle_mobile.framework in Frameworks */, D3831F70E7E0B565B9AC22DA /* Pods_paddle_mobile.framework in Frameworks */,
FC4FD97A2140E4980073E130 /* libpaddle-mobile.a in Frameworks */, FC4FD97A2140E4980073E130 /* libpaddle-mobile.a in Frameworks */,
); );
...@@ -289,6 +300,9 @@ ...@@ -289,6 +300,9 @@
336CBE234BF5DE48658DE65F /* Frameworks */ = { 336CBE234BF5DE48658DE65F /* Frameworks */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C28FE02C21BA68C00054EFAC /* Metal.framework */,
C28FE02E21BA68C00054EFAC /* MetalKit.framework */,
C28FE02D21BA68C00054EFAC /* MetalPerformanceShaders.framework */,
FC4FD97D2140F2C30073E130 /* libstdc++.tbd */, FC4FD97D2140F2C30073E130 /* libstdc++.tbd */,
DD2E06330A1E7129C918DB46 /* Pods_paddle_mobile.framework */, DD2E06330A1E7129C918DB46 /* Pods_paddle_mobile.framework */,
); );
...@@ -325,6 +339,8 @@ ...@@ -325,6 +339,8 @@
FC039B6C20E11C3C0081E9F8 /* paddle-mobile */ = { FC039B6C20E11C3C0081E9F8 /* paddle-mobile */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C28FDF8221B7858F0054EFAC /* MobileNetCombined.swift */,
C28FDF8321B7858F0054EFAC /* YoloNet.swift */,
FCE9D7B6214F869000B520C3 /* Net.swift */, FCE9D7B6214F869000B520C3 /* Net.swift */,
FC9A19E22148C31300CD9CBF /* MobilenetSSD_AR.swift */, FC9A19E22148C31300CD9CBF /* MobilenetSSD_AR.swift */,
FC33B0EF2147659000714A93 /* MobileNet.swift */, FC33B0EF2147659000714A93 /* MobileNet.swift */,
...@@ -681,6 +697,7 @@ ...@@ -681,6 +697,7 @@
FC039BBA20E11CC20081E9F8 /* TensorDesc.swift in Sources */, FC039BBA20E11CC20081E9F8 /* TensorDesc.swift in Sources */,
FC039BA020E11CB20081E9F8 /* Dim.swift in Sources */, FC039BA020E11CB20081E9F8 /* Dim.swift in Sources */,
FC039BB820E11CC20081E9F8 /* framework.pb.swift in Sources */, FC039BB820E11CC20081E9F8 /* framework.pb.swift in Sources */,
C28FDF8521B7858F0054EFAC /* YoloNet.swift in Sources */,
FC039B9920E11C9A0081E9F8 /* Types.swift in Sources */, FC039B9920E11C9A0081E9F8 /* Types.swift in Sources */,
FC4CB74920F0B954007C0C6D /* ConvKernel.metal in Sources */, FC4CB74920F0B954007C0C6D /* ConvKernel.metal in Sources */,
FCA3A1632132A4AC00084FE5 /* ReshapeKernel.metal in Sources */, FCA3A1632132A4AC00084FE5 /* ReshapeKernel.metal in Sources */,
...@@ -725,6 +742,7 @@ ...@@ -725,6 +742,7 @@
FCE9D7B7214F869000B520C3 /* Net.swift in Sources */, FCE9D7B7214F869000B520C3 /* Net.swift in Sources */,
FC0E2DBE20EE460D009C1FAC /* BatchNormKernel.swift in Sources */, FC0E2DBE20EE460D009C1FAC /* BatchNormKernel.swift in Sources */,
FC039BAB20E11CBC0081E9F8 /* Operator.swift in Sources */, FC039BAB20E11CBC0081E9F8 /* Operator.swift in Sources */,
C28FDF8421B7858F0054EFAC /* MobileNetCombined.swift in Sources */,
FCD04E6A20F319EC0007374F /* SoftmaxOp.swift in Sources */, FCD04E6A20F319EC0007374F /* SoftmaxOp.swift in Sources */,
FC292C82214255BD00CF622F /* MobileNetSSD.swift in Sources */, FC292C82214255BD00CF622F /* MobileNetSSD.swift in Sources */,
FCBCCC612122FBDF00D94F7E /* PriorBoxKernel.swift in Sources */, FCBCCC612122FBDF00D94F7E /* PriorBoxKernel.swift in Sources */,
...@@ -885,9 +903,9 @@ ...@@ -885,9 +903,9 @@
buildSettings = { buildSettings = {
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = ""; CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Manual;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = A798K58VVL; DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1; DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
...@@ -904,10 +922,11 @@ ...@@ -904,10 +922,11 @@
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/paddle-mobile/CPU", "$(PROJECT_DIR)/paddle-mobile/CPU",
); );
MACH_O_TYPE = mh_dylib; MACH_O_TYPE = staticlib;
MTL_LANGUAGE_REVISION = UseDeploymentTarget; MTL_LANGUAGE_REVISION = UseDeploymentTarget;
PRODUCT_BUNDLE_IDENTIFIER = "orange.paddle-mobile"; PRODUCT_BUNDLE_IDENTIFIER = "orange.paddle-mobile";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0; SWIFT_VERSION = 4.0;
...@@ -921,9 +940,9 @@ ...@@ -921,9 +940,9 @@
buildSettings = { buildSettings = {
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = ""; CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Manual;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = A798K58VVL; DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1; DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath"; DYLIB_INSTALL_NAME_BASE = "@rpath";
...@@ -940,10 +959,11 @@ ...@@ -940,10 +959,11 @@
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/paddle-mobile/CPU", "$(PROJECT_DIR)/paddle-mobile/CPU",
); );
MACH_O_TYPE = mh_dylib; MACH_O_TYPE = staticlib;
MTL_LANGUAGE_REVISION = UseDeploymentTarget; MTL_LANGUAGE_REVISION = UseDeploymentTarget;
PRODUCT_BUNDLE_IDENTIFIER = "orange.paddle-mobile"; PRODUCT_BUNDLE_IDENTIFIER = "orange.paddle-mobile";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0; SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import MetalKit
import CoreMedia
fileprivate var defaultMetalLibrary: MTLLibrary? fileprivate var defaultMetalLibrary: MTLLibrary?
fileprivate var paddleMobileMetalLibrary: MTLLibrary? fileprivate var paddleMobileMetalLibrary: MTLLibrary?
......
//
// MobileNetCombined.swift
// paddle-mobile
//
// Created by Xiao,Haichun on 2018/12/5.
// Copyright © 2018 orange. All rights reserved.
//
import Foundation
public class MobileNetCombined: Net {
@objc public override init(device: MTLDevice) {
super.init(device: device)
means = [0, 0, 0]
scale = 1
except = 0
modelPath = Bundle.main.path(forResource: "combined_mobilenet_model", ofType: nil) ?! "model null"
paramPath = Bundle.main.path(forResource: "combined_mobilenet_params", ofType: nil) ?! "para null"
modelDir = ""
//preprocessKernel = GenetPreProccess.init(device: device)
dim = (n: 1, h: 416, w: 416, c: 3)
}
@objc override public init(device: MTLDevice,paramPointer: UnsafeMutableRawPointer, paramSize:Int, modePointer: UnsafeMutableRawPointer, modelSize: Int) {
super.init(device:device,paramPointer:paramPointer,paramSize:paramSize,modePointer:modePointer,modelSize:modelSize)
means = [0, 0, 0]
scale = 1
except = 0
modelPath = ""
paramPath = ""
modelDir = ""
//preprocessKernel = GenetPreProccess.init(device: device)
dim = (n: 1, h: 416, w: 416, c: 3)
}
// class GenetPreProccess: CusomKernel {
// init(device: MTLDevice) {
// let s = CusomKernel.Shape.init(inWidth: 128, inHeight: 128, inChannel: 3)
// super.init(device: device, inFunctionName: "genet_preprocess", outputDim: s, usePaddleMobileLib: false)
// }
// }
override public func resultStr(res: ResultHolder) -> String {
// fatalError()
return " \(res.result![0]) ... "
}
}
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
import Foundation import Foundation
import Metal
public class ResultHolder: NSObject { public class ResultHolder: NSObject {
@objc public let result: UnsafeMutablePointer<Float32>? @objc public let result: UnsafeMutablePointer<Float32>?
......
...@@ -67,7 +67,8 @@ class OpCreator<P: PrecisionType> { ...@@ -67,7 +67,8 @@ class OpCreator<P: PrecisionType> {
gFlatten : FlattenOp<P>.creat, gFlatten : FlattenOp<P>.creat,
gConvAddPreluType : ConvAddPreluOp<P>.creat, gConvAddPreluType : ConvAddPreluOp<P>.creat,
gConvAddAddPreluType : ConvAddAddPreluOp<P>.creat, gConvAddAddPreluType : ConvAddAddPreluOp<P>.creat,
gElementwiseAddPreluType: ElementwiseAddPreluOp<P>.creat] gElementwiseAddPreluType : ElementwiseAddPreluOp<P>.creat,
gFusionConvAddType : ConvAddOp<P>.creat]
private init(){} private init(){}
} }
...@@ -26,7 +26,7 @@ protocol OpParam { ...@@ -26,7 +26,7 @@ protocol OpParam {
var output: OutputType { get set } var output: OutputType { get set }
func outputDesc() -> String func outputDesc() -> String
associatedtype ParamPrecisionType: PrecisionType //associatedtype ParamPrecisionType: PrecisionType
init(opDesc: OpDesc, inScope: Scope) throws init(opDesc: OpDesc, inScope: Scope) throws
static func getFirstTensor<VarType: Variant>(key: String, map: [String : [String]], from: Scope) throws -> VarType 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 static func inputX<VarType: Variant>(inputs: [String : [String]], from: Scope) throws -> VarType
......
...@@ -159,6 +159,7 @@ let gFlatten = "flatten" ...@@ -159,6 +159,7 @@ let gFlatten = "flatten"
let gConvAddPreluType = "conv_add_prelu" let gConvAddPreluType = "conv_add_prelu"
let gConvAddAddPreluType = "conv_add_add_prelu" let gConvAddAddPreluType = "conv_add_add_prelu"
let gElementwiseAddPreluType = "elementwise_add_prelu" let gElementwiseAddPreluType = "elementwise_add_prelu"
let gFusionConvAddType = "fusion_conv_add"
let opInfos = [gConvType : (inputs: ["Input"], outputs: ["Output"]), let opInfos = [gConvType : (inputs: ["Input"], outputs: ["Output"]),
...@@ -188,5 +189,6 @@ let opInfos = [gConvType : (inputs: ["Input"], outputs: ["Out ...@@ -188,5 +189,6 @@ let opInfos = [gConvType : (inputs: ["Input"], outputs: ["Out
gFlatten : (inputs: ["X"], outputs: ["Out"]), gFlatten : (inputs: ["X"], outputs: ["Out"]),
gConvAddPreluType : (inputs: ["Input"], outputs: ["Out"]), gConvAddPreluType : (inputs: ["Input"], outputs: ["Out"]),
gConvAddAddPreluType : (inputs: ["Input"], outputs: ["Out"]), gConvAddAddPreluType : (inputs: ["Input"], outputs: ["Out"]),
gElementwiseAddPreluType : (inputs: ["X"], outputs: ["Out"]) gElementwiseAddPreluType : (inputs: ["X"], outputs: ["Out"]),
gFusionConvAddType : (inputs: ["Input"], outputs: ["Out"])
] ]
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import Metal
class BatchNormParam<P: PrecisionType>: OpParam { class BatchNormParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
input = try BatchNormParam.inputX(inputs: opDesc.inputs, from: inScope) input = try BatchNormParam.inputX(inputs: opDesc.inputs, from: inScope)
......
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import Metal
class BilinearInterpParam<P: PrecisionType>: OpParam { class BilinearInterpParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
input = try BilinearInterpParam.inputX(inputs: opDesc.inputs, from: inScope) input = try BilinearInterpParam.inputX(inputs: opDesc.inputs, from: inScope)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class BoxcoderParam<P: PrecisionType>: OpParam { class BoxcoderParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
priorBox = try BoxcoderParam.getFirstTensor(key: "PriorBox", map: opDesc.inputs, from: inScope) priorBox = try BoxcoderParam.getFirstTensor(key: "PriorBox", map: opDesc.inputs, from: inScope)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class ConcatParam<P: PrecisionType>: OpParam { class ConcatParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
guard let xlist = opDesc.inputs["X"] else { guard let xlist = opDesc.inputs["X"] else {
......
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import Metal
class ConvAddAddPreluParam<P: PrecisionType>: OpParam { class ConvAddAddPreluParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
filter = try ConvAddAddPreluParam.inputFilter(paraInputs: opDesc.paraInputs, from: inScope) filter = try ConvAddAddPreluParam.inputFilter(paraInputs: opDesc.paraInputs, from: inScope)
...@@ -34,8 +35,8 @@ class ConvAddAddPreluParam<P: PrecisionType>: OpParam { ...@@ -34,8 +35,8 @@ class ConvAddAddPreluParam<P: PrecisionType>: OpParam {
} }
let input: Texture<P> let input: Texture<P>
let y: Tensor<ParamPrecisionType> let y: Tensor<P>
let filter: Tensor<ParamPrecisionType> let filter: Tensor<P>
let mode: String let mode: String
let alpha: Tensor<P> let alpha: Tensor<P>
var output: Texture<P> var output: Texture<P>
......
...@@ -16,7 +16,7 @@ import Foundation ...@@ -16,7 +16,7 @@ import Foundation
class ConvAddBatchNormReluParam<P: PrecisionType>: OpParam { class ConvAddBatchNormReluParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
...@@ -42,12 +42,12 @@ class ConvAddBatchNormReluParam<P: PrecisionType>: OpParam { ...@@ -42,12 +42,12 @@ class ConvAddBatchNormReluParam<P: PrecisionType>: OpParam {
let input: Texture<P> let input: Texture<P>
let variance: Tensor<ParamPrecisionType> let variance: Tensor<P>
let bias: Tensor<ParamPrecisionType> let bias: Tensor<P>
let mean: Tensor<ParamPrecisionType> let mean: Tensor<P>
let scale: Tensor<ParamPrecisionType> let scale: Tensor<P>
let y: Tensor<ParamPrecisionType> let y: Tensor<P>
let filter: Tensor<ParamPrecisionType> let filter: Tensor<P>
let epsilon: Float32 let epsilon: Float32
var newScale: MTLBuffer? var newScale: MTLBuffer?
var newBiase: MTLBuffer? var newBiase: MTLBuffer?
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class ConvAddParam<P: PrecisionType>: OpParam { class ConvAddParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
filter = try ConvAddParam.inputFilter(paraInputs: opDesc.paraInputs, from: inScope) filter = try ConvAddParam.inputFilter(paraInputs: opDesc.paraInputs, from: inScope)
...@@ -33,8 +33,8 @@ class ConvAddParam<P: PrecisionType>: OpParam { ...@@ -33,8 +33,8 @@ class ConvAddParam<P: PrecisionType>: OpParam {
} }
let input: Texture<P> let input: Texture<P>
let y: Tensor<ParamPrecisionType> let y: Tensor<P>
let filter: Tensor<ParamPrecisionType> let filter: Tensor<P>
var output: Texture<P> var output: Texture<P>
let stride: [Int32] let stride: [Int32]
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class ConvAddPreluParam<P: PrecisionType>: OpParam { class ConvAddPreluParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
filter = try ConvAddPreluParam.inputFilter(paraInputs: opDesc.paraInputs, from: inScope) filter = try ConvAddPreluParam.inputFilter(paraInputs: opDesc.paraInputs, from: inScope)
...@@ -34,8 +34,8 @@ class ConvAddPreluParam<P: PrecisionType>: OpParam { ...@@ -34,8 +34,8 @@ class ConvAddPreluParam<P: PrecisionType>: OpParam {
} }
let input: Texture<P> let input: Texture<P>
let y: Tensor<ParamPrecisionType> let y: Tensor<P>
let filter: Tensor<ParamPrecisionType> let filter: Tensor<P>
let mode: String let mode: String
let alpha: Tensor<P> let alpha: Tensor<P>
var output: Texture<P> var output: Texture<P>
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class ConvBNReluParam<P: PrecisionType>: OpParam { class ConvBNReluParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
filter = try ConvBNReluParam.inputFilter(paraInputs: opDesc.paraInputs, from: inScope) filter = try ConvBNReluParam.inputFilter(paraInputs: opDesc.paraInputs, from: inScope)
...@@ -38,11 +38,11 @@ class ConvBNReluParam<P: PrecisionType>: OpParam { ...@@ -38,11 +38,11 @@ class ConvBNReluParam<P: PrecisionType>: OpParam {
let input: Texture<P> let input: Texture<P>
let variance: Tensor<ParamPrecisionType> let variance: Tensor<P>
let bias: Tensor<ParamPrecisionType> let bias: Tensor<P>
let mean: Tensor<ParamPrecisionType> let mean: Tensor<P>
let scale: Tensor<ParamPrecisionType> let scale: Tensor<P>
let filter: Tensor<ParamPrecisionType> let filter: Tensor<P>
let epsilon: Float32 let epsilon: Float32
var newScale: MTLBuffer? var newScale: MTLBuffer?
var newBiase: MTLBuffer? var newBiase: MTLBuffer?
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class ConvParam<P: PrecisionType>: OpParam { class ConvParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
filter = try ConvParam.inputFilter(paraInputs: opDesc.paraInputs, from: inScope) filter = try ConvParam.inputFilter(paraInputs: opDesc.paraInputs, from: inScope)
...@@ -32,7 +32,7 @@ class ConvParam<P: PrecisionType>: OpParam { ...@@ -32,7 +32,7 @@ class ConvParam<P: PrecisionType>: OpParam {
} }
let input: Texture<P> let input: Texture<P>
let filter: Tensor<ParamPrecisionType> let filter: Tensor<P>
var output: Texture<P> var output: Texture<P>
let stride: [Int32] let stride: [Int32]
let paddings: [Int32] let paddings: [Int32]
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class ConvTransposeParam<P: PrecisionType>: ConvParam<P> { class ConvTransposeParam<P: PrecisionType>: ConvParam<P> {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
try super.init(opDesc: opDesc, inScope: inScope) try super.init(opDesc: opDesc, inScope: inScope)
......
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
// limitations under the License. */ // limitations under the License. */
import Foundation import Foundation
import Metal
class ElementwiseAddParam<P: PrecisionType>: OpParam { class ElementwiseAddParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
inputX = try ElementwiseAddParam.inputX(inputs: opDesc.inputs, from: inScope) inputX = try ElementwiseAddParam.inputX(inputs: opDesc.inputs, from: inScope)
......
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import Metal
class ElementwiseAddPreluParam<P: PrecisionType>: OpParam { class ElementwiseAddPreluParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
alpha = try ElementwiseAddPreluParam.paramInputAlpha(inputs: opDesc.paraInputs, from: inScope) alpha = try ElementwiseAddPreluParam.paramInputAlpha(inputs: opDesc.paraInputs, from: inScope)
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import MetalKit
import CoreMedia
class FeedParam<P: PrecisionType>: OpParam{ class FeedParam<P: PrecisionType>: OpParam{
var output: Texture<P> var output: Texture<P>
...@@ -30,7 +32,7 @@ class FeedParam<P: PrecisionType>: OpParam{ ...@@ -30,7 +32,7 @@ class FeedParam<P: PrecisionType>: OpParam{
} }
} }
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
} }
class FeedOp<P: PrecisionType>: Operator<Texture2DTo2DArrayKernel<P>, FeedParam<P>>, Runable, Creator, InferShaperable { class FeedOp<P: PrecisionType>: Operator<Texture2DTo2DArrayKernel<P>, FeedParam<P>>, Runable, Creator, InferShaperable {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import Metal
class FetchParam<P: PrecisionType>: OpParam{ class FetchParam<P: PrecisionType>: OpParam{
var output: FetchHolder var output: FetchHolder
...@@ -29,7 +30,7 @@ class FetchParam<P: PrecisionType>: OpParam{ ...@@ -29,7 +30,7 @@ class FetchParam<P: PrecisionType>: OpParam{
} }
} }
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
} }
class FetchKernel<P: PrecisionType>: Kernel, Computable { class FetchKernel<P: PrecisionType>: Kernel, Computable {
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class FlattenParam<P: PrecisionType>: OpParam { class FlattenParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
input = try FlattenParam.inputX(inputs: opDesc.inputs, from: inScope) input = try FlattenParam.inputX(inputs: opDesc.inputs, from: inScope)
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import Metal
struct ConcatTestParam: TestParam { struct ConcatTestParam: TestParam {
var input: [MTLTexture] var input: [MTLTexture]
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import Metal
struct ConvAddBatchNormReluTestParam: TestParam { struct ConvAddBatchNormReluTestParam: TestParam {
let inputTexture: MTLTexture let inputTexture: MTLTexture
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
import Metal
import Foundation import Foundation
struct ShapeMetalParam { struct ShapeMetalParam {
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import MetalKit
import CoreMedia
struct Texture2DTo2DArrayParam { struct Texture2DTo2DArrayParam {
let input: MTLTexture let input: MTLTexture
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class MulticlassNMSParam<P: PrecisionType>: OpParam { class MulticlassNMSParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
scores = try MulticlassNMSParam.getFirstTensor(key: "Scores", map: opDesc.inputs, from: inScope) scores = try MulticlassNMSParam.getFirstTensor(key: "Scores", map: opDesc.inputs, from: inScope)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class PoolParam<P: PrecisionType>: OpParam { class PoolParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
input = try PoolParam.inputX(inputs: opDesc.inputs, from: inScope) input = try PoolParam.inputX(inputs: opDesc.inputs, from: inScope)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class PreluParam<P: PrecisionType>: OpParam { class PreluParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
input = try PreluParam.inputX(inputs: opDesc.inputs, from: inScope) input = try PreluParam.inputX(inputs: opDesc.inputs, from: inScope)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class PriorBoxParam<P: PrecisionType>: OpParam { class PriorBoxParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
min_max_aspect_ratios_order = try PriorBoxParam.getAttr(key: "min_max_aspect_ratios_order", attrs: opDesc.attrs) min_max_aspect_ratios_order = try PriorBoxParam.getAttr(key: "min_max_aspect_ratios_order", attrs: opDesc.attrs)
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
import Foundation import Foundation
class ReluParam<P: PrecisionType>: OpParam { class ReluParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
input = try ReluParam.inputX(inputs: opDesc.inputs, from: inScope) input = try ReluParam.inputX(inputs: opDesc.inputs, from: inScope)
......
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import Metal
class ReshapeParam<P: PrecisionType>: OpParam { class ReshapeParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
input = try ReshapeParam.inputX(inputs: opDesc.inputs, from: inScope) input = try ReshapeParam.inputX(inputs: opDesc.inputs, from: inScope)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class ShapeParam<P: PrecisionType>: OpParam { class ShapeParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P // typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
input = try ShapeParam.input(inputs: opDesc.inputs, from: inScope) input = try ShapeParam.input(inputs: opDesc.inputs, from: inScope)
......
...@@ -13,16 +13,17 @@ ...@@ -13,16 +13,17 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import Metal
class SoftmaxParam<P: PrecisionType>: OpParam { class SoftmaxParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
input = try SoftmaxParam.inputX(inputs: opDesc.inputs, from: inScope) input = try SoftmaxParam.inputX(inputs: opDesc.inputs, from: inScope)
output = try SoftmaxParam.outputOut(outputs: opDesc.outputs, from: inScope) output = try SoftmaxParam.outputOut(outputs: opDesc.outputs, from: inScope)
assert(input.tensorDim.dims.count == 2) //assert(input.tensorDim.dims.count == 2)
assert(input.transpose == [0, 1, 2, 3]) //assert(input.transpose == [0, 1, 2, 3])
output.dim = input.dim output.dim = input.dim
output.tensorDim = input.tensorDim output.tensorDim = input.tensorDim
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import Foundation import Foundation
class SplitParam<P: PrecisionType>: OpParam { class SplitParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
input = try SplitParam.inputX(inputs: opDesc.inputs, from: inScope) input = try SplitParam.inputX(inputs: opDesc.inputs, from: inScope)
......
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import Metal
class TransposeParam<P: PrecisionType>: OpParam { class TransposeParam<P: PrecisionType>: OpParam {
typealias ParamPrecisionType = P //typealias ParamPrecisionType = P
required init(opDesc: OpDesc, inScope: Scope) throws { required init(opDesc: OpDesc, inScope: Scope) throws {
do { do {
input = try TransposeParam.inputX(inputs: opDesc.inputs, from: inScope) input = try TransposeParam.inputX(inputs: opDesc.inputs, from: inScope)
......
...@@ -33,7 +33,7 @@ class ScaleKernel: CusomKernel { ...@@ -33,7 +33,7 @@ class ScaleKernel: CusomKernel {
} }
public class Runner: NSObject { @objc public class Runner: NSObject {
var program: Program? var program: Program?
var executor: Executor<Float32>? var executor: Executor<Float32>?
var queue: MTLCommandQueue? var queue: MTLCommandQueue?
......
...@@ -203,6 +203,7 @@ class ProgramOptimize<P: PrecisionType> { ...@@ -203,6 +203,7 @@ class ProgramOptimize<P: PrecisionType> {
var typeMapNodes: [String : [(node: Node, output: [String : Node])]] = [:] var typeMapNodes: [String : [(node: Node, output: [String : Node])]] = [:]
let block = originProgramDesc.blocks[0] let block = originProgramDesc.blocks[0]
for opDesc in block.ops { for opDesc in block.ops {
print(opDesc.type)
guard let opInputKeys = opInfos[opDesc.type]?.inputs, let outputKeys = opInfos[opDesc.type]?.outputs else { guard let opInputKeys = opInfos[opDesc.type]?.inputs, let outputKeys = opInfos[opDesc.type]?.outputs else {
fatalError() fatalError()
} }
......
...@@ -85,6 +85,7 @@ extension VarDesc: CustomStringConvertible, CustomDebugStringConvertible { ...@@ -85,6 +85,7 @@ extension VarDesc: CustomStringConvertible, CustomDebugStringConvertible {
if let inTensorDesc = tensorDesc { if let inTensorDesc = tensorDesc {
str += " dim size: \(inTensorDesc.dims.count) \n" str += " dim size: \(inTensorDesc.dims.count) \n"
str += " dim: \(inTensorDesc.dims) \n" str += " dim: \(inTensorDesc.dims) \n"
str += "type:\(self.type) \n"
} else { } else {
str += " no dim info" str += " no dim info"
} }
......
//
// YoloNet.swift
// paddle-mobile
//
// Created by Xiao,Haichun on 2018/12/5.
// Copyright © 2018 orange. All rights reserved.
//
import Foundation
import Metal
public class YoloNet: Net {
@objc public override init(device: MTLDevice) {
super.init(device: device)
means = [0, 0, 0]
scale = 1
except = 0
modelPath = Bundle.main.path(forResource: "yolo_model", ofType: nil) ?! "model null"
paramPath = Bundle.main.path(forResource: "yolo_params", ofType: nil) ?! "para null"
modelDir = ""
//preprocessKernel = GenetPreProccess.init(device: device)
dim = (n: 1, h: 224, w: 224, c: 3)
}
@objc override public init(device: MTLDevice,paramPointer: UnsafeMutableRawPointer, paramSize:Int, modePointer: UnsafeMutableRawPointer, modelSize: Int) {
super.init(device:device,paramPointer:paramPointer,paramSize:paramSize,modePointer:modePointer,modelSize:modelSize)
means = [0, 0, 0]
scale = 1
except = 0
modelPath = ""
paramPath = ""
modelDir = ""
//preprocessKernel = GenetPreProccess.init(device: device)
dim = (n: 1, h: 224, w: 224, c: 3)
}
// class GenetPreProccess: CusomKernel {
// init(device: MTLDevice) {
// let s = CusomKernel.Shape.init(inWidth: 128, inHeight: 128, inChannel: 3)
// super.init(device: device, inFunctionName: "genet_preprocess", outputDim: s, usePaddleMobileLib: false)
// }
// }
override public func resultStr(res: ResultHolder) -> String {
// fatalError()
return " \(res.result![0]) ... "
}
}
...@@ -13,8 +13,10 @@ ...@@ -13,8 +13,10 @@
limitations under the License. */ limitations under the License. */
import Foundation import Foundation
import MetalKit
import CoreMedia
protocol Tensorial: CustomStringConvertible, CustomDebugStringConvertible{ protocol Tensorial: Variant {
var dim: Dim { get set } var dim: Dim { get set }
func numel() -> Int func numel() -> Int
var layout: DataLayout { get } var layout: DataLayout { get }
...@@ -61,7 +63,7 @@ class Tensor<P: PrecisionType>: Tensorial { ...@@ -61,7 +63,7 @@ class Tensor<P: PrecisionType>: Tensorial {
} }
} }
required init(inDim: Dim, inLayout: DataLayout = DataLayout.NCHW()) { init(inDim: Dim, inLayout: DataLayout = DataLayout.NCHW()) {
dim = inDim dim = inDim
let size = inDim.numel() * MemoryLayout<P>.size let size = inDim.numel() * MemoryLayout<P>.size
let pointer = UnsafeMutablePointer<P>.allocate(capacity: size) let pointer = UnsafeMutablePointer<P>.allocate(capacity: size)
......
...@@ -204,7 +204,8 @@ void fill_split_arg(struct SplitConvArgs *arg, framework::Tensor *input, ...@@ -204,7 +204,8 @@ void fill_split_arg(struct SplitConvArgs *arg, framework::Tensor *input,
arg->conv_arg[i].image.address = input_ptr; arg->conv_arg[i].image.address = input_ptr;
arg->conv_arg[i].image.scale_address = input->scale; arg->conv_arg[i].image.scale_address = input->scale;
arg->conv_arg[i].image.channels = (uint32_t)input->dims()[1]; arg->conv_arg[i].image.channels =
(uint32_t)get_aligned_channel_num((int)(input->dims()[1])); // NOLINT
arg->conv_arg[i].image.height = (uint32_t)input->dims()[2]; arg->conv_arg[i].image.height = (uint32_t)input->dims()[2];
arg->conv_arg[i].image.width = (uint32_t)input->dims()[3]; arg->conv_arg[i].image.width = (uint32_t)input->dims()[3];
arg->conv_arg[i].image.pad_height = (uint32_t)padding_h; arg->conv_arg[i].image.pad_height = (uint32_t)padding_h;
...@@ -216,7 +217,7 @@ void fill_split_arg(struct SplitConvArgs *arg, framework::Tensor *input, ...@@ -216,7 +217,7 @@ void fill_split_arg(struct SplitConvArgs *arg, framework::Tensor *input,
int num_after_alignment = filter::calc_aligned_num( int num_after_alignment = filter::calc_aligned_num(
arg->filter_num, (int)input->dims()[1]); // NOLINT arg->filter_num, (int)input->dims()[1]); // NOLINT
arg->conv_arg[i].free_space = arg->conv_arg[i].free_space =
fpga_malloc(num_after_alignment * 2 * sizeof(half)); fpga_malloc(num_after_alignment * 2 * sizeof(float)); // half
} }
} }
......
...@@ -16,7 +16,6 @@ limitations under the License. */ ...@@ -16,7 +16,6 @@ limitations under the License. */
#include <memory.h> #include <memory.h>
#include <algorithm> #include <algorithm>
#include "fpga/common/fpga_common.h" #include "fpga/common/fpga_common.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace fpga { namespace fpga {
namespace filter { namespace filter {
...@@ -88,12 +87,25 @@ void align_filter(float **data_in, int num, int channel, int height, ...@@ -88,12 +87,25 @@ void align_filter(float **data_in, int num, int channel, int height,
*data_in = new_data; *data_in = new_data;
fpga_free(temp); fpga_free(temp);
} }
void convert_to_fp16(float **data_in, int data_size) {
float *tmp = *data_in;
// half_float::half *tmp_data = (half_float::half *)fpga_malloc(data_size *
// sizeof(half_float::half));
int16_t *tmp_data =
(int16_t *)fpga_malloc(data_size * sizeof(int16_t)); // NOLINT
for (int i = 0; i < data_size; i++) {
// tmp_data[i] = (half_float::half)((*data_in)[i]);
tmp_data[i] = fp32_2_fp16((*data_in)[i]);
}
*data_in = (float *)tmp_data; // NOLINT
fpga_free(tmp);
}
void format_filter(float **data_in, int num, int channel, int height, int width, void format_filter(float **data_in, int num, int channel, int height, int width,
int group_num, float max) { int group_num, float max) {
convert_to_hwc(data_in, num, channel, height, width); convert_to_hwc(data_in, num, channel, height, width);
align_filter(data_in, num, channel, height, width); align_filter(data_in, num, channel, height, width);
int pixel_num = calc_aligned_total_pixel_num(num, channel, height, width); int pixel_num = calc_aligned_total_pixel_num(num, channel, height, width);
convert_to_fp16(data_in, pixel_num);
fpga_flush(*data_in, pixel_num * sizeof(float)); fpga_flush(*data_in, pixel_num * sizeof(float));
} }
...@@ -115,6 +127,7 @@ void format_fc_filter(float **data_in, int num, int channel, int height, ...@@ -115,6 +127,7 @@ void format_fc_filter(float **data_in, int num, int channel, int height,
convert_fc_filter(data_in, num, chw); convert_fc_filter(data_in, num, chw);
align_filter(data_in, num, channel, height, width); align_filter(data_in, num, channel, height, width);
int pixel_num = calc_aligned_total_pixel_num(num, channel, height, width); int pixel_num = calc_aligned_total_pixel_num(num, channel, height, width);
convert_to_fp16(data_in, pixel_num);
fpga_flush(*data_in, pixel_num * sizeof(float)); fpga_flush(*data_in, pixel_num * sizeof(float));
} }
......
此差异已折叠。
...@@ -113,6 +113,12 @@ int fpga_invalidate(void *address, size_t size) { ...@@ -113,6 +113,12 @@ int fpga_invalidate(void *address, size_t size) {
return 0; return 0;
#endif #endif
} }
uint64_t vaddr_to_paddr(void *address) {
#ifdef PADDLE_MOBILE_ZU5
return driver::vaddr_to_paddr(address);
#else
return 0;
#endif
}
} // namespace fpga } // namespace fpga
} // namespace paddle_mobile } // namespace paddle_mobile
...@@ -197,21 +197,21 @@ void QuantizeKernel<CPU, float>::Compute(const QuantizeParam<CPU> &param) { ...@@ -197,21 +197,21 @@ void QuantizeKernel<CPU, float>::Compute(const QuantizeParam<CPU> &param) {
} }
max_abs = std::max(max_abs, 1e-6f); max_abs = std::max(max_abs, 1e-6f);
param.online_scale_->mutable_data<float>()[0] = max_abs; param.online_scale_->mutable_data<float>()[0] = max_abs;
// switch (param.round_type_) { switch (param.round_type_) {
// case ROUND_NEAREST_TO_EVEN: case ROUND_NEAREST_TO_EVEN:
// Quantize<ROUND_NEAREST_TO_EVEN>(input, scale, output); Quantize<ROUND_NEAREST_TO_EVEN>(input, max_abs, param.offline_, output);
// break; break;
// case ROUND_NEAREST_TOWARDS_ZERO: case ROUND_NEAREST_TOWARDS_ZERO:
// Quantize<ROUND_NEAREST_TOWARDS_ZERO>(input, scale, output); Quantize<ROUND_NEAREST_TOWARDS_ZERO>(input, max_abs, param.offline_,
// break; output);
// case ROUND_NEAREST_AWAY_ZERO: break;
// Quantize<ROUND_NEAREST_AWAY_ZERO>(input, scale, output); case ROUND_NEAREST_AWAY_ZERO:
// break;
// default:
// LOG(kLOG_ERROR) << "round type is not supported.";
// break;
// }
Quantize<ROUND_NEAREST_AWAY_ZERO>(input, max_abs, param.offline_, output); Quantize<ROUND_NEAREST_AWAY_ZERO>(input, max_abs, param.offline_, output);
break;
default:
LOG(kLOG_ERROR) << "round type is not supported.";
break;
}
} }
} // namespace operators } // namespace operators
......
...@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and ...@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include "operators/kernel/feed_kernel.h" #include "operators/kernel/feed_kernel.h"
#include "fpga/V2/filter.h"
namespace paddle_mobile { namespace paddle_mobile {
namespace operators { namespace operators {
...@@ -24,7 +24,6 @@ bool FeedKernel<FPGA, float>::Init(FeedParam<FPGA> *param) { ...@@ -24,7 +24,6 @@ bool FeedKernel<FPGA, float>::Init(FeedParam<FPGA> *param) {
fpga::format_fp16_ofm(output, aligned_channel); fpga::format_fp16_ofm(output, aligned_channel);
return true; return true;
} }
template <> template <>
void FeedKernel<FPGA, float>::Compute(const FeedParam<FPGA> &param) { void FeedKernel<FPGA, float>::Compute(const FeedParam<FPGA> &param) {
auto input = auto input =
...@@ -33,6 +32,9 @@ void FeedKernel<FPGA, float>::Compute(const FeedParam<FPGA> &param) { ...@@ -33,6 +32,9 @@ void FeedKernel<FPGA, float>::Compute(const FeedParam<FPGA> &param) {
auto input_ptr = input->data<float>(); auto input_ptr = input->data<float>();
Tensor *output = param.Out(); Tensor *output = param.Out();
auto output_ptr = output->data<float>(); auto output_ptr = output->data<float>();
auto channel = input->dims()[1];
uint32_t aligned_channels =
fpga::filter::calc_aligned_channel((int)channel); // NOLINT
fpga::BypassArgs args = {fpga::DATA_TYPE_FP32}; fpga::BypassArgs args = {fpga::DATA_TYPE_FP32};
...@@ -41,7 +43,7 @@ void FeedKernel<FPGA, float>::Compute(const FeedParam<FPGA> &param) { ...@@ -41,7 +43,7 @@ void FeedKernel<FPGA, float>::Compute(const FeedParam<FPGA> &param) {
args.input_layout_type = fpga::LAYOUT_CHW; args.input_layout_type = fpga::LAYOUT_CHW;
args.output_layout_type = fpga::LAYOUT_HWC; args.output_layout_type = fpga::LAYOUT_HWC;
args.image.address = reinterpret_cast<void *>(input_ptr); args.image.address = reinterpret_cast<void *>(input_ptr);
args.image.channels = (uint32_t)input->dims()[1]; args.image.channels = aligned_channels;
args.image.height = (uint32_t)input->dims()[2]; args.image.height = (uint32_t)input->dims()[2];
args.image.width = (uint32_t)input->dims()[3]; args.image.width = (uint32_t)input->dims()[3];
args.image.pad_height = 0; args.image.pad_height = 0;
......
...@@ -25,7 +25,7 @@ bool SoftmaxKernel<FPGA, float>::Init(SoftmaxParam<FPGA> *param) { ...@@ -25,7 +25,7 @@ bool SoftmaxKernel<FPGA, float>::Init(SoftmaxParam<FPGA> *param) {
auto input_ptr = input->data<float>(); auto input_ptr = input->data<float>();
auto float_input = new Tensor; auto float_input = new Tensor;
float_input->mutable_data<float>({1, input->dims()[1]}); float_input->mutable_data<float>({1, input->dims()[1]});
fpga::format_fp32_ofm(float_input, 8); fpga::format_fp32_ofm(float_input, 1024);
fpga::BypassArgs args = {fpga::DATA_TYPE_FP16}; fpga::BypassArgs args = {fpga::DATA_TYPE_FP16};
args.input_layout_type = fpga::LAYOUT_HWC; args.input_layout_type = fpga::LAYOUT_HWC;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册