pwrliang commented on code in PR #465: URL: https://github.com/apache/sedona-db/pull/465#discussion_r2695269576
########## rust/sedona-spatial-join-gpu/benches/gpu_spatial_join.rs: ########## @@ -0,0 +1,360 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use arrow::datatypes::{DataType, Field, Schema}; +use arrow_array::{Int32Array, RecordBatch}; +use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; +use datafusion::execution::context::TaskContext; +use datafusion::physical_plan::ExecutionPlan; +use futures::StreamExt; +use sedona_schema::crs::lnglat; +use sedona_schema::datatypes::{Edges, SedonaType, WKB_GEOMETRY}; +use sedona_spatial_join_gpu::{ + GeometryColumnInfo, GpuSpatialJoinConfig, GpuSpatialJoinExec, GpuSpatialPredicate, + SpatialPredicate, +}; +use sedona_testing::create::create_array_storage; +use std::sync::Arc; +use tokio::runtime::Runtime; + +// Helper execution plan that returns a single pre-loaded batch +struct SingleBatchExec { + schema: Arc<Schema>, + batch: RecordBatch, + props: datafusion::physical_plan::PlanProperties, +} + +impl SingleBatchExec { + fn new(batch: RecordBatch) -> Self { + let schema = batch.schema(); + let eq_props = datafusion::physical_expr::EquivalenceProperties::new(schema.clone()); + let partitioning = datafusion::physical_plan::Partitioning::UnknownPartitioning(1); + let props = datafusion::physical_plan::PlanProperties::new( + eq_props, + partitioning, + datafusion::physical_plan::execution_plan::EmissionType::Final, + datafusion::physical_plan::execution_plan::Boundedness::Bounded, + ); + Self { + schema, + batch, + props, + } + } +} + +impl std::fmt::Debug for SingleBatchExec { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "SingleBatchExec") + } +} + +impl datafusion::physical_plan::DisplayAs for SingleBatchExec { + fn fmt_as( + &self, + _t: datafusion::physical_plan::DisplayFormatType, + f: &mut std::fmt::Formatter, + ) -> std::fmt::Result { + write!(f, "SingleBatchExec") + } +} + +impl datafusion::physical_plan::ExecutionPlan for SingleBatchExec { + fn name(&self) -> &str { + "SingleBatchExec" + } + + fn as_any(&self) -> &dyn std::any::Any { + self + } + + fn schema(&self) -> Arc<Schema> { + self.schema.clone() + } + + fn properties(&self) -> &datafusion::physical_plan::PlanProperties { + &self.props + } + + fn children(&self) -> Vec<&Arc<dyn datafusion::physical_plan::ExecutionPlan>> { + vec![] + } + + fn with_new_children( + self: Arc<Self>, + _children: Vec<Arc<dyn datafusion::physical_plan::ExecutionPlan>>, + ) -> datafusion_common::Result<Arc<dyn datafusion::physical_plan::ExecutionPlan>> { + Ok(self) + } + + fn execute( + &self, + _partition: usize, + _context: Arc<datafusion::execution::context::TaskContext>, + ) -> datafusion_common::Result<datafusion::physical_plan::SendableRecordBatchStream> { + use datafusion::physical_plan::{RecordBatchStream, SendableRecordBatchStream}; + use futures::Stream; + use std::pin::Pin; + use std::task::{Context, Poll}; + + struct OnceBatchStream { + schema: Arc<Schema>, + batch: Option<RecordBatch>, + } + + impl Stream for OnceBatchStream { + type Item = datafusion_common::Result<RecordBatch>; + + fn poll_next( + mut self: Pin<&mut Self>, + _cx: &mut Context<'_>, + ) -> Poll<Option<Self::Item>> { + Poll::Ready(self.batch.take().map(Ok)) + } + } + + impl RecordBatchStream for OnceBatchStream { + fn schema(&self) -> Arc<Schema> { + self.schema.clone() + } + } + + Ok(Box::pin(OnceBatchStream { + schema: self.schema.clone(), + batch: Some(self.batch.clone()), + }) as SendableRecordBatchStream) + } +} + +/// Generate random points within a bounding box +fn generate_random_points(count: usize) -> Vec<String> { + use rand::Rng; + let mut rng = rand::thread_rng(); + (0..count) + .map(|_| { + let x: f64 = rng.gen_range(-180.0..180.0); + let y: f64 = rng.gen_range(-90.0..90.0); + format!("POINT ({} {})", x, y) + }) + .collect() +} Review Comment: @zhangfengcdt Hi Feng, do we still need this benchmark program? It compares to a brute-force CPU implementation. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
