Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple from Blaze - part 2 #38

Merged
merged 10 commits into from
Sep 29, 2024
Merged

Decouple from Blaze - part 2 #38

merged 10 commits into from
Sep 29, 2024

Conversation

mkatliar
Copy link
Owner

@mkatliar mkatliar commented Sep 27, 2024

The primary goal was to make the RegisterMatrixTest.testPotrf work on ARM. The Blaze matrices had to be replaced by BLAST matrices, and multiple other changes were required to achieve this.

This PR is big, but it is difficult to split it into smaller ones, because the changes are not independent. Summary of the changes:

  • RegisterMatrixTest.testPotrf works
  • Added reference gemm() implementation
  • Cleaned-up few other tests in RegisterMatrixTest
  • Added DynamicMatrix class
  • Functions trans(), submatrix(), randomize(), makePositiveDefinite() implemented for BLAST matrices
  • Randomize.hpp moved to blast/math/algorithm.
  • The Testing.hpp file ~300 lines of formatting changes

@mkatliar mkatliar changed the title [WIP] Decouple from Blaze - part 2 Decouple from Blaze - part 2 Sep 27, 2024
@mkatliar mkatliar requested a review from roversch September 27, 2024 11:54
@mkatliar mkatliar self-assigned this Sep 27, 2024
@mkatliar mkatliar added the enhancement New feature or request label Sep 27, 2024
Copy link
Collaborator

@roversch roversch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As always, some high-level comments :)

Since the tests run, I assume the code is correct

* @throw @a std::invalid_argument if non-square matrix is provided
*/
template <Matrix MT>
inline void makePositiveDefinite(MT& matrix)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make in C++ often refers to making a new object (make_unique etc.)

better name: fillPositiveDefinite?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name was borrowed from Blaze, and there is already code that uses makePositiveDefinite(). Also it is possible to make an already existing matrix positive-definite, so the name seems to make sense.

, spacing_ {nextMultiple(SO == columnMajor ? m : n, SimdSize_v<T>)}
// Initialize padding elements to 0 to prevent denorms in calculations.
// Denorms can significantly impair performance, see https://github.com/giaf/blasfeo/issues/103
, v_ {new(std::align_val_t {alignment_}) T[spacing_ * (SO == columnMajor ? n : m)] {}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not introduce capacity_ as in static matrix?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In DynamicMatrix, capacity is not known at compile-time. So it would be an extra field taking memory but not used.

{
ET v {};
for (size_t k = 0; k < K; ++k)
v += *(~A)(i, k) * *(~B)(k, j);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a horrible syntax 😛

Copy link
Owner Author

@mkatliar mkatliar Sep 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat ugly, yes. The ~ makes any matrix pointer unaligned, and * is the dereferencing.

Any suggestions on how to improve the syntax?

* @tparam AF whether the submatrix lop left element is aligned
*/
template <Matrix MT, AlignmentFlag AF>
class Submatrix
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the name 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain in the comments why mdspan wasn't used as an implementation?

Copy link
Owner Author

@mkatliar mkatliar Sep 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not used it because:

  • it does not know whether it is aligned or not, which is a blocker
  • everywhere in the code matrix elements are accessed with (), and std::mdspan uses []. It would require changes all over the code to make it work with std::mdspan
  • I wanted to have more control over the implementation, in case there is or will be something that std::mdspan lacks

@@ -0,0 +1,18 @@
#pragma once
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does __restrict really make a difference? Or do you do it because Blaze had it as well?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not check, but it might. I think Blaze uses it for a reason.

@mkatliar mkatliar merged commit 85721d3 into master Sep 29, 2024
2 checks passed
@mkatliar mkatliar deleted the decouple_from_blaze-2 branch September 29, 2024 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants