import json, platform, time

def main():
    result={"project":"ALERUNO EffectProof — AMD Runtime Probe","machine":platform.machine(),"rocm_available":False,"device":"UNKNOWN","runs":0,"avg_latency_ms":None,"truth_boundary":"No AMD/ROCm execution is claimed unless the runtime detects ROCm/HIP."}
    try:
        import torch
        hip=getattr(torch.version,"hip",None)
        result["torch_version"]=torch.__version__
        result["rocm_version"]=hip
        result["rocm_available"]=bool(hip and torch.cuda.is_available())
        result["device"]="AMD_ROCM" if result["rocm_available"] else "CPU_OR_NON_ROCM"
        dev="cuda" if result["rocm_available"] else "cpu"
        x=torch.randn(256,256,device=dev); y=torch.randn(256,256,device=dev)
        for _ in range(10): _=x@y
        if result["rocm_available"]: torch.cuda.synchronize()
        n=100; t=time.perf_counter()
        for _ in range(n): _=x@y
        if result["rocm_available"]: torch.cuda.synchronize()
        result["runs"]=n; result["avg_latency_ms"]=(time.perf_counter()-t)*1000/n
    except Exception as e:
        result["error"]=repr(e)
    print(json.dumps(result,indent=2))
    open("AMD_RUNTIME_RECEIPT.json","w").write(json.dumps(result,indent=2))

if __name__=="__main__": main()
