MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / try_swap_to_unified_allocator

Function try_swap_to_unified_allocator

python/stringzillas.c:137–151  ·  view source on GitHub ↗

* @brief Helper function to automatically swap a Strs object's allocator to unified memory for GPU kernels. * @param[in] strs_obj The Strs object to swap allocator for * @return sz_true_k on success, sz_false_k on failure * @note Sets Pythonic error on failure. */

Source from the content-addressed store, hash-verified

135 * @note Sets Pythonic error on failure.
136 */
137static inline sz_bool_t try_swap_to_unified_allocator(PyObject *strs_obj) {
138 if (!strs_obj || !sz_py_replace_strings_allocator) return sz_false_k;
139
140 // Try to swap to unified allocator - this will be a no-op if already using it
141 sz_bool_t success = sz_py_replace_strings_allocator(strs_obj, &unified_allocator);
142
143 if (!success) {
144 // Always fatal: GPU kernels require unified/device-accessible memory
145 PyErr_SetString(PyExc_RuntimeError,
146 "Device memory mismatch: GPU kernels require unified/device-accessible memory. "
147 "Consider reducing input size, freeing memory, or using CPU capabilities.");
148 return sz_false_k;
149 }
150 return sz_true_k;
151}
152
153/**
154 * @brief Helper function to determine if unified memory is required based on capabilities and device scope.

Callers 6

NeedlemanWunsch_callFunction · 0.85
SmithWaterman_callFunction · 0.85
Fingerprints_callFunction · 0.85
module_to_deviceFunction · 0.85

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…