GpuForward.create constructor
GpuForward.create({})
Starts the GPU of the kernels asset, or with libPath of the library
there, and prepares cache's weights for it. The native CPU kernels
must already be loaded: they map the cache.
Implementation
factory GpuForward.create({
String? libPath,
required String modelDir,
required Lfm3Config config,
required Q8Cache cache,
required int maxSeq,
required int maxChunk,
}) {
if (libPath != null) DynamicLibrary.open(libPath);
if (_init() != 1) throw StateError('the GPU is unavailable');
if (!config.sandwichNorm || config.convKernel > 16) {
throw UnsupportedError(
'the GPU path implements sandwich norms and conv kernels up to 16',
);
}
// Attention keeps one score per key in threadgroup memory, next to the
// kernel's own 128 bytes of scratch.
if (maxSeq * 4 + 128 > _maxThreadgroupMemory()) {
throw ArgumentError('--max-seq=$maxSeq is too long for GPU attention');
}
// A GPU library from elsewhere (the lab's, for parity checks) may
// predate control vectors.
final steers =
libPath == null ||
DynamicLibrary.open(libPath).providesSymbol('lab_gpu_enc_steer');
final gpu = GpuForward._(config, maxSeq, maxChunk, steers);
try {
gpu._load(modelDir, cache);
} catch (_) {
gpu.dispose();
rethrow;
}
return gpu;
}