@@ -13,13 +13,19 @@ use std::ptr;
1313use std:: sync:: Arc ;
1414
1515use arrow_schema:: ffi:: FFI_ArrowSchema ;
16+ use vortex:: array:: stream:: ArrayStreamExt ;
1617use vortex:: compressor:: BtrBlocksCompressorBuilder ;
1718use vortex:: error:: VortexResult ;
1819use vortex:: error:: vortex_ensure;
20+ use vortex:: file:: OpenOptionsSessionExt ;
1921use vortex:: file:: WriteStrategyBuilder ;
22+ use vortex:: io:: VortexReadAt ;
23+ use vortex:: io:: runtime:: BlockingRuntime ;
24+ use vortex:: io:: session:: RuntimeSessionExt ;
2025use vortex:: session:: SessionExt ;
2126use vortex:: session:: VortexSession ;
2227use vortex_cuda:: CudaSession ;
28+ use vortex_cuda:: PooledFileReadAt ;
2329use vortex_cuda:: arrow:: ArrowDeviceArray ;
2430use vortex_cuda:: arrow:: ArrowDeviceArrayStream ;
2531use vortex_cuda:: arrow:: DeviceArrayExt ;
@@ -104,6 +110,58 @@ pub unsafe extern "C-unwind" fn vx_cuda_array_sink_open_file(
104110 } )
105111}
106112
113+ /// Scan a local Vortex file through pinned host buffers and export an Arrow C Device stream.
114+ ///
115+ /// The file must use encodings and layouts supported by the CUDA execution path, such as files
116+ /// written by [`vx_cuda_array_sink_open_file`]. Pinned staging buffers are reused across scans made
117+ /// with the same CUDA session.
118+ ///
119+ /// On success returns `0` and writes an owned [`ArrowDeviceArrayStream`] to `out_stream`. The
120+ /// caller must release the stream and each array produced by it through their embedded Arrow
121+ /// release callbacks.
122+ ///
123+ /// On error returns `1` and, when `error_out` is non-null, writes a `vx_error` (free with
124+ /// `vx_error_free`).
125+ ///
126+ /// # Safety
127+ ///
128+ /// `session` must be a valid borrowed handle created by `vortex-ffi`. `path` must be valid for the
129+ /// duration of this call and contain UTF-8. `out_stream` must be a valid writable pointer. If
130+ /// `error_out` is non-null, it must be valid for writing one error pointer.
131+ #[ unsafe( no_mangle) ]
132+ pub unsafe extern "C-unwind" fn vx_cuda_scan_path_arrow_device_stream (
133+ session : * const vx_session ,
134+ path : vx_view ,
135+ out_stream : * mut ArrowDeviceArrayStream ,
136+ error_out : * mut * mut vx_error ,
137+ ) -> c_int {
138+ try_or ( error_out, VX_CUDA_ERR , || {
139+ vortex_ensure ! ( !out_stream. is_null( ) , "null ArrowDeviceArrayStream output" ) ;
140+
141+ let path = unsafe { path. as_str ( ) } ?. to_owned ( ) ;
142+ let session = session_with_cuda ( unsafe { vx_session_ref ( session) } ?) ?;
143+ let cuda_session = session. get :: < CudaSession > ( ) ;
144+ let stream = cuda_session. stream ( ) ?;
145+ let pool = Arc :: clone ( cuda_session. pinned_buffer_pool ( ) ) ;
146+ drop ( cuda_session) ;
147+
148+ let reader: Arc < dyn VortexReadAt > = Arc :: new ( PooledFileReadAt :: open (
149+ path,
150+ session. handle ( ) ,
151+ pool,
152+ stream,
153+ ) ?) ;
154+ let array_stream = ffi_runtime ( ) . block_on ( async {
155+ let file = session. open_options ( ) . open ( reader) . await ?;
156+ Ok :: < _ , vortex:: error:: VortexError > ( file. scan ( ) ?. into_array_stream ( ) ?. boxed ( ) )
157+ } ) ?;
158+ let device_stream = array_stream. export_device_array_stream ( & session, ffi_runtime ( ) ) ?;
159+
160+ unsafe { ptr:: write ( out_stream, device_stream) } ;
161+ Ok ( VX_CUDA_OK )
162+ } )
163+ }
164+
107165/// Export a borrowed Vortex array for cuDF's Arrow Device import path.
108166///
109167/// On success returns `0` and writes independently releasable `out_schema` and `out_array`; the
0 commit comments