Sparse Core: Replace malloc/free with conditional_aligned
Reference issue
What does this implement/fix?
The sparse classes currently use a mix of std::malloc, std::realloc, and std::free for memory management instead of the aligned_malloc family of functions defined in Memory.h. Other than consistency with the dense classes, this will enable users to track heap allocations with #define EIGEN_RUNTIME_NO_MALLOC and related mechanisms. Also, there may be some advantage to ensuring that the sparse matrices use aligned storage for vectorization.
Additional information
Benchmark measurement:
double sse no align Total duration: 21531, per iteration: 2153.1
double sse align Total duration: 21691, per iteration: 2169.1
double avx no align Total duration: 21548, per iteration: 2154.8
double avx align Total duration: 21448, per iteration: 2144.8
double old sse Total duration: 95201, per iteration: 9520.1
double old avx Total duration: 97138, per iteration: 9713.8
I did this test 10 times for size = 1000.
template<typename Scalar, bool Align>
void testSparseAlign(Index size)
{
SparseMatrix<Scalar, ColMajor, int, Align> A(size, size);
for (int i = 0; i < size; i++)
for (int j = 0; j <= i; j++)
A.coeffRef(size-i-1, j) = i*j;
std::cout << A.nonZeros() << "\n";
std::cout << A.data().allocatedSize() << "\n";
std::cout << A.sum() << "\n";
}
Edited by Rasmus Munk Larsen