PyRAML测量功耗

PyRAML测量功耗

total_pkg_energy = 0
    total_dram_energy = 0
    count = 0
    for i in range(repetitions):
        measure = pyRAPL.Measurement('bar')
        with measure:
            with torch.no_grad():
                _ = model(input_ids=inputs['input_ids'])
        pkg_energy = measure.result.pkg
        dram_energy = measure.result.dram
        if pkg_energy[0] > 0 or pkg_energy[1]> 0:
            count += 1
            total_pkg_energy += pkg_energy[0] + pkg_energy[1]
            total_dram_energy += dram_energy[0] + dram_energy[1]
            
    average_pkg_energy = total_pkg_energy / count
    average_dram_energy = total_dram_energy / count
    average_total_energy = (total_pkg_energy + total_dram_energy) / count
    print(f"pkh energy: {average_pkg_energy / 1e6:.4f} Joules")
    print(f"dram energy: {average_dram_energy  / 1e6:.4f} Joules")
    print(f"total energy: {average_total_energy / 1e6:.4f} Joules")

posted @ 2024-10-01 20:23  信海  阅读(9)  评论(0编辑  收藏  举报