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

HW VDF #148

Merged
merged 154 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
3f763ee
Clean up unused variables
rostislav Nov 16, 2022
6c9f57c
Add functions to 'integer' and Reducer classes to allow linking
rostislav Dec 20, 2022
e5df211
Hardware VDF support - WIP
rostislav Dec 20, 2022
f665374
hw: Fix problems with intermediate values' computation
rostislav Jan 13, 2023
22079b5
Use 'inline' explicitly for some functions in 'integer' class
rostislav Jan 15, 2023
6d1184b
hw: Initial support for proof generation
rostislav Jan 15, 2023
59382ff
hw: Fix bugs in proof generation, add proof verification
rostislav Jan 17, 2023
5541cb8
hw: Abort prover if generated proof fails verification
rostislav Jan 17, 2023
afed76d
Use path 'src/hw/libftd2xx' for VDF device interface library
rostislav Jan 17, 2023
e8739b6
hw: Distinguish emulated and real HW at runtime
rostislav Jan 17, 2023
62744bc
hw: Add minimal readme.txt
rostislav Jan 17, 2023
428c1c0
hw: Fix linker failure
rostislav Jan 17, 2023
9364333
Add workaround for a rare failure during form exponentiation
rostislav Jan 18, 2023
0b3c4ab
hw: Calculate and print hardware VDF speed
rostislav Jan 19, 2023
e6156d6
hw: Print software VDF iteration count and speed
rostislav Jan 20, 2023
315fe94
cleanup compiler warnings
sean-sn Jan 20, 2023
de87fbd
Updated hw with ASIC registers and code to setup ASIC
sean-sn Jan 20, 2023
f0184fc
Remove iteration count mask since SPI is stable on board
sean-sn Jan 20, 2023
7142dd6
hw: Set voltage, get power and temperature in HW initialization
sean-sn Jan 23, 2023
09c669e
hw: Update emulator to support new hardware operations
rostislav Jan 23, 2023
960220d
hw: Fix conversion specifiers for printing floating-point numbers
rostislav Jan 24, 2023
f7bdc43
hw: Fix printing of uninitialized values in emulator
rostislav Jan 24, 2023
fabc907
hw: Fix incorrect data read from status registers in emulator
rostislav Jan 25, 2023
9156cad
hw: Fix division by zero error when printing performance stats
rostislav Jan 25, 2023
1a14dc2
hw: Refactor HW interface, simplify handling of VDF values
rostislav Jan 26, 2023
c0940ca
hw: Fix leak of ChiaDriver object
rostislav Jan 26, 2023
94e47b6
hw: Simplify ChiaDriver, fix memory leak in FtdiDriver
rostislav Jan 26, 2023
52bfe6d
hw: Add shutdown function for emulator
rostislav Jan 26, 2023
a0518be
Revert incorrect cleanup of compiler warnings in 'integer' class
rostislav Jan 27, 2023
70d554d
bqfc.h: Fix incorrect function prototype
rostislav Jan 27, 2023
81b3381
hw: Add support for stopping VDF before completion
rostislav Jan 27, 2023
2b32143
hw: Support stopping a job via control regs in emulator
rostislav Jan 28, 2023
4ae607d
hw: Initial version of hardware VDF client and timelord emulator
rostislav Jan 28, 2023
22f94c9
hw: Fix compiler warning due to using a non-virtual destructor
rostislav Jan 30, 2023
80483a2
Move Prover base class to a separate file, declare it in vdf_base.hpp
rostislav Jan 31, 2023
ce83b22
Fix compiler warnings in VDF proof generation
rostislav Jan 31, 2023
476df56
hw: Add documentation about running VDF client with emulated timelord
rostislav Jan 31, 2023
77815a3
hw: Fix documentation mistakes about building and running with timelord
rostislav Jan 31, 2023
01060e9
hw: Fix invalid memory access to old VDF values in work queue
rostislav Jan 31, 2023
9566698
tl_emu.py: Specify a seed for generating durations of VDF runs
rostislav Jan 31, 2023
add02b4
hw: Add small sleep to VDF threads in emulator
rostislav Feb 1, 2023
959b92b
hw: Reduce logging in the emulator
rostislav Feb 1, 2023
3019982
hw: Add logic for enabling and disabling VDF engines in emulator
rostislav Feb 1, 2023
eafeb87
hw: Print details when getting an invalid VDF value, do not abort
rostislav Feb 1, 2023
5096f32
hw: Reduce amount of logging, move logging functions to a separate file
rostislav Feb 1, 2023
4073ef8
hw: Add logging of HW VDF client state changes
rostislav Feb 1, 2023
5aab750
tl_emu.py: Print discriminant of the challenge sent to VDF client
rostislav Feb 1, 2023
c92833a
hw: Update discriminants used in hw_main test
rostislav Feb 1, 2023
8895675
hw: Fix rare race condition between job threads in emulator
rostislav Feb 1, 2023
bdd42be
hw: Log when proof is requested in HW VDF client
rostislav Feb 2, 2023
1966984
tl_emu.py: Write discriminant and initial form in separate chunks
rostislav Feb 2, 2023
d7299ef
hw: Reduce logging of aux threads, log VDF progress very 10s
rostislav Feb 3, 2023
34f2122
hw: Reduce logging of ASIC temp, read status registers only if requested
rostislav Feb 6, 2023
d46c8c1
tl_emu.py: Do not wait if VDF client stops prematurely
rostislav Feb 7, 2023
ad16f7d
hw: Shut down HW VDF client gracefully when interrupted
rostislav Feb 7, 2023
27907e2
tl_emu.py: Request several proofs for random iteration counts
rostislav Feb 9, 2023
6a5c582
hw: Parse iteration counts for proofs in VDF client
rostislav Feb 9, 2023
c9faf44
hw: Add support for arbitrary initial form value
rostislav Feb 9, 2023
71ce4b5
tl_emu.py: Add verification of proofs
rostislav Feb 10, 2023
2042d85
hw: Submit proofs to timelord from HW VDF client
rostislav Feb 10, 2023
ed2f483
hw: Add documentation about running a hardware timelord in testnet
rostislav Feb 10, 2023
0fbb461
tl_emu.py: Print VDF index in error messages
rostislav Feb 13, 2023
5127c72
hw: Do not error out when receiving partial data from timelord
rostislav Feb 13, 2023
6848e62
tl_emu.py: Free VDF slot before closing connection to avoid a race
rostislav Feb 13, 2023
76302ee
hw: Simplify 'chia' commands for running a timelord in readme.txt
rostislav Feb 14, 2023
f44ae8f
hw: Increase interval between ASIC temperature readings to 20000 cycles
rostislav Feb 14, 2023
00fd1a7
hw: Choose the most efficient k value for computing proofs
rostislav Feb 15, 2023
a834511
hw: Log all queued proof iterations on one line
rostislav Feb 15, 2023
9700c78
Reducer.h: Change abs() -> labs() to avoid implicit integer truncation
rostislav Feb 16, 2023
b575a76
hw: Add proof checkpoints, reduce delay when requesting a proof
rostislav Feb 24, 2023
e088427
hw: Log time spent computing a proof
rostislav Feb 24, 2023
0882075
hw: Fix access to invalid x value when computing proof
rostislav Feb 24, 2023
bb3fe8e
hw: Do not log single occurrences of bad VDF values
rostislav Feb 24, 2023
ef67e69
hw: Log whether a proof thread computes a proof checkpoint
rostislav Feb 24, 2023
0e1b08f
hw: Accept frequency and board voltage as CLI args to VDF client
rostislav Mar 1, 2023
b341485
hw: Avoid excessive logging of work queue size warnings
rostislav Mar 3, 2023
daa5ab7
hw: Choose proof checkpoints according to requested proof iterations
rostislav Mar 13, 2023
d9b57fd
Added compensation register write to voltage regulator setup.
SchaffHub Mar 20, 2023
58d911d
hw: Refactor storage of CLI options in VDF client
rostislav Mar 20, 2023
9a78c90
hw: Add --ip option to VDF client to connect to remote timelord
rostislav Mar 21, 2023
a76ac97
Modified reset to work with open-drain style GPIO when
SchaffHub Mar 23, 2023
6757401
Merge branch 'hw_vdf' of github.com:Chia-Network/chiavdf-private into…
SchaffHub Mar 23, 2023
faa1af5
hw: Add option to set number of VDF aux threads per VDF engine
rostislav Mar 27, 2023
c033857
hw: Print a more detailed usage message in VDF client
rostislav Mar 28, 2023
7554d3b
hw: Add safety limits for setting frequency and voltage
rostislav Mar 28, 2023
93586d8
hw: Add option to set number of VDF proof threads
rostislav Mar 29, 2023
d38fcee
hw: Add option to list available devices
rostislav Mar 29, 2023
ca8cacf
hw: Fix usage of CS_ACTIVE_NEGTIVE which has been changed in libftd2xx
rostislav Mar 30, 2023
5cd9850
hw: Set default board voltage to 0.88 V as intended by design
rostislav Mar 31, 2023
8b93d49
hw: Print average iters per intermediate value when stopping
rostislav Mar 31, 2023
45c6409
hw: Allow enabling individual VDF engines with a mask argument
rostislav Apr 6, 2023
dcc74d2
hw: Increase max number of VDF aux threads to 28
rostislav Apr 7, 2023
0f6bc25
hw: Add more documentation on hardware VDF client
rostislav Apr 7, 2023
ffb966b
hw: Add constants for default ASIC frequency and voltage
rostislav Apr 28, 2023
429aa0e
hw: Send all log messages to stderr
rostislav May 2, 2023
14ffa4f
hw: Add timestamps to log messages
rostislav May 3, 2023
2e12b3e
hw: Fix inconsistent newlines in log output
rostislav May 4, 2023
b840531
hw: Fix incorrect logic for queueing proof requests
rostislav May 10, 2023
b410636
hw: Use a large enough type for busy aux threads mask
rostislav May 11, 2023
8942918
hw: Remove unneeded checkpoint proofs from queue when possible
rostislav May 15, 2023
33acbe9
hw: Change to 'integer' objects in 'struct vdf_state'
rostislav May 24, 2023
494fa48
hw: Remove timestamps from startup error messages
rostislav May 25, 2023
e7acd73
Merge remote-tracking branch 'origin/main' into hw_vdf
rostislav May 30, 2023
326687d
Testing build in CI
cmmarslender May 30, 2023
edccfaa
Try w/ ${{ github.workspace }}
cmmarslender May 30, 2023
9f06cb0
Add the libft4222.so to the artifacts
cmmarslender May 30, 2023
93997a1
Build a .deb
cmmarslender May 30, 2023
b07a3f0
Fix path to copy .so to
cmmarslender May 30, 2023
8890677
Try simplified build
cmmarslender May 30, 2023
0083e1b
Add symlink to .so
cmmarslender May 30, 2023
ee0ba28
Add the USB permissions for all users
cmmarslender May 31, 2023
9b82b15
Mkdir
cmmarslender May 31, 2023
563b432
Try an always numerical sha version
cmmarslender May 31, 2023
2a5001b
Use run ID for an always incrementing version number
cmmarslender May 31, 2023
f173d2c
Add parallel prover with 2 threads
rostislav Jun 12, 2023
10bd761
hw: Update proof segment sizes for parallel prover
rostislav Jun 13, 2023
ea18012
Also build the debs on hw_vdf for now
cmmarslender Jun 13, 2023
6d8bdbd
hw: Limit maximum number of segments in VDF proofs to 64
rostislav Jun 22, 2023
07a1b12
hw: Increase maximum iteration count to 2 billion
rostislav Jun 23, 2023
ad098e8
hw: Gracefully shutdown VDF client after receiving SIGTERM
rostislav Jun 28, 2023
a6d469e
hw: Fix access to proofs array without a lock
rostislav Jun 29, 2023
24ee15c
Allow external linking of form::check_valid()
rostislav Jun 29, 2023
621f183
hw: Avoid extra memory allocation in prepare_job()
rostislav Jun 29, 2023
faea774
Allow external linking of ParallelProver::GenerateProof()
rostislav Jun 30, 2023
0cc3246
hw: Fix memory leak in 'struct job_state'
rostislav Jun 30, 2023
5726af0
hw: Fix memory leaks in hw_vdf_client
rostislav Jul 1, 2023
ff6e50f
hw: Try reconnecting to timelord until connection is successful
rostislav Jul 10, 2023
dc5e33e
hw: Log timelord port when connecting to it
rostislav Jul 11, 2023
b17a712
hw: Add milliseconds to timestamps in logs
rostislav Jul 11, 2023
90e1fa8
hw: Allocate extra array of intermediate values to avoid race condition
rostislav Jul 14, 2023
ca1897a
hw: Allow up to 64 auxiliary threads
rostislav Jul 21, 2023
ca68c4b
hw: Do not crash if hardware is not present or initialization fails
rostislav Jul 28, 2023
8bbd7b3
hw: Fix memory leak in hw_main after hardware initialization failure
rostislav Jul 28, 2023
85b4515
hw: Handle unexpected disconnection to timelord in VDF client
rostislav Aug 2, 2023
1a98791
hw: Cleanup emulator code
rostislav Aug 11, 2023
74a8c69
hw: Add error injection to emulator
rostislav Aug 11, 2023
808bd1c
hw: Cleanup trailing whitespace
rostislav Aug 11, 2023
26a5801
hw: Gracefully handle bad VDF values received from hardware
rostislav Aug 17, 2023
28d8ef4
hw: Fix zero division error when retrieved VDF value has a=0
rostislav Aug 17, 2023
c49084d
hw: Clean up unused declarations
rostislav Aug 26, 2023
90e2c72
hw: Decrease PLL frequency after encountering hardware errors
rostislav Aug 29, 2023
9ee5026
hw: Remove duplicate PLL frequencies
rostislav Aug 29, 2023
24f087b
hw: Validate --auto-freq-period option, update VDF client's usage text
rostislav Aug 29, 2023
ae29a14
hw: Add PLL registers to emulator
rostislav Sep 5, 2023
f8ee738
hw: Log ASIC frequency together with temperature
rostislav Sep 5, 2023
a27d342
Rename libftd2xx -> libft4222
rostislav Sep 6, 2023
68c99aa
Rename hw_main -> hw_test
rostislav Sep 6, 2023
af9de8d
Add release specific logic to publish debs to releases
cmmarslender Sep 6, 2023
4160bd4
hw: Change defaults in hw_test to 3 VDF engines and 10^6 iterations
rostislav Sep 6, 2023
5538e32
Replace tabs with spaces to keep consistent style
rostislav Sep 6, 2023
a4612b6
Add new README_ASIC.md, remove old hw/readme.txt
rostislav Sep 6, 2023
4669dd0
hw: Handle multiple repeating iteration counts as a hardware error
rostislav Sep 7, 2023
c3f3825
hw: Increase PLL frequency after running without errors for N seconds
rostislav Sep 8, 2023
51b5b3b
hw: Reset device when setting PLL frequency during HW initialization
rostislav Sep 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .github/workflows/hw-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: HW Build

on:
push:
branches:
- main
release:
types: [published]
pull_request:
branches:
- '**'
workflow_dispatch:

concurrency:
# SHA is added to the end if on `main` to let all main workflows run
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/heads/long_lived/')) && github.sha || '' }}
cancel-in-progress: true

permissions:
contents: write

jobs:
build-hw:
name: Build HW VDF Client
runs-on: [ubuntu-latest]
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set Env
uses: Chia-Network/actions/setjobenv@main
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install deps
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake libgmp-dev libboost-system-dev

- name: Download USB drivers
run: |
mkdir libft4222
cd libft4222
wget https://download.chia.net/vdf/libft4222-linux-1.4.4.170.tgz
tar -xvzf libft4222-linux-1.4.4.170.tgz
ln -s ${{ github.workspace }}/libft4222 ${{ github.workspace }}/src/hw/libft4222
ln -s ${{ github.workspace }}/libft4222/build-x86_64/libft4222.so.1.4.4.170 ${{ github.workspace }}/libft4222/build-x86_64/libft4222.so

- name: Compile
working-directory: "${{ github.workspace }}/src"
run: make -f Makefile.vdf-client emu_hw_test hw_test emu_hw_vdf_client hw_vdf_client

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: hw-vdf
path: |
${{ github.workspace }}/src/emu_hw_test
${{ github.workspace }}/src/hw_test
${{ github.workspace }}/src/hw_vdf_client
${{ github.workspace }}/src/emu_hw_vdf_client
${{ github.workspace }}/src/hw/libft4222/build-x86_64/libft4222.so

- name: Assemble .deb
env:
INSTALLER_VERSION: "${{ env.RELEASE_TAG || format('0.0.1-{0}', github.run_id) }}"
PLATFORM: "amd64"
run: |
pip install j2cli
CLI_DEB_BASE="chiavdf-hw_$INSTALLER_VERSION-1_$PLATFORM"
mkdir -p "dist/$CLI_DEB_BASE/usr/bin"
mkdir -p "dist/$CLI_DEB_BASE/usr/lib"
mkdir -p "dist/$CLI_DEB_BASE/DEBIAN"
mkdir -p "dist/$CLI_DEB_BASE/etc/udev/rules.d"
j2 -o "dist/$CLI_DEB_BASE/DEBIAN/control" assets/deb/control.j2

cp ${{ github.workspace }}/src/emu_hw_test dist/$CLI_DEB_BASE/usr/bin/
cp ${{ github.workspace }}/src/hw_test dist/$CLI_DEB_BASE/usr/bin/
cp ${{ github.workspace }}/src/hw_vdf_client dist/$CLI_DEB_BASE/usr/bin/
cp ${{ github.workspace }}/src/emu_hw_vdf_client dist/$CLI_DEB_BASE/usr/bin/
cp ${{ github.workspace }}/src/hw/libft4222/build-x86_64/libft4222.so dist/$CLI_DEB_BASE/usr/lib/
echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="601c", MODE="0666"' > dist/$CLI_DEB_BASE/etc/udev/rules.d/99-chiavdf.rules
dpkg-deb --build --root-owner-group "dist/$CLI_DEB_BASE"

echo "DEB_NAME=$CLI_DEB_BASE.deb" >> $GITHUB_ENV

- name: Upload Installer
uses: actions/upload-artifact@v3
with:
name: installer
path: |
${{ github.workspace }}/dist/${{ env.DEB_NAME }}

- name: Upload release artifacts
if: env.RELEASE == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload \
$RELEASE_TAG \
dist/${{ env.DEB_NAME }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ src/vdf_client
src/1weso_test
src/2weso_test
src/prover_test
src/emu_hw_test
src/hw_test
src/emu_hw_vdf_client
src/hw_vdf_client
/verifier
/verifier_test
/build/*
Expand All @@ -33,6 +37,9 @@ src/prover_test
*.o
*.s

# external library
/src/hw/libft4222

# pyenv
.python-version
.eggs
Expand Down
76 changes: 76 additions & 0 deletions README_ASIC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# ASIC timelord user guide

## Initial setup

Download and unpack LibFT4222 library:
```bash
# in chiavdf directory
wget https://ftdichip.com/wp-content/uploads/2022/06/libft4222-linux-1.4.4.170.tgz
mkdir src/hw/libft4222
tar -C src/hw/libft4222 -xf libft4222-linux-1.4.4.170.tgz
ln -s libft4222.so.1.4.4.170 src/hw/libft4222/build-x86_64/libft4222.so
```

Build binaries:
```bash
cd src
make -f Makefile.vdf-client emu_hw_test hw_test emu_hw_vdf_client hw_vdf_client
```

Connect the Chia VDF ASIC device and verify that it is detected:
```bash
# in chiavdf/src/ directory
LD_LIBRARY_PATH=hw/libft4222/build-x86_64 ./hw_vdf_client --list
```

If the device is shown in the list, check if it's working:
```bash
LD_LIBRARY_PATH=hw/libft4222/build-x86_64 ./hw_test
```

Output should contain lines similar to the following:
```
VDF 0: 1000000 HW iters done in 2s, HW speed: 714720 ips
```

## Running

You should have a Chia full node running and synced.

Start timelord (but not timelord-launcher) in chia-blockchain:
```bash
chia start timelord-only
```

Start hardware VDF client (`8000` specifies timelord's port number):
```bash
# in chiavdf/src/ directory
LD_LIBRARY_PATH=hw/libft4222/build-x86_64 ./hw_vdf_client 8000
```

The VDF client accepts a number of options:
```
Usage: ./hw_vdf_client [OPTIONS] PORT [N_VDFS]
List of options [default, min - max]:
--freq N - set ASIC frequency [1100, 200 - 2200]
--voltage N - set board voltage [0.88, 0.7 - 1.0]
--ip A.B.C.D - timelord IP address [localhost]
Allows connecting to a timelord running on a remote host. Useful when running multiple machines with VDF hardware connecting to a single timelord.
--vdfs-mask N - mask for enabling VDF engines [7, 1 - 7]
The ASIC has 3 VDF engines numbered 0, 1, 2. If not running all 3 engines, the mask can be specified to enable specific engines. It must be the result of bitwise OR of the engine bits (1, 2, 4 for engines 0, 1, 2).
--vdf-threads N - number of software threads per VDF engine [4, 2 - 64]
Number of software threads computing intermediate values and proofs per VDF engine.
--proof-threads N - number of proof threads per VDF engine
Number of software threads only computing proofs per VDF engine. Must be less than --vdf-threads.
--auto-freq-period N - auto-adjust frequency every N seconds [0, 10 - inf]
--list - list available devices and exit
```

## Shutting down

Stop timelord:
```bash
chia stop timelord-only
```

Stop the VDF client by pressing Control-C or killing the process with `SIGTERM`.
6 changes: 6 additions & 0 deletions assets/deb/control.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Package: chiavdf-hw
Version: {{ INSTALLER_VERSION }}
Architecture: {{ PLATFORM }}
Maintainer: Chia Network Inc <[email protected]>
Description: Hardware VDF Client
Depends: libgmp-dev, libboost-system-dev
31 changes: 25 additions & 6 deletions src/Makefile.vdf-client
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ else
NOPIE = -no-pie
endif

LDFLAGS += -flto $(NOPIE)
LDFLAGS += -flto $(NOPIE) -g
LDLIBS += -lgmpxx -lgmp -lboost_system -pthread
CXXFLAGS += -flto -std=c++1z -D VDF_MODE=0 -D FAST_MACHINE=1 -pthread $(NOPIE) -fvisibility=hidden
ifeq ($(UNAME),Darwin)
CXXFLAGS += -D CHIAOSX=1
endif

OPT_CFLAGS = -O3
OPT_CFLAGS = -O3 -g

ifneq ($(ASAN),)
LDFLAGS += -fsanitize=address -fsanitize=undefined
Expand All @@ -27,15 +27,16 @@ endif

.PHONY: all clean

all: vdf_client prover_test 1weso_test 2weso_test vdf_bench
BINS = vdf_client prover_test 1weso_test 2weso_test vdf_bench
all: $(BINS)

clean:
rm -f *.o vdf_client prover_test 1weso_test 2weso_test compile_asm vdf_bench
rm -f *.o hw/*.o $(BINS) compile_asm emu_hw_test hw_test hw_vdf_client emu_hw_vdf_client

vdf_client vdf_bench prover_test 1weso_test 2weso_test avx512_test: %: %.o lzcnt.o asm_compiled.o avx2_asm_compiled.o avx512_asm_compiled.o
$(BINS) avx512_test: %: %.o lzcnt.o asm_compiled.o avx2_asm_compiled.o avx512_asm_compiled.o
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

vdf_client.o vdf_bench.o prover_test.o 1weso_test.o 2weso_test.o avx512_test.o: CXXFLAGS += $(OPT_CFLAGS)
$(addsuffix .o,$(BINS)) avx512_test.o: CXXFLAGS += $(OPT_CFLAGS)

lzcnt.o: refcode/lzcnt.c
$(CC) -c refcode/lzcnt.c
Expand All @@ -51,3 +52,21 @@ avx512_asm_compiled.s: compile_asm

compile_asm: compile_asm.o
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

HW_OBJS = $(addprefix hw/,hw_util.o hw_proof.o hw_interface.o chia_driver.o ftdi_driver.o vdf_driver.o pll_freqs.o) vdf_base.o lzcnt.o
EMU_OBJS = hw/emu_funcs.o hw/emu_runner.o
HW_LIB = hw/libft4222/build-x86_64/libft4222.so

hw_test: hw/hw_test.o $(HW_OBJS) $(HW_LIB) hw/real_hw.o
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

emu_hw_test: hw/hw_test.o $(HW_OBJS) $(EMU_OBJS)
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

hw_vdf_client: hw/hw_vdf_client.o $(HW_OBJS) $(HW_LIB) hw/real_hw.o
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

emu_hw_vdf_client: hw/hw_vdf_client.o $(HW_OBJS) $(EMU_OBJS)
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

hw/hw_test.o hw/hw_vdf_client.o $(HW_OBJS) $(EMU_OBJS): CXXFLAGS += -I. -Ihw -Ihw/libft4222 $(OPT_CFLAGS) -Wall
4 changes: 2 additions & 2 deletions src/Reducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class alignas(64) Reducer {
/**
* @brief run - runs reduction algorithm for cg context params
*/
inline void run() {
void run() {
while (!isReduced()) {
int_fast64_t a, b, c;
{
Expand Down Expand Up @@ -229,7 +229,7 @@ bool bLZCHasHW=false;

// The condition (abs(v_) | abs(x_)) <= THRESH protects against
// overflow
below_threshold = (abs(v_) | abs(x_)) <= THRESH ? 1 : 0;
below_threshold = (labs(v_) | labs(x_)) <= THRESH ? 1 : 0;
} while (below_threshold && a > c && c > 0);

if (below_threshold) {
Expand Down
2 changes: 1 addition & 1 deletion src/bqfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ enum BQFC_FLAGS {
*/
int bqfc_serialize_only(uint8_t *out_str, const struct qfb_c *c, size_t d_bits)
{
size_t offset, bytes, size, g_size;
size_t offset, g_size;

d_bits = (d_bits + 31) & ~(size_t)31;

Expand Down
2 changes: 1 addition & 1 deletion src/bqfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ int bqfc_serialize_only(uint8_t *out_str, const struct qfb_c *c, size_t d_bits);
int bqfc_deserialize_only(struct qfb_c *out_c, const uint8_t *str, size_t d_bits);

int bqfc_serialize(uint8_t *out_str, mpz_t a, mpz_t b, size_t d_bits);
int bqfc_deserialize(mpz_t out_a, mpz_t out_b, const mpz_t D, const uint8_t *str, size_t d_bits);
int bqfc_deserialize(mpz_t out_a, mpz_t out_b, const mpz_t D, const uint8_t *str, size_t size, size_t d_bits);

#endif // BQFC_H
39 changes: 39 additions & 0 deletions src/hw/chia_driver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "chia_driver.hpp"

void ChiaDriver::SerializeJob(uint8_t *buf,
uint32_t job_id,
uint64_t iteration_count,
mpz_t a,
mpz_t f,
mpz_t d,
mpz_t l) {
size_t offset = 0;
const size_t reg_size = REG_BYTES;
offset += write_bytes(reg_size, offset, buf, job_id);
offset += write_bytes(2 * reg_size, offset, buf, iteration_count);
offset += write_bytes(reg_size * CHIA_VDF_CMD_A_MULTIREG_COUNT,
offset, buf, a, NUM_2X_COEFFS);
offset += write_bytes(reg_size * CHIA_VDF_CMD_F_MULTIREG_COUNT,
offset, buf, f, NUM_2X_COEFFS);
offset += write_bytes(reg_size * CHIA_VDF_CMD_D_MULTIREG_COUNT,
offset, buf, d, NUM_4X_COEFFS);
offset += write_bytes(reg_size * CHIA_VDF_CMD_L_MULTIREG_COUNT,
offset, buf, l, NUM_1X_COEFFS);
// The last word is 0x1 to start the job
offset += write_bytes(reg_size, offset, buf, (uint32_t)0x1);
}

void ChiaDriver::DeserializeJob(uint8_t *buf,
uint32_t &job_id,
uint64_t &iteration_count,
mpz_t a,
mpz_t f) {
size_t offset = 0;
const size_t reg_size = REG_BYTES;
offset += read_bytes(reg_size, offset, buf, job_id);
offset += read_bytes(2 * reg_size, offset, buf, iteration_count);
offset += read_bytes(reg_size * CHIA_VDF_STATUS_A_MULTIREG_COUNT,
offset, buf, a, NUM_2X_COEFFS);
offset += read_bytes(reg_size * CHIA_VDF_STATUS_F_MULTIREG_COUNT,
offset, buf, f, NUM_2X_COEFFS);
}
44 changes: 44 additions & 0 deletions src/hw/chia_driver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef CHIA_DRIVER_HPP
#define CHIA_DRIVER_HPP

#include <gmp.h>

#include "vdf_driver.hpp"
#include "chia_registers.hpp"

class ChiaDriver : public VdfDriver {
public:
const static unsigned NUM_1X_COEFFS = 18;
const static unsigned NUM_2X_COEFFS = 34;
const static unsigned NUM_3X_COEFFS = 52;
const static unsigned NUM_4X_COEFFS = 68;

ChiaDriver() :
VdfDriver(16 /*WORD_BITS*/, 19 /*REDUNDANT_BITS*/, true) {
}

virtual size_t CmdSize() {
return (CHIA_VDF_CMD_START_REG_OFFSET -
CHIA_VDF_CMD_JOB_ID_REG_OFFSET + REG_BYTES);
}

virtual size_t StatusSize() {
return (CHIA_VDF_STATUS_END_REG_OFFSET -
CHIA_VDF_STATUS_ITER_0_REG_OFFSET);
}

void SerializeJob(uint8_t *buf,
uint32_t job_id,
uint64_t iteration_count,
mpz_t a,
mpz_t f,
mpz_t d,
mpz_t l);

void DeserializeJob(uint8_t *buf,
uint32_t &job_id,
uint64_t &iteration_count,
mpz_t a,
mpz_t f);
};
#endif
Loading
Loading