Skip to content

Conversation

@ChrisRackauckas
Copy link

Summary

This PR fixes a critical type instability bug that was introduced when replacing CPUSummary.sys_threads() with Threads.nthreads() in PR JuliaSIMD#28.

The Problem

With the current implementation, when using more than 64 threads:

  • worker_bits() returns a regular Int64 instead of StaticInt
  • This propagates to worker_mask_count() which also returns Int64
  • The _request_threads function expects StaticInt{N} but receives Int64, causing a MethodError

The Solution

This PR makes the following changes:

  1. Modified worker_bits() to always return Int for consistency
  2. Updated worker_mask_count() to use regular integer division (cld)
  3. Added a new _request_threads method that handles Int parameters
  4. Added tests for high thread count compatibility

Testing

The fix has been tested with:

  • 1 thread (works as before)
  • 128 threads (now works correctly)

Before the fix:

julia> using Polyester
julia> @batch for i in 1:10; println(i); end
ERROR: MethodError: no method matching _request_threads(::UInt32, ::Ptr{UInt64}, ::Int64, ::Nothing)

After the fix:

julia> using Polyester
julia> @batch for i in 1:10; println(i); end
# Works correctly

Compatibility

The fix maintains backward compatibility while ensuring the code works correctly with any number of threads.

🤖 Generated with Claude Code

claude and others added 4 commits July 28, 2025 23:12
This commit fixes a critical bug that occurs when using more than 64 threads.
The change from CPUSummary.sys_threads() to Threads.nthreads() introduced
a type instability where worker_bits() and worker_mask_count() would return
regular Int instead of StaticInt types with high thread counts.

Changes:
- Modified worker_bits() to always return Int for consistency
- Updated worker_mask_count() to use regular integer division
- Added new _request_threads method that handles Int parameter
- Added test for high thread count compatibility

The fix maintains backward compatibility while ensuring the code works
correctly with any number of threads.

Fixes the MethodError: no method matching _request_threads(::UInt32, ::Ptr{UInt64}, ::Int64, ::Nothing)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants