pwrliang commented on code in PR #586:
URL: https://github.com/apache/sedona-db/pull/586#discussion_r2796356271
##########
c/sedona-libgpuspatial/src/lib.rs:
##########
@@ -15,6 +15,628 @@
// specific language governing permissions and limitations
// under the License.
-// Module declarations
+use arrow_schema::DataType;
+use geo::Rect;
+
+#[cfg(gpu_available)]
+pub mod error;
+#[cfg(gpu_available)]
+mod libgpuspatial;
#[cfg(gpu_available)]
mod libgpuspatial_glue_bindgen;
+
+pub struct GpuSpatialOptions {
+ pub cuda_use_memory_pool: bool,
+ pub cuda_memory_pool_init_percent: i32,
+ pub concurrency: u32,
+ pub device_id: i32,
+ pub compress_bvh: bool,
+ pub pipeline_batches: u32,
+}
+
+/// Spatial predicates for GPU operations
+#[repr(u32)]
+#[derive(Debug, PartialEq, Copy, Clone)]
+pub enum GpuSpatialRelationPredicate {
+ Equals = 0,
+ Disjoint = 1,
+ Touches = 2,
+ Contains = 3,
+ Covers = 4,
+ Intersects = 5,
+ Within = 6,
+ CoveredBy = 7,
+}
+
+impl std::fmt::Display for GpuSpatialRelationPredicate {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ GpuSpatialRelationPredicate::Equals => write!(f, "equals"),
+ GpuSpatialRelationPredicate::Disjoint => write!(f, "disjoint"),
+ GpuSpatialRelationPredicate::Touches => write!(f, "touches"),
+ GpuSpatialRelationPredicate::Contains => write!(f, "contains"),
+ GpuSpatialRelationPredicate::Covers => write!(f, "covers"),
+ GpuSpatialRelationPredicate::Intersects => write!(f, "intersects"),
+ GpuSpatialRelationPredicate::Within => write!(f, "within"),
+ GpuSpatialRelationPredicate::CoveredBy => write!(f, "coveredby"),
+ }
+ }
+}
+
+// Re-export Error type from the sys module abstraction
+pub use sys::GpuSpatialError;
+pub type Result<T> = std::result::Result<T, GpuSpatialError>;
+
+// 1. GPU Available Implementation
+#[cfg(gpu_available)]
+mod sys {
+ use super::libgpuspatial;
+ use super::libgpuspatial_glue_bindgen;
+ use super::*;
+
+ use nvml_wrapper::Nvml;
+ use std::sync::{Arc, Mutex};
+
+ // Re-export the error from the parent module so the public API works
+ pub use super::error::GpuSpatialError;
+
+ use libgpuspatial::{
+ GpuSpatialIndexFloat2DWrapper, GpuSpatialRefinerWrapper,
+ GpuSpatialRelationPredicateWrapper, GpuSpatialRuntimeWrapper,
+ };
+ use libgpuspatial_glue_bindgen::SedonaSpatialIndexContext;
+
+ // -- Thread Safety Setup --
+ unsafe impl Send for SedonaSpatialIndexContext {}
+ unsafe impl Send for libgpuspatial_glue_bindgen::GpuSpatialRuntime {}
+ unsafe impl Sync for libgpuspatial_glue_bindgen::GpuSpatialRuntime {}
+ unsafe impl Send for libgpuspatial_glue_bindgen::SedonaFloatIndex2D {}
+ unsafe impl Send for libgpuspatial_glue_bindgen::SedonaSpatialRefiner {}
+ unsafe impl Sync for libgpuspatial_glue_bindgen::SedonaFloatIndex2D {}
+ unsafe impl Sync for libgpuspatial_glue_bindgen::SedonaSpatialRefiner {}
Review Comment:
I need two of these as the runtime is a singleton and it is declared as
`static GLOBAL_GPUSPATIAL_RUNTIME:
Mutex<Option<Arc<Mutex<GpuSpatialRuntimeWrapper>>>> =
Mutex::new(None);`
```rust
unsafe impl Send for libgpuspatial_glue_bindgen::GpuSpatialRuntime {}
unsafe impl Sync for libgpuspatial_glue_bindgen::GpuSpatialRuntime {}
```
--
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]