XNNPackDelegateOptions constructor
Creates XNNPACK delegate options.
Implementation
factory XNNPackDelegateOptions({
int numThreads = 1,
int flags = 0,
String? weightCacheFilePath,
}) {
final options = calloc<TfLiteXNNPackDelegateOptions>();
// Build the options struct in Dart rather than calling the native
// TfLiteXNNPackDelegateOptionsDefault(), which returns the struct by value.
// That by-value FFI return (a >16-byte struct goes through the AArch64 x8
// hidden-pointer trampoline) crashes the Dart VM on the arm64 Android
// emulator; upstream tflite_flutter avoids it the same way. calloc already
// zero-initialized every field, so we only set what differs from zero and
// replicate the QS8 + QU8 quantization flags that Default() would have set.
options.ref.num_threads = numThreads;
options.ref.flags = flags != 0
? flags
: TFLITE_XNNPACK_DELEGATE_FLAG_QS8 | TFLITE_XNNPACK_DELEGATE_FLAG_QU8;
Pointer<Utf8>? nativePath;
if (weightCacheFilePath != null) {
nativePath = weightCacheFilePath.toNativeUtf8();
options.ref.weight_cache_file_path = nativePath.cast<Char>();
}
return XNNPackDelegateOptions._(options, nativePath);
}