pub async fn dispatch_mining_batch(
ctx: &GpuContext,
batch: &MiningBatch<'_>,
) -> Result<Vec<MineResult>, GpuError>Expand description
Dispatch a mining batch on the GPU and return all matching nonces found.
Examples found in repository?
examples/bench.rs (line 26)
14async fn bench_batch(ctx: &GpuContext, batch_size: u32) -> Result<BenchSample, GpuError> {
15 let batch = MiningBatch {
16 tx_prefix: b"bench-prefix",
17 tx_suffix: b"bench-suffix",
18 start_nonce: START_NONCE,
19 batch_size,
20 target_zeros: 64, // effectively impossible target; keeps the kernel busy
21 use_cbor_nonce: false,
22 };
23
24 let start = Instant::now();
25 // Ignore results; we only care about throughput.
26 let _ = dispatch_mining_batch(ctx, &batch).await?;
27 let elapsed = start.elapsed().as_secs_f64().max(1e-9);
28
29 Ok(BenchSample {
30 elapsed_ms: elapsed * 1_000.0,
31 hashes_per_sec: batch_size as f64 / elapsed,
32 })
33}
34
35async fn memory_pressure_check(ctx: &GpuContext, batch_size: u32) -> Result<(), GpuError> {
36 // Use large buffers to validate allocation/dispatch under heavier pressure.
37 let blob = vec![0u8; 512 * 1024];
38 for i in 0..3 {
39 let batch = MiningBatch {
40 tx_prefix: &blob,
41 tx_suffix: &blob,
42 start_nonce: START_NONCE + (i as u64) * batch_size as u64,
43 batch_size,
44 target_zeros: 64,
45 use_cbor_nonce: false,
46 };
47 let _ = dispatch_mining_batch(ctx, &batch).await?;
48 }
49 Ok(())
50}