Why do payload types need to be bitwise comparable in static_map? #426
-
Why do values need to be bitwise-comparable in static_map (since keys are unique)? This is preventing the use of float as the value type, which would be valuable. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
We use atomic compare-and-swap operations to swap keys/payloads into slots in a concurrency-safe manner. These CAS instructions work on bitwise comparison, hence the restriction. By default, we make the decision if a given type is bitwise comparable based on the result of
|
Beta Was this translation helpful? Give feedback.
-
@jrhemstad I'd rather keep performance-related settings as an opt-out rather than opt-in, i.e., we could add a global flag This, of course, should be documented with an example, as @kevkrist suggested. Closing this discussion here but opening a new issue to track the idea. |
Beta Was this translation helpful? Give feedback.
We internally dispatch different insertion strategies depending on the key/value types and GPU architecture to achieve best performance. If
sizeof(Key)+sizeof(Payload) <= 8
, we can swap the entire pair into a slot with a single "packed" CAS operation. If the combined size exceeds the GPUs native CAS size, we swap the key and the payload in separately. This is done by either a back-to-back CAS strategy or a CAS operation on the key followed by a dependent relaxed write operation on the payload.To answer your question regarding
cuco::is_bitwise_comparable_v(T)
: The most restrictive strategy (and the fastest one too) here is the packed CAS approach, which requires both keys and payloads to …