diff --git a/disperser/cmd/encoder/config.go b/disperser/cmd/encoder/config.go index bfa90acd00..9f03baeb28 100644 --- a/disperser/cmd/encoder/config.go +++ b/disperser/cmd/encoder/config.go @@ -28,7 +28,7 @@ type Config struct { EncoderConfig kzg.KzgConfig LoggerConfig common.LoggerConfig ServerConfig *encoder.ServerConfig - MetricsConfig encoder.MetricsConfig + MetricsConfig *encoder.MetricsConfig } func NewConfig(ctx *cli.Context) (Config, error) { @@ -58,9 +58,9 @@ func NewConfig(ctx *cli.Context) (Config, error) { RequestPoolSize: ctx.GlobalInt(flags.RequestPoolSizeFlag.Name), EnableGnarkChunkEncoding: ctx.Bool(flags.EnableGnarkChunkEncodingFlag.Name), Backend: ctx.String(flags.BackendFlag.Name), - EnableGPU: ctx.Bool(flags.EnableGPUFlag.Name), + GPUEnable: ctx.Bool(flags.GPUEnableFlag.Name), }, - MetricsConfig: encoder.MetricsConfig{ + MetricsConfig: &encoder.MetricsConfig{ HTTPPort: ctx.GlobalString(flags.MetricsHTTPPort.Name), EnableMetrics: ctx.GlobalBool(flags.EnableMetrics.Name), }, diff --git a/disperser/cmd/encoder/flags/flags.go b/disperser/cmd/encoder/flags/flags.go index da0048c428..eafcaf0679 100644 --- a/disperser/cmd/encoder/flags/flags.go +++ b/disperser/cmd/encoder/flags/flags.go @@ -68,11 +68,11 @@ var ( Required: false, EnvVar: common.PrefixEnvVar(envVarPrefix, "ENABLE_GNARK_CHUNK_ENCODING"), } - EnableGPUFlag = cli.BoolFlag{ - Name: common.PrefixFlag(FlagPrefix, "enable-gpu"), + GPUEnableFlag = cli.BoolFlag{ + Name: common.PrefixFlag(FlagPrefix, "gpu-enable"), Usage: "Enable GPU", Required: false, - EnvVar: common.PrefixEnvVar(envVarPrefix, "ENABLE_GPU"), + EnvVar: common.PrefixEnvVar(envVarPrefix, "GPU_ENABLE"), } BackendFlag = cli.StringFlag{ Name: common.PrefixFlag(FlagPrefix, "backend"), @@ -95,7 +95,7 @@ var optionalFlags = []cli.Flag{ EnableGnarkChunkEncodingFlag, EncoderVersionFlag, S3BucketNameFlag, - EnableGPUFlag, + GPUEnableFlag, BackendFlag, } diff --git a/disperser/cmd/encoder/main.go b/disperser/cmd/encoder/main.go index 91f80d2521..3d9e172f59 100644 --- a/disperser/cmd/encoder/main.go +++ b/disperser/cmd/encoder/main.go @@ -74,7 +74,7 @@ func RunEncoderServer(ctx *cli.Context) error { // Create the encoder opts := []rs.EncoderOption{ rs.WithBackend(backendType), - rs.WithGPU(config.ServerConfig.EnableGPU), + rs.WithGPU(config.ServerConfig.GPUEnable), } rsEncoder, err := rs.NewEncoder(opts...) if err != nil { @@ -86,7 +86,7 @@ func RunEncoderServer(ctx *cli.Context) error { prover.WithKZGConfig(&config.EncoderConfig), prover.WithLoadG2Points(false), prover.WithBackend(backendType), - prover.WithGPU(config.ServerConfig.EnableGPU), + prover.WithGPU(config.ServerConfig.GPUEnable), prover.WithRSEncoder(rsEncoder), } prover, err := prover.NewProver(popts...) @@ -127,7 +127,7 @@ func RunEncoderServer(ctx *cli.Context) error { prover.WithKZGConfig(&config.EncoderConfig), prover.WithLoadG2Points(true), prover.WithBackend(backendType), - prover.WithGPU(config.ServerConfig.EnableGPU), + prover.WithGPU(config.ServerConfig.GPUEnable), } prover, err := prover.NewProver(opts...) if err != nil { diff --git a/disperser/encoder/config.go b/disperser/encoder/config.go index 2edd10b0e0..cfdcf2fe46 100644 --- a/disperser/encoder/config.go +++ b/disperser/encoder/config.go @@ -10,5 +10,5 @@ type ServerConfig struct { RequestPoolSize int EnableGnarkChunkEncoding bool Backend string - EnableGPU bool + GPUEnable bool } diff --git a/encoding/backend.go b/encoding/backend.go index a897a08738..30b9d350a4 100644 --- a/encoding/backend.go +++ b/encoding/backend.go @@ -12,7 +12,7 @@ const ( type Config struct { NumWorker uint64 BackendType BackendType - EnableGPU bool + GPUEnable bool Verbose bool } diff --git a/encoding/icicle/device_setup.go b/encoding/icicle/device_setup.go index 2d53f9872b..b8f560d272 100644 --- a/encoding/icicle/device_setup.go +++ b/encoding/icicle/device_setup.go @@ -22,10 +22,16 @@ type IcicleDevice struct { SRSG1Icicle []icicle_bn254.Affine } -// IcicleDeviceConfig holds configuration options for device setup +// IcicleDeviceConfig holds configuration options for a single device. +// - The GPUEnable parameter is used to enable GPU acceleration. +// - The NTTSize parameter is used to set the maximum domain size for NTT configuration. +// - The FFTPointsT and SRSG1 parameters are used to set up the MSM configuration. +// - MSM setup is optional and can be skipped by not providing these parameters. +// The reason for this is that not all applications require an MSM setup. type IcicleDeviceConfig struct { - EnableGPU bool + GPUEnable bool NTTSize uint8 + // MSM setup parameters (optional) FFTPointsT [][]bn254.G1Affine SRSG1 []bn254.G1Affine @@ -35,7 +41,7 @@ type IcicleDeviceConfig struct { func NewIcicleDevice(config IcicleDeviceConfig) (*IcicleDevice, error) { icicle_runtime.LoadBackendFromEnvOrDefault() - device := setupDevice(config.EnableGPU) + device := setupDevice(config.GPUEnable) var wg sync.WaitGroup wg.Add(1) @@ -55,18 +61,18 @@ func NewIcicleDevice(config IcicleDeviceConfig) (*IcicleDevice, error) { // Setup NTT nttCfg, icicleErr = SetupNTT(config.NTTSize) if icicleErr != icicle_runtime.Success { - setupErr = fmt.Errorf("could not setup NTT") + setupErr = fmt.Errorf("could not setup NTT: %v", icicleErr.AsString()) return } // Setup MSM if parameters are provided if config.FFTPointsT != nil && config.SRSG1 != nil { - flatFftPointsT, srsG1Icicle, msmCfg, _, icicleErr = SetupMsm( + flatFftPointsT, srsG1Icicle, msmCfg, icicleErr = SetupMsmG1( config.FFTPointsT, config.SRSG1, ) if icicleErr != icicle_runtime.Success { - setupErr = fmt.Errorf("could not setup MSM") + setupErr = fmt.Errorf("could not setup MSM: %v", icicleErr.AsString()) return } } @@ -88,8 +94,8 @@ func NewIcicleDevice(config IcicleDeviceConfig) (*IcicleDevice, error) { } // setupDevice initializes either a GPU or CPU device -func setupDevice(enableGPU bool) icicle_runtime.Device { - if enableGPU { +func setupDevice(gpuEnable bool) icicle_runtime.Device { + if gpuEnable { return setupGPUDevice() } diff --git a/encoding/icicle/msm_setup.go b/encoding/icicle/msm_setup.go index 06632a408f..79c469e80e 100644 --- a/encoding/icicle/msm_setup.go +++ b/encoding/icicle/msm_setup.go @@ -9,7 +9,8 @@ import ( "github.com/ingonyama-zk/icicle/v3/wrappers/golang/runtime" ) -func SetupMsm(rowsG1 [][]bn254.G1Affine, srsG1 []bn254.G1Affine) ([]icicle_bn254.Affine, []icicle_bn254.Affine, core.MSMConfig, core.MSMConfig, runtime.EIcicleError) { +// SetupMsmG1 initializes the MSM configuration for G1 points. +func SetupMsmG1(rowsG1 [][]bn254.G1Affine, srsG1 []bn254.G1Affine) ([]icicle_bn254.Affine, []icicle_bn254.Affine, core.MSMConfig, runtime.EIcicleError) { rowsG1Icicle := make([]icicle_bn254.Affine, 0) for _, row := range rowsG1 { @@ -19,22 +20,14 @@ func SetupMsm(rowsG1 [][]bn254.G1Affine, srsG1 []bn254.G1Affine) ([]icicle_bn254 srsG1Icicle := BatchConvertGnarkAffineToIcicleAffine(srsG1) cfgBn254 := core.GetDefaultMSMConfig() - cfgBn254G2 := core.GetDefaultMSMConfig() cfgBn254.IsAsync = true - cfgBn254G2.IsAsync = true streamBn254, err := runtime.CreateStream() if err != runtime.Success { - return nil, nil, cfgBn254, cfgBn254G2, err - } - - streamBn254G2, err := runtime.CreateStream() - if err != runtime.Success { - return nil, nil, cfgBn254, cfgBn254G2, err + return nil, nil, cfgBn254, err } cfgBn254.StreamHandle = streamBn254 - cfgBn254G2.StreamHandle = streamBn254G2 - return rowsG1Icicle, srsG1Icicle, cfgBn254, cfgBn254G2, runtime.Success + return rowsG1Icicle, srsG1Icicle, cfgBn254, runtime.Success } diff --git a/encoding/icicle/ntt_setup.go b/encoding/icicle/ntt_setup.go index 499e91b2f4..20ecae2b9d 100644 --- a/encoding/icicle/ntt_setup.go +++ b/encoding/icicle/ntt_setup.go @@ -12,7 +12,8 @@ import ( "github.com/ingonyama-zk/icicle/v3/wrappers/golang/runtime" ) -// batchSize is number of batches +// SetupNTT initializes the NTT domain with the domain size of maxScale. +// It returns the NTT configuration and an error if the initialization fails. func SetupNTT(maxScale uint8) (core.NTTConfig[[bn254.SCALAR_LIMBS]uint32], runtime.EIcicleError) { cfg := core.GetDefaultNTTInitDomainConfig() diff --git a/encoding/kzg/prover/icicle.go b/encoding/kzg/prover/icicle.go index a32f26227a..9797483f45 100644 --- a/encoding/kzg/prover/icicle.go +++ b/encoding/kzg/prover/icicle.go @@ -19,7 +19,7 @@ func CreateIcicleBackendProver(p *Prover, params encoding.EncodingParams, fs *ff } icicleDevice, err := icicle.NewIcicleDevice(icicle.IcicleDeviceConfig{ - EnableGPU: p.Config.EnableGPU, + GPUEnable: p.Config.GPUEnable, NTTSize: defaultNTTSize, FFTPointsT: fftPointsT, SRSG1: p.Srs.G1[:p.KzgConfig.SRSNumberToLoad], diff --git a/encoding/kzg/prover/noicicle.go b/encoding/kzg/prover/noicicle.go index 7e4f68f588..af7b613fcd 100644 --- a/encoding/kzg/prover/noicicle.go +++ b/encoding/kzg/prover/noicicle.go @@ -10,10 +10,6 @@ import ( "github.com/Layr-Labs/eigenda/encoding/kzg" ) -func SetupIcicleDevice(enableGPU bool) interface{} { - return nil -} - func CreateIcicleBackendProver(p *Prover, params encoding.EncodingParams, fs *fft.FFTSettings, ks *kzg.KZGSettings) (*ParametrizedProver, error) { // Not supported return nil, fmt.Errorf("icicle backend called without icicle build tag") diff --git a/encoding/kzg/prover/prover.go b/encoding/kzg/prover/prover.go index 9183955105..7eefdcc92a 100644 --- a/encoding/kzg/prover/prover.go +++ b/encoding/kzg/prover/prover.go @@ -42,7 +42,7 @@ var _ encoding.Prover = &Prover{} // Default configuration values const ( defaultBackend = encoding.BackendDefault - defaultEnableGPU = false + defaultGPUEnable = false defaultLoadG2Points = true defaultPreloadEncoder = false defaultNTTSize = 25 // Used for NTT setup in Icicle backend @@ -60,7 +60,7 @@ func WithBackend(backend encoding.BackendType) ProverOption { // WithGPU enables or disables GPU usage func WithGPU(enable bool) ProverOption { return func(e *Prover) error { - e.Config.EnableGPU = enable + e.Config.GPUEnable = enable return nil } } @@ -138,7 +138,7 @@ func NewProver(opts ...ProverOption) (*Prover, error) { Config: &encoding.Config{ NumWorker: uint64(runtime.GOMAXPROCS(0)), BackendType: defaultBackend, - EnableGPU: defaultEnableGPU, + GPUEnable: defaultGPUEnable, Verbose: defaultVerbose, }, @@ -489,7 +489,7 @@ func (p *Prover) newProver(params encoding.EncodingParams) (*ParametrizedProver, } func (p *Prover) createDefaultBackendProver(params encoding.EncodingParams, fs *fft.FFTSettings, ks *kzg.KZGSettings) (*ParametrizedProver, error) { - if p.Config.EnableGPU { + if p.Config.GPUEnable { return nil, fmt.Errorf("GPU is not supported in default backend") } diff --git a/encoding/rs/encoder.go b/encoding/rs/encoder.go index 54224dc40d..9068c5b422 100644 --- a/encoding/rs/encoder.go +++ b/encoding/rs/encoder.go @@ -31,7 +31,7 @@ type EncoderDevice interface { // Default configuration values const ( defaultBackend = encoding.BackendDefault - defaultEnableGPU = false + defaultGPUEnable = false defaultVerbose = false ) @@ -44,7 +44,7 @@ func WithBackend(backend encoding.BackendType) EncoderOption { func WithGPU(enable bool) EncoderOption { return func(e *Encoder) { - e.Config.EnableGPU = enable + e.Config.GPUEnable = enable } } @@ -66,7 +66,7 @@ func NewEncoder(opts ...EncoderOption) (*Encoder, error) { Config: &encoding.Config{ NumWorker: uint64(runtime.GOMAXPROCS(0)), BackendType: defaultBackend, - EnableGPU: defaultEnableGPU, + GPUEnable: defaultGPUEnable, Verbose: defaultVerbose, }, @@ -134,7 +134,7 @@ func (e *Encoder) CreateFFTSettings(params encoding.EncodingParams) *fft.FFTSett } func (e *Encoder) createDefaultBackendEncoder(params encoding.EncodingParams, fs *fft.FFTSettings) (*ParametrizedEncoder, error) { - if e.Config.EnableGPU { + if e.Config.GPUEnable { return nil, fmt.Errorf("GPU is not supported in default backend") } diff --git a/encoding/rs/icicle.go b/encoding/rs/icicle.go index c830afc09b..2a4fa24787 100644 --- a/encoding/rs/icicle.go +++ b/encoding/rs/icicle.go @@ -15,7 +15,7 @@ const ( func CreateIcicleBackendEncoder(e *Encoder, params encoding.EncodingParams, fs *fft.FFTSettings) (*ParametrizedEncoder, error) { icicleDevice, err := icicle.NewIcicleDevice(icicle.IcicleDeviceConfig{ - EnableGPU: e.Config.EnableGPU, + GPUEnable: e.Config.GPUEnable, NTTSize: defaultNTTSize, // No MSM setup needed for encoder }) diff --git a/encoding/rs/noicicle.go b/encoding/rs/noicicle.go index 668ab004ed..aea08badb4 100644 --- a/encoding/rs/noicicle.go +++ b/encoding/rs/noicicle.go @@ -9,10 +9,6 @@ import ( "github.com/Layr-Labs/eigenda/encoding/fft" ) -func SetupIcicleDevice(enableGPU bool) interface{} { - return nil -} - func CreateIcicleBackendEncoder(p *Encoder, params encoding.EncodingParams, fs *fft.FFTSettings) (*ParametrizedEncoder, error) { // Not supported return nil, fmt.Errorf("icicle backend called without icicle build tag")