Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does gnark start GPU acceleration? #1130

Open
weijizhen opened this issue May 10, 2024 · 1 comment
Open

How does gnark start GPU acceleration? #1130

weijizhen opened this issue May 10, 2024 · 1 comment

Comments

@weijizhen
Copy link

I am at gnark/.../example, a main. go was created, such as the following code:
package main

import (
"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend"
"github.com/consensys/gnark/backend/groth16"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/frontend/cs/r1cs"
)

// CubicCircuit defines a simple circuit
// x**3 + x + 5 == y
type CubicCircuit struct {
// struct tags on a variable is optional
// default uses variable name and secret visibility.
X frontend.Variable gnark:"x"
Y frontend.Variable gnark:",public"
}

// Define declares the circuit constraints
// x**3 + x + 5 == y
func (circuit *CubicCircuit) Define(api frontend.API) error {
x3 := api.Mul(circuit.X, circuit.X, circuit.X)
api.AssertIsEqual(circuit.Y, api.Add(x3, circuit.X, 5))
return nil
}

func main() {
// compiles our circuit into a R1CS
var circuit CubicCircuit
ccs, _ := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)

// groth16 zkSNARK: Setup
pk, vk, _ := groth16.Setup(ccs)

// witness definition
assignment := CubicCircuit{X: 3, Y: 35}
witness, _ := frontend.NewWitness(&assignment, ecc.BN254.ScalarField())
publicWitness, _ := witness.Public()

// groth16: Prove & Verify
proof, _ := groth16.Prove(ccs, pk, witness, backend.WithIcicleAcceleration())
//proof, _ := groth16.Prove(ccs, pk, witness)
groth16.Verify(proof, vk, publicWitness)

}

errors:
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lbn254: No such file or directory
collect2: error: ld returned 1 exit status

Should I download the article first and then compile it?
Finally, to gnark/.../example and to execute "go run -tags=icicle main.go"
What should I do?

@ivokub
Copy link
Collaborator

ivokub commented May 13, 2024

Hi, indeed setting up the GPU support is a bit cumbersome and depends on the ICICLE library being set up correctly. Have a look at https://github.com/ingonyama-zk/icicle/tree/main/wrappers/golang on how to build ICICLE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants