brotensor/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
5 / 5
100.0%
Branches:
-
-%
Functions:
2 / 4
50.0%

src/jit/trace_contract.h
Line Branch Exec Source
1 #pragma once
2
3 // Synthesizes brass GpuKernelContract descriptors for Vulkan trace-JIT kernels
4 // (ElementwisePlan and RowNormPlan), formally verifies emitted SPIR-V against
5 // those contracts to issue GpuProofReceipts, and validates runtime bind args.
6
7 #include "spirv_emit.h"
8
9 #include <brass/verify/gpu_kernel_prover.hpp>
10 #include <brass/verify/gpu_proof_receipt.hpp>
11
12 #include <cstdint>
13 #include <span>
14 #include <string>
15
16 namespace brotensor::jit::spirv {
17
18 6 struct TraceProofResult {
19 6 bool proven = false;
20 brass::verify::GpuProofReceipt receipt;
21 std::string diagnostic;
22 };
23
24 2 struct TraceTuneResult {
25 1 bool tuned = false;
26 brass::target::SpirvKernel spirv;
27 brass::verify::GpuProofReceipt receipt;
28 std::string winning_candidate;
29 1 double winning_cost = 0.0;
30 std::string diagnostic;
31 };
32
33 brass::verify::GpuKernelContract build_elementwise_contract(
34 const plan::ElementwisePlan& plan,
35 int lanes);
36
37 brass::verify::GpuKernelContract build_row_norm_contract(
38 const plan::RowNormPlan& plan,
39 int lanes);
40
41 TraceProofResult verify_and_issue_trace_receipt(
42 const brass::target::SpirvKernel& kernel,
43 const brass::verify::GpuKernelContract& contract);
44
45 TraceTuneResult tune_elementwise_spirv_verified(
46 const TraceDAG& dag,
47 const plan::ElementwisePlan& plan,
48 int lanes);
49
50 bool validate_trace_bind_args(
51 const brass::verify::GpuKernelContract& contract,
52 std::span<const uint64_t> out_addrs,
53 std::span<const uint64_t> in_addrs,
54 std::span<const uint64_t> out_bytes,
55 std::span<const uint64_t> in_bytes,
56 const uint32_t* slot_count,
57 std::string* err_out = nullptr);
58
59 } // namespace brotensor::jit::spirv
60