@@ -26,7 +26,6 @@ use vortex::array::validity::Validity;
2626use vortex:: buffer:: Buffer ;
2727use vortex:: buffer:: ByteBuffer ;
2828use vortex:: dtype:: DType ;
29- use vortex:: dtype:: Nullability ;
3029use vortex:: error:: VortexExpect ;
3130use vortex:: error:: VortexResult ;
3231use vortex:: session:: VortexSession ;
@@ -45,6 +44,15 @@ async fn binary_on_device(
4544 views : Buffer < BinaryView > ,
4645 buffers : Arc < [ ByteBuffer ] > ,
4746 ctx : & mut CudaExecutionCtx ,
47+ ) -> VortexResult < ArrayRef > {
48+ binary_on_device_with_validity ( views, buffers, Validity :: NonNullable , ctx) . await
49+ }
50+
51+ async fn binary_on_device_with_validity (
52+ views : Buffer < BinaryView > ,
53+ buffers : Arc < [ ByteBuffer ] > ,
54+ validity : Validity ,
55+ ctx : & mut CudaExecutionCtx ,
4856) -> VortexResult < ArrayRef > {
4957 let views = ctx
5058 . ensure_on_device ( BufferHandle :: new_host ( views. into_byte_buffer ( ) ) )
@@ -60,8 +68,8 @@ async fn binary_on_device(
6068 Ok ( VarBinViewArray :: new_handle (
6169 views,
6270 device_buffers. into ( ) ,
63- DType :: Binary ( Nullability :: NonNullable ) ,
64- Validity :: NonNullable ,
71+ DType :: Binary ( validity . nullability ( ) ) ,
72+ validity ,
6573 )
6674 . into_array ( ) )
6775}
@@ -85,6 +93,14 @@ async fn out_of_line_binary(len: usize, ctx: &mut CudaExecutionCtx) -> VortexRes
8593 binary_on_device ( views, Arc :: from ( [ values] ) , ctx) . await
8694}
8795
96+ async fn sliced_validity_binary ( len : usize , ctx : & mut CudaExecutionCtx ) -> VortexResult < ArrayRef > {
97+ let views =
98+ Buffer :: from_iter ( ( 0 ..len) . map ( |idx| BinaryView :: make_view ( & idx. to_le_bytes ( ) , 0 , 0 ) ) ) ;
99+ let validity = Validity :: from_iter ( ( 0 ..=len) . map ( |idx| idx % 3 != 0 ) ) . slice ( 1 ..len + 1 ) ?;
100+
101+ binary_on_device_with_validity ( views, Arc :: from ( [ ] ) , validity, ctx) . await
102+ }
103+
88104unsafe fn release_arrow_device_array ( array : & mut ArrowDeviceArray ) {
89105 unsafe {
90106 if let Some ( release) = array. array . release {
@@ -154,6 +170,35 @@ fn benchmark_arrow_binary_export(c: &mut Criterion) {
154170 } ) ;
155171 } ,
156172 ) ;
173+
174+ group. throughput ( Throughput :: Bytes (
175+ ( len * ( size_of :: < BinaryView > ( ) + 8 ) + len. div_ceil ( 8 ) ) as u64 ,
176+ ) ) ;
177+ group. bench_with_input (
178+ BenchmarkId :: new ( "cuda/arrow_binary/sliced_validity" , len_label) ,
179+ & len,
180+ |b, & len| {
181+ b. iter_custom ( |iters| {
182+ let timed = TimedLaunchStrategy :: default ( ) ;
183+ let timer = timed. timer ( ) ;
184+
185+ let mut cuda_ctx = CudaSession :: create_execution_ctx ( & VortexSession :: empty ( ) )
186+ . vortex_expect ( "failed to create execution context" )
187+ . with_launch_strategy ( Arc :: new ( timed) ) ;
188+ let array = block_on ( sliced_validity_binary ( len, & mut cuda_ctx) )
189+ . vortex_expect ( "failed to create binary fixture" ) ;
190+
191+ for _ in 0 ..iters {
192+ let mut exported =
193+ block_on ( array. clone ( ) . export_device_array ( & mut cuda_ctx) )
194+ . vortex_expect ( "failed to export device array" ) ;
195+ unsafe { release_arrow_device_array ( & mut exported) } ;
196+ }
197+
198+ Duration :: from_nanos ( timer. load ( Ordering :: Relaxed ) )
199+ } ) ;
200+ } ,
201+ ) ;
157202 }
158203
159204 group. finish ( ) ;
0 commit comments