提交 bae31c56 编写于 作者: X xiaohaichun

add gpu predict interface

上级 7dc9fd05
...@@ -126,14 +126,23 @@ ...@@ -126,14 +126,23 @@
- (void)predict { - (void)predict {
_texture = [self createTextureFromImage:[UIImage imageNamed:@"hand.jpg"] device:self.device]; _texture = [self createTextureFromImage:[UIImage imageNamed:@"hand.jpg"] device:self.device];
NSTimeInterval startTime = [[NSDate date] timeIntervalSince1970];
NSInteger max = 428;
for (int i = 0;i < max; i ++) {
[_runner predict:_texture withCompletion:^(BOOL success , NSArray<NSNumber *> *result) { [_runner predict:_texture withCompletion:^(BOOL success , NSArray<NSNumber *> *result) {
if (success) { if (success) {
for (int i = 0; i < result.count; i ++) { if (i == max -1) {
NSNumber *number = result[i]; double time = [[NSDate date] timeIntervalSince1970] - startTime;
NSLog(@"result %d = %f:",i, [number floatValue]); time = (time/max)*1000;
NSLog(@"gap ==== %fms",time);
} }
// for (int i = 0; i < result.count; i ++) {
// NSNumber *number = result[i];
// NSLog(@"result %d = %f:",i, [number floatValue]);
// }
} }
}]; }];
}
} }
- (void)didReceiveMemoryWarning { - (void)didReceiveMemoryWarning {
......
...@@ -21,6 +21,16 @@ typedef enum : NSUInteger { ...@@ -21,6 +21,16 @@ typedef enum : NSUInteger {
GenetType, GenetType,
} NetType; } NetType;
@interface PaddleMobileGPUResult: NSObject
@property (assign, nonatomic) float *output;
@property (assign, nonatomic) int outputSize;
-(void)releaseOutput;
@end
@interface ModelConfig: NSObject @interface ModelConfig: NSObject
/* /*
...@@ -81,6 +91,12 @@ typedef enum : NSUInteger { ...@@ -81,6 +91,12 @@ typedef enum : NSUInteger {
*/ */
-(void)predict:(id<MTLTexture>)texture withCompletion:(void (^)(BOOL, NSArray<NSNumber *> *))completion; -(void)predict:(id<MTLTexture>)texture withCompletion:(void (^)(BOOL, NSArray<NSNumber *> *))completion;
/*
* texture: 需要进行预测的图像转换的 texture
* completion: 预测完成回调
*/
-(void)predict:(id<MTLTexture>)texture withResultCompletion:(void (^)(BOOL, PaddleMobileGPUResult *))completion;
/* /*
* 清理内存 * 清理内存
*/ */
......
...@@ -14,6 +14,26 @@ ...@@ -14,6 +14,26 @@
@implementation ModelConfig @implementation ModelConfig
@end @end
@interface PaddleMobileGPUResult ()
@property (strong, nonatomic) ResultHolder *resultHolder;
- (void)setOutputResult:(ResultHolder *)resultHolder;
@end
@implementation PaddleMobileGPUResult
- (void)setOutputResult:(ResultHolder *)resultHolder {
self.resultHolder = resultHolder;
self.output = resultHolder.result;
self.outputSize = resultHolder.capacity;
}
-(void)releaseOutput {
[self.resultHolder releasePointer];
}
@end
@interface PaddleMobileGPU () @interface PaddleMobileGPU ()
{ {
Runner *runner; Runner *runner;
...@@ -52,7 +72,14 @@ ...@@ -52,7 +72,14 @@
[result releasePointer]; [result releasePointer];
}]; }];
// [runner predictWithTexture:texture completion:completion]; }
-(void)predict:(id<MTLTexture>)texture withResultCompletion:(void (^)(BOOL, PaddleMobileGPUResult *))completion {
[runner predictWithTexture:texture completion:^(BOOL success, ResultHolder * _Nullable result) {
PaddleMobileGPUResult *gpuResult = [[PaddleMobileGPUResult alloc] init];
[gpuResult setOutputResult:result];
completion(success, gpuResult);
}];
} }
-(void)clear { -(void)clear {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册