* @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. */
| 135 | * @note Sets Pythonic error on failure. |
| 136 | */ |
| 137 | static 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. |
no test coverage detected
searching dependent graphs…