Skip to content

Commit

Permalink
stark252 rust crate
Browse files Browse the repository at this point in the history
  • Loading branch information
yshekel committed Jun 25, 2024
1 parent b322df8 commit d93975f
Show file tree
Hide file tree
Showing 22 changed files with 170 additions and 38 deletions.
5 changes: 3 additions & 2 deletions icicle_v3/backend/cpu/src/field/cpu_ntt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<scalar_t>));

eIcicleError cpu_ntt_release_domain(const Device& device)
template <typename S = scalar_t>
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);
REGISTER_NTT_RELEASE_DOMAIN_BACKEND("CPU", cpu_ntt_release_domain<scalar_t>);
2 changes: 1 addition & 1 deletion icicle_v3/backend/cuda/src/ntt/cuda_ntt.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions icicle_v3/include/icicle/curves/montgomery_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace icicle {
using AffineConvertMontImpl = std::function<eIcicleError(
const Device& device, const affine_t* input, size_t n, bool is_into, const VecOpsConfig& config, affine_t* output)>;

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 { \
Expand All @@ -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 { \
Expand All @@ -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 { \
Expand All @@ -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 { \
Expand Down
2 changes: 1 addition & 1 deletion icicle_v3/include/icicle/device_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeviceAPI> api);
void register_deviceAPI(const std::string& deviceType, std::shared_ptr<DeviceAPI> api);

/**
* @brief Register DeviceAPI instance for a device type.
Expand Down
2 changes: 1 addition & 1 deletion icicle_v3/include/icicle/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<type, ST_name_##api_name>; \
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); \
Expand Down
2 changes: 1 addition & 1 deletion icicle_v3/include/icicle/ecntt.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace icicle {
NTTConfig<scalar_t>& 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 { \
Expand Down
4 changes: 2 additions & 2 deletions icicle_v3/include/icicle/matrix_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 { \
Expand All @@ -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 { \
Expand Down
8 changes: 4 additions & 4 deletions icicle_v3/include/icicle/msm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 { \
Expand All @@ -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 { \
Expand All @@ -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 { \
Expand All @@ -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 { \
Expand Down
12 changes: 7 additions & 5 deletions icicle_v3/include/icicle/ntt.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace icicle {
using NttImpl = std::function<eIcicleError(
const Device& device, const scalar_t* input, int size, NTTDir dir, NTTConfig<scalar_t>& 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 { \
Expand All @@ -163,7 +163,7 @@ namespace icicle {
NTTConfig<scalar_t>& 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 { \
Expand All @@ -178,7 +178,7 @@ namespace icicle {
using NttInitDomainImpl = std::function<eIcicleError(
const Device& device, const scalar_t& primitive_root, const NTTInitDomainConfig& config)>;

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 { \
Expand All @@ -189,9 +189,11 @@ namespace icicle {
}

/*************************** RELEASE DOMAIN ***************************/
using NttReleaseDomainImpl = std::function<eIcicleError(const Device& device)>;
// 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<eIcicleError(const Device& device, const scalar_t& dummy)>;

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 { \
Expand Down
14 changes: 7 additions & 7 deletions icicle_v3/include/icicle/vec_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 { \
Expand All @@ -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 { \
Expand All @@ -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 { \
Expand All @@ -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 { \
Expand All @@ -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 { \
Expand All @@ -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 { \
Expand All @@ -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 { \
Expand Down
2 changes: 1 addition & 1 deletion icicle_v3/src/device_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeviceAPI> api)
void register_deviceAPI(const std::string& deviceType, std::shared_ptr<DeviceAPI> api)
{
ICICLE_LOG_DEBUG << "deviceAPI registered for " << deviceType;
DeviceAPIRegistry::Global().register_deviceAPI(deviceType, api);
Expand Down
7 changes: 6 additions & 1 deletion icicle_v3/src/ntt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<scalar_t>()
Expand Down
1 change: 1 addition & 0 deletions wrappers/rust_v3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"icicle-runtime",
"icicle-core",
"icicle-fields/icicle-babybear",
"icicle-fields/icicle-stark252",
]
exclude = []

Expand Down
1 change: 0 additions & 1 deletion wrappers/rust_v3/icicle-core/src/ntt/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion wrappers/rust_v3/icicle-core/src/test_utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ pub static TEST_REF_DEVICE: Lazy<Mutex<Device>> = 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
Expand Down
6 changes: 0 additions & 6 deletions wrappers/rust_v3/icicle-core/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,3 @@ pub trait MontgomeryConvertible: Sized {
fn to_mont(values: &mut DeviceSlice<Self>, stream: &IcicleStream) -> eIcicleError;
fn from_mont(values: &mut DeviceSlice<Self>, stream: &IcicleStream) -> eIcicleError;
}

// pub trait IcicleResultWrap {
// fn wrap(self) -> IcicleResult<()>;
// fn wrap_value<T>(self, value: T) -> IcicleResult<T>;
// fn wrap_maybe_uninit<T>(self, value: MaybeUninit<T>) -> IcicleResult<T>;
// }
20 changes: 20 additions & 0 deletions wrappers/rust_v3/icicle-fields/icicle-stark252/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Loading

0 comments on commit d93975f

Please sign in to comment.