pwrliang commented on code in PR #310: URL: https://github.com/apache/sedona-db/pull/310#discussion_r2583522330
########## c/sedona-libgpuspatial/build.rs: ########## @@ -0,0 +1,132 @@ +// 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 std::env; +use std::path::PathBuf; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-changed=libgpuspatial"); + println!("cargo::rustc-check-cfg=cfg(gpu_available)"); + + // Check if gpu feature is enabled + let gpu_feature_enabled = env::var("CARGO_FEATURE_GPU").is_ok(); + + if !gpu_feature_enabled { + println!( + "cargo:warning=GPU feature not enabled. Use --features gpu to enable GPU support." + ); + // Create empty bindings file so the build doesn't fail + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + std::fs::write(out_path.join("bindings.rs"), "// GPU feature not enabled\n") + .expect("Couldn't write empty bindings!"); + return; + } + + // Check if libgpuspatial submodule exists + let libgpuspatial_path = std::path::Path::new("./libgpuspatial/CMakeLists.txt"); + if !libgpuspatial_path.exists() { + println!("cargo:warning=libgpuspatial submodule not found. GPU functionality will not be available."); + println!("cargo:warning=To enable GPU support, initialize the submodule: git submodule update --init --recursive"); + + // Create empty bindings file so the build doesn't fail + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + std::fs::write( + out_path.join("bindings.rs"), + "// libgpuspatial submodule not available\n", + ) + .expect("Couldn't write empty bindings!"); + return; + } + + // Check if CUDA is available + let cuda_available = env::var("CUDA_HOME").is_ok() + || std::path::Path::new("/usr/local/cuda").exists() + || which::which("nvcc").is_ok(); + + if cuda_available { + // Compile the library for A10 (86), L4, L40 (89) GPUs + // You should adjust this based on your target GPUs + // Otherwise, it calls JIT compilation which has a startup overhead + + let dst = cmake::Config::new("./libgpuspatial") + .define("CMAKE_CUDA_ARCHITECTURES", "86") + .define("CMAKE_POLICY_VERSION_MINIMUM", "3.5") // Allow older CMake versions + .define("CMAKE_BUILD_TYPE", "Release") // Set build type to Debug or Release Review Comment: I have removed CMAKE_BUILD_TYPE. -- 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]
