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

Matrix-free MG transfer: Switch interpolation matrices to double type #16721

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

kronbichler
Copy link
Member

As discussed in #16719, the extension of the matrix-free multigrid infrastructure to complex numbers (which is a desirable goal) necessitates some different choices. Thanks to #15207 and #15217, that switch is rather easy from a software point of view, as the tensor product evaluators already support that setting.

This pull request might not be the final step, because storing the tabulated shape functions as double entries is not the right choice when the work arrays are of type VectorizedArray<float>, but the compiler generates surprisingly good code nonetheless, keeping it to a single conversion double -> float in reading the array. On AMD CPUs I tested, I can hardly see performance impact of the additional instructions, albeit I believe that Intel CPUs (up to Ice Lake at least) will lead to half the throughput on the inner kernel because the conversion/broadcast from register is on the same execution units as the arithmetic work; on the other hand, the vector access is a much larger share of the instructions in this scenario. So given the background, I am happy to pull this to our main branch right away, and find a better solution later when we have made a step towards complex numbers elsewhere. The idea for the better solution is to select float as the number type when there is VectorizedArray<float> or VectorizedArray<std::complex<float>> or std::complex<VectorizedArray<float>> or something like that, and double in the other cases. But that can wait, as surprising as this might sound coming from me.

@peterrum peterrum self-requested a review March 6, 2024 11:32
Copy link
Member

@peterrum peterrum left a comment

Choose a reason for hiding this comment

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

Could you check if we have a test with float?

@kronbichler
Copy link
Member Author

We have the performance test timing_mg_glob_coarsen with

using VectorTypeMG = LinearAlgebra::distributed::Vector<float>;

Regarding correctness, I see it in
test<2, 1, double>();
test<2, 2, float>();
test<3, 1, double>();
test<3, 2, float>();
(where I checked that it performs the vcvtsd2ss for converting double -> float follow by vbroadcastss between registers) but I believe we have many more.

@peterrum
Copy link
Member

peterrum commented Mar 6, 2024

Thanks for checking!

Comment on lines -118 to +125
template <int dim, typename Number>
template <int dim, typename Number, typename Number2>
class CellProlongator
{
public:
CellProlongator(const AlignedVector<Number> &prolongation_matrix,
const AlignedVector<Number> &prolongation_matrix_1d,
const Number *evaluation_data_coarse,
Number *evaluation_data_fine)
const Number2 *evaluation_data_coarse,
Number2 *evaluation_data_fine)
Copy link
Member

Choose a reason for hiding this comment

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

Do you actually need both Number and Number2 as template arguments? At least at the call sites you modify below, Number is always double.

Copy link
Member Author

Choose a reason for hiding this comment

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

My hope is to later use it with either float or double, depending on VectorType::value_type and with the right choice for complex numbers. I can change it for now if you prefer.

Copy link
Member

Choose a reason for hiding this comment

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

If you've got plans for it, let's leave it as is.

@bangerth bangerth merged commit fd7a092 into dealii:master Mar 6, 2024
12 checks passed
@kronbichler kronbichler deleted the fix_mg_type branch March 18, 2024 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants