diff --git a/examples/rust/msm/run.sh b/examples/rust/msm/run.sh index c775e603..795f8bd4 100755 --- a/examples/rust/msm/run.sh +++ b/examples/rust/msm/run.sh @@ -8,9 +8,9 @@ show_help() { echo "Usage: $0 [-d DEVICE_TYPE] [-b BACKEND_INSTALL_DIR]" echo echo "Options:" - echo " -d DEVICE_TYPE Specify the device type (default: CPU)" - echo " -b BACKEND_INSTALL_DIR Specify the backend installation directory (default: empty)" - echo " -h Show this help message" + echo " -d DEVICE_TYPE Specify the device type (default: CPU)" + echo " -b ICICLE_BACKEND_INSTALL_DIR Specify the backend installation directory (default: empty)" + echo " -h Show this help message" exit 0 } @@ -21,7 +21,7 @@ while getopts ":d:b:h" opt; do DEVICE_TYPE=$OPTARG ;; b ) - BACKEND_INSTALL_DIR="$(realpath ${OPTARG})" + ICICLE_BACKEND_INSTALL_DIR="$(realpath ${OPTARG})" ;; h ) show_help @@ -39,7 +39,7 @@ done # Set default values if not provided : "${DEVICE_TYPE:=CPU}" -: "${BACKEND_INSTALL_DIR:=}" +: "${ICICLE_BACKEND_INSTALL_DIR:=}" # Create necessary directories mkdir -p build/example @@ -49,11 +49,13 @@ ICILE_DIR=$(realpath "../../../icicle_v3/") ICICLE_CUDA_SOURCE_DIR="${ICILE_DIR}/backend/cuda" # Build Icicle and the example app that links to it -if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then +if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${ICICLE_BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then echo "Building icicle with CUDA backend" - BACKEND_INSTALL_DIR="./target/release/deps/icicle/lib/backend" - cargo run --release --features=cuda -- --device-type "${DEVICE_TYPE}" --backend-install-dir "${BACKEND_INSTALL_DIR}" + cargo build --release --features=cuda + export ICICLE_BACKEND_INSTALL_DIR=$(realpath "./target/release/deps/icicle/lib/backend") + cargo run --release --features=cuda -- --device-type "${DEVICE_TYPE}" else - echo "Building icicle without CUDA backend, BACKEND_INSTALL_DIR=${BACKEND_INSTALL_DIR}" - cargo run --release -- --device-type "${DEVICE_TYPE}" --backend-install-dir "${BACKEND_INSTALL_DIR}" + echo "Building icicle without CUDA backend, BACKEND_INSTALL_DIR=${ICICLE_BACKEND_INSTALL_DIR}" + export ICICLE_BACKEND_INSTALL_DIR="$ICICLE_BACKEND_INSTALL_DIR"; + cargo run --release -- --device-type "${DEVICE_TYPE}" fi diff --git a/examples/rust/msm/src/main.rs b/examples/rust/msm/src/main.rs index 3152d1b0..4f40e670 100644 --- a/examples/rust/msm/src/main.rs +++ b/examples/rust/msm/src/main.rs @@ -25,23 +25,16 @@ struct Args { /// Device type (e.g., "CPU", "CUDA") #[arg(short, long, default_value = "CPU")] device_type: String, - - /// Backend installation directory - #[arg(short, long, default_value = "")] - backend_install_dir: String, } // Load backend and set device fn try_load_and_set_backend_device(args: &Args) { - if !args - .backend_install_dir - .is_empty() - { - println!("Trying to load backend from {}", &args.backend_install_dir); - icicle_runtime::runtime::load_backend(&args.backend_install_dir).unwrap(); + if args.device_type != "CPU" { + icicle_runtime::runtime::load_backend_from_env_or_default().unwrap(); } println!("Setting device {}", args.device_type); - icicle_runtime::set_device(&icicle_runtime::Device::new(&args.device_type, 0)).unwrap(); + let device = icicle_runtime::Device::new(&args.device_type, 0 /* =device_id*/); + icicle_runtime::set_device(&device).unwrap(); } fn main() { diff --git a/examples/rust/ntt/run.sh b/examples/rust/ntt/run.sh index c775e603..795f8bd4 100755 --- a/examples/rust/ntt/run.sh +++ b/examples/rust/ntt/run.sh @@ -8,9 +8,9 @@ show_help() { echo "Usage: $0 [-d DEVICE_TYPE] [-b BACKEND_INSTALL_DIR]" echo echo "Options:" - echo " -d DEVICE_TYPE Specify the device type (default: CPU)" - echo " -b BACKEND_INSTALL_DIR Specify the backend installation directory (default: empty)" - echo " -h Show this help message" + echo " -d DEVICE_TYPE Specify the device type (default: CPU)" + echo " -b ICICLE_BACKEND_INSTALL_DIR Specify the backend installation directory (default: empty)" + echo " -h Show this help message" exit 0 } @@ -21,7 +21,7 @@ while getopts ":d:b:h" opt; do DEVICE_TYPE=$OPTARG ;; b ) - BACKEND_INSTALL_DIR="$(realpath ${OPTARG})" + ICICLE_BACKEND_INSTALL_DIR="$(realpath ${OPTARG})" ;; h ) show_help @@ -39,7 +39,7 @@ done # Set default values if not provided : "${DEVICE_TYPE:=CPU}" -: "${BACKEND_INSTALL_DIR:=}" +: "${ICICLE_BACKEND_INSTALL_DIR:=}" # Create necessary directories mkdir -p build/example @@ -49,11 +49,13 @@ ICILE_DIR=$(realpath "../../../icicle_v3/") ICICLE_CUDA_SOURCE_DIR="${ICILE_DIR}/backend/cuda" # Build Icicle and the example app that links to it -if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then +if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${ICICLE_BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then echo "Building icicle with CUDA backend" - BACKEND_INSTALL_DIR="./target/release/deps/icicle/lib/backend" - cargo run --release --features=cuda -- --device-type "${DEVICE_TYPE}" --backend-install-dir "${BACKEND_INSTALL_DIR}" + cargo build --release --features=cuda + export ICICLE_BACKEND_INSTALL_DIR=$(realpath "./target/release/deps/icicle/lib/backend") + cargo run --release --features=cuda -- --device-type "${DEVICE_TYPE}" else - echo "Building icicle without CUDA backend, BACKEND_INSTALL_DIR=${BACKEND_INSTALL_DIR}" - cargo run --release -- --device-type "${DEVICE_TYPE}" --backend-install-dir "${BACKEND_INSTALL_DIR}" + echo "Building icicle without CUDA backend, BACKEND_INSTALL_DIR=${ICICLE_BACKEND_INSTALL_DIR}" + export ICICLE_BACKEND_INSTALL_DIR="$ICICLE_BACKEND_INSTALL_DIR"; + cargo run --release -- --device-type "${DEVICE_TYPE}" fi diff --git a/examples/rust/ntt/src/main.rs b/examples/rust/ntt/src/main.rs index 2c3e0769..ea6a303f 100644 --- a/examples/rust/ntt/src/main.rs +++ b/examples/rust/ntt/src/main.rs @@ -19,23 +19,16 @@ struct Args { /// Device type (e.g., "CPU", "CUDA") #[arg(short, long, default_value = "CPU")] device_type: String, - - /// Backend installation directory - #[arg(short, long, default_value = "")] - backend_install_dir: String, } // Load backend and set device fn try_load_and_set_backend_device(args: &Args) { - if !args - .backend_install_dir - .is_empty() - { - println!("Trying to load backend from {}", &args.backend_install_dir); - icicle_runtime::runtime::load_backend(&args.backend_install_dir).unwrap(); + if args.device_type != "CPU" { + icicle_runtime::runtime::load_backend_from_env_or_default().unwrap(); } println!("Setting device {}", args.device_type); - icicle_runtime::set_device(&icicle_runtime::Device::new(&args.device_type, 0)).unwrap(); + let device = icicle_runtime::Device::new(&args.device_type, 0 /* =device_id*/); + icicle_runtime::set_device(&device).unwrap(); } fn main() { diff --git a/examples/rust/polynomials/run.sh b/examples/rust/polynomials/run.sh index c775e603..795f8bd4 100755 --- a/examples/rust/polynomials/run.sh +++ b/examples/rust/polynomials/run.sh @@ -8,9 +8,9 @@ show_help() { echo "Usage: $0 [-d DEVICE_TYPE] [-b BACKEND_INSTALL_DIR]" echo echo "Options:" - echo " -d DEVICE_TYPE Specify the device type (default: CPU)" - echo " -b BACKEND_INSTALL_DIR Specify the backend installation directory (default: empty)" - echo " -h Show this help message" + echo " -d DEVICE_TYPE Specify the device type (default: CPU)" + echo " -b ICICLE_BACKEND_INSTALL_DIR Specify the backend installation directory (default: empty)" + echo " -h Show this help message" exit 0 } @@ -21,7 +21,7 @@ while getopts ":d:b:h" opt; do DEVICE_TYPE=$OPTARG ;; b ) - BACKEND_INSTALL_DIR="$(realpath ${OPTARG})" + ICICLE_BACKEND_INSTALL_DIR="$(realpath ${OPTARG})" ;; h ) show_help @@ -39,7 +39,7 @@ done # Set default values if not provided : "${DEVICE_TYPE:=CPU}" -: "${BACKEND_INSTALL_DIR:=}" +: "${ICICLE_BACKEND_INSTALL_DIR:=}" # Create necessary directories mkdir -p build/example @@ -49,11 +49,13 @@ ICILE_DIR=$(realpath "../../../icicle_v3/") ICICLE_CUDA_SOURCE_DIR="${ICILE_DIR}/backend/cuda" # Build Icicle and the example app that links to it -if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then +if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${ICICLE_BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then echo "Building icicle with CUDA backend" - BACKEND_INSTALL_DIR="./target/release/deps/icicle/lib/backend" - cargo run --release --features=cuda -- --device-type "${DEVICE_TYPE}" --backend-install-dir "${BACKEND_INSTALL_DIR}" + cargo build --release --features=cuda + export ICICLE_BACKEND_INSTALL_DIR=$(realpath "./target/release/deps/icicle/lib/backend") + cargo run --release --features=cuda -- --device-type "${DEVICE_TYPE}" else - echo "Building icicle without CUDA backend, BACKEND_INSTALL_DIR=${BACKEND_INSTALL_DIR}" - cargo run --release -- --device-type "${DEVICE_TYPE}" --backend-install-dir "${BACKEND_INSTALL_DIR}" + echo "Building icicle without CUDA backend, BACKEND_INSTALL_DIR=${ICICLE_BACKEND_INSTALL_DIR}" + export ICICLE_BACKEND_INSTALL_DIR="$ICICLE_BACKEND_INSTALL_DIR"; + cargo run --release -- --device-type "${DEVICE_TYPE}" fi diff --git a/examples/rust/polynomials/src/main.rs b/examples/rust/polynomials/src/main.rs index 125cfbea..377f4a7d 100644 --- a/examples/rust/polynomials/src/main.rs +++ b/examples/rust/polynomials/src/main.rs @@ -25,20 +25,12 @@ struct Args { /// Device type (e.g., "CPU", "CUDA") #[arg(short, long, default_value = "CPU")] device_type: String, - - /// Backend installation directory - #[arg(short, long, default_value = "/opt/icicle/backend")] - backend_install_dir: String, } // Load backend and set device fn try_load_and_set_backend_device(args: &Args) { - if !args - .backend_install_dir - .is_empty() - { - println!("Trying to load backend from {}", &args.backend_install_dir); - icicle_runtime::runtime::load_backend(&args.backend_install_dir).unwrap(); + if args.device_type != "CPU" { + icicle_runtime::runtime::load_backend_from_env_or_default().unwrap(); } println!("Setting device {}", args.device_type); let device = icicle_runtime::Device::new(&args.device_type, 0 /* =device_id*/); diff --git a/icicle_v3/include/icicle/errors.h b/icicle_v3/include/icicle/errors.h index b91c666b..178801d1 100644 --- a/icicle_v3/include/icicle/errors.h +++ b/icicle_v3/include/icicle/errors.h @@ -23,7 +23,8 @@ namespace icicle { STREAM_DESTRUCTION_FAILED, ///< Stream destruction failed API_NOT_IMPLEMENTED, ///< The API is not implemented for a device INVALID_ARGUMENT, ///< Invalid argument passed - UNKNOWN_ERROR ///< An unknown error occurred + BACKEND_LOAD_FAILED, ///< Failed to load the backend + UNKNOWN_ERROR, ///< An unknown error occurred }; /** @@ -59,6 +60,8 @@ namespace icicle { return "eIcicleError::API_NOT_IMPLEMENTED"; case eIcicleError::INVALID_ARGUMENT: return "eIcicleError::INVALID_ARGUMENT"; + case eIcicleError::BACKEND_LOAD_FAILED: + return "eIcicleError::BACKEND_LOAD_FAILED"; case eIcicleError::UNKNOWN_ERROR: default: return "eIcicleError::UNKNOWN_ERROR"; diff --git a/icicle_v3/include/icicle/runtime.h b/icicle_v3/include/icicle/runtime.h index 7712f8cb..4b6848a9 100644 --- a/icicle_v3/include/icicle/runtime.h +++ b/icicle_v3/include/icicle/runtime.h @@ -8,7 +8,7 @@ using namespace icicle; /** - * @brief Search and load icicle backed to process + * @brief load icicle backed to process from install dir * * @param path Path of the backend library or directory where backend libraries are installed @@ -16,6 +16,18 @@ using namespace icicle; */ extern "C" eIcicleError icicle_load_backend(const char* path, bool is_recursive); +/** + * @brief Attempts to load the backend from either the environment variable or the default install directory. + * + * This function first checks if the environment variable `ICICLE_BACKEND_INSTALL_DIR` is set and points to an existing + * directory. If so, it attempts to load the backend from that directory. If the environment variable is not set or the + * directory does not exist, it falls back to the default directory (`/opt/icicle/backend`). If neither option is + * successful, the function returns an error. + * + * @return eIcicleError The status of the backend loading operation, indicating success or failure. + */ +extern "C" eIcicleError icicle_load_backend_from_env_or_default(); + /** * @brief Set active device for thread * diff --git a/icicle_v3/src/runtime.cpp b/icicle_v3/src/runtime.cpp index b30ad505..4871c6b4 100644 --- a/icicle_v3/src/runtime.cpp +++ b/icicle_v3/src/runtime.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "icicle/runtime.h" #include "icicle/device_api.h" @@ -304,4 +305,32 @@ extern "C" eIcicleError icicle_load_backend(const char* path, bool is_recursive) } return eIcicleError::SUCCESS; +} + +extern "C" eIcicleError icicle_load_backend_from_env_or_default() +{ + // First, check the environment variable + const char* env_dir = std::getenv("ICICLE_BACKEND_INSTALL_DIR"); + if (env_dir && std::filesystem::exists(env_dir)) { + // Attempt to load the backend from the environment variable directory + eIcicleError result = icicle_load_backend(env_dir, true /*=recursive*/); + if (result == eIcicleError::SUCCESS) { + ICICLE_LOG_INFO << "ICICLE backend loaded from $ICICLE_BACKEND_INSTALL_DIR=" << env_dir; + return result; + } + } + + // If not found or failed, fall back to the default directory + const std::string default_dir = "/opt/icicle/backend"; + if (std::filesystem::exists(default_dir)) { + eIcicleError result = icicle_load_backend(default_dir.c_str(), true /*=recursive*/); + if (result == eIcicleError::SUCCESS) { + ICICLE_LOG_INFO << "ICICLE backend loaded from " << default_dir; + return result; + } + } + + // If neither works, return a failure status + ICICLE_LOG_INFO << "Failed to load backend from any known directory."; + return eIcicleError::BACKEND_LOAD_FAILED; } \ No newline at end of file diff --git a/icicle_v3/tests/test_curve_api.cpp b/icicle_v3/tests/test_curve_api.cpp index 6ac9fd0a..ae761efa 100644 --- a/icicle_v3/tests/test_curve_api.cpp +++ b/icicle_v3/tests/test_curve_api.cpp @@ -35,8 +35,9 @@ public: static void SetUpTestSuite() { #ifdef BACKEND_BUILD_DIR - icicle_load_backend(BACKEND_BUILD_DIR, true); + setenv("ICICLE_BACKEND_INSTALL_DIR", BACKEND_BUILD_DIR, 0 /*=replace*/); #endif + icicle_load_backend_from_env_or_default(); // check targets are loaded and choose main and reference targets auto regsitered_devices = get_registered_devices_list(); diff --git a/icicle_v3/tests/test_device_api.cpp b/icicle_v3/tests/test_device_api.cpp index 1fa7ed65..68c5c000 100644 --- a/icicle_v3/tests/test_device_api.cpp +++ b/icicle_v3/tests/test_device_api.cpp @@ -23,8 +23,9 @@ public: static void SetUpTestSuite() { #ifdef BACKEND_BUILD_DIR - icicle_load_backend(BACKEND_BUILD_DIR, true); + setenv("ICICLE_BACKEND_INSTALL_DIR", BACKEND_BUILD_DIR, 0 /*=replace*/); #endif + icicle_load_backend_from_env_or_default(); s_regsitered_devices = get_registered_devices_list(); ASSERT_GT(s_regsitered_devices.size(), 0); } diff --git a/icicle_v3/tests/test_field_api.cpp b/icicle_v3/tests/test_field_api.cpp index e6c6d300..80427e58 100644 --- a/icicle_v3/tests/test_field_api.cpp +++ b/icicle_v3/tests/test_field_api.cpp @@ -38,8 +38,9 @@ public: static void SetUpTestSuite() { #ifdef BACKEND_BUILD_DIR - icicle_load_backend(BACKEND_BUILD_DIR, true); + setenv("ICICLE_BACKEND_INSTALL_DIR", BACKEND_BUILD_DIR, 0 /*=replace*/); #endif + icicle_load_backend_from_env_or_default(); // check targets are loaded and choose main and reference targets auto regsitered_devices = get_registered_devices_list(); diff --git a/icicle_v3/tests/test_polynomial_api.cpp b/icicle_v3/tests/test_polynomial_api.cpp index a800e04d..3f72f3dc 100644 --- a/icicle_v3/tests/test_polynomial_api.cpp +++ b/icicle_v3/tests/test_polynomial_api.cpp @@ -36,8 +36,9 @@ public: static void SetUpTestSuite() { #ifdef BACKEND_BUILD_DIR - icicle_load_backend(BACKEND_BUILD_DIR, true); + setenv("ICICLE_BACKEND_INSTALL_DIR", BACKEND_BUILD_DIR, 0 /*=replace*/); #endif + icicle_load_backend_from_env_or_default(); s_registered_devices = get_registered_devices_list(); // init NTT domain diff --git a/wrappers/rust_v3/icicle-core/build.rs b/wrappers/rust_v3/icicle-core/build.rs index 9dec9ce4..8651f652 100644 --- a/wrappers/rust_v3/icicle-core/build.rs +++ b/wrappers/rust_v3/icicle-core/build.rs @@ -15,7 +15,7 @@ fn main() { // default backends dir println!( - "cargo:rustc-env=DEFAULT_BACKEND_INSTALL_DIR={}/icicle/lib/backend", + "cargo:rustc-env=ICICLE_BACKEND_INSTALL_DIR={}/icicle/lib/backend", deps_dir.display() ); } diff --git a/wrappers/rust_v3/icicle-core/src/curve.rs b/wrappers/rust_v3/icicle-core/src/curve.rs index 1c686618..8b0f2cbe 100644 --- a/wrappers/rust_v3/icicle-core/src/curve.rs +++ b/wrappers/rust_v3/icicle-core/src/curve.rs @@ -19,9 +19,19 @@ pub trait Curve: Debug + PartialEq + Copy + Clone { #[doc(hidden)] fn generate_random_affine_points(size: usize) -> Vec>; #[doc(hidden)] - fn convert_affine_montgomery(points: *mut Affine, len: usize, is_into: bool, stream: &IcicleStream) -> eIcicleError; + fn convert_affine_montgomery( + points: *mut Affine, + len: usize, + is_into: bool, + stream: &IcicleStream, + ) -> eIcicleError; #[doc(hidden)] - fn convert_projective_montgomery(points: *mut Projective, len: usize, is_into: bool, stream: &IcicleStream) -> eIcicleError; + fn convert_projective_montgomery( + points: *mut Projective, + len: usize, + is_into: bool, + stream: &IcicleStream, + ) -> eIcicleError; } /// A [projective](https://hyperelliptic.org/EFD/g1p/auto-shortw-projective.html) elliptic curve point. @@ -118,14 +128,14 @@ impl From> for Affine { impl MontgomeryConvertible for Affine { fn to_mont(values: &mut DeviceSlice, stream: &IcicleStream) -> eIcicleError { - if !values.is_on_active_device(){ + if !values.is_on_active_device() { panic!("values not allocated on an inactive device"); } C::convert_affine_montgomery(unsafe { values.as_mut_ptr() }, values.len(), true, stream) } fn from_mont(values: &mut DeviceSlice, stream: &IcicleStream) -> eIcicleError { - if !values.is_on_active_device(){ + if !values.is_on_active_device() { panic!("values not allocated on an inactive device"); } C::convert_affine_montgomery(unsafe { values.as_mut_ptr() }, values.len(), false, stream) @@ -134,14 +144,14 @@ impl MontgomeryConvertible for Affine { impl MontgomeryConvertible for Projective { fn to_mont(values: &mut DeviceSlice, stream: &IcicleStream) -> eIcicleError { - if !values.is_on_active_device(){ + if !values.is_on_active_device() { panic!("values not allocated on an inactive device"); } C::convert_projective_montgomery(unsafe { values.as_mut_ptr() }, values.len(), true, stream) } fn from_mont(values: &mut DeviceSlice, stream: &IcicleStream) -> eIcicleError { - if !values.is_on_active_device(){ + if !values.is_on_active_device() { panic!("values not allocated on an inactive device"); } C::convert_projective_montgomery(unsafe { values.as_mut_ptr() }, values.len(), false, stream) @@ -238,15 +248,7 @@ macro_rules! impl_curve { config.is_result_on_device = true; config.is_async = false; config.stream_handle = (&*stream).into(); - unsafe { - $curve_prefix_ident::_convert_affine_montgomery( - points, - len, - is_into, - &config, - points - ) - } + unsafe { $curve_prefix_ident::_convert_affine_montgomery(points, len, is_into, &config, points) } } fn convert_projective_montgomery( @@ -260,15 +262,7 @@ macro_rules! impl_curve { config.is_result_on_device = true; config.is_async = false; config.stream_handle = (&*stream).into(); - unsafe { - $curve_prefix_ident::_convert_projective_montgomery( - points, - len, - is_into, - &config, - points - ) - } + unsafe { $curve_prefix_ident::_convert_projective_montgomery(points, len, is_into, &config, points) } } } }; @@ -306,4 +300,4 @@ macro_rules! impl_curve_tests { } } }; -} \ No newline at end of file +} diff --git a/wrappers/rust_v3/icicle-core/src/field.rs b/wrappers/rust_v3/icicle-core/src/field.rs index dd10b35e..4bcec6fe 100644 --- a/wrappers/rust_v3/icicle-core/src/field.rs +++ b/wrappers/rust_v3/icicle-core/src/field.rs @@ -190,7 +190,7 @@ macro_rules! impl_scalar_field { } impl MontgomeryConvertibleField<$field_name> for $field_cfg { - fn to_mont(values: &mut DeviceSlice<$field_name>, stream: &IcicleStream) -> eIcicleError { + fn to_mont(values: &mut DeviceSlice<$field_name>, stream: &IcicleStream) -> eIcicleError { // check device slice is on active device if !values.is_on_active_device() { panic!("input not allocated on an inactive device"); diff --git a/wrappers/rust_v3/icicle-core/src/lib.rs b/wrappers/rust_v3/icicle-core/src/lib.rs index a7c318f6..dcb887be 100644 --- a/wrappers/rust_v3/icicle-core/src/lib.rs +++ b/wrappers/rust_v3/icicle-core/src/lib.rs @@ -3,8 +3,8 @@ pub mod ecntt; pub mod field; pub mod msm; pub mod ntt; -pub mod vec_ops; pub mod polynomials; +pub mod vec_ops; #[doc(hidden)] pub mod test_utilities; diff --git a/wrappers/rust_v3/icicle-core/src/msm/mod.rs b/wrappers/rust_v3/icicle-core/src/msm/mod.rs index 86833ab6..77d0d8c7 100644 --- a/wrappers/rust_v3/icicle-core/src/msm/mod.rs +++ b/wrappers/rust_v3/icicle-core/src/msm/mod.rs @@ -33,7 +33,8 @@ pub struct MSMConfig { pub bitsize: i32, batch_size: i32, - are_bases_shared: bool, /// MSMs in batch share the bases. If false, expecting #bases==#scalars + are_bases_shared: bool, + /// MSMs in batch share the bases. If false, expecting #bases==#scalars are_scalars_on_device: bool, pub are_scalars_montgomery_form: bool, are_bases_on_device: bool, @@ -54,7 +55,7 @@ pub const IS_BIG_TRIANGLE: &str = "is_big_triangle"; impl Default for MSMConfig { fn default() -> Self { Self { - stream_handle: std::ptr::null_mut(), + stream_handle: std::ptr::null_mut(), precompute_factor: 1, c: 0, bitsize: 0, diff --git a/wrappers/rust_v3/icicle-core/src/msm/tests.rs b/wrappers/rust_v3/icicle-core/src/msm/tests.rs index 136bce5b..3511d3d4 100644 --- a/wrappers/rust_v3/icicle-core/src/msm/tests.rs +++ b/wrappers/rust_v3/icicle-core/src/msm/tests.rs @@ -100,7 +100,7 @@ where ::Config: GenerateRandom, { // let test_sizes = [1000, 1 << 16]; //TODO - uncomment this line after implementing fast msm - let test_sizes = [100]; + let test_sizes = [100]; // let batch_sizes = [1, 3, 1 << 4]; let batch_sizes = [1, 3]; //TODO - uncomment this line after implementing fast msm let mut stream = IcicleStream::create().unwrap(); @@ -184,12 +184,12 @@ where { // let test_sizes = [1 << 10, 10000]; // TODO - uncomment this line after implementing fast msm let test_sizes = [1 << 10]; // TODO - remove this line after implementing fast msm - // let test_threshold = 1 << 11; // TODO - uncomment this line after implementing fast msm - // let batch_sizes = [1, 3, 1 << 4]; // TODO - uncomment this line after implementing fast msm + // let test_threshold = 1 << 11; // TODO - uncomment this line after implementing fast msm + // let batch_sizes = [1, 3, 1 << 4]; // TODO - uncomment this line after implementing fast msm let batch_sizes = [1, 3]; // TODO - remove this line after implementing fast msm let rng = &mut thread_rng(); for test_size in test_sizes { - let test_threshold = test_size>>2; // TODO - remove this line after implementing fast msm + let test_threshold = test_size >> 2; // TODO - remove this line after implementing fast msm for batch_size in batch_sizes { let points = generate_random_affine_points_with_zeroes::(test_size * batch_size, 100); let mut scalars = vec![C::ScalarField::zero(); test_size * batch_size]; diff --git a/wrappers/rust_v3/icicle-core/src/ntt/tests.rs b/wrappers/rust_v3/icicle-core/src/ntt/tests.rs index 570a2526..a2f9ee6e 100644 --- a/wrappers/rust_v3/icicle-core/src/ntt/tests.rs +++ b/wrappers/rust_v3/icicle-core/src/ntt/tests.rs @@ -239,7 +239,7 @@ where let coset_generators = [ F::Config::generate_random(1)[0], get_root_of_unity::(test_size as u64), - F::one(), + F::one(), ]; for coset_gen in coset_generators { let mut scalars = F::Config::generate_random(test_size); diff --git a/wrappers/rust_v3/icicle-core/src/polynomials/mod.rs b/wrappers/rust_v3/icicle-core/src/polynomials/mod.rs index 3f7a8603..f053e0e1 100644 --- a/wrappers/rust_v3/icicle-core/src/polynomials/mod.rs +++ b/wrappers/rust_v3/icicle-core/src/polynomials/mod.rs @@ -140,7 +140,7 @@ macro_rules! impl_univariate_polynomial_api { pub fn coeffs_mut_slice(&mut self) -> &mut DeviceSlice<$field> { unsafe { - let mut len: u64 = 0; + let mut len: u64 = 0; let mut coeffs_mut = get_coeffs_ptr(self.handle, &mut len); let s = slice::from_raw_parts_mut(coeffs_mut, len as usize); DeviceSlice::from_mut_slice(s) @@ -413,9 +413,12 @@ macro_rules! impl_polynomial_tests { $field:ident ) => { use super::*; - use icicle_core::ntt::{get_root_of_unity, initialize_domain, release_domain, NTTDomain, NTTInitDomainConfig, CUDA_NTT_FAST_TWIDDLES_MODE}; - use icicle_core::vec_ops::{add_scalars, mul_scalars, sub_scalars, VecOps, VecOpsConfig}; + use icicle_core::ntt::{ + get_root_of_unity, initialize_domain, release_domain, NTTDomain, NTTInitDomainConfig, + CUDA_NTT_FAST_TWIDDLES_MODE, + }; use icicle_core::test_utilities; + use icicle_core::vec_ops::{add_scalars, mul_scalars, sub_scalars, VecOps, VecOpsConfig}; use icicle_runtime::memory::{DeviceVec, HostSlice}; use std::sync::Once; @@ -497,7 +500,7 @@ macro_rules! impl_polynomial_tests { fn randomize_poly(size: usize) -> Poly { let coeffs = randomize_coeffs::<$field>(size); - Poly::from_coeffs(HostSlice::from_slice(&coeffs), size) + Poly::from_coeffs(HostSlice::from_slice(&coeffs), size) } static INIT: Once = Once::new(); diff --git a/wrappers/rust_v3/icicle-core/src/test_utilities.rs b/wrappers/rust_v3/icicle-core/src/test_utilities.rs index ff595999..3e3c7291 100644 --- a/wrappers/rust_v3/icicle-core/src/test_utilities.rs +++ b/wrappers/rust_v3/icicle-core/src/test_utilities.rs @@ -10,7 +10,7 @@ pub static TEST_REF_DEVICE: Lazy> = Lazy::new(|| Mutex::new(Device pub fn test_load_and_init_devices() { INIT.get_or_init(move || { - runtime::load_backend(env!("DEFAULT_BACKEND_INSTALL_DIR")).unwrap(); + runtime::load_backend_from_env_or_default().unwrap(); let registered_devices = runtime::get_registered_devices().unwrap(); assert!(registered_devices.len() >= 2); // select main and ref devices diff --git a/wrappers/rust_v3/icicle-core/src/vec_ops/mod.rs b/wrappers/rust_v3/icicle-core/src/vec_ops/mod.rs index c52df188..fb88cb7f 100644 --- a/wrappers/rust_v3/icicle-core/src/vec_ops/mod.rs +++ b/wrappers/rust_v3/icicle-core/src/vec_ops/mod.rs @@ -88,13 +88,13 @@ fn check_vec_ops_args<'a, F>( } // check device slices are on active device - if a.is_on_device() && !a.is_on_active_device(){ + if a.is_on_device() && !a.is_on_active_device() { panic!("input a is allocated on an inactive device"); } - if b.is_on_device() && !b.is_on_active_device(){ + if b.is_on_device() && !b.is_on_active_device() { panic!("input b is allocated on an inactive device"); } - if result.is_on_device() && !result.is_on_active_device(){ + if result.is_on_device() && !result.is_on_active_device() { panic!("output is allocated on an inactive device"); } @@ -196,7 +196,7 @@ macro_rules! impl_vec_ops_field { ) => { mod $field_prefix_ident { - use crate::vec_ops::{$field, HostOrDeviceSlice}; + use crate::vec_ops::{$field, HostOrDeviceSlice}; use icicle_core::vec_ops::VecOpsConfig; use icicle_runtime::errors::eIcicleError; diff --git a/wrappers/rust_v3/icicle-core/src/vec_ops/tests.rs b/wrappers/rust_v3/icicle-core/src/vec_ops/tests.rs index 497b0deb..4d733385 100644 --- a/wrappers/rust_v3/icicle-core/src/vec_ops/tests.rs +++ b/wrappers/rust_v3/icicle-core/src/vec_ops/tests.rs @@ -1,7 +1,10 @@ #![allow(unused_imports)] use crate::test_utilities; use crate::traits::GenerateRandom; -use crate::vec_ops::{add_scalars, mul_scalars, sub_scalars, bit_reverse, bit_reverse_inplace, transpose_matrix, FieldImpl, VecOps, VecOpsConfig}; +use crate::vec_ops::{ + add_scalars, bit_reverse, bit_reverse_inplace, mul_scalars, sub_scalars, transpose_matrix, FieldImpl, VecOps, + VecOpsConfig, +}; use icicle_runtime::device::Device; use icicle_runtime::memory::{DeviceVec, HostSlice}; use icicle_runtime::{runtime, stream::IcicleStream}; @@ -108,7 +111,7 @@ where ::Config: VecOps + GenerateRandom, { test_utilities::test_set_main_device(); - + const LOG_SIZE: u32 = 20; const TEST_SIZE: usize = 1 << LOG_SIZE; let input_vec = F::Config::generate_random(TEST_SIZE); diff --git a/wrappers/rust_v3/icicle-curves/icicle-bls12-377/build.rs b/wrappers/rust_v3/icicle-curves/icicle-bls12-377/build.rs index 7f1bfeb7..6e378358 100644 --- a/wrappers/rust_v3/icicle-curves/icicle-bls12-377/build.rs +++ b/wrappers/rust_v3/icicle-curves/icicle-bls12-377/build.rs @@ -87,7 +87,7 @@ fn main() { // default backends dir println!( - "cargo:rustc-env=DEFAULT_BACKEND_INSTALL_DIR={}/lib/backend", + "cargo:rustc-env=ICICLE_BACKEND_INSTALL_DIR={}/lib/backend", icicle_install_dir.display() ); } diff --git a/wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/ecntt/mod.rs b/wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/ecntt/mod.rs index 33960a05..5fd84e76 100644 --- a/wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/ecntt/mod.rs +++ b/wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/ecntt/mod.rs @@ -10,7 +10,7 @@ pub(crate) mod tests { use crate::curve::{CurveCfg, ScalarField}; use icicle_core::ecntt::tests::*; - use icicle_core::impl_ecntt_tests; + use icicle_core::impl_ecntt_tests; impl_ecntt_tests!(ScalarField, CurveCfg); } diff --git a/wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/lib.rs b/wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/lib.rs index 57a87671..b33cfe39 100644 --- a/wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/lib.rs +++ b/wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/lib.rs @@ -2,5 +2,5 @@ pub mod curve; pub mod ecntt; pub mod msm; pub mod ntt; +pub mod polynomials; pub mod vec_ops; -pub mod polynomials; \ No newline at end of file diff --git a/wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/ntt/mod.rs b/wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/ntt/mod.rs index cbd6ea16..c0600d07 100644 --- a/wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/ntt/mod.rs +++ b/wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/ntt/mod.rs @@ -16,6 +16,6 @@ pub(crate) mod tests { use icicle_core::impl_ntt_tests; use icicle_core::ntt::tests::*; use serial_test::{parallel, serial}; - + impl_ntt_tests!(ScalarField); } diff --git a/wrappers/rust_v3/icicle-curves/icicle-bls12-381/build.rs b/wrappers/rust_v3/icicle-curves/icicle-bls12-381/build.rs index 29af2b0a..a15cdec5 100644 --- a/wrappers/rust_v3/icicle-curves/icicle-bls12-381/build.rs +++ b/wrappers/rust_v3/icicle-curves/icicle-bls12-381/build.rs @@ -53,7 +53,7 @@ fn main() { // default backends dir println!( - "cargo:rustc-env=DEFAULT_BACKEND_INSTALL_DIR={}/lib/backend", + "cargo:rustc-env=ICICLE_BACKEND_INSTALL_DIR={}/lib/backend", icicle_install_dir.display() ); } diff --git a/wrappers/rust_v3/icicle-curves/icicle-bls12-381/src/ecntt/mod.rs b/wrappers/rust_v3/icicle-curves/icicle-bls12-381/src/ecntt/mod.rs index e2e9da3b..d1a79538 100644 --- a/wrappers/rust_v3/icicle-curves/icicle-bls12-381/src/ecntt/mod.rs +++ b/wrappers/rust_v3/icicle-curves/icicle-bls12-381/src/ecntt/mod.rs @@ -10,7 +10,7 @@ pub(crate) mod tests { use crate::curve::{CurveCfg, ScalarField}; use icicle_core::ecntt::tests::*; - use icicle_core::impl_ecntt_tests; + use icicle_core::impl_ecntt_tests; impl_ecntt_tests!(ScalarField, CurveCfg); } diff --git a/wrappers/rust_v3/icicle-curves/icicle-bls12-381/src/lib.rs b/wrappers/rust_v3/icicle-curves/icicle-bls12-381/src/lib.rs index 7dbb6c46..b33cfe39 100644 --- a/wrappers/rust_v3/icicle-curves/icicle-bls12-381/src/lib.rs +++ b/wrappers/rust_v3/icicle-curves/icicle-bls12-381/src/lib.rs @@ -2,5 +2,5 @@ pub mod curve; pub mod ecntt; pub mod msm; pub mod ntt; -pub mod vec_ops; pub mod polynomials; +pub mod vec_ops; diff --git a/wrappers/rust_v3/icicle-curves/icicle-bn254/build.rs b/wrappers/rust_v3/icicle-curves/icicle-bn254/build.rs index 86687d9a..8d8dd0bd 100644 --- a/wrappers/rust_v3/icicle-curves/icicle-bn254/build.rs +++ b/wrappers/rust_v3/icicle-curves/icicle-bn254/build.rs @@ -53,7 +53,7 @@ fn main() { // default backends dir println!( - "cargo:rustc-env=DEFAULT_BACKEND_INSTALL_DIR={}/lib/backend", + "cargo:rustc-env=ICICLE_BACKEND_INSTALL_DIR={}/lib/backend", icicle_install_dir.display() ); } diff --git a/wrappers/rust_v3/icicle-curves/icicle-bn254/src/ecntt/mod.rs b/wrappers/rust_v3/icicle-curves/icicle-bn254/src/ecntt/mod.rs index 66151ea0..87b371b2 100644 --- a/wrappers/rust_v3/icicle-curves/icicle-bn254/src/ecntt/mod.rs +++ b/wrappers/rust_v3/icicle-curves/icicle-bn254/src/ecntt/mod.rs @@ -10,7 +10,7 @@ pub(crate) mod tests { use crate::curve::{CurveCfg, ScalarField}; use icicle_core::ecntt::tests::*; - use icicle_core::impl_ecntt_tests; + use icicle_core::impl_ecntt_tests; impl_ecntt_tests!(ScalarField, CurveCfg); } diff --git a/wrappers/rust_v3/icicle-curves/icicle-bn254/src/lib.rs b/wrappers/rust_v3/icicle-curves/icicle-bn254/src/lib.rs index 7dbb6c46..b33cfe39 100644 --- a/wrappers/rust_v3/icicle-curves/icicle-bn254/src/lib.rs +++ b/wrappers/rust_v3/icicle-curves/icicle-bn254/src/lib.rs @@ -2,5 +2,5 @@ pub mod curve; pub mod ecntt; pub mod msm; pub mod ntt; -pub mod vec_ops; pub mod polynomials; +pub mod vec_ops; diff --git a/wrappers/rust_v3/icicle-curves/icicle-grumpkin/build.rs b/wrappers/rust_v3/icicle-curves/icicle-grumpkin/build.rs index f380fbfe..9ca659e4 100644 --- a/wrappers/rust_v3/icicle-curves/icicle-grumpkin/build.rs +++ b/wrappers/rust_v3/icicle-curves/icicle-grumpkin/build.rs @@ -46,7 +46,7 @@ fn main() { // default backends dir println!( - "cargo:rustc-env=DEFAULT_BACKEND_INSTALL_DIR={}/lib/backend", + "cargo:rustc-env=ICICLE_BACKEND_INSTALL_DIR={}/lib/backend", icicle_install_dir.display() ); } diff --git a/wrappers/rust_v3/icicle-fields/icicle-babybear/build.rs b/wrappers/rust_v3/icicle-fields/icicle-babybear/build.rs index 6e3aba55..351b4de9 100644 --- a/wrappers/rust_v3/icicle-fields/icicle-babybear/build.rs +++ b/wrappers/rust_v3/icicle-fields/icicle-babybear/build.rs @@ -46,7 +46,7 @@ fn main() { // default backends dir println!( - "cargo:rustc-env=DEFAULT_BACKEND_INSTALL_DIR={}/lib/backend", + "cargo:rustc-env=ICICLE_BACKEND_INSTALL_DIR={}/lib/backend", icicle_install_dir.display() ); } diff --git a/wrappers/rust_v3/icicle-fields/icicle-babybear/src/lib.rs b/wrappers/rust_v3/icicle-fields/icicle-babybear/src/lib.rs index c1c2a189..a95ac089 100644 --- a/wrappers/rust_v3/icicle-fields/icicle-babybear/src/lib.rs +++ b/wrappers/rust_v3/icicle-fields/icicle-babybear/src/lib.rs @@ -1,4 +1,4 @@ pub mod field; pub mod ntt; -pub mod vec_ops; pub mod polynomials; +pub mod vec_ops; diff --git a/wrappers/rust_v3/icicle-fields/icicle-babybear/src/ntt/mod.rs b/wrappers/rust_v3/icicle-fields/icicle-babybear/src/ntt/mod.rs index bc4342bd..b41bbd82 100644 --- a/wrappers/rust_v3/icicle-fields/icicle-babybear/src/ntt/mod.rs +++ b/wrappers/rust_v3/icicle-fields/icicle-babybear/src/ntt/mod.rs @@ -23,12 +23,12 @@ pub(crate) mod tests { impl_ntt_tests!(ScalarField); // Tests against risc0 and plonky3 - use super::{ExtensionField}; + use super::ExtensionField; use icicle_core::{ - ntt::{initialize_domain, ntt_inplace, release_domain, NTTConfig, NTTInitDomainConfig, NTTDir}, - traits::{FieldImpl, GenerateRandom} + ntt::{initialize_domain, ntt_inplace, release_domain, NTTConfig, NTTDir, NTTInitDomainConfig}, + traits::{FieldImpl, GenerateRandom}, }; - use icicle_runtime::{memory::HostSlice}; + use icicle_runtime::memory::HostSlice; use risc0_core::field::{ baby_bear::{Elem, ExtElem}, Elem as FieldElem, RootsOfUnity, diff --git a/wrappers/rust_v3/icicle-fields/icicle-stark252/build.rs b/wrappers/rust_v3/icicle-fields/icicle-stark252/build.rs index 346151c4..7fef554b 100644 --- a/wrappers/rust_v3/icicle-fields/icicle-stark252/build.rs +++ b/wrappers/rust_v3/icicle-fields/icicle-stark252/build.rs @@ -45,7 +45,7 @@ fn main() { // default backends dir println!( - "cargo:rustc-env=DEFAULT_BACKEND_INSTALL_DIR={}/lib/backend", + "cargo:rustc-env=ICICLE_BACKEND_INSTALL_DIR={}/lib/backend", icicle_install_dir.display() ); } diff --git a/wrappers/rust_v3/icicle-fields/icicle-stark252/src/lib.rs b/wrappers/rust_v3/icicle-fields/icicle-stark252/src/lib.rs index c1c2a189..a95ac089 100644 --- a/wrappers/rust_v3/icicle-fields/icicle-stark252/src/lib.rs +++ b/wrappers/rust_v3/icicle-fields/icicle-stark252/src/lib.rs @@ -1,4 +1,4 @@ pub mod field; pub mod ntt; -pub mod vec_ops; pub mod polynomials; +pub mod vec_ops; diff --git a/wrappers/rust_v3/icicle-fields/icicle-stark252/src/ntt/mod.rs b/wrappers/rust_v3/icicle-fields/icicle-stark252/src/ntt/mod.rs index 46d0a3df..fe92b55e 100644 --- a/wrappers/rust_v3/icicle-fields/icicle-stark252/src/ntt/mod.rs +++ b/wrappers/rust_v3/icicle-fields/icicle-stark252/src/ntt/mod.rs @@ -15,9 +15,8 @@ pub(crate) mod tests { impl_ntt_tests!(ScalarField); - use icicle_core::{ - ntt::{initialize_domain, ntt_inplace, release_domain, NTTConfig, NTTInitDomainConfig, NTTDir}, + ntt::{initialize_domain, ntt_inplace, release_domain, NTTConfig, NTTDir, NTTInitDomainConfig}, traits::{FieldImpl, GenerateRandom}, }; use icicle_runtime::memory::HostSlice; @@ -39,9 +38,13 @@ pub(crate) mod tests { release_domain::().unwrap(); // release domain from previous tests, if exists - let log_sizes = [15, 20]; + let log_sizes = [15, 20]; let lw_root_of_unity = Stark252PrimeField::get_primitive_root_of_unity(log_sizes[log_sizes.len() - 1]).unwrap(); - initialize_domain(ScalarField::from_bytes_le(&lw_root_of_unity.to_bytes_le()), &NTTInitDomainConfig::default()).unwrap(); + initialize_domain( + ScalarField::from_bytes_le(&lw_root_of_unity.to_bytes_le()), + &NTTInitDomainConfig::default(), + ) + .unwrap(); for log_size in log_sizes { let ntt_size = 1 << log_size; diff --git a/wrappers/rust_v3/icicle-runtime/build.rs b/wrappers/rust_v3/icicle-runtime/build.rs index 115093df..6c25a87d 100644 --- a/wrappers/rust_v3/icicle-runtime/build.rs +++ b/wrappers/rust_v3/icicle-runtime/build.rs @@ -43,7 +43,7 @@ fn main() { // default backends dir println!( - "cargo:rustc-env=DEFAULT_BACKEND_INSTALL_DIR={}/lib/backend", + "cargo:rustc-env=ICICLE_BACKEND_INSTALL_DIR={}/lib/backend", icicle_install_dir.display() ); } diff --git a/wrappers/rust_v3/icicle-runtime/src/device.rs b/wrappers/rust_v3/icicle-runtime/src/device.rs index 01a59625..9248a805 100644 --- a/wrappers/rust_v3/icicle-runtime/src/device.rs +++ b/wrappers/rust_v3/icicle-runtime/src/device.rs @@ -76,4 +76,3 @@ impl fmt::Debug for Device { .finish() } } - diff --git a/wrappers/rust_v3/icicle-runtime/src/memory.rs b/wrappers/rust_v3/icicle-runtime/src/memory.rs index a5f699ab..a89139ae 100644 --- a/wrappers/rust_v3/icicle-runtime/src/memory.rs +++ b/wrappers/rust_v3/icicle-runtime/src/memory.rs @@ -55,9 +55,11 @@ impl HostOrDeviceSlice for DeviceSlice { true } - fn is_on_active_device(&self) -> bool { - runtime::is_active_device_memory(self.0.as_ptr() as *const c_void) + runtime::is_active_device_memory( + self.0 + .as_ptr() as *const c_void, + ) } unsafe fn as_ptr(&self) -> *const T { @@ -125,11 +127,11 @@ impl DeviceSlice { self.len() == val.len(), "In copy from host, destination and source slices have different lengths" ); - + if self.is_empty() { return Ok(()); } - if !self.is_on_active_device(){ + if !self.is_on_active_device() { panic!("not allocated on an inactive device"); } @@ -148,7 +150,7 @@ impl DeviceSlice { if self.is_empty() { return Ok(()); } - if !self.is_on_active_device(){ + if !self.is_on_active_device() { panic!("not allocated on an inactive device"); } @@ -166,7 +168,7 @@ impl DeviceSlice { if self.is_empty() { return Ok(()); } - if !self.is_on_active_device(){ + if !self.is_on_active_device() { panic!("not allocated on an inactive device"); } @@ -190,10 +192,10 @@ impl DeviceSlice { if self.is_empty() { return Ok(()); } - if !self.is_on_active_device(){ + if !self.is_on_active_device() { panic!("not allocated on an inactive device"); } - + let size = size_of::() * self.len(); unsafe { runtime::icicle_copy_to_host_async( diff --git a/wrappers/rust_v3/icicle-runtime/src/runtime.rs b/wrappers/rust_v3/icicle-runtime/src/runtime.rs index 2128261d..290f03e9 100644 --- a/wrappers/rust_v3/icicle-runtime/src/runtime.rs +++ b/wrappers/rust_v3/icicle-runtime/src/runtime.rs @@ -9,6 +9,7 @@ pub type IcicleStreamHandle = *mut c_void; extern "C" { fn icicle_load_backend(path: *const c_char, is_recursive: bool) -> eIcicleError; + fn icicle_load_backend_from_env_or_default() -> eIcicleError; fn icicle_set_device(device: &Device) -> eIcicleError; fn icicle_get_active_device(device: &mut Device) -> eIcicleError; fn icicle_is_host_memory(ptr: *const c_void) -> eIcicleError; @@ -42,6 +43,10 @@ extern "C" { fn icicle_get_registered_devices(output: *mut c_char, output_size: usize) -> eIcicleError; } +pub fn load_backend_from_env_or_default() -> Result<(), eIcicleError> { + unsafe { icicle_load_backend_from_env_or_default().wrap() } +} + pub fn load_backend(path: &str) -> Result<(), eIcicleError> { let c_path = CString::new(path).unwrap(); unsafe { icicle_load_backend(c_path.as_ptr(), true).wrap() } diff --git a/wrappers/rust_v3/icicle-runtime/src/tests.rs b/wrappers/rust_v3/icicle-runtime/src/tests.rs index 7f30705b..737016cb 100644 --- a/wrappers/rust_v3/icicle-runtime/src/tests.rs +++ b/wrappers/rust_v3/icicle-runtime/src/tests.rs @@ -33,8 +33,7 @@ mod tests { fn initialize() { INIT.call_once(|| { - // load backends to process - load_backend(&env!("DEFAULT_BACKEND_INSTALL_DIR")).unwrap(); + load_backend_from_env_or_default(); let _ = runtime::get_registered_devices().unwrap(); }); }