Skip to content

Commit

Permalink
Respond to some PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dmanc committed Nov 14, 2024
1 parent 76fc855 commit 9f3a9d6
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 50 deletions.
6 changes: 3 additions & 3 deletions disperser/cmd/encoder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
},
Expand Down
8 changes: 4 additions & 4 deletions disperser/cmd/encoder/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -95,7 +95,7 @@ var optionalFlags = []cli.Flag{
EnableGnarkChunkEncodingFlag,
EncoderVersionFlag,
S3BucketNameFlag,
EnableGPUFlag,
GPUEnableFlag,
BackendFlag,
}

Expand Down
6 changes: 3 additions & 3 deletions disperser/cmd/encoder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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...)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion disperser/encoder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ type ServerConfig struct {
RequestPoolSize int
EnableGnarkChunkEncoding bool
Backend string
EnableGPU bool
GPUEnable bool
}
2 changes: 1 addition & 1 deletion encoding/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
type Config struct {
NumWorker uint64
BackendType BackendType
EnableGPU bool
GPUEnable bool
Verbose bool
}

Expand Down
22 changes: 14 additions & 8 deletions encoding/icicle/device_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
}
}
Expand All @@ -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()
}

Expand Down
15 changes: 4 additions & 11 deletions encoding/icicle/msm_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
3 changes: 2 additions & 1 deletion encoding/icicle/ntt_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion encoding/kzg/prover/icicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
4 changes: 0 additions & 4 deletions encoding/kzg/prover/noicicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions encoding/kzg/prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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,
},

Expand Down Expand Up @@ -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")
}

Expand Down
8 changes: 4 additions & 4 deletions encoding/rs/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type EncoderDevice interface {
// Default configuration values
const (
defaultBackend = encoding.BackendDefault
defaultEnableGPU = false
defaultGPUEnable = false
defaultVerbose = false
)

Expand All @@ -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
}
}

Expand All @@ -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,
},

Expand Down Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion encoding/rs/icicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
4 changes: 0 additions & 4 deletions encoding/rs/noicicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 9f3a9d6

Please sign in to comment.