util
— Utilities¶
affect.util
¶
Usage¶
This module provides for creating and performing operations with aligned and compressed arrays.
CompressedArray |
|
empty_aligned |
|
zeros_aligned |
|
byte_align |
|
is_byte_aligned |
|
take |
|
compress |
|
decompress |
It also provides some basic functions for debugging and testing.
arrays_share_data |
|
get_array_base |
|
ConsoleCode |
|
print_blue |
|
print_bold |
|
print_green |
|
print_yellow |
|
print_function_starting |
|
print_array_info |
Data alignment¶
Data alignment for arrays means putting the data at a memory address equal to some multiple of the word size. This is done to increase efficiency of data loads and stores to and from the processor. Processors are designed to efficiently move data to and from memory addresses that are on specific byte boundaries.
In addition to creating the data on aligned boundaries (that aligns the base pointer), the compiler is able to make optimizations when the data access (including base-pointer plus index) is known to be aligned by 64 bytes. Special SIMD instructions can be utilized by the compiler for certain platforms. For example, the compiler/platform may support the special instructions on processors such as the Intel® AVX-512 instructions, which enables processing of twice the number of data elements that AVX/AVX2 can process with a single instruction and four times that of SSE.
By default, the compiler cannot know nor assume data is aligned inside loops without some help from the programmer. Thus, you must also inform the compiler of this alignment via a combination of pragmas (C/C++) or keywords, clauses, or attributes so that compilers can generate optimal code.
For the Intel® Many Integrated Core Architecture such (Intel® Xeon Phi™ Coprocessor), memory movement is optimal when the data starting address lies on 64 byte boundaries. Thus, by default, at least at the time of this writing it is optimal to create data objects with starting addresses that are modulo 64 bytes. For slightly less ambitious modern architectures, such as Intel® Skylake, 32 byte aligned addresses may be recommended.
Aligned arrays¶
These functions create and perform other operations on
numpy.ndarray
objects. All arrays created by calls to affect,
and those used internally in affect, are aligned. The two main
functions used to created aligned arrays are empty_aligned()
and
zeros_aligned()
that behave similarly to numpy.empty()
and
numpy.zeros()
, respectively.
For now this module defaults to using a 64 byte boundary. To align the data
of numpy.ndarray
to the word boundaries, during allocation it may
be necessary to insert some unused bytes at the start of the block, this is
data padding.
Array compression¶
The method of array compression is multithreaded and fast and can usually compress an array of integers to around a fourth of the original size. It does not compress arrays of floating point values as efficiently.
Printing, Debugging, Testing¶
Most of these functions are used internally for testing, but you may find them of value for regular use.
Exceptions¶
The exceptions thrown from this module are a part of the interface just as much as the functions and classes. We define an Error root exception to allow you to insulate yourself from this API. All the exceptions raised by this module inherit from it.
Error |
|
IllegalArgumentError |
|
UnsupportedArrayType |