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

Clean up pack reordering #5782

Closed

Conversation

xu-shawn
Copy link
Contributor

Also fixes the strict aliasing violation in the current implementation

no functional change

@xu-shawn xu-shawn mentioned this pull request Jan 15, 2025
@xu-shawn xu-shawn force-pushed the cleanup_pack_ordering_2_pr branch 4 times, most recently from 75b6283 to 7e080de Compare January 15, 2025 23:58
no functional change
@xu-shawn xu-shawn force-pushed the cleanup_pack_ordering_2_pr branch from 7e080de to 78852e1 Compare January 16, 2025 03:38
@vondele vondele requested a review from Sopel97 January 18, 2025 19:03
@vondele vondele added the simplification A simplification patch label Jan 18, 2025
Copy link
Member

@Sopel97 Sopel97 left a comment

Choose a reason for hiding this comment

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

Overall it's a step in the right direction, but the crux is that the permutations are very coupled with the inference implementation, and this patch would make the connection very loose, by extracting the permutation definitions to a different class.

As a middle ground I'd propose simple permute/unpermute helper functions that take a raw memory block (128 bytes in this case), the size of elements being permuted (16 bytes in this case), and an array defining the permutation. The permutation should be specified in the FeatureTransformer class, preferably close to loading the weights.

src/nnue/nnue_feature_transformer.h Outdated Show resolved Hide resolved
Comment on lines 297 to 299
void permute_weights(Function order_fn) {
for (IndexType i = 0; i < HalfDimensions; i += Packing::process_chunk)
order_fn(&biases[i]);
Copy link
Member

Choose a reason for hiding this comment

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

I don't like how there's no indication that order_fn should be one a 2 specific member functions of Packing. Perhaps permute_for_packus_epi16 and unpermute_for_packus_epi16 should be modified to work on multiple permutation blocks and be called directly instead of this function.

src/nnue/nnue_feature_transformer.h Show resolved Hide resolved
src/nnue/nnue_feature_transformer.h Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
simplification A simplification patch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants