Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ batchdep: build/.supraseal-install
batchdep: $(BUILD_DEPS)
.PHONY: batchdep

batch: CURIO_TAGS+= supraseal
batch: CURIO_TAGS+= supraseal_nvme
batch: CGO_LDFLAGS_ALLOW='.*'
batch: batchdep batch-build
.PHONY: batch


batch-calibnet: CURIO_TAGS+= supraseal
batch-calibnet: CURIO_TAGS+= supraseal_nvme
batch-calibnet: CURIO_TAGS+= calibnet
batch-calibnet: CGO_LDFLAGS_ALLOW='.*'
batch-calibnet: batchdep batch-build
Expand Down
69 changes: 69 additions & 0 deletions cmd/curio/batch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package main

import (
"fmt"

"github.com/urfave/cli/v2"
"golang.org/x/xerrors"

"github.com/filecoin-project/curio/cmd/curio/internal/translations"
"github.com/filecoin-project/curio/lib/supraffi"
)

var batchCmd = &cli.Command{
Name: "batch",
Usage: translations.T("Manage batch sealing operations"),
Subcommands: []*cli.Command{
batchSetupCmd,
},
}

var batchSetupCmd = &cli.Command{
Name: "setup",
Usage: translations.T("Setup SPDK for batch sealing (configures hugepages and binds NVMe devices)"),
Description: translations.T(`Setup SPDK for batch sealing operations.

This command automatically:
- Downloads SPDK if not already available
- Configures 1GB hugepages (36 pages minimum)
- Binds NVMe devices for use with SupraSeal

Requires root/sudo access for SPDK setup operations.`),
Flags: []cli.Flag{
&cli.IntFlag{
Name: "hugepages",
Usage: translations.T("Number of 1GB hugepages to configure"),
Value: 36,
},
&cli.IntFlag{
Name: "min-pages",
Usage: translations.T("Minimum number of hugepages required"),
Value: 36,
},
},
Action: func(cctx *cli.Context) error {
nrHuge := cctx.Int("hugepages")
minPages := cctx.Int("min-pages")

fmt.Println("Setting up SPDK for batch sealing...")
fmt.Printf("Configuring %d hugepages (minimum required: %d)\n", nrHuge, minPages)

err := supraffi.CheckAndSetupSPDK(nrHuge, minPages)
if err != nil {
return xerrors.Errorf("SPDK setup failed: %w\n\n"+
"Please ensure you have:\n"+
"1. Root/sudo access for SPDK setup\n"+
"2. Raw NVMe devices available (no filesystems on them)\n"+
"3. Sufficient hugepages configured (see documentation)", err)
}

fmt.Println("✓ SPDK setup completed successfully")
fmt.Println("\nNext steps:")
fmt.Println("1. Verify hugepages: cat /proc/meminfo | grep Huge")
fmt.Println("2. Configure your batch sealing layer (see documentation)")
fmt.Println("3. Start batch sealing operations")

return nil
},
}

1 change: 1 addition & 0 deletions cmd/curio/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func main() {
ffiCmd,
calcCmd,
toolboxCmd,
batchCmd,
}

jaeger := tracing.SetupJaegerTracing("curio")
Expand Down
26 changes: 23 additions & 3 deletions documentation/en/supraseal.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,33 @@ The build should be run on the target machine. Binaries won't be portable betwee

### Setup NVMe devices for SPDK:

{% hint style="info" %}
This is only needed while batch sealing is in beta, future versions of Curio will handle this automatically.
{% hint style="success" %}
SPDK setup can be done automatically using the Curio CLI command:
{% endhint %}

```bash
sudo curio batch setup
```

This command will:
- Download SPDK if not already available
- Configure 1GB hugepages (36 pages by default)
- Bind NVMe devices for use with SupraSeal

You can customize the number of hugepages:

```bash
sudo curio batch setup --hugepages 36 --min-pages 36
```

Alternatively, if you need to manually check SPDK status or unbind devices, you can use:

```bash
cd extern/supraseal/deps/spdk-v24.05/
env NRHUGE=36 ./scripts/setup.sh
# Check status
sudo ./scripts/setup.sh status
# Manually run setup (not normally needed)
sudo env NRHUGE=36 ./scripts/setup.sh
```

### Benchmark NVME IOPS
Expand Down
26 changes: 23 additions & 3 deletions documentation/zh/supraseal.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,33 @@ Hugepagesize: 1048576 kB
### Setup NVMe devices for SPDK:
### 为SPDK设置NVMe设备:

{% hint style="info" %}
这只在批量密封处于测试阶段时需要,Curio的未来版本将自动处理这个问题。
{% hint style="success" %}
可以使用 Curio CLI 命令自动完成 SPDK 设置:
{% endhint %}

```bash
sudo curio batch setup
```

此命令将:
- 如果尚未可用,则下载 SPDK
- 配置 1GB 大页面(默认 36 页)
- 绑定 NVMe 设备以供 SupraSeal 使用

您可以自定义大页面数量:

```bash
sudo curio batch setup --hugepages 36 --min-pages 36
```

或者,如果您需要手动检查 SPDK 状态或解绑设备,可以使用:

```bash
cd extern/supraseal/deps/spdk-v24.05/
env NRHUGE=36 ./scripts/setup.sh
# 检查状态
sudo ./scripts/setup.sh status
# 手动运行设置(通常不需要)
sudo env NRHUGE=36 ./scripts/setup.sh
```


Expand Down
2 changes: 1 addition & 1 deletion extern/supraseal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ During the build process it will clone and build SPDK, sppark, and blst.
./build.sh
```

SPDK must be setup after every reboot:
SPDK setup is automatic when using Curio's batch sealer.
```
cd deps/spdk-v24.05
sudo env NRHUGE=36 ./scripts/setup.sh
Expand Down
91 changes: 36 additions & 55 deletions extern/supraseal/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ CXXSTD=`$CXX -dM -E -x c++ /dev/null | \

INCLUDE="-I$SPDK/include -I$SPDK/isa-l/.. -I$SPDK/dpdk/build/include"
CFLAGS="$SECTOR_SIZE $INCLUDE -g -O2"
CXXFLAGS="$CFLAGS -march=native $CXXSTD \
# Use x86-64-v3 CPU flags to match GOAMD64=v3 requirement (equivalent to Intel Haswell/AMD Excavator+)
# GCC multiversioning will provide CPU-specific optimizations at runtime
CXXFLAGS="$CFLAGS -march=x86-64-v3 -mtune=generic $CXXSTD \
-fPIC -fno-omit-frame-pointer -fno-strict-aliasing \
-fstack-protector -fno-common \
-D_GNU_SOURCE -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 \
Expand Down Expand Up @@ -275,33 +277,38 @@ if [ ! -d "deps/blst" ]; then
git clone https://github.com/supranational/blst.git deps/blst
(cd deps/blst
git checkout bef14ca512ea575aff6f661fdad794263938795d
./build.sh -march=native)
./build.sh -march=x86-64-v3)
fi

$CC -c sha/sha_ext_mbx2.S -o obj/sha_ext_mbx2.o

# Generate .h files for the Poseidon constants
xxd -i poseidon/constants/constants_2 > obj/constants_2.h
xxd -i poseidon/constants/constants_4 > obj/constants_4.h
xxd -i poseidon/constants/constants_8 > obj/constants_8.h
xxd -i poseidon/constants/constants_11 > obj/constants_11.h
xxd -i poseidon/constants/constants_16 > obj/constants_16.h
xxd -i poseidon/constants/constants_24 > obj/constants_24.h
xxd -i poseidon/constants/constants_36 > obj/constants_36.h
# Generate .h files for the Poseidon constants (needed for tree_r binaries)
# These are fast and can run in parallel, but must complete before tree_r binaries compile
xxd -i poseidon/constants/constants_2 > obj/constants_2.h &
xxd -i poseidon/constants/constants_4 > obj/constants_4.h &
xxd -i poseidon/constants/constants_8 > obj/constants_8.h &
xxd -i poseidon/constants/constants_11 > obj/constants_11.h &
xxd -i poseidon/constants/constants_16 > obj/constants_16.h &
xxd -i poseidon/constants/constants_24 > obj/constants_24.h &
xxd -i poseidon/constants/constants_36 > obj/constants_36.h &

# Compile all object files in parallel - these are independent of constants headers
# SHA extension code with x86-64-v3 flags to match GOAMD64=v3
# The code uses SHA-NI instructions which are available on Intel Haswell+ and AMD Zen+
# Runtime will detect CPU capabilities and use appropriate version
$CC -c -march=x86-64-v3 -mtune=generic sha/sha_ext_mbx2.S -o obj/sha_ext_mbx2.o &
# Compile multiversion wrapper for CPU-specific optimizations
$CXX $CXXFLAGS -Ideps/blst/src -c sha/sha_ext_mbx2_wrapper.cpp -o obj/sha_ext_mbx2_wrapper.o &

# PC1
$CXX $CXXFLAGS -Ideps/sppark/util -o obj/pc1.o -c pc1/pc1.cpp &

# PC2
# PC2 - compile once with unified interface supporting both NVMe and FileReader
$CXX $CXXFLAGS -o obj/streaming_node_reader_nvme.o -c nvme/streaming_node_reader_nvme.cpp &
$CXX $CXXFLAGS -o obj/ring_t.o -c nvme/ring_t.cpp &
$NVCC $CFLAGS $CUDA_ARCH -std=c++17 -DNO_SPDK -Xcompiler -march=native \
# Single compilation of pc2.cu - works with both reader types via template interface
$NVCC $CFLAGS $CUDA_ARCH -std=c++17 -DNO_SPDK \
-Xcompiler -march=x86-64-v3,-mtune=generic \
-Xcompiler -Wall,-Wextra,-Wno-subobject-linkage,-Wno-unused-parameter \
-Ideps/sppark -Ideps/sppark/util -Ideps/blst/src -c pc2/cuda/pc2.cu -o obj/pc2.o &
# File-reader variant of pc2 for tree_r_file
$NVCC $CFLAGS $CUDA_ARCH -std=c++17 -DNO_SPDK -DSTREAMING_NODE_READER_FILES -DRENAME_PC2_HASH_FILES -Xcompiler -march=native \
-Xcompiler -Wall,-Wextra,-Wno-subobject-linkage,-Wno-unused-parameter \
-Ideps/sppark -Ideps/sppark/util -Ideps/blst/src -c pc2/cuda/pc2.cu -o obj/pc2_files.o &

$CXX $CXXFLAGS $INCLUDE -Iposeidon -Ideps/sppark -Ideps/sppark/util -Ideps/blst/src \
-c sealing/supra_seal.cpp -o obj/supra_seal.o -Wno-subobject-linkage &
Expand All @@ -311,74 +318,48 @@ $CXX $CXXFLAGS $INCLUDE -DSTREAMING_NODE_READER_FILES -Iposeidon -Ideps/sppark -

wait

# Sppark object dedupe
nm obj/pc2.o | grep -E 'select_gpu|all_gpus|cuda_available|gpu_props|ngpus|drop_gpu_ptr_t|clone_gpu_ptr_t' | awk '{print $3 " supra_" $3}' > symbol_rename.txt
nm obj/pc2_files.o | grep -E 'select_gpu|all_gpus|cuda_available|gpu_props|ngpus|drop_gpu_ptr_t|clone_gpu_ptr_t' | awk '{print $3 " supra_" $3}' >> symbol_rename.txt
# Deduplicate symbol rename entries
sort -u -o symbol_rename.txt symbol_rename.txt

for obj in obj/pc1.o obj/pc2.o obj/pc2_files.o obj/ring_t.o obj/streaming_node_reader_nvme.o obj/supra_seal.o obj/supra_tree_r_file.o obj/sha_ext_mbx2.o; do
objcopy --redefine-syms=symbol_rename.txt $obj
done

# Weaken duplicate symbols between pc2.o and pc2_files.o to avoid multiple-definition at link time
nm -g --defined-only obj/pc2.o | awk '{print $3}' | sort -u > obj/syms_pc2.txt
nm -g --defined-only obj/pc2_files.o | awk '{print $3}' | sort -u > obj/syms_pc2_files.txt
comm -12 obj/syms_pc2.txt obj/syms_pc2_files.txt | grep -v '^pc2_hash_files' > obj/syms_dups.txt
if [ -s obj/syms_dups.txt ]; then
while read -r sym; do
objcopy --weaken-symbol="$sym" obj/pc2_files.o
done < obj/syms_dups.txt
fi

rm symbol_rename.txt

# All object files and constants headers are now ready
ar rvs obj/libsupraseal.a \
obj/pc1.o \
obj/pc2.o \
obj/pc2_files.o \
obj/ring_t.o \
obj/streaming_node_reader_nvme.o \
obj/supra_seal.o \
obj/supra_tree_r_file.o \
obj/sha_ext_mbx2.o
obj/sha_ext_mbx2.o \
obj/sha_ext_mbx2_wrapper.o

# Build binaries in parallel
# Note: tree_r binaries compile poseidon.cpp which includes constants_*.h files
# These are guaranteed to be ready after the wait above
$CXX $CXXFLAGS -Ideps/sppark -Ideps/sppark/util -Ideps/blst/src \
-o bin/seal demos/main.cpp \
-Lobj -lsupraseal \
$LDFLAGS -Ldeps/blst -lblst -L$CUDA/lib64 -lcudart_static -lgmp -lconfig++ &

# tree-r CPU only
$CXX $SECTOR_SIZE $CXXSTD -pthread -g -O3 -march=native \
# tree-r CPU only (uses poseidon.cpp which includes constants_*.h)
$CXX $SECTOR_SIZE $CXXSTD -pthread -g -O3 -march=x86-64-v3 -mtune=generic \
-Wall -Wextra -Werror -Wno-subobject-linkage \
tools/tree_r.cpp poseidon/poseidon.cpp \
-o bin/tree_r_cpu -Iposeidon -Ideps/sppark -Ideps/blst/src -L deps/blst -lblst &

# tree-r CPU + GPU
$NVCC $SECTOR_SIZE -DNO_SPDK -DSTREAMING_NODE_READER_FILES \
$CUDA_ARCH -std=c++17 -g -O3 -Xcompiler -march=native \
$CUDA_ARCH -std=c++17 -g -O3 -Xcompiler -march=x86-64-v3,-mtune=generic \
-Xcompiler -Wall,-Wextra,-Werror \
-Xcompiler -Wno-subobject-linkage,-Wno-unused-parameter \
-x cu tools/tree_r.cpp -o bin/tree_r \
-Iposeidon -Ideps/sppark -Ideps/sppark/util -Ideps/blst/src -L deps/blst -lblst -lconfig++ &

# tree-d CPU only
$CXX -DRUNTIME_SECTOR_SIZE $CXXSTD -g -O3 -march=native \
$CXX -DRUNTIME_SECTOR_SIZE $CXXSTD -g -O3 -march=x86-64-v3 -mtune=generic \
-Wall -Wextra -Werror -Wno-subobject-linkage \
tools/tree_d.cpp \
-o bin/tree_d_cpu -Ipc1 -L deps/blst -lblst &

# Standalone GPU pc2
$NVCC $SECTOR_SIZE -DNO_SPDK -DSTREAMING_NODE_READER_FILES \
$CUDA_ARCH -std=c++17 -g -O3 -Xcompiler -march=native \
-Xcompiler -Wall,-Wextra,-Werror \
-Xcompiler -Wno-subobject-linkage,-Wno-unused-parameter \
-x cu tools/tree_r.cpp -o bin/tree_r \
-Iposeidon -Ideps/sppark -Ideps/sppark/util -Ideps/blst/src -L deps/blst -lblst -lconfig++ &

# Standalone GPU pc2
$NVCC $SECTOR_SIZE -DNO_SPDK -DSTREAMING_NODE_READER_FILES \
$CUDA_ARCH -std=c++17 -g -O3 -Xcompiler -march=native \
$CUDA_ARCH -std=c++17 -g -O3 -Xcompiler -march=x86-64-v3,-mtune=generic \
-Xcompiler -Wall,-Wextra,-Werror \
-Xcompiler -Wno-subobject-linkage,-Wno-unused-parameter \
-x cu tools/pc2.cu -o bin/pc2 \
Expand Down
Loading
Loading