mirror of
https://github.com/ggerganov/whisper.cpp.git
synced 2025-06-25 04:01:50 +02:00
coreml : backport CoreML features to macos < 14 (#3255)
This commit is contained in:
parent
9c47902308
commit
0083335ba0
@ -58,6 +58,7 @@ if (WHISPER_COREML)
|
|||||||
set(TARGET whisper.coreml)
|
set(TARGET whisper.coreml)
|
||||||
|
|
||||||
add_library(${TARGET}
|
add_library(${TARGET}
|
||||||
|
coreml/whisper-compat.m
|
||||||
coreml/whisper-encoder.h
|
coreml/whisper-encoder.h
|
||||||
coreml/whisper-encoder.mm
|
coreml/whisper-encoder.mm
|
||||||
coreml/whisper-encoder-impl.h
|
coreml/whisper-encoder-impl.h
|
||||||
@ -76,6 +77,7 @@ if (WHISPER_COREML)
|
|||||||
COMPILE_FLAGS "-fobjc-arc"
|
COMPILE_FLAGS "-fobjc-arc"
|
||||||
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
|
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(${TARGET} PROPERTIES FOLDER "libs")
|
set_target_properties(${TARGET} PROPERTIES FOLDER "libs")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
10
src/coreml/whisper-compat.h
Normal file
10
src/coreml/whisper-compat.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#import <CoreML/CoreML.h>
|
||||||
|
|
||||||
|
@interface MLModel (Compat)
|
||||||
|
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
|
||||||
|
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler;
|
||||||
|
|
||||||
|
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
|
||||||
|
options:(MLPredictionOptions *) options
|
||||||
|
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler;
|
||||||
|
@end
|
35
src/coreml/whisper-compat.m
Normal file
35
src/coreml/whisper-compat.m
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#import "whisper-compat.h"
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
@implementation MLModel (Compat)
|
||||||
|
|
||||||
|
#if !defined(MAC_OS_X_VERSION_14_00) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_14_00
|
||||||
|
|
||||||
|
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
|
||||||
|
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler {
|
||||||
|
[NSOperationQueue.new addOperationWithBlock:^{
|
||||||
|
NSError *error = nil;
|
||||||
|
id<MLFeatureProvider> prediction = [self predictionFromFeatures:input error:&error];
|
||||||
|
|
||||||
|
[NSOperationQueue.mainQueue addOperationWithBlock:^{
|
||||||
|
completionHandler(prediction, error);
|
||||||
|
}];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
|
||||||
|
options:(MLPredictionOptions *) options
|
||||||
|
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler {
|
||||||
|
[NSOperationQueue.new addOperationWithBlock:^{
|
||||||
|
NSError *error = nil;
|
||||||
|
id<MLFeatureProvider> prediction = [self predictionFromFeatures:input options:options error:&error];
|
||||||
|
|
||||||
|
[NSOperationQueue.mainQueue addOperationWithBlock:^{
|
||||||
|
completionHandler(prediction, error);
|
||||||
|
}];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@end
|
@ -8,6 +8,7 @@
|
|||||||
#error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
|
#error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#import "whisper-compat.h"
|
||||||
#import "whisper-decoder-impl.h"
|
#import "whisper-decoder-impl.h"
|
||||||
|
|
||||||
@implementation whisper_decoder_implInput
|
@implementation whisper_decoder_implInput
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
|
#error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#import "whisper-compat.h"
|
||||||
#import "whisper-encoder-impl.h"
|
#import "whisper-encoder-impl.h"
|
||||||
|
|
||||||
@implementation whisper_encoder_implInput
|
@implementation whisper_encoder_implInput
|
||||||
|
Loading…
x
Reference in New Issue
Block a user