()
| 850 | |
| 851 | |
| 852 | def test_device_interface_array(): |
| 853 | cffi = pytest.importorskip("pyarrow.cffi", exc_type=ImportError) |
| 854 | ffi = cffi.ffi |
| 855 | |
| 856 | c_schema = ffi.new("struct ArrowSchema*") |
| 857 | ptr_schema = int(ffi.cast("uintptr_t", c_schema)) |
| 858 | c_array = ffi.new("struct ArrowDeviceArray*") |
| 859 | ptr_array = int(ffi.cast("uintptr_t", c_array)) |
| 860 | |
| 861 | typ = pa.list_(pa.int32()) |
| 862 | arr = pa.array([[1], [2, 42]], type=typ) |
| 863 | |
| 864 | # copy to device |
| 865 | _, buf = make_random_buffer(size=10, target='device') |
| 866 | mm_cuda = buf.memory_manager |
| 867 | carr = arr.copy_to(mm_cuda) |
| 868 | |
| 869 | # Type is known up front |
| 870 | carr._export_to_c_device(ptr_array) |
| 871 | |
| 872 | # verify exported struct |
| 873 | assert c_array.device_type == 2 # ARROW_DEVICE_CUDA 2 |
| 874 | assert c_array.device_id == global_context.device_number |
| 875 | assert c_array.array.length == 2 |
| 876 | |
| 877 | # Delete recreate C++ object from exported pointer |
| 878 | del carr |
| 879 | carr_new = pa.Array._import_from_c_device(ptr_array, typ) |
| 880 | assert carr_new.type == pa.list_(pa.int32()) |
| 881 | arr_new = carr_new.copy_to(pa.default_cpu_memory_manager()) |
| 882 | assert arr_new.equals(arr) |
| 883 | |
| 884 | del carr_new |
| 885 | # Now released |
| 886 | with pytest.raises(ValueError, match="Cannot import released ArrowArray"): |
| 887 | pa.Array._import_from_c_device(ptr_array, typ) |
| 888 | |
| 889 | # Schema is exported and imported at the same time |
| 890 | carr = arr.copy_to(mm_cuda) |
| 891 | carr._export_to_c_device(ptr_array, ptr_schema) |
| 892 | # Delete and recreate C++ objects from exported pointers |
| 893 | del carr |
| 894 | carr_new = pa.Array._import_from_c_device(ptr_array, ptr_schema) |
| 895 | assert carr_new.type == pa.list_(pa.int32()) |
| 896 | arr_new = carr_new.copy_to(pa.default_cpu_memory_manager()) |
| 897 | assert arr_new.equals(arr) |
| 898 | |
| 899 | del carr_new |
| 900 | # Now released |
| 901 | with pytest.raises(ValueError, match="Cannot import released ArrowSchema"): |
| 902 | pa.Array._import_from_c_device(ptr_array, ptr_schema) |
| 903 | |
| 904 | |
| 905 | def test_device_interface_batch_array(): |
nothing calls this directly
no test coverage detected