@@ -232,22 +232,6 @@ fn self_dists_all_stream_generic<const BB: usize, W: IoWrite + Send>(
232232 completeness_cutoff : f64 ,
233233 threads : usize ,
234234) -> Result < ( ) , Error > {
235- #[ cfg( feature = "wgpu" ) ]
236- {
237- if matches ! ( dist_type, DistType :: Jaccard ( ..) ) {
238- return dists_all_stream_wgpu :: < BB , W > (
239- writer,
240- sketches,
241- None ,
242- & dist_type,
243- completeness_vec,
244- None ,
245- completeness_cutoff,
246- ) ;
247- }
248- log:: warn!( "The wgpu backend does not support core/accessory distances yet; using the CPU" ) ;
249- }
250-
251235 let ani = matches ! ( dist_type, DistType :: Jaccard ( _, _, true ) ) ;
252236 let k_vals = match dist_type {
253237 DistType :: Jaccard ( k_idx, k_val, _) => Some ( ( k_idx, k_val) ) ,
@@ -333,22 +317,25 @@ fn self_dists_all_stream_generic<const BB: usize, W: IoWrite + Send>(
333317
334318
335319/// GPU (wgpu) variant of [`self_dists_all_stream`] (`query_sketches` = None) and
336- /// [`cross_dists_all_stream`], for Jaccard distances and ANI. Same line format; pairs come
337- /// out tile by tile and chunk by chunk, in no global order, as in the CUDA code.
320+ /// [`cross_dists_all_stream`], for Jaccard distances and ANI, on GPU `gpu_device` of
321+ /// [`available_gpus`] (None: wgpu's choice). Same line format; pairs come out tile by tile
322+ /// and chunk by chunk, in no global order, as in the CUDA code.
338323#[ cfg( feature = "wgpu" ) ]
339- fn dists_all_stream_wgpu < const BB : usize , W : IoWrite + Send > (
324+ pub fn dists_all_stream_gpu < W : IoWrite + Send > (
340325 writer : & mut W ,
341326 ref_sketches : & MultiSketch ,
342327 query_sketches : Option < & MultiSketch > ,
343- dist_type : & DistType ,
328+ dist_type : DistType ,
344329 ref_completeness_vec : Option < & Vec < f64 > > ,
345330 query_completeness_vec : Option < & Vec < f64 > > ,
346331 completeness_cutoff : f64 ,
332+ gpu_device : Option < usize > ,
347333) -> Result < ( ) , Error > {
348334 let pool_size = rayon:: current_num_threads ( ) ;
349335 if pool_size < 2 {
350336 bail ! ( "GPU dense streaming requires a Rayon producer and writer; configure the pool with set_threads_with_writer()" ) ;
351337 }
338+ let bin_bits = if ref_sketches. is_legacy_format ( ) { LEGACY_BIN_BITS } else { BIN_BITS } ;
352339 let ref_names = <DistanceMatrix as Distances >:: sketch_names ( ref_sketches) ;
353340 let query_names = query_sketches. map ( <DistanceMatrix as Distances >:: sketch_names) ;
354341
@@ -372,11 +359,12 @@ fn dists_all_stream_wgpu<const BB: usize, W: IoWrite + Send>(
372359 let gpu_result = pollster:: block_on ( get_distances_wgpu (
373360 ref_sketches,
374361 query_sketches,
375- dist_type,
362+ & dist_type,
376363 ref_completeness_vec,
377364 query_completeness_vec,
378365 completeness_cutoff,
379- BB ,
366+ bin_bits,
367+ gpu_device,
380368 |tile, dists| match & query_names {
381369 // Self mode: both sides from the reference set, the lower index first
382370 None => tile. consume ( dists, & ref_names, & ref_names, false , & text_tx) ,
@@ -391,6 +379,33 @@ fn dists_all_stream_wgpu<const BB: usize, W: IoWrite + Send>(
391379 } )
392380}
393381
382+ /// Stand-in for builds without the `wgpu` feature, so callers need no cfg of their own
383+ #[ cfg( not( feature = "wgpu" ) ) ]
384+ pub fn dists_all_stream_gpu < W : IoWrite + Send > (
385+ _writer : & mut W ,
386+ _ref_sketches : & MultiSketch ,
387+ _query_sketches : Option < & MultiSketch > ,
388+ _dist_type : DistType ,
389+ _ref_completeness_vec : Option < & Vec < f64 > > ,
390+ _query_completeness_vec : Option < & Vec < f64 > > ,
391+ _completeness_cutoff : f64 ,
392+ _gpu_device : Option < usize > ,
393+ ) -> Result < ( ) , Error > {
394+ bail ! ( "This sketchlib was built without GPU support: rebuild it with --features wgpu" )
395+ }
396+
397+ /// The GPUs [`dists_all_stream_gpu`] can use, one line each, `index: name (type, backend)`
398+ #[ cfg( feature = "wgpu" ) ]
399+ pub fn available_gpus ( ) -> Result < Vec < String > , Error > {
400+ Ok ( crate :: gpu:: dists_wgpu:: gpu_list ( ) )
401+ }
402+
403+ /// Stand-in for builds without the `wgpu` feature
404+ #[ cfg( not( feature = "wgpu" ) ) ]
405+ pub fn available_gpus ( ) -> Result < Vec < String > , Error > {
406+ bail ! ( "This sketchlib was built without GPU support: rebuild it with --features wgpu" )
407+ }
408+
394409/// Self query mode (dense, all distances)
395410pub fn self_dists_knn < ' a > (
396411 sketches : & ' a MultiSketch ,
@@ -709,22 +724,6 @@ fn cross_dists_all_stream_generic<const BB: usize, W: IoWrite + Send>(
709724 completeness_cutoff : f64 ,
710725 threads : usize ,
711726) -> Result < ( ) , Error > {
712- #[ cfg( feature = "wgpu" ) ]
713- {
714- if matches ! ( dist_type, DistType :: Jaccard ( ..) ) {
715- return dists_all_stream_wgpu :: < BB , W > (
716- writer,
717- ref_sketches,
718- Some ( query_sketches) ,
719- & dist_type,
720- ref_completeness_vec,
721- query_completeness_vec,
722- completeness_cutoff,
723- ) ;
724- }
725- log:: warn!( "The wgpu backend does not support core/accessory distances yet; using the CPU" ) ;
726- }
727-
728727 let ani = matches ! ( dist_type, DistType :: Jaccard ( _, _, true ) ) ;
729728 let k_vals = match dist_type {
730729 DistType :: Jaccard ( k_idx, k_val, _) => Some ( ( k_idx, k_val) ) ,
0 commit comments