From d93975f9ac034f90c72704b23c6ccd3241f28713 Mon Sep 17 00:00:00 2001 From: Yuval Shekel Date: Tue, 25 Jun 2024 18:13:07 +0300 Subject: [PATCH] stark252 rust crate --- icicle_v3/backend/cpu/src/field/cpu_ntt.cpp | 5 +- icicle_v3/backend/cuda/src/ntt/cuda_ntt.cu | 2 +- .../icicle/curves/montgomery_conversion.h | 8 ++-- icicle_v3/include/icicle/device_api.h | 2 +- icicle_v3/include/icicle/dispatcher.h | 2 +- icicle_v3/include/icicle/ecntt.h | 2 +- icicle_v3/include/icicle/matrix_ops.h | 4 +- icicle_v3/include/icicle/msm.h | 8 ++-- icicle_v3/include/icicle/ntt.h | 12 +++-- icicle_v3/include/icicle/vec_ops.h | 14 +++--- icicle_v3/src/device_api.cpp | 2 +- icicle_v3/src/ntt.cpp | 7 ++- wrappers/rust_v3/Cargo.toml | 1 + wrappers/rust_v3/icicle-core/src/ntt/tests.rs | 1 - .../rust_v3/icicle-core/src/test_utilities.rs | 6 ++- wrappers/rust_v3/icicle-core/src/traits.rs | 6 --- .../icicle-fields/icicle-stark252/Cargo.toml | 20 ++++++++ .../icicle-fields/icicle-stark252/build.rs | 46 +++++++++++++++++++ .../icicle-stark252/src/field.rs | 19 ++++++++ .../icicle-fields/icicle-stark252/src/lib.rs | 3 ++ .../icicle-stark252/src/ntt/mod.rs | 21 +++++++++ .../icicle-stark252/src/vec_ops/mod.rs | 17 +++++++ 22 files changed, 170 insertions(+), 38 deletions(-) create mode 100644 wrappers/rust_v3/icicle-fields/icicle-stark252/Cargo.toml create mode 100644 wrappers/rust_v3/icicle-fields/icicle-stark252/build.rs create mode 100644 wrappers/rust_v3/icicle-fields/icicle-stark252/src/field.rs create mode 100644 wrappers/rust_v3/icicle-fields/icicle-stark252/src/lib.rs create mode 100644 wrappers/rust_v3/icicle-fields/icicle-stark252/src/ntt/mod.rs create mode 100644 wrappers/rust_v3/icicle-fields/icicle-stark252/src/vec_ops/mod.rs diff --git a/icicle_v3/backend/cpu/src/field/cpu_ntt.cpp b/icicle_v3/backend/cpu/src/field/cpu_ntt.cpp index 2d5cd70743..f9281b985f 100644 --- a/icicle_v3/backend/cpu/src/field/cpu_ntt.cpp +++ b/icicle_v3/backend/cpu/src/field/cpu_ntt.cpp @@ -24,10 +24,11 @@ eIcicleError cpu_ntt_init_domain(const Device& device, const S& primitive_root, REGISTER_NTT_INIT_DOMAIN_BACKEND("CPU", (cpu_ntt_init_domain)); -eIcicleError cpu_ntt_release_domain(const Device& device) +template +eIcicleError cpu_ntt_release_domain(const Device& device, const S& dummy) { ICICLE_LOG_ERROR << "cpu_ntt_release_domain() not implemented"; return eIcicleError::API_NOT_IMPLEMENTED; } -REGISTER_NTT_RELEASE_DOMAIN_BACKEND("CPU", cpu_ntt_release_domain); \ No newline at end of file +REGISTER_NTT_RELEASE_DOMAIN_BACKEND("CPU", cpu_ntt_release_domain); \ No newline at end of file diff --git a/icicle_v3/backend/cuda/src/ntt/cuda_ntt.cu b/icicle_v3/backend/cuda/src/ntt/cuda_ntt.cu index 7e4bebbc7a..50300cd859 100644 --- a/icicle_v3/backend/cuda/src/ntt/cuda_ntt.cu +++ b/icicle_v3/backend/cuda/src/ntt/cuda_ntt.cu @@ -20,7 +20,7 @@ namespace icicle { return translateCudaError(err); } - eIcicleError ntt_cuda_release_domain(const Device& device) + eIcicleError ntt_cuda_release_domain(const Device& device, const scalar_t& dummy) { using namespace device_context; DeviceContext device_context = get_default_device_context(); diff --git a/icicle_v3/include/icicle/curves/montgomery_conversion.h b/icicle_v3/include/icicle/curves/montgomery_conversion.h index b74981e472..9772b8e25b 100644 --- a/icicle_v3/include/icicle/curves/montgomery_conversion.h +++ b/icicle_v3/include/icicle/curves/montgomery_conversion.h @@ -22,7 +22,7 @@ namespace icicle { using AffineConvertMontImpl = std::function; - extern "C" void register_affine_convert_montgomery(const std::string& deviceType, AffineConvertMontImpl); + void register_affine_convert_montgomery(const std::string& deviceType, AffineConvertMontImpl); #define REGISTER_AFFINE_CONVERT_MONTGOMERY_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -40,7 +40,7 @@ namespace icicle { const VecOpsConfig& config, projective_t* output)>; - extern "C" void register_projective_convert_montgomery(const std::string& deviceType, ProjectiveConvertMontImpl); + void register_projective_convert_montgomery(const std::string& deviceType, ProjectiveConvertMontImpl); #define REGISTER_PROJECTIVE_CONVERT_MONTGOMERY_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -59,7 +59,7 @@ namespace icicle { const VecOpsConfig& config, g2_affine_t* output)>; - extern "C" void register_affine_g2_convert_montgomery(const std::string& deviceType, AffineG2ConvertMontImpl); + void register_affine_g2_convert_montgomery(const std::string& deviceType, AffineG2ConvertMontImpl); #define REGISTER_AFFINE_G2_CONVERT_MONTGOMERY_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -77,7 +77,7 @@ namespace icicle { const VecOpsConfig& config, g2_projective_t* output)>; - extern "C" void register_projective_g2_convert_montgomery(const std::string& deviceType, ProjectiveG2ConvertMontImpl); + void register_projective_g2_convert_montgomery(const std::string& deviceType, ProjectiveG2ConvertMontImpl); #define REGISTER_PROJECTIVE_G2_CONVERT_MONTGOMERY_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ diff --git a/icicle_v3/include/icicle/device_api.h b/icicle_v3/include/icicle/device_api.h index 76f8656012..0a8e5c3acc 100644 --- a/icicle_v3/include/icicle/device_api.h +++ b/icicle_v3/include/icicle/device_api.h @@ -187,7 +187,7 @@ namespace icicle { * @param deviceType The device type to register the DeviceAPI for. * @param api An instance of the derived api type to be used as deviceAPI interface. */ - extern "C" void register_deviceAPI(const std::string& deviceType, std::shared_ptr api); + void register_deviceAPI(const std::string& deviceType, std::shared_ptr api); /** * @brief Register DeviceAPI instance for a device type. diff --git a/icicle_v3/include/icicle/dispatcher.h b/icicle_v3/include/icicle/dispatcher.h index 4ad36966b8..3d88cbf00c 100644 --- a/icicle_v3/include/icicle/dispatcher.h +++ b/icicle_v3/include/icicle/dispatcher.h @@ -48,7 +48,7 @@ class tIcicleDispatcher #define ICICLE_DISPATCHER_INST(dispatcher_class_name, api_name, type) \ constexpr char ST_name_##api_name[]{#api_name}; \ using dispatcher_class_name = tIcicleDispatcher; \ - extern "C" void register_##api_name(const std::string& deviceType, type impl) \ + void register_##api_name(const std::string& deviceType, type impl) \ { \ ICICLE_LOG_DEBUG << #api_name << " registered for " << deviceType; \ dispatcher_class_name::Global()._register(deviceType, impl); \ diff --git a/icicle_v3/include/icicle/ecntt.h b/icicle_v3/include/icicle/ecntt.h index 669a4426c8..564f725a7c 100644 --- a/icicle_v3/include/icicle/ecntt.h +++ b/icicle_v3/include/icicle/ecntt.h @@ -21,7 +21,7 @@ namespace icicle { NTTConfig& config, projective_t* output)>; - extern "C" void register_ecntt(const std::string& deviceType, ECNttFieldImpl impl); + void register_ecntt(const std::string& deviceType, ECNttFieldImpl impl); #define REGISTER_ECNTT_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ diff --git a/icicle_v3/include/icicle/matrix_ops.h b/icicle_v3/include/icicle/matrix_ops.h index 08d3441f0c..4f6bbecc6a 100644 --- a/icicle_v3/include/icicle/matrix_ops.h +++ b/icicle_v3/include/icicle/matrix_ops.h @@ -45,7 +45,7 @@ namespace icicle { const VecOpsConfig& config, scalar_t* out)>; - extern "C" void register_matrix_transpose(const std::string& deviceType, scalarMatrixOpImpl impl); + void register_matrix_transpose(const std::string& deviceType, scalarMatrixOpImpl impl); #define REGISTER_MATRIX_TRANSPOSE_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -64,7 +64,7 @@ namespace icicle { const VecOpsConfig& config, extension_t* out)>; - extern "C" void register_extension_matrix_transpose(const std::string& deviceType, extFieldMatrixOpImpl impl); + void register_extension_matrix_transpose(const std::string& deviceType, extFieldMatrixOpImpl impl); #define REGISTER_MATRIX_TRANSPOSE_EXT_FIELD_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ diff --git a/icicle_v3/include/icicle/msm.h b/icicle_v3/include/icicle/msm.h index bceaad4d2b..1d582bca37 100644 --- a/icicle_v3/include/icicle/msm.h +++ b/icicle_v3/include/icicle/msm.h @@ -120,7 +120,7 @@ namespace icicle { const MSMConfig& config, projective_t* results)>; - extern "C" void register_msm(const std::string& deviceType, MsmImpl impl); + void register_msm(const std::string& deviceType, MsmImpl impl); #define REGISTER_MSM_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -138,7 +138,7 @@ namespace icicle { const MsmPreComputeConfig& config, affine_t* output_bases)>; - extern "C" void register_msm_precompute_bases(const std::string& deviceType, MsmPreComputeImpl impl); + void register_msm_precompute_bases(const std::string& deviceType, MsmPreComputeImpl impl); #define REGISTER_MSM_PRE_COMPUTE_BASES_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -157,7 +157,7 @@ namespace icicle { const MSMConfig& config, g2_projective_t* results)>; - extern "C" void register_msm_g2(const std::string& deviceType, MsmG2Impl impl); + void register_msm_g2(const std::string& deviceType, MsmG2Impl impl); #define REGISTER_MSM_G2_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -175,7 +175,7 @@ namespace icicle { const MsmPreComputeConfig& config, g2_affine_t* output_bases)>; - extern "C" void register_msm_g2_precompute_bases(const std::string& deviceType, MsmG2PreComputeImpl impl); + void register_msm_g2_precompute_bases(const std::string& deviceType, MsmG2PreComputeImpl impl); #define REGISTER_MSM_G2_PRE_COMPUTE_BASES_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ diff --git a/icicle_v3/include/icicle/ntt.h b/icicle_v3/include/icicle/ntt.h index 033928cc73..11b97fc86c 100644 --- a/icicle_v3/include/icicle/ntt.h +++ b/icicle_v3/include/icicle/ntt.h @@ -144,7 +144,7 @@ namespace icicle { using NttImpl = std::function& config, scalar_t* output)>; - extern "C" void register_ntt(const std::string& deviceType, NttImpl impl); + void register_ntt(const std::string& deviceType, NttImpl impl); #define REGISTER_NTT_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -163,7 +163,7 @@ namespace icicle { NTTConfig& config, extension_t* output)>; - extern "C" void register_ntt_ext_field(const std::string& deviceType, NttExtFieldImpl impl); + void register_ntt_ext_field(const std::string& deviceType, NttExtFieldImpl impl); #define REGISTER_NTT_EXT_FIELD_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -178,7 +178,7 @@ namespace icicle { using NttInitDomainImpl = std::function; - extern "C" void register_ntt_init_domain(const std::string& deviceType, NttInitDomainImpl); + void register_ntt_init_domain(const std::string& deviceType, NttInitDomainImpl); #define REGISTER_NTT_INIT_DOMAIN_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -189,9 +189,11 @@ namespace icicle { } /*************************** RELEASE DOMAIN ***************************/ - using NttReleaseDomainImpl = std::function; + // Note: 'dummy' is a workaround for the function required per field but need to differentiate by type when + // calling. TODO Yuval: avoid this param somehow + using NttReleaseDomainImpl = std::function; - extern "C" void register_ntt_release_domain(const std::string& deviceType, NttReleaseDomainImpl); + void register_ntt_release_domain(const std::string& deviceType, NttReleaseDomainImpl); #define REGISTER_NTT_RELEASE_DOMAIN_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ diff --git a/icicle_v3/include/icicle/vec_ops.h b/icicle_v3/include/icicle/vec_ops.h index 19b7589e6d..aedfc09052 100644 --- a/icicle_v3/include/icicle/vec_ops.h +++ b/icicle_v3/include/icicle/vec_ops.h @@ -68,7 +68,7 @@ namespace icicle { const VecOpsConfig& config, scalar_t* output)>; - extern "C" void register_vector_add(const std::string& deviceType, scalarVectorOpImpl impl); + void register_vector_add(const std::string& deviceType, scalarVectorOpImpl impl); #define REGISTER_VECTOR_ADD_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -78,7 +78,7 @@ namespace icicle { }(); \ } - extern "C" void register_vector_sub(const std::string& deviceType, scalarVectorOpImpl impl); + void register_vector_sub(const std::string& deviceType, scalarVectorOpImpl impl); #define REGISTER_VECTOR_SUB_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ static bool UNIQUE(_reg_vec_sub) = []() -> bool { \ @@ -87,7 +87,7 @@ namespace icicle { }(); \ } - extern "C" void register_vector_mul(const std::string& deviceType, scalarVectorOpImpl impl); + void register_vector_mul(const std::string& deviceType, scalarVectorOpImpl impl); #define REGISTER_VECTOR_MUL_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -105,7 +105,7 @@ namespace icicle { const VecOpsConfig& config, scalar_t* output)>; - extern "C" void register_scalar_convert_montgomery(const std::string& deviceType, scalarConvertMontgomeryImpl); + void register_scalar_convert_montgomery(const std::string& deviceType, scalarConvertMontgomeryImpl); #define REGISTER_CONVERT_MONTGOMERY_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -124,7 +124,7 @@ namespace icicle { const VecOpsConfig& config, extension_t* output)>; - extern "C" void register_extension_vector_add(const std::string& deviceType, extFieldVectorOpImpl impl); + void register_extension_vector_add(const std::string& deviceType, extFieldVectorOpImpl impl); #define REGISTER_VECTOR_ADD_EXT_FIELD_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ @@ -134,7 +134,7 @@ namespace icicle { }(); \ } - extern "C" void register_extension_vector_sub(const std::string& deviceType, extFieldVectorOpImpl impl); + void register_extension_vector_sub(const std::string& deviceType, extFieldVectorOpImpl impl); #define REGISTER_VECTOR_SUB_EXT_FIELD_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ static bool UNIQUE(_reg_vec_sub_ext_field) = []() -> bool { \ @@ -143,7 +143,7 @@ namespace icicle { }(); \ } - extern "C" void register_extension_vector_mul(const std::string& deviceType, extFieldVectorOpImpl impl); + void register_extension_vector_mul(const std::string& deviceType, extFieldVectorOpImpl impl); #define REGISTER_VECTOR_MUL_EXT_FIELD_BACKEND(DEVICE_TYPE, FUNC) \ namespace { \ diff --git a/icicle_v3/src/device_api.cpp b/icicle_v3/src/device_api.cpp index 1c42b6c0bb..4459cdcccb 100644 --- a/icicle_v3/src/device_api.cpp +++ b/icicle_v3/src/device_api.cpp @@ -116,7 +116,7 @@ namespace icicle { DeviceAPI* get_deviceAPI(const Device& device) { return DeviceAPIRegistry::Global().get_deviceAPI(device).get(); } - extern "C" void register_deviceAPI(const std::string& deviceType, std::shared_ptr api) + void register_deviceAPI(const std::string& deviceType, std::shared_ptr api) { ICICLE_LOG_DEBUG << "deviceAPI registered for " << deviceType; DeviceAPIRegistry::Global().register_deviceAPI(deviceType, api); diff --git a/icicle_v3/src/ntt.cpp b/icicle_v3/src/ntt.cpp index d1ebbc9dbf..43ddac3747 100644 --- a/icicle_v3/src/ntt.cpp +++ b/icicle_v3/src/ntt.cpp @@ -52,7 +52,12 @@ namespace icicle { /*************************** RELEASE DOMAIN ***************************/ ICICLE_DISPATCHER_INST(NttReleaseDomainDispatcher, ntt_release_domain, NttReleaseDomainImpl); - extern "C" eIcicleError CONCAT_EXPAND(FIELD, ntt_release_domain)() { return NttReleaseDomainDispatcher::execute(); } + extern "C" eIcicleError CONCAT_EXPAND(FIELD, ntt_release_domain)() + { + // Note: passing zero is a workaround for the function required per field but need to differentiate by type when + // calling + return NttReleaseDomainDispatcher::execute(scalar_t::zero()); + } template <> eIcicleError ntt_release_domain() diff --git a/wrappers/rust_v3/Cargo.toml b/wrappers/rust_v3/Cargo.toml index f2802369d3..dd0ef50502 100644 --- a/wrappers/rust_v3/Cargo.toml +++ b/wrappers/rust_v3/Cargo.toml @@ -4,6 +4,7 @@ members = [ "icicle-runtime", "icicle-core", "icicle-fields/icicle-babybear", + "icicle-fields/icicle-stark252", ] exclude = [] diff --git a/wrappers/rust_v3/icicle-core/src/ntt/tests.rs b/wrappers/rust_v3/icicle-core/src/ntt/tests.rs index 5b40f384df..f12a299ef6 100644 --- a/wrappers/rust_v3/icicle-core/src/ntt/tests.rs +++ b/wrappers/rust_v3/icicle-core/src/ntt/tests.rs @@ -2,7 +2,6 @@ use crate::ntt::{NttAlgorithm, Ordering, CUDA_NTT_ALGORITHM, CUDA_NTT_FAST_TWIDD use crate::test_utilities; use crate::vec_ops::{transpose_matrix, VecOps, VecOpsConfig}; use icicle_runtime::{ - device::Device, memory::{DeviceVec, HostSlice}, runtime, stream::IcicleStream, diff --git a/wrappers/rust_v3/icicle-core/src/test_utilities.rs b/wrappers/rust_v3/icicle-core/src/test_utilities.rs index 4eb5f74b5a..42071f00f7 100644 --- a/wrappers/rust_v3/icicle-core/src/test_utilities.rs +++ b/wrappers/rust_v3/icicle-core/src/test_utilities.rs @@ -10,7 +10,11 @@ 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"), true).unwrap(); + // let default_backend_install_dir = env!("DEFAULT_BACKEND_INSTALL_DIR"); + runtime::load_backend(env!("DEFAULT_BACKEND_INSTALL_DIR"), true).unwrap(); + // runtime::load_backend(&format!("{}/cuda", default_backend_install_dir), true).unwrap(); + // runtime::load_backend(&format!("{}/babybear", default_backend_install_dir), true).unwrap(); + // runtime::load_backend(&format!("{}/stark252", default_backend_install_dir), true).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/traits.rs b/wrappers/rust_v3/icicle-core/src/traits.rs index 1b8db7c24c..ec7aa28f75 100644 --- a/wrappers/rust_v3/icicle-core/src/traits.rs +++ b/wrappers/rust_v3/icicle-core/src/traits.rs @@ -30,9 +30,3 @@ pub trait MontgomeryConvertible: Sized { fn to_mont(values: &mut DeviceSlice, stream: &IcicleStream) -> eIcicleError; fn from_mont(values: &mut DeviceSlice, stream: &IcicleStream) -> eIcicleError; } - -// pub trait IcicleResultWrap { -// fn wrap(self) -> IcicleResult<()>; -// fn wrap_value(self, value: T) -> IcicleResult; -// fn wrap_maybe_uninit(self, value: MaybeUninit) -> IcicleResult; -// } diff --git a/wrappers/rust_v3/icicle-fields/icicle-stark252/Cargo.toml b/wrappers/rust_v3/icicle-fields/icicle-stark252/Cargo.toml new file mode 100644 index 0000000000..c5f8b5c765 --- /dev/null +++ b/wrappers/rust_v3/icicle-fields/icicle-stark252/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "icicle-stark252" +version.workspace = true +edition.workspace = true +authors.workspace = true +homepage.workspace = true +repository.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +icicle-core = {workspace = true } +icicle-runtime = { workspace = true } + +[dev-dependencies] +criterion = "0.3" +serial_test = "3.0.0" + +[build-dependencies] +cmake = "0.1.50" diff --git a/wrappers/rust_v3/icicle-fields/icicle-stark252/build.rs b/wrappers/rust_v3/icicle-fields/icicle-stark252/build.rs new file mode 100644 index 0000000000..6fa466e9bd --- /dev/null +++ b/wrappers/rust_v3/icicle-fields/icicle-stark252/build.rs @@ -0,0 +1,46 @@ +use cmake::Config; +use std::{env, path::PathBuf}; + +fn main() { + // Construct the path to the deps directory + let out_dir = env::var("OUT_DIR").expect("OUT_DIR is not set"); + let build_dir = PathBuf::from(format!("{}/../../../", &out_dir)); + let deps_dir = build_dir.join("deps"); + + // Construct the path to icicle source directory + let main_dir = env::current_dir().expect("Failed to get current directory"); + let icicle_src_dir = PathBuf::from(format!("{}/../../../../icicle_v3", main_dir.display())); + + println!("cargo:rerun-if-env-changed=CXXFLAGS"); + println!("cargo:rerun-if-changed={}", icicle_src_dir.display()); + + // Base config + let mut config = Config::new(format!("{}", icicle_src_dir.display())); + // Check if ICICLE_INSTALL_DIR is defined + let icicle_install_dir = if let Ok(dir) = env::var("ICICLE_INSTALL_DIR") { + PathBuf::from(dir) + } else { + // Define the default install directory to be under the build directory + PathBuf::from(format!("{}/icicle/", deps_dir.display())) + }; + config + .define("FIELD", "stark252") + .define("CMAKE_BUILD_TYPE", "Release") + .define("CMAKE_INSTALL_PREFIX", &icicle_install_dir); + + // Build + let _ = config + .build_target("install") + .build(); + + println!("cargo:rustc-link-search={}/lib", icicle_install_dir.display()); + println!("cargo:rustc-link-lib=icicle_field_stark252"); + println!("cargo:rustc-link-lib=stdc++"); + println!("cargo:rustc-link-arg=-Wl,-rpath,{}/lib", icicle_install_dir.display()); // Add RPATH linker arguments + + // default backends dir + println!( + "cargo:rustc-env=DEFAULT_BACKEND_INSTALL_DIR={}/lib/backend", + icicle_install_dir.display() + ); +} diff --git a/wrappers/rust_v3/icicle-fields/icicle-stark252/src/field.rs b/wrappers/rust_v3/icicle-fields/icicle-stark252/src/field.rs new file mode 100644 index 0000000000..7e68612bb5 --- /dev/null +++ b/wrappers/rust_v3/icicle-fields/icicle-stark252/src/field.rs @@ -0,0 +1,19 @@ +use icicle_core::field::{Field, MontgomeryConvertibleField}; +use icicle_core::traits::{FieldConfig, FieldImpl, GenerateRandom}; +use icicle_core::{impl_field, impl_scalar_field}; +use icicle_runtime::errors::eIcicleError; +use icicle_runtime::memory::{DeviceSlice, HostOrDeviceSlice}; +use icicle_runtime::stream::IcicleStream; + +pub(crate) const SCALAR_LIMBS: usize = 8; + +impl_scalar_field!("stark252", stark252, SCALAR_LIMBS, ScalarField, ScalarCfg); + +#[cfg(test)] +mod tests { + use super::ScalarField; + use icicle_core::impl_field_tests; + use icicle_core::tests::*; + + impl_field_tests!(ScalarField); +} diff --git a/wrappers/rust_v3/icicle-fields/icicle-stark252/src/lib.rs b/wrappers/rust_v3/icicle-fields/icicle-stark252/src/lib.rs new file mode 100644 index 0000000000..bbc98aeba4 --- /dev/null +++ b/wrappers/rust_v3/icicle-fields/icicle-stark252/src/lib.rs @@ -0,0 +1,3 @@ +pub mod field; +pub mod ntt; +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 new file mode 100644 index 0000000000..9da4433db4 --- /dev/null +++ b/wrappers/rust_v3/icicle-fields/icicle-stark252/src/ntt/mod.rs @@ -0,0 +1,21 @@ +use crate::field::{ScalarCfg, ScalarField}; +use icicle_core::ntt::{NTTConfig, NTTDir, NTTDomain, NTTInitDomainConfig, NTT}; +use icicle_core::{impl_ntt, impl_ntt_without_domain}; +use icicle_runtime::errors::eIcicleError; +use icicle_runtime::memory::HostOrDeviceSlice; + +impl_ntt!("stark252", stark252, ScalarField, ScalarCfg); + +#[cfg(test)] +pub(crate) mod tests { + use crate::field::ScalarField; + use icicle_core::impl_ntt_tests; + use icicle_core::ntt::tests::*; + use serial_test::{parallel, serial}; + use std::sync::OnceLock; + + impl_ntt_tests!(ScalarField); +} + +// TODO Yuval : V2 has tests against lambdaworks, do we still need it? +// UPDATE: team decided to keep it diff --git a/wrappers/rust_v3/icicle-fields/icicle-stark252/src/vec_ops/mod.rs b/wrappers/rust_v3/icicle-fields/icicle-stark252/src/vec_ops/mod.rs new file mode 100644 index 0000000000..7f71c81934 --- /dev/null +++ b/wrappers/rust_v3/icicle-fields/icicle-stark252/src/vec_ops/mod.rs @@ -0,0 +1,17 @@ +use crate::field::{ScalarCfg, ScalarField}; + +use icicle_core::impl_vec_ops_field; +use icicle_core::vec_ops::{VecOps, VecOpsConfig}; +use icicle_runtime::errors::eIcicleError; +use icicle_runtime::memory::HostOrDeviceSlice; + +impl_vec_ops_field!("stark252", stark252, ScalarField, ScalarCfg); + +#[cfg(test)] +pub(crate) mod tests { + use crate::field::ScalarField; + use icicle_core::impl_vec_ops_tests; + use icicle_core::vec_ops::tests::*; + + impl_vec_ops_tests!(ScalarField); +}