Commit a40adb2f authored by niwinkle's avatar niwinkle
Browse files

Delete flop_calc.py

parent 60b97bb4
import numpy as np
import matplotlib.pyplot as plt
# functions return a tuple containing (adds and subs, mults, divs)
def calc_flops_matmul(n, m, p):
return (n * m * p, n * m * p, 0)
def calc_flops_trsv(n, diagonal_is_one=False):
return (n * (n - 1) / 2, n * (n - 1) / 2, 0 if diagonal_is_one else n)
def calc_flops_trsm(n, m, diagonal_is_one=False):
return (m * n * (n - 1) / 2, m * n * (n - 1) / 2, m * (0 if diagonal_is_one else n))
def calc_lu_simple(n):
return (n*(1-3*n+2*n*n) / 6, n*(1-3*n+2*n*n) / 6, n*(n - 1) / 2)
def calc_lu_blocked(n, block_size):
if (n <= block_size): return calc_lu_simple(n)
a00 = calc_lu_simple(block_size)
a01 = calc_flops_trsm(block_size, n - block_size, diagonal_is_one=True)
a10 = calc_flops_trsm(block_size, n - block_size)
a11 = calc_flops_matmul(n - block_size, block_size, n - block_size)
rest = calc_lu_blocked(n - block_size, block_size)
return tuple(np.array(a00) + a01 + a10 + a11 + rest)
def print_info(n, gigaflops_per_second, actual_seconds, bandwidth, datatype_size=8):
fneed = calc_lu_simple(n)
flops = gigaflops_per_second * 1_000_000_000
needed_seconds = (fneed[0] + fneed[1] + fneed[2]) / flops
data_size = n * n * datatype_size
operational_intensity = (fneed[0] + fneed[1] + fneed[2]) / data_size
print("lu decomposition of a " + str(n) + "x" + str(n) + " matrix needs " + str(fneed) + " flops")
print("lu decomposition of a " + str(n) + "x" + str(n) + " matrix takes at least " + str(needed_seconds) + " seconds on a " + str(gigaflops_per_second) + " gigaflops machine")
achieved_flops = (fneed[0] + fneed[1] + fneed[2]) / (actual_seconds * flops)
print("achieved performance: " + str(achieved_flops))
#plt.plot([operational_intensity], [gigaflops_per_second], 'ro')
plt.plot([operational_intensity], [achieved_flops], 'ro')
plt.plot([1, 512], [gigaflops_per_second, gigaflops_per_second], lw=1)
plt.plot([1, 512], [1 * flops / bandwidth, 512 * flops / bandwidth], lw=1)
plt.xlabel("FLOPS/byte")
plt.ylabel("GFLOPS")
plt.xscale("log", basex=2)
plt.yscale("log", basey=2)
plt.show()
print_info(4096, 8, 9, 8_000_000_000)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment