tadeja commented on code in PR #50923:
URL: https://github.com/apache/arrow/pull/50923#discussion_r4422716976


##########
ci/scripts/install_numba.sh:
##########
@@ -34,6 +34,12 @@ if [ -n "${ARROW_PYTHON_VENV:-}" ]; then
   . "${ARROW_PYTHON_VENV}/bin/activate"
 fi
 
+# Numba-CUDA 0.30.4 uses np.row_stack, which was removed in NumPy 2.5.
+# TODO: Remove after https://github.com/NVIDIA/numba-cuda/pull/916 is released.

Review Comment:
   ```suggestion
   # Upstream recommends NumPy <=2.4, no plan to fix this:
   # https://github.com/NVIDIA/numba-cuda/issues/907#issuecomment-5620678407
   ```



##########
python/pyarrow/tests/test_cuda_numba_interop.py:
##########
@@ -50,8 +52,14 @@ def teardown_module(module):
                          ids=context_choice_ids)
 def test_context(c):
     ctx, nb_ctx = context_choices[c]
-    assert ctx.handle == nb_ctx.handle.value
-    assert ctx.handle == ctx.to_numba().handle.value
+    converted = ctx.to_numba()
+    assert type(converted.handle) is type(nb_ctx.handle)
+    if isinstance(converted.handle, ctypes.c_void_p):

Review Comment:
   ```suggestion
       assert type(converted.handle) is type(nb_ctx.handle)
       # Built-in Numba CUDA and numba-cuda <0.28 use ctypes.c_void_p (legacy),
       # numba-cuda >=0.28 uses cuda.bindings.driver.CUcontext
       if isinstance(converted.handle, ctypes.c_void_p):
   ```



##########
python/pyarrow/_cuda.pyx:
##########
@@ -16,13 +16,43 @@
 # under the License.
 
 
+import ctypes
+
+from pyarrow.vendored.version import Version
+
 from pyarrow.lib cimport *
 from pyarrow.includes.libarrow_cuda cimport *
 from pyarrow.lib import allocate_buffer, as_buffer, ArrowTypeError
 from pyarrow.util import get_contiguous_span
 cimport cpython as cp
 
 
+_NUMBA_CUDA_NATIVE_CONTEXT_VERSION = Version("0.28")
+
+
+def _numba_context_handle_value(handle):
+    """Return the integer value of a legacy or native Numba context handle."""
+    if hasattr(handle, "value"):

Review Comment:
   ```suggestion
       """Return the integer value of a legacy or native Numba context 
handle."""
       # Legacy ctypes.c_void_p handle (built-in Numba CUDA or numba-cuda <0.28)
       if hasattr(handle, "value"):
   ```



##########
python/pyarrow/_cuda.pyx:
##########
@@ -16,13 +16,43 @@
 # under the License.
 
 
+import ctypes
+
+from pyarrow.vendored.version import Version
+
 from pyarrow.lib cimport *
 from pyarrow.includes.libarrow_cuda cimport *
 from pyarrow.lib import allocate_buffer, as_buffer, ArrowTypeError
 from pyarrow.util import get_contiguous_span
 cimport cpython as cp
 
 
+_NUMBA_CUDA_NATIVE_CONTEXT_VERSION = Version("0.28")
+
+
+def _numba_context_handle_value(handle):
+    """Return the integer value of a legacy or native Numba context handle."""
+    if hasattr(handle, "value"):
+        return handle.value
+    return int(handle)

Review Comment:
   ```suggestion
           return handle.value
       # Native cuda.bindings.driver.CUcontext handle (numba-cuda >=0.28)
       return int(handle)
   ```



##########
python/pyarrow/_cuda.pyx:
##########
@@ -16,13 +16,43 @@
 # under the License.
 
 
+import ctypes
+
+from pyarrow.vendored.version import Version
+
 from pyarrow.lib cimport *
 from pyarrow.includes.libarrow_cuda cimport *
 from pyarrow.lib import allocate_buffer, as_buffer, ArrowTypeError
 from pyarrow.util import get_contiguous_span
 cimport cpython as cp
 
 
+_NUMBA_CUDA_NATIVE_CONTEXT_VERSION = Version("0.28")
+
+
+def _numba_context_handle_value(handle):
+    """Return the integer value of a legacy or native Numba context handle."""
+    if hasattr(handle, "value"):
+        return handle.value
+    return int(handle)
+
+
+def _make_numba_context_handle(uintptr_t handle):
+    """Create the context handle representation expected by Numba."""
+    import numba.cuda
+
+    # numba-cuda 0.28 replaced ctypes context handles with CUContext type.
+    if getattr(numba.cuda, "implementation", None) == "NVIDIA":
+        import numba_cuda
+
+        version = Version(numba_cuda.__version__)
+        if version >= _NUMBA_CUDA_NATIVE_CONTEXT_VERSION:
+            from cuda.bindings.driver import CUcontext
+            return CUcontext(handle)
+
+    return ctypes.c_void_p(handle)

Review Comment:
   ```suggestion
               return CUcontext(handle)
   
       # Legacy handle for built-in Numba CUDA and numba-cuda <0.28
       return ctypes.c_void_p(handle)
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to