From d28f929ddec4cf8d0125fdb9425bc454bdb0631b Mon Sep 17 00:00:00 2001 From: liuruilong Date: Fri, 7 Sep 2018 10:35:16 +0800 Subject: [PATCH] add new interface --- .../paddle-mobile.xcodeproj/project.pbxproj | 12 +++ .../paddle-mobile/PaddleMobileGPU.h | 90 +++++++++++++++++++ .../paddle-mobile/PaddleMobileGPU.m | 9 ++ 3 files changed, 111 insertions(+) create mode 100644 metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.h create mode 100644 metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.m diff --git a/metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj b/metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj index 8153a46cd8..d0f4b38df6 100644 --- a/metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj +++ b/metal/paddle-mobile/paddle-mobile.xcodeproj/project.pbxproj @@ -41,6 +41,8 @@ FC0E2DBE20EE460D009C1FAC /* BatchNormKernel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC0E2DBD20EE460D009C1FAC /* BatchNormKernel.swift */; }; FC0E2DC020EE461F009C1FAC /* ElementwiseAddKernel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC0E2DBF20EE461F009C1FAC /* ElementwiseAddKernel.swift */; }; FC1B16B320EC9A4F00678B91 /* Kernels.metal in Sources */ = {isa = PBXBuildFile; fileRef = FC1B16B220EC9A4F00678B91 /* Kernels.metal */; }; + FC292C5421421B2F00CF622F /* PaddleMobileGPU.h in Headers */ = {isa = PBXBuildFile; fileRef = FC292C5321421B2E00CF622F /* PaddleMobileGPU.h */; }; + FC292C5621421B4600CF622F /* PaddleMobileGPU.m in Sources */ = {isa = PBXBuildFile; fileRef = FC292C5521421B4600CF622F /* PaddleMobileGPU.m */; }; FC3602CC2108819F00FACB58 /* PaddleMobileUnitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC3602CB2108819F00FACB58 /* PaddleMobileUnitTest.swift */; }; FC4CB74920F0B954007C0C6D /* ConvKernel.metal in Sources */ = {isa = PBXBuildFile; fileRef = FC4CB74820F0B954007C0C6D /* ConvKernel.metal */; }; FC4CB74B20F12C30007C0C6D /* ProgramOptimize.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC4CB74A20F12C30007C0C6D /* ProgramOptimize.swift */; }; @@ -137,6 +139,8 @@ FC0E2DBF20EE461F009C1FAC /* ElementwiseAddKernel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ElementwiseAddKernel.swift; sourceTree = ""; }; FC1B16B220EC9A4F00678B91 /* Kernels.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = Kernels.metal; sourceTree = ""; }; FC27990D21341016000B6BAD /* BoxCoder.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = BoxCoder.metal; sourceTree = ""; }; + FC292C5321421B2E00CF622F /* PaddleMobileGPU.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PaddleMobileGPU.h; sourceTree = ""; }; + FC292C5521421B4600CF622F /* PaddleMobileGPU.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PaddleMobileGPU.m; sourceTree = ""; }; FC3602CB2108819F00FACB58 /* PaddleMobileUnitTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaddleMobileUnitTest.swift; sourceTree = ""; }; FC4CB74820F0B954007C0C6D /* ConvKernel.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = ConvKernel.metal; sourceTree = ""; }; FC4CB74A20F12C30007C0C6D /* ProgramOptimize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgramOptimize.swift; sourceTree = ""; }; @@ -246,6 +250,8 @@ FC039B6C20E11C3C0081E9F8 /* paddle-mobile */ = { isa = PBXGroup; children = ( + FC292C5521421B4600CF622F /* PaddleMobileGPU.m */, + FC292C5321421B2E00CF622F /* PaddleMobileGPU.h */, FC4FD9762140E4920073E130 /* CPU */, FC4FD9742140E1DE0073E130 /* PaddleMobile.swift */, FC039BAE20E11CC20081E9F8 /* Program */, @@ -418,6 +424,7 @@ buildActionMask = 2147483647; files = ( FC4FD9792140E4980073E130 /* PaddleMobile.h in Headers */, + FC292C5421421B2F00CF622F /* PaddleMobileGPU.h in Headers */, FC039B6F20E11C3C0081E9F8 /* paddle_mobile.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -455,6 +462,7 @@ TargetAttributes = { FC039B6920E11C3C0081E9F8 = { CreatedOnToolsVersion = 9.3.1; + LastSwiftMigration = 0940; }; }; }; @@ -557,6 +565,7 @@ FC039BBF20E11CC20081E9F8 /* Attribute.swift in Sources */, FCD04E7420F3437E0007374F /* ConvAddKernel.swift in Sources */, FC039BB920E11CC20081E9F8 /* Scope.swift in Sources */, + FC292C5621421B4600CF622F /* PaddleMobileGPU.m in Sources */, FCD04E6620F314C50007374F /* PoolOp.swift in Sources */, FC039BAC20E11CBC0081E9F8 /* BatchNormOp.swift in Sources */, FCBCCC6F2123097100D94F7E /* MulticlassNMSOp.swift in Sources */, @@ -724,6 +733,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = CDF58151D902A1CBAE56A0C2 /* Pods-paddle-mobile.debug.xcconfig */; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; DEFINES_MODULE = YES; @@ -749,6 +759,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "orange.paddle-mobile"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -758,6 +769,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = E2A7957C92EDA5C3BEC0FFC2 /* Pods-paddle-mobile.release.xcconfig */; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; DEFINES_MODULE = YES; diff --git a/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.h b/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.h new file mode 100644 index 0000000000..b2bc293084 --- /dev/null +++ b/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.h @@ -0,0 +1,90 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + +#import +#import + +typedef enum : NSUInteger { + MobileNet, + MobileNetSSD, + Genet, +} Net; + +@interface ModelConfig: NSObject + +/* + * 预处理需要用到的值 (三个) + */ +@property (strong, nonatomic) NSArray *means; +/* + * 预处理需要用到的 scale 值 + */ +@property (assign, nonatomic) float scale; + +/* + * 输出维度信息 [n c h w] + */ +@property (strong, nonatomic) NSArray *dims; + +/* + * 模型参数内存地址 + */ +@property (assign, nonatomic) void *paramPointer; + +/* + * 模型参数占用内存大小 (kb) + */ +@property (assign, nonatomic) int paramSize; + +/* + * 模型内存地址 + */ +@property (assign, nonatomic) void *modelPointer; + +/* + * 模型占用内存大小 (kb) + */ +@property (assign, nonatomic) int modelSize; + +@end + +@interface PaddleMobileGPU: NSObject + +/* + * 初始化 + */ +-(instancetype)initWithCommandQueue:(id)queue net:(Net)netType modelConfig:(ModelConfig *)config; + +/* + * paramPointer 模型参数内存地址 + * paramSize 模型参数占用内存大小 (kb) + * modelPointer 模型内存地址 + * modelSize 模型占用内存大小 (kb) + */ +-(BOOL)load; + +/* + * texture: 需要进行预测的图像转换的 texture + * completion: 预测完成回调 + */ +-(void)predict:(id)texture withCompletion:(void (^)(BOOL, NSArray *))completion; + +/* + * 清理内存 + */ +-(void)clrear; + +@end + + diff --git a/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.m b/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.m new file mode 100644 index 0000000000..fd98dbc866 --- /dev/null +++ b/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.m @@ -0,0 +1,9 @@ +// +// PaddleMobileGPU.m +// paddle-mobile +// +// Created by liuRuiLong on 2018/9/7. +// Copyright © 2018年 orange. All rights reserved. +// + +#import -- GitLab