@@ -104,148 +104,52 @@ where
104104#[ cfg( test) ]
105105#[ cfg( cuda_available) ]
106106mod tests {
107+ use rstest:: rstest;
107108 use vortex_array:: IntoArray ;
108109 use vortex_array:: arrays:: PrimitiveArray ;
109110 use vortex_array:: assert_arrays_eq;
110111 use vortex_array:: validity:: Validity :: NonNullable ;
111112 use vortex_buffer:: Buffer ;
113+ use vortex_dtype:: NativePType ;
112114 use vortex_error:: VortexExpect ;
113115 use vortex_fastlanes:: FoRArray ;
116+ use vortex_scalar:: Scalar ;
114117 use vortex_session:: VortexSession ;
115118
116119 use super :: * ;
120+ use crate :: CanonicalCudaExt ;
117121 use crate :: session:: CudaSession ;
118122
119- #[ tokio:: test]
120- async fn test_cuda_for_decompression_u8 ( ) {
121- let mut cuda_ctx = CudaSession :: create_execution_ctx ( VortexSession :: empty ( ) )
122- . vortex_expect ( "failed to create execution context" ) ;
123-
124- #[ allow( clippy:: cast_possible_truncation) ]
125- let input_data: Vec < u8 > = ( 0 ..5000 ) . map ( |i| ( i % 246 ) as u8 ) . collect ( ) ;
126-
127- let for_array = FoRArray :: try_new (
128- PrimitiveArray :: new ( Buffer :: from ( input_data) , NonNullable ) . into_array ( ) ,
129- 10u8 . into ( ) ,
130- )
131- . vortex_expect ( "failed to create FoR array" ) ;
132-
133- // Decode on CPU
134- let cpu_result = for_array
135- . to_canonical ( )
136- . vortex_expect ( "CPU canonicalize failed" ) ;
137-
138- // Decode on GPU
139- let gpu_result = FoRExecutor
140- . execute ( for_array. to_array ( ) , & mut cuda_ctx)
141- . await
142- . vortex_expect ( "GPU decompression failed" ) ;
143-
144- // Copy GPU result back to host for comparison
145- let gpu_host = Buffer :: < u8 > :: from_byte_buffer (
146- gpu_result. into_primitive ( ) . buffer_handle ( ) . to_host ( ) . await ,
147- ) ;
148- let gpu_array = PrimitiveArray :: new ( gpu_host, NonNullable ) ;
149-
150- assert_arrays_eq ! ( cpu_result. into_array( ) , gpu_array. into_array( ) ) ;
151- }
152-
153- #[ tokio:: test]
154- async fn test_cuda_for_decompression_u16 ( ) {
155- let mut cuda_ctx = CudaSession :: create_execution_ctx ( VortexSession :: empty ( ) )
156- . vortex_expect ( "failed to create execution context" ) ;
157-
158- let input_data: Vec < u16 > = ( 0 ..5000 ) . map ( |i| ( i % 5000 ) as u16 ) . collect ( ) ;
159-
160- let for_array = FoRArray :: try_new (
161- PrimitiveArray :: new ( Buffer :: from ( input_data) , NonNullable ) . into_array ( ) ,
162- 1000u16 . into ( ) ,
163- )
164- . vortex_expect ( "failed to create FoR array" ) ;
165-
166- // Decode on CPU
167- let cpu_result = for_array
168- . to_canonical ( )
169- . vortex_expect ( "CPU canonicalize failed" ) ;
170-
171- // Decode on GPU
172- let gpu_result = FoRExecutor
173- . execute ( for_array. to_array ( ) , & mut cuda_ctx)
174- . await
175- . vortex_expect ( "GPU decompression failed" ) ;
176-
177- // Copy GPU result back to host for comparison
178- let gpu_host = Buffer :: < u16 > :: from_byte_buffer (
179- gpu_result. into_primitive ( ) . buffer_handle ( ) . to_host ( ) . await ,
180- ) ;
181- let gpu_array = PrimitiveArray :: new ( gpu_host, NonNullable ) ;
182-
183- assert_arrays_eq ! ( cpu_result. into_array( ) , gpu_array. into_array( ) ) ;
184- }
185-
186- #[ tokio:: test]
187- async fn test_cuda_for_decompression_u32 ( ) {
188- let mut cuda_ctx = CudaSession :: create_execution_ctx ( VortexSession :: empty ( ) )
189- . vortex_expect ( "failed to create execution context" ) ;
190-
191- let input_data: Vec < u32 > = ( 0 ..5000 ) . map ( |i| ( i % 5000 ) as u32 ) . collect ( ) ;
192-
193- let for_array = FoRArray :: try_new (
123+ fn make_for_array < T : NativePType + Into < Scalar > > ( input_data : Vec < T > , reference : T ) -> FoRArray {
124+ FoRArray :: try_new (
194125 PrimitiveArray :: new ( Buffer :: from ( input_data) , NonNullable ) . into_array ( ) ,
195- 100000u32 . into ( ) ,
126+ reference . into ( ) ,
196127 )
197- . vortex_expect ( "failed to create FoR array" ) ;
198-
199- // Decode on CPU
200- let cpu_result = for_array
201- . to_canonical ( )
202- . vortex_expect ( "CPU canonicalize failed" ) ;
203-
204- // Decode on GPU
205- let gpu_result = FoRExecutor
206- . execute ( for_array. to_array ( ) , & mut cuda_ctx)
207- . await
208- . vortex_expect ( "GPU decompression failed" ) ;
209-
210- // Copy GPU result back to host for comparison
211- let gpu_host = Buffer :: < u32 > :: from_byte_buffer (
212- gpu_result. into_primitive ( ) . buffer_handle ( ) . to_host ( ) . await ,
213- ) ;
214- let gpu_array = PrimitiveArray :: new ( gpu_host, NonNullable ) ;
215-
216- assert_arrays_eq ! ( cpu_result. into_array( ) , gpu_array. into_array( ) ) ;
128+ . unwrap ( )
217129 }
218130
131+ #[ rstest]
132+ #[ case:: u8( make_for_array( ( 0 ..5000 ) . map( |i| ( i % 246 ) as u8 ) . collect( ) , 10u8 ) ) ]
133+ #[ case:: u16( make_for_array( ( 0 ..5000 ) . map( |i| ( i % 5000 ) as u16 ) . collect( ) , 1000u16 ) ) ]
134+ #[ case:: u32( make_for_array( ( 0 ..5000 ) . map( |i| ( i % 5000 ) as u32 ) . collect( ) , 100000u32 ) ) ]
135+ #[ case:: u64( make_for_array( ( 0 ..5000 ) . map( |i| ( i % 5000 ) as u64 ) . collect( ) , 1000000u64 ) ) ]
219136 #[ tokio:: test]
220- async fn test_cuda_for_decompression_u64 ( ) {
137+ async fn test_cuda_for_decompression ( # [ case ] for_array : FoRArray ) -> VortexResult < ( ) > {
221138 let mut cuda_ctx = CudaSession :: create_execution_ctx ( VortexSession :: empty ( ) )
222139 . vortex_expect ( "failed to create execution context" ) ;
223140
224- let input_data: Vec < u64 > = ( 0 ..5000 ) . map ( |i| ( i % 5000 ) as u64 ) . collect ( ) ;
225-
226- let for_array = FoRArray :: try_new (
227- PrimitiveArray :: new ( Buffer :: from ( input_data) , NonNullable ) . into_array ( ) ,
228- 1000000u64 . into ( ) ,
229- )
230- . vortex_expect ( "failed to create FoR array" ) ;
231-
232- // Decode on CPU
233- let cpu_result = for_array
234- . to_canonical ( )
235- . vortex_expect ( "CPU canonicalize failed" ) ;
141+ let cpu_result = for_array. to_canonical ( ) ?;
236142
237- // Decode on GPU
238143 let gpu_result = FoRExecutor
239144 . execute ( for_array. to_array ( ) , & mut cuda_ctx)
240145 . await
241- . vortex_expect ( "GPU decompression failed" ) ;
146+ . vortex_expect ( "GPU decompression failed" )
147+ . into_host ( )
148+ . await ?
149+ . into_array ( ) ;
242150
243- // Copy GPU result back to host for comparison
244- let gpu_host = Buffer :: < u64 > :: from_byte_buffer (
245- gpu_result. into_primitive ( ) . buffer_handle ( ) . to_host ( ) . await ,
246- ) ;
247- let gpu_array = PrimitiveArray :: new ( gpu_host, NonNullable ) ;
151+ assert_arrays_eq ! ( cpu_result. into_array( ) , gpu_result) ;
248152
249- assert_arrays_eq ! ( cpu_result . into_array ( ) , gpu_array . into_array ( ) ) ;
153+ Ok ( ( ) )
250154 }
251155}
0 commit comments