Kernel Library
The Parabix Kernel Library has a number of useful kernels for building applications.
Input Kernels: Sources
#include <kernel/io/source_kernel.h>
Source kernels are kernels that provide the input data streams for processing by other kernels. There are source kernels for obtaining input streams from the operating systems (files or devices) as well as from memory buffers.
ReadSourceKernel
produces a data stream by using the operating system read
call to populate the input stream. Normally, the stream set produceed is a ```1xi8`` stream set, i.e., a stream set consisting of a single stream of 8-bit values (bytes).
Typical usage:
StreamSet * const ByteStream = P->CreateStreamSet(1, 8);
P->CreateKernelCall<ReadSourceKernel>(fileDescriptor, ByteStream);
Here P
is a program or pipeline builder, and fileDescriptor
is
scalar integer for an open file or device. In addition to byte streams, read source kernels may produce streams of 16-, 32, or 64-bit values.
MMapSourceKernel
is a substitution for ReadSourceKernel
that may be used to
populate an input stream using the operating system mmap
facility on Posix-based systems. Its usage is restricted to input from open file descriptors that correspond to plain files, it may not be used with devices or with standard input.
FDSourceKernel
is a somewhat more flexible input kernel that allows the choice of using read
or mmap
at run-time. It takes one additional input parameter,
a boolean scalar value identifying whether to use mmap
if possible. If this scalar is given the value 1 (true), then mmap
will be used for ordinary files, while read
will be used for devices or standard input.
MemorySourceKernel
is a kernel that produces a stream set from a memory buffer. Its parameters are a scalar pointer to the buffer, and a scalar length of the buffer.
Output Kernels: Sinks
#include <kernel/io/stdout_kernel.h>
Output to stdout or to a file may be achieved using sink kernels.
StdOutKernel
produces the contents of a stream on stdout.
P->CreateKernelCall<StdOutKernel>(codeUnitStream);
Here codeUnitStream
is typically a stream of bytes (8-bit code units), but
may also be a stream of 16, 32 or 64 bit units.
FileSinkKernel
produces output to a named file. The file name is
provided as a scalar pointer to a C-string (null-terminated file name).
P->CreateKernelCall<FileSink>(outputFileName, codeUnitStream);