mirror of
https://github.com/pseXperiments/icicle.git
synced 2026-01-08 23:17:54 -05:00
move backend-specific-config to open part to avoid installing it
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
using namespace bn254;
|
||||
|
||||
#include "examples_utils.h"
|
||||
#include "icicle/backend/ntt_config.h"
|
||||
|
||||
void initialize_input(const unsigned ntt_size, const unsigned batch_size, scalar_t* elements)
|
||||
{
|
||||
@@ -41,7 +42,7 @@ int main(int argc, char* argv[])
|
||||
auto ntt_init_domain_cfg = default_ntt_init_domain_config();
|
||||
// set CUDA backend specific flag for init_domain
|
||||
ConfigExtension backend_cfg_ext;
|
||||
backend_cfg_ext.set("fast_twiddles", true);
|
||||
backend_cfg_ext.set(CudaBackendConfig::CUDA_NTT_FAST_TWIDDLES_MODE, true);
|
||||
ntt_init_domain_cfg.ext = &backend_cfg_ext;
|
||||
ICICLE_CHECK(bn254_ntt_init_domain(&basic_root, ntt_init_domain_cfg));
|
||||
|
||||
@@ -78,7 +79,7 @@ int main(int argc, char* argv[])
|
||||
config_compute.stream = stream_compute;
|
||||
// backend specific config extension
|
||||
ConfigExtension ntt_cfg_ext;
|
||||
ntt_cfg_ext.set("ntt_algorithm", 2); // mixed-radix
|
||||
ntt_cfg_ext.set(CudaBackendConfig::CUDA_NTT_ALGORITHM, CudaBackendConfig::NttAlgorithm::MixedRadix);
|
||||
config_compute.ext = &ntt_cfg_ext;
|
||||
|
||||
for (int run = 0; run < 10; run++) {
|
||||
@@ -115,8 +116,8 @@ int main(int argc, char* argv[])
|
||||
// Clean-up
|
||||
for (int i = 0; i < 2; i++) {
|
||||
ICICLE_CHECK(icicle_free(d_vec[i]));
|
||||
delete[](h_inp[i]);
|
||||
delete[](h_out[i]);
|
||||
delete[] (h_inp[i]);
|
||||
delete[] (h_out[i]);
|
||||
}
|
||||
ICICLE_CHECK(icicle_destroy_stream(stream_compute));
|
||||
ICICLE_CHECK(icicle_destroy_stream(stream_d2h));
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
using namespace bn254;
|
||||
|
||||
#include "examples_utils.h"
|
||||
#include "icicle/backend/ntt_config.h"
|
||||
|
||||
void initialize_input(const unsigned ntt_size, const unsigned nof_ntts, scalar_t* elements);
|
||||
int validate_output(const unsigned ntt_size, const unsigned nof_ntts, scalar_t* elements);
|
||||
@@ -33,7 +34,8 @@ int main(int argc, char* argv[])
|
||||
scalar_t basic_root = scalar_t::omega(log_ntt_size /*NTT_LOG_SIZscalar_t*/);
|
||||
auto ntt_init_domain_cfg = default_ntt_init_domain_config();
|
||||
ConfigExtension backend_cfg_ext;
|
||||
backend_cfg_ext.set("fast_twiddles", true); // optionally construct fast_twiddles for CUDA backend
|
||||
backend_cfg_ext.set(
|
||||
CudaBackendConfig::CUDA_NTT_FAST_TWIDDLES_MODE, true); // optionally construct fast_twiddles for CUDA backend
|
||||
ntt_init_domain_cfg.ext = &backend_cfg_ext;
|
||||
ICICLE_CHECK(bn254_ntt_init_domain(&basic_root, ntt_init_domain_cfg));
|
||||
|
||||
@@ -48,7 +50,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
// NTT radix-2 alg
|
||||
std::cout << "\nRunning NTT radix-2 alg with on-host data" << std::endl;
|
||||
ntt_cfg_ext.set("ntt_algorithm", 1); // radix-2
|
||||
ntt_cfg_ext.set(CudaBackendConfig::CUDA_NTT_ALGORITHM, CudaBackendConfig::NttAlgorithm::Radix2);
|
||||
START_TIMER(Radix2);
|
||||
ICICLE_CHECK(bn254_ntt(input.get(), ntt_size, NTTDir::kForward, config, output.get()));
|
||||
END_TIMER(Radix2, "Radix2 NTT");
|
||||
@@ -58,7 +60,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
// NTT mixed-radix alg
|
||||
std::cout << "\nRunning NTT mixed-radix alg with on-host data" << std::endl;
|
||||
ntt_cfg_ext.set("ntt_algorithm", 2); // mixed-radix
|
||||
ntt_cfg_ext.set(CudaBackendConfig::CUDA_NTT_ALGORITHM, CudaBackendConfig::NttAlgorithm::MixedRadix);
|
||||
START_TIMER(MixedRadix);
|
||||
ICICLE_CHECK(bn254_ntt(input.get(), ntt_size, NTTDir::kForward, config, output.get()));
|
||||
END_TIMER(MixedRadix, "MixedRadix NTT");
|
||||
|
||||
13
icicle_v3/include/icicle/backend/msm_config.h
Normal file
13
icicle_v3/include/icicle/backend/msm_config.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
/********* CPU Backend Configurations *********/
|
||||
|
||||
/********* CUDA Backend Configurations *********/
|
||||
|
||||
namespace CudaBackendConfig {
|
||||
// Backend-specific configuration flags as constexpr strings
|
||||
constexpr const char* CUDA_MSM_IS_BIG_TRIANGLE = "is_big_triangle";
|
||||
constexpr const char* CUDA_MSM_LARGE_BUCKET_FACTOR = "large_bucket_factor";
|
||||
constexpr const int CUDA_MSM_LARGE_BUCKET_FACTOR_DEFAULT_VAL = 10;
|
||||
|
||||
} // namespace CudaBackendConfig
|
||||
18
icicle_v3/include/icicle/backend/ntt_config.h
Normal file
18
icicle_v3/include/icicle/backend/ntt_config.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
/********* CPU Backend Configurations *********/
|
||||
|
||||
/********* CUDA Backend Configurations *********/
|
||||
|
||||
namespace CudaBackendConfig {
|
||||
// Enumeration for NTT (Number Theoretic Transform) algorithms
|
||||
enum NttAlgorithm {
|
||||
Auto, ///< Automatically choose the algorithm
|
||||
Radix2, ///< Use Radix-2 algorithm
|
||||
MixedRadix ///< Use Mixed Radix algorithm
|
||||
};
|
||||
|
||||
// Backend-specific configuration flags as constexpr strings
|
||||
constexpr const char* CUDA_NTT_FAST_TWIDDLES_MODE = "fast_twiddles"; ///< Enable fast twiddles mode
|
||||
constexpr const char* CUDA_NTT_ALGORITHM = "ntt_algorithm"; ///< Set NTT algorithm
|
||||
} // namespace CudaBackendConfig
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "icicle/fields/field_config.h"
|
||||
#include "icicle/utils/log.h"
|
||||
#include "icicle/backend/ntt_config.h"
|
||||
|
||||
using namespace field_config;
|
||||
using namespace icicle;
|
||||
@@ -26,10 +27,6 @@ static int ITERS = 16;
|
||||
static inline std::string s_main_target;
|
||||
static inline std::string s_reference_target;
|
||||
|
||||
// TODO Yuval: better include the CUDA configs and use instead of redefine
|
||||
#define CUDA_NTT_FAST_TWIDDLES_MODE "fast_twiddles"
|
||||
#define CUDA_NTT_ALGORITHM "ntt_algorithm"
|
||||
|
||||
template <typename T>
|
||||
class FieldApiTest : public ::testing::Test
|
||||
{
|
||||
@@ -328,7 +325,7 @@ TYPED_TEST(FieldApiTest, ntt)
|
||||
init_domain_config.stream = stream;
|
||||
init_domain_config.is_async = false;
|
||||
ConfigExtension ext;
|
||||
ext.set(CUDA_NTT_FAST_TWIDDLES_MODE, true);
|
||||
ext.set(CudaBackendConfig::CUDA_NTT_FAST_TWIDDLES_MODE, true);
|
||||
init_domain_config.ext = &ext;
|
||||
|
||||
auto config = default_ntt_config<scalar_t>();
|
||||
|
||||
@@ -49,8 +49,8 @@ pub struct MSMConfig {
|
||||
}
|
||||
|
||||
// backend specific options
|
||||
pub const LARGE_BUCKET_FACTOR: &str = "large_bucket_factor";
|
||||
pub const IS_BIG_TRIANGLE: &str = "is_big_triangle";
|
||||
pub const CUDA_MSM_LARGE_BUCKET_FACTOR: &str = "large_bucket_factor";
|
||||
pub const CUDA_MSM_IS_BIG_TRIANGLE: &str = "is_big_triangle";
|
||||
|
||||
impl Default for MSMConfig {
|
||||
fn default() -> Self {
|
||||
@@ -297,7 +297,7 @@ macro_rules! impl_msm_bench {
|
||||
) => {
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use icicle_core::curve::{Affine, Curve, Projective};
|
||||
use icicle_core::msm::{msm, MSMConfig, LARGE_BUCKET_FACTOR, MSM};
|
||||
use icicle_core::msm::{msm, MSMConfig, CUDA_MSM_LARGE_BUCKET_FACTOR, MSM};
|
||||
use icicle_core::traits::{FieldImpl, GenerateRandom};
|
||||
use icicle_runtime::{
|
||||
device::Device,
|
||||
@@ -364,7 +364,7 @@ macro_rules! impl_msm_bench {
|
||||
cfg.stream_handle = *stream;
|
||||
cfg.is_async = true;
|
||||
cfg.ext
|
||||
.set_int(LARGE_BUCKET_FACTOR, 5);
|
||||
.set_int(CUDA_MSM_LARGE_BUCKET_FACTOR, 5);
|
||||
cfg.c = 4;
|
||||
|
||||
warmup(&stream).unwrap();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::curve::{Affine, Curve, Projective};
|
||||
use crate::msm::{msm, precompute_bases, MSMConfig, LARGE_BUCKET_FACTOR, MSM};
|
||||
use crate::msm::{msm, precompute_bases, MSMConfig, CUDA_MSM_LARGE_BUCKET_FACTOR, MSM};
|
||||
use crate::test_utilities;
|
||||
use crate::traits::{FieldImpl, GenerateRandom, MontgomeryConvertible};
|
||||
use icicle_runtime::{
|
||||
@@ -109,7 +109,7 @@ where
|
||||
cfg.stream_handle = *stream;
|
||||
cfg.is_async = true;
|
||||
cfg.ext
|
||||
.set_int(LARGE_BUCKET_FACTOR, 5);
|
||||
.set_int(CUDA_MSM_LARGE_BUCKET_FACTOR, 5);
|
||||
cfg.c = 4;
|
||||
runtime::warmup(&stream).unwrap();
|
||||
stream
|
||||
|
||||
Reference in New Issue
Block a user