MCPcopy Create free account
hub / github.com/apache/arrow / test_device_interface_batch_array

Function test_device_interface_batch_array

python/pyarrow/tests/test_cuda.py:905–958  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

903
904
905def test_device_interface_batch_array():
906 cffi = pytest.importorskip("pyarrow.cffi", exc_type=ImportError)
907 ffi = cffi.ffi
908
909 c_schema = ffi.new("struct ArrowSchema*")
910 ptr_schema = int(ffi.cast("uintptr_t", c_schema))
911 c_array = ffi.new("struct ArrowDeviceArray*")
912 ptr_array = int(ffi.cast("uintptr_t", c_array))
913
914 batch = make_recordbatch(10)
915 schema = batch.schema
916 cbuf = cuda.serialize_record_batch(batch, global_context)
917 cbatch = cuda.read_record_batch(cbuf, schema)
918
919 # Schema is known up front
920 cbatch._export_to_c_device(ptr_array)
921
922 # verify exported struct
923 assert c_array.device_type == 2 # ARROW_DEVICE_CUDA 2
924 assert c_array.device_id == global_context.device_number
925 assert c_array.array.length == 10
926
927 # Delete recreate C++ object from exported pointer
928 del cbatch
929 cbatch_new = pa.RecordBatch._import_from_c_device(ptr_array, schema)
930 assert cbatch_new.schema == schema
931 batch_new = cbatch_new.copy_to(pa.default_cpu_memory_manager())
932 assert batch_new.equals(batch)
933
934 del cbatch_new
935 # Now released
936 with pytest.raises(ValueError, match="Cannot import released ArrowArray"):
937 pa.RecordBatch._import_from_c_device(ptr_array, schema)
938
939 # Schema is exported and imported at the same time
940 cbatch = cuda.read_record_batch(cbuf, schema)
941 cbatch._export_to_c_device(ptr_array, ptr_schema)
942 # Delete and recreate C++ objects from exported pointers
943 del cbatch
944 cbatch_new = pa.RecordBatch._import_from_c_device(ptr_array, ptr_schema)
945 assert cbatch_new.schema == schema
946 batch_new = cbatch_new.copy_to(pa.default_cpu_memory_manager())
947 assert batch_new.equals(batch)
948
949 del cbatch_new
950 # Now released
951 with pytest.raises(ValueError, match="Cannot import released ArrowSchema"):
952 pa.RecordBatch._import_from_c_device(ptr_array, ptr_schema)
953
954 # Not a struct type
955 pa.int32()._export_to_c(ptr_schema)
956 with pytest.raises(ValueError,
957 match="ArrowSchema describes non-struct type"):
958 pa.RecordBatch._import_from_c_device(ptr_array, ptr_schema)
959
960
961def test_print_array():

Callers

nothing calls this directly

Calls 5

make_recordbatchFunction · 0.85
equalsMethod · 0.80
newMethod · 0.45
castMethod · 0.45
read_record_batchMethod · 0.45

Tested by

no test coverage detected