@@ -14,6 +14,7 @@ use std::ptr;
1414use arrow_schema:: ffi:: FFI_ArrowSchema ;
1515use vortex:: error:: VortexResult ;
1616use vortex:: error:: vortex_ensure;
17+ use vortex:: error:: vortex_err;
1718use vortex:: session:: VortexSession ;
1819use vortex_cuda:: CudaSession ;
1920use vortex_cuda:: arrow:: ArrowDeviceArray ;
@@ -34,20 +35,14 @@ use vortex_ffi::vx_session_ref;
3435const VX_CUDA_OK : c_int = 0 ;
3536const VX_CUDA_ERR : c_int = 1 ;
3637
37- /// Return a Vortex session with a [`CudaSession`] session variable.
38- ///
39- /// If `session` already has CUDA support, this returns a clone of it. Otherwise it
40- /// returns a new session cloned from `session` with a default [`CudaSession`] attached.
41- fn session_with_cuda ( session : & VortexSession ) -> VortexResult < VortexSession > {
42- if session. get_opt :: < CudaSession > ( ) . is_some ( ) {
43- return Ok ( session. clone ( ) ) ;
38+ fn session_with_cuda ( session : & VortexSession ) -> VortexResult < & VortexSession > {
39+ if session. get_opt :: < CudaSession > ( ) . is_none ( ) {
40+ return Err ( vortex_err ! (
41+ InvalidArgument : "CUDA session state is not configured; create the session with vx_cuda_session_new"
42+ ) ) ;
4443 }
4544
46- Ok ( session
47- . clone ( )
48- . into_builder ( )
49- . with_some ( CudaSession :: try_default ( ) ?)
50- . build ( ) )
45+ Ok ( session)
5146}
5247
5348/// Create a CUDA Vortex session.
@@ -65,7 +60,7 @@ pub unsafe extern "C-unwind" fn vx_cuda_session_new(
6560 try_or ( error_out, ptr:: null_mut ( ) , || {
6661 let cuda_session = CudaSession :: try_default ( ) ?;
6762 Ok ( vx_session_new_with ( |session| {
68- session. into_builder ( ) . with_some ( cuda_session) . build ( )
63+ session. with_some ( cuda_session)
6964 } ) )
7065 } )
7166}
@@ -101,7 +96,7 @@ pub unsafe extern "C-unwind" fn vx_cuda_array_export_arrow_device(
10196
10297 let session = session_with_cuda ( unsafe { vx_session_ref ( session) } ?) ?;
10398 let array = unsafe { vx_array_ref ( array) } ?. clone ( ) ;
104- let mut ctx = CudaSession :: create_execution_ctx ( & session) ?;
99+ let mut ctx = CudaSession :: create_execution_ctx ( session) ?;
105100 let exported =
106101 futures:: executor:: block_on ( array. export_device_array_with_schema ( & mut ctx) ) ?;
107102
@@ -146,7 +141,7 @@ pub unsafe extern "C-unwind" fn vx_cuda_partition_scan_arrow_device_stream(
146141
147142 let session = session_with_cuda ( unsafe { vx_session_ref ( session) } ?) ?;
148143 // Drive the stream on the same runtime the partition's scan spawned its work onto.
149- let device_stream = array_stream. export_device_array_stream ( & session, ffi_runtime ( ) ) ?;
144+ let device_stream = array_stream. export_device_array_stream ( session, ffi_runtime ( ) ) ?;
150145
151146 unsafe { ptr:: write ( out_stream, device_stream) } ;
152147 Ok ( VX_CUDA_OK )
@@ -177,6 +172,12 @@ mod tests {
177172 Box :: into_raw ( Box :: new ( session) ) . cast :: < vx_session > ( )
178173 }
179174
175+ fn test_cuda_session ( ) -> VortexResult < VortexSession > {
176+ Ok ( vortex:: array:: array_session ( )
177+ . with_some ( CudaSession :: try_default ( ) ?)
178+ . build ( ) )
179+ }
180+
180181 unsafe fn free_test_session ( session : * mut vx_session ) {
181182 unsafe { drop ( Box :: from_raw ( session. cast :: < VortexSession > ( ) ) ) } ;
182183 }
@@ -216,9 +217,9 @@ mod tests {
216217 }
217218
218219 #[ cuda_test]
219- fn test_export_primitive_arrow_device ( ) {
220+ fn test_export_primitive_arrow_device ( ) -> VortexResult < ( ) > {
220221 let mut error = ptr:: null_mut ( ) ;
221- let session = test_session ( VortexSession :: default ( ) ) ;
222+ let session = test_session ( test_cuda_session ( ) ? ) ;
222223 let array = test_array ( PrimitiveArray :: from_iter ( 0u32 ..5 ) ) ;
223224 let mut schema = FFI_ArrowSchema :: empty ( ) ;
224225 let mut device_array = empty_device_array ( ) ;
@@ -235,7 +236,7 @@ mod tests {
235236 assert_eq ! ( status, VX_CUDA_OK ) ;
236237 assert ! ( error. is_null( ) ) ;
237238
238- let field = Field :: try_from ( & schema) . expect ( "schema should be a field" ) ;
239+ let field = Field :: try_from ( & schema) ? ;
239240 assert_eq ! ( field. name( ) , "" ) ;
240241 assert_eq ! ( device_array. array. length, 5 ) ;
241242 assert_eq ! ( device_array. array. n_buffers, 2 ) ;
@@ -249,12 +250,13 @@ mod tests {
249250 free_test_array ( array) ;
250251 free_test_session ( session) ;
251252 }
253+ Ok ( ( ) )
252254 }
253255
254256 #[ cuda_test]
255257 fn test_export_struct_arrow_device_table ( ) -> VortexResult < ( ) > {
256258 let mut error = ptr:: null_mut ( ) ;
257- let session = test_session ( VortexSession :: default ( ) ) ;
259+ let session = test_session ( test_cuda_session ( ) ? ) ;
258260 let array = test_array ( StructArray :: try_new (
259261 [ "ids" , "values" ] . into ( ) ,
260262 vec ! [
0 commit comments