|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/fatih/color" |
| 7 | + "github.com/urfave/cli/v2" |
| 8 | + |
| 9 | + "github.com/filecoin-project/curio/tasks/sealsupra" |
| 10 | +) |
| 11 | + |
| 12 | +var calcCmd = &cli.Command{ |
| 13 | + Name: "calc", |
| 14 | + Usage: "Math Utils", |
| 15 | + Flags: []cli.Flag{ |
| 16 | + &cli.StringFlag{ |
| 17 | + Name: "actor", |
| 18 | + }, |
| 19 | + }, |
| 20 | + Subcommands: []*cli.Command{ |
| 21 | + calcBatchCpuCmd, |
| 22 | + calcSuprasealConfigCmd, |
| 23 | + }, |
| 24 | +} |
| 25 | + |
| 26 | +var calcBatchCpuCmd = &cli.Command{ |
| 27 | + Name: "batch-cpu", |
| 28 | + Usage: "Analyze and display the layout of batch sealer threads", |
| 29 | + Description: `Analyze and display the layout of batch sealer threads on your CPU. |
| 30 | +
|
| 31 | +It provides detailed information about CPU utilization for batch sealing operations, including core allocation, thread |
| 32 | +distribution for different batch sizes.`, |
| 33 | + Flags: []cli.Flag{ |
| 34 | + &cli.BoolFlag{Name: "dual-hashers", Value: true}, |
| 35 | + }, |
| 36 | + Action: func(cctx *cli.Context) error { |
| 37 | + info, err := sealsupra.GetSystemInfo() |
| 38 | + if err != nil { |
| 39 | + return err |
| 40 | + } |
| 41 | + |
| 42 | + fmt.Println("Basic CPU Information") |
| 43 | + fmt.Println("") |
| 44 | + fmt.Printf("Processor count: %d\n", info.ProcessorCount) |
| 45 | + fmt.Printf("Core count: %d\n", info.CoreCount) |
| 46 | + fmt.Printf("Thread count: %d\n", info.CoreCount*info.ThreadsPerCore) |
| 47 | + fmt.Printf("Threads per core: %d\n", info.ThreadsPerCore) |
| 48 | + fmt.Printf("Cores per L3 cache (CCX): %d\n", info.CoresPerL3) |
| 49 | + fmt.Printf("L3 cache count (CCX count): %d\n", info.CoreCount/info.CoresPerL3) |
| 50 | + |
| 51 | + ccxFreeCores := info.CoresPerL3 - 1 // one core per ccx goes to the coordinator |
| 52 | + ccxFreeThreads := ccxFreeCores * info.ThreadsPerCore |
| 53 | + fmt.Printf("Hasher Threads per CCX: %d\n", ccxFreeThreads) |
| 54 | + |
| 55 | + sectorsPerThread := 1 |
| 56 | + if cctx.Bool("dual-hashers") { |
| 57 | + sectorsPerThread = 2 |
| 58 | + } |
| 59 | + |
| 60 | + sectorsPerCCX := ccxFreeThreads * sectorsPerThread |
| 61 | + fmt.Printf("Sectors per CCX: %d\n", sectorsPerCCX) |
| 62 | + |
| 63 | + fmt.Println("---------") |
| 64 | + |
| 65 | + printForBatchSize := func(batchSize int) { |
| 66 | + fmt.Printf("Batch Size: %s sectors\n", color.CyanString("%d", batchSize)) |
| 67 | + fmt.Println() |
| 68 | + |
| 69 | + config, err := sealsupra.GenerateSupraSealConfig(*info, cctx.Bool("dual-hashers"), batchSize, nil) |
| 70 | + if err != nil { |
| 71 | + fmt.Printf("Error generating config: %s\n", err) |
| 72 | + return |
| 73 | + } |
| 74 | + |
| 75 | + fmt.Printf("Required Threads: %d\n", config.RequiredThreads) |
| 76 | + fmt.Printf("Required CCX: %d\n", config.RequiredCCX) |
| 77 | + fmt.Printf("Required Cores: %d hasher (+4 minimum for non-hashers)\n", config.RequiredCores) |
| 78 | + |
| 79 | + enoughCores := config.RequiredCores <= info.CoreCount |
| 80 | + if enoughCores { |
| 81 | + fmt.Printf("Enough cores available for hashers %s\n", color.GreenString("✔")) |
| 82 | + } else { |
| 83 | + fmt.Printf("Not enough cores available for hashers %s\n", color.RedString("✘")) |
| 84 | + return |
| 85 | + } |
| 86 | + |
| 87 | + fmt.Printf("Non-hasher cores: %d\n", info.CoreCount-config.RequiredCores) |
| 88 | + |
| 89 | + if config.P2WrRdOverlap { |
| 90 | + color.Yellow("! P2 writer will share a core with P2 reader, performance may be impacted") |
| 91 | + } |
| 92 | + if config.P2HsP1WrOverlap { |
| 93 | + color.Yellow("! P2 hasher will share a core with P1 writer, performance may be impacted") |
| 94 | + } |
| 95 | + if config.P2HcP2RdOverlap { |
| 96 | + color.Yellow("! P2 hasher_cpu will share a core with P2 reader, performance may be impacted") |
| 97 | + } |
| 98 | + |
| 99 | + fmt.Println() |
| 100 | + fmt.Printf("pc1 writer: %d\n", config.Topology.PC1Writer) |
| 101 | + fmt.Printf("pc1 reader: %d\n", config.Topology.PC1Reader) |
| 102 | + fmt.Printf("pc1 orchestrator: %d\n", config.Topology.PC1Orchestrator) |
| 103 | + fmt.Println() |
| 104 | + fmt.Printf("pc2 reader: %d\n", config.Topology.PC2Reader) |
| 105 | + fmt.Printf("pc2 hasher: %d\n", config.Topology.PC2Hasher) |
| 106 | + fmt.Printf("pc2 hasher_cpu: %d\n", config.Topology.PC2HasherCPU) |
| 107 | + fmt.Printf("pc2 writer: %d\n", config.Topology.PC2Writer) |
| 108 | + fmt.Printf("pc2 writer_cores: %d\n", config.Topology.PC2WriterCores) |
| 109 | + fmt.Println() |
| 110 | + fmt.Printf("c1 reader: %d\n", config.Topology.C1Reader) |
| 111 | + fmt.Println() |
| 112 | + |
| 113 | + fmt.Printf("Unoccupied Cores: %d\n\n", config.UnoccupiedCores) |
| 114 | + |
| 115 | + fmt.Println("{") |
| 116 | + fmt.Printf(" sectors = %d;\n", batchSize) |
| 117 | + fmt.Println(" coordinators = (") |
| 118 | + for i, coord := range config.Topology.SectorConfigs[0].Coordinators { |
| 119 | + fmt.Printf(" { core = %d;\n hashers = %d; }", coord.Core, coord.Hashers) |
| 120 | + if i < len(config.Topology.SectorConfigs[0].Coordinators)-1 { |
| 121 | + fmt.Println(",") |
| 122 | + } else { |
| 123 | + fmt.Println() |
| 124 | + } |
| 125 | + } |
| 126 | + fmt.Println(" )") |
| 127 | + fmt.Println("}") |
| 128 | + |
| 129 | + fmt.Println("---------") |
| 130 | + } |
| 131 | + |
| 132 | + printForBatchSize(16) |
| 133 | + printForBatchSize(32) |
| 134 | + printForBatchSize(64) |
| 135 | + printForBatchSize(128) |
| 136 | + |
| 137 | + return nil |
| 138 | + }, |
| 139 | +} |
| 140 | + |
| 141 | +var calcSuprasealConfigCmd = &cli.Command{ |
| 142 | + Name: "supraseal-config", |
| 143 | + Usage: "Generate a supra_seal configuration", |
| 144 | + Description: `Generate a supra_seal configuration for a given batch size. |
| 145 | +
|
| 146 | +This command outputs a configuration expected by SupraSeal. Main purpose of this command is for debugging and testing. |
| 147 | +The config can be used directly with SupraSeal binaries to test it without involving Curio.`, |
| 148 | + Flags: []cli.Flag{ |
| 149 | + &cli.BoolFlag{ |
| 150 | + Name: "dual-hashers", |
| 151 | + Value: true, |
| 152 | + Usage: "Zen3 and later supports two sectors per thread, set to false for older CPUs", |
| 153 | + }, |
| 154 | + &cli.IntFlag{ |
| 155 | + Name: "batch-size", |
| 156 | + Aliases: []string{"b"}, |
| 157 | + Required: true, |
| 158 | + }, |
| 159 | + }, |
| 160 | + Action: func(cctx *cli.Context) error { |
| 161 | + cstr, err := sealsupra.GenerateSupraSealConfigString(cctx.Bool("dual-hashers"), cctx.Int("batch-size"), nil) |
| 162 | + if err != nil { |
| 163 | + return err |
| 164 | + } |
| 165 | + |
| 166 | + fmt.Println(cstr) |
| 167 | + return nil |
| 168 | + }, |
| 169 | +} |
0 commit comments