HPTT#
High-Performance Tensor Transpose library, originally by Paul Springer. Forked and refactored to use Stripes, Einsums’ SIMD library, instead of raw compiler intrinsics.
See the original Github repo for the
upstream project. See THIRD-PARTY-LICENSES.txt for licensing information.
Overview#
HPTT performs multi-dimensional tensor transpositions using a plan-based execution model. The key abstraction is the transpose plan, a precomputed strategy for permuting indices of an N-dimensional tensor, including blocking, threading, and micro-kernel selection.
Supported Types#
floatanddoubleuse full SIMD-accelerated micro-kernels.std::complex<float>andstd::complex<double>also use SIMD micro-kernels, built on Stripes’ complex vectors.Half and bfloat16 kernels are built when the target has FP16 or BF16 vector arithmetic.
How It Works#
Plan creation.
create_plan()analyzes the tensor dimensions, strides, and permutation pattern to select an optimal blocking strategy and thread decomposition.Execution.
execute()runs the plan, performing the transpose using SIMD micro-kernels for the inner loops and OpenMP threads for parallelism.
#include <Einsums/HPTT/HPTT.hpp>
// Transpose a 3D tensor: C[j,k,i] = alpha * A[i,j,k] + beta * C[j,k,i]
int perm[] = {1, 2, 0}; // Permutation: dimension 0 -> position 2, etc.
size_t size[] = {10, 20, 30}; // Dimensions of A
float alpha = 1.0f, beta = 0.0f;
auto plan = einsums::hptt::create_plan(perm, 3, alpha, A, size, nullptr,
beta, C, nullptr, einsums::hptt::ESTIMATE, 4);
plan->execute();
SIMD Refactoring#
The HPTT micro-kernels were refactored from raw SSE/AVX/AVX-512/NEON intrinsics
to use Stripes (stripes::), Einsums’ SIMD library. This provides three benefits:
Portability: the same code runs on x86_64, from SSE2 through AVX-512, and on ARM NEON.
Maintainability: roughly 30 lines of
stripes::calls replace about 510 lines of raw intrinsics per type.Performance: a 10 to 15 percent improvement on Apple Silicon, and a substantial improvement for complex datatypes.
The micro-kernels use:
stripes::loadu/stripes::storeufor data movementstripes::broadcastfor alpha/beta scalingstripes::fmaddfor fused multiply-addstripes::transpose_inplacefor in-register 4x4/8x8/16x16 transposes (stripes::complex_transpose_inplacefor complex types)stripes::stream_storefor non-temporal writes (cache-bypass for large transposes)stripes::prefetchfor prefetching next blocks
See the API reference of this module for more details.