diff --git a/metal/paddle-mobile-demo/paddle-mobile-demo/LoadPointerViewController.m b/metal/paddle-mobile-demo/paddle-mobile-demo/LoadPointerViewController.m index a15dcbaa143026a421585dc2a830319db74ed958..8837a7c3dec25738dcaaac058bc65fa132d05051 100644 --- a/metal/paddle-mobile-demo/paddle-mobile-demo/LoadPointerViewController.m +++ b/metal/paddle-mobile-demo/paddle-mobile-demo/LoadPointerViewController.m @@ -126,14 +126,23 @@ - (void)predict { _texture = [self createTextureFromImage:[UIImage imageNamed:@"hand.jpg"] device:self.device]; - [_runner predict:_texture withCompletion:^(BOOL success , NSArray *result) { - if (success) { - for (int i = 0; i < result.count; i ++) { - NSNumber *number = result[i]; - NSLog(@"result %d = %f:",i, [number floatValue]); + NSTimeInterval startTime = [[NSDate date] timeIntervalSince1970]; + NSInteger max = 428; + for (int i = 0;i < max; i ++) { + [_runner predict:_texture withCompletion:^(BOOL success , NSArray *result) { + if (success) { + if (i == max -1) { + double time = [[NSDate date] timeIntervalSince1970] - startTime; + 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 { diff --git a/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.h b/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.h index 6d1d92e5142bcb489477077b6a0a30bcd7355200..00149053dfe6891f07f816feef524db35474a18b 100644 --- a/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.h +++ b/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.h @@ -21,6 +21,16 @@ typedef enum : NSUInteger { GenetType, } NetType; +@interface PaddleMobileGPUResult: NSObject + +@property (assign, nonatomic) float *output; + +@property (assign, nonatomic) int outputSize; + +-(void)releaseOutput; + +@end + @interface ModelConfig: NSObject /* @@ -81,6 +91,12 @@ typedef enum : NSUInteger { */ -(void)predict:(id)texture withCompletion:(void (^)(BOOL, NSArray *))completion; +/* + * texture: 需要进行预测的图像转换的 texture + * completion: 预测完成回调 + */ +-(void)predict:(id)texture withResultCompletion:(void (^)(BOOL, PaddleMobileGPUResult *))completion; + /* * 清理内存 */ diff --git a/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.m b/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.m index 48f39d0b1bd9f5258712fac40f80668d879bb0b1..4d572df9ffbd0c271de04c455e38842262a9abc4 100644 --- a/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.m +++ b/metal/paddle-mobile/paddle-mobile/PaddleMobileGPU.m @@ -14,6 +14,26 @@ @implementation ModelConfig @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 () { Runner *runner; @@ -52,7 +72,14 @@ [result releasePointer]; }]; -// [runner predictWithTexture:texture completion:completion]; +} + +-(void)predict:(id)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 {