You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mahout.apache.org by "viiccwen (via GitHub)" <gi...@apache.org> on 2026/01/25 09:07:26 UTC

[PR] [QDP] Fix misaligned memory access in L2 norm batch kernel [mahout]

viiccwen opened a new pull request, #941:
URL: https://github.com/apache/mahout/pull/941

   ### Purpose of PR
   <!-- Describe what this PR does. -->
   The `l2_norm_batch_kernel` uses vectorized `double2` loads (16-byte alignment required) to compute L2 norms for batched samples. However, when `sample_len` is odd, the base offset `base = sample_idx * sample_len` may be odd, causing `input_batch + base` to be misaligned (offset by 8 bytes instead of 16 bytes).
   
   Added alignment handling logic to ensure vectorized loads always start from properly aligned addresses:
   
   1. **Alignment check**: Check if `base` is even (16-byte aligned for `double2`)
   2. **Peel first element**: If misaligned, handle the first element separately using a single `double` load
   3. **Vectorized loads**: Start vectorized `double2` loads from the second element (`base + 1`), which is guaranteed to be 16-byte aligned
   4. **Index separation**: Strictly separate "aligned sub-array index" from "original sample index" to avoid confusion and bugs
   
   ### Related Issues or PRs
   closes #940 
   
   ### Changes Made
   <!-- Please mark one with an "x"   -->
   - [x] Bug fix
   - [ ] New feature
   - [ ] Refactoring
   - [ ] Documentation
   - [x] Test
   - [ ] CI/CD pipeline
   - [ ] Other
   
   ### Breaking Changes
   <!-- Does this PR introduce a breaking change? -->
   - [ ] Yes
   - [x] No
   
   ### Checklist
   <!-- Please mark each item with an "x" when complete -->
   <!-- If not all items are complete, please open this as a **Draft PR**.
   Once all requirements are met, mark as ready for review. -->
   
   - [ ] Added or updated unit tests for all changes
   - [ ] Added or updated documentation for all changes
   - [ ] Successfully built and ran all unit tests or manual tests locally
   - [ ] PR title follows "MAHOUT-XXX: Brief Description" format (if related to an issue)
   - [ ] Code follows ASF guidelines
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] Fix misaligned memory access in L2 norm batch kernel [mahout]

Posted by "ryankert01 (via GitHub)" <gi...@apache.org>.
ryankert01 closed pull request #941: [QDP] Fix misaligned memory access in L2 norm batch kernel
URL: https://github.com/apache/mahout/pull/941


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] Fix misaligned memory access in L2 norm batch kernel [mahout]

Posted by "ryankert01 (via GitHub)" <gi...@apache.org>.
ryankert01 commented on PR #941:
URL: https://github.com/apache/mahout/pull/941#issuecomment-3796388866

   Overall make sense, just not the standard way to implement this.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] Fix misaligned memory access in L2 norm batch kernel [mahout]

Posted by "ryankert01 (via GitHub)" <gi...@apache.org>.
ryankert01 commented on code in PR #941:
URL: https://github.com/apache/mahout/pull/941#discussion_r2725294517


##########
qdp/qdp-kernels/src/amplitude.cu:
##########
@@ -371,17 +371,32 @@ __global__ void l2_norm_batch_kernel(
 
     double local_sum = 0.0;
 
+    // Alignment peel for double2 (16B) loads

Review Comment:
   the comments should include more details
   ```suggestion
       // Alignment peel for double2 (16B) loads
       // 1. **Alignment check**: Check if `base` is even (16-byte aligned for `double2`)
       // 2. **Peel first element**: If misaligned, handle the first element separately using a single `double` load
       // 3. **Vectorized loads**: Start vectorized `double2` loads from the second element (`base + 1`), which is guaranteed to be 16-byte aligned
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org