White Papers

7
|
QAT Whitepaper
© 2019 Dell Inc. or its subsidiaries.
3.3 Programming Example
The QATzip has been carefully designed to provide a simple programming API. The following code segment is complete:
As can be seen, there is no explicit requirement to initialize
access to hardware. This is taken care of in the first
QATzip API call.
Applications can explicitly initiate and setup the QATzip
library to configure specific session parameters used in
the compress and decompress calls. Examples are
shown in Table 1.
Parameter
Range
Default
Notes
Huffman
Encoding
Dynamic |
Static
Dynamic
Headers
None | gzip |
gzip with
extenstions
gzip with
extensions
Compression
Level
1-9
1
level nine invokes
a software compression
algorithm for the best
possible compression
ratio
Size of data
passed to
hardware
1 KB - 512 KB
64 KB
Min size for
hardware
128 bytes and
higher
1024 bytes
no upper limit
Table 1 Selected QATzip session parameters
Finally, the QATzip library includes its own allocation and free APIs qzMalloc() and qzFree(). If appropriate,
an application can allocate memory that will be compressed or decompressed using these APIs. qzMalloc will returned
pinned memory if available. This will lead to improved latency as the data is already in DMA-friendly memory and will not
have to be copied. The qzCompress and qzDecompress APIs accept both pinned memory and regular memory without
the caller having to indicate which type is being used in a specific call.
[gmcfadde@localhost small]$ cat Makefile
INC_DIR=/opt/intel/QATzip/include/
smallQz: main.c
gcc -g -O0 -I$(INC_DIR) main.c -o smallQz -lqatzip
[gmcfadde@localhost small]$ cat main.c
#include <stdio.h>
#include <stdlib.h>
#include “qatzip.h”
int main( int argc, char *argv[ ] )
{
int rc;
unsigned int i_len, o_len;
unsigned char *in, *out;
QzSession_T sess = {0};
i_len = 128*1024;
o_len = 128*1024;
in = malloc(i_len);
out = malloc(o_len);
if ( NULL == in || NULL == out )
{
printf( “memory failure\n” ); return 2;
}
rc = qzCompress( &sess, in, &i_len, out, &o_len, 1 );
printf( “In len = %d, out len = %d, rc = %d\n”, i_len, o_len, rc );
return rc;
}
[gmcfadde@localhost small]$
[gmcfadde@localhost small]$ touch main.c
[gmcfadde@localhost small]$ make
gcc -g -O0 -I/opt/intel/QATzip/include/ main.c -o smallQz -lqatzip
[gmcfadde@localhost small]$ ./smallQz
In len = 131072, out len = 234, rc = 0
[gmcfadde@localhost small]$