Exemplo n.º 1
0
def plot_risk():
    """
        plot a two dimensional slack surface
    """
    mua, vra, pra = pgen.get_pdf(plot=False, write=False)
    deadline = ptsl.D

    a1 = range(1, 17)
    a2 = range(1, 17)
    shape = (len(a1), len(a2))
    X, Y = meshgrid(a1, a2)
    Z1 = np.full(shape, -1.0)  # Risk Power Surface
    Z2 = np.full(shape, -1.0)  # Peak Power Surface

    for x in a1:
        for y in a2:
            mu = mua[x - 1] + mua[y - 1]
            vr = vra[x - 1] + vra[y - 1]

            dist = stats.norm(loc=mu, scale=np.sqrt(vr))
            risk = dist.sf(deadline)

            Z1[x - 1, y - 1] = risk
            Z2[x - 1, y - 1] = np.max([pra[x - 1], pra[y - 1]])

    fig = plt.figure()
    ax = fig.gca(projection='3d')
    surf = ax.plot_surface(X,
                           Y,
                           Z1,
                           rstride=1,
                           cstride=1,
                           cmap=cm.Greys,
                           linewidth=0,
                           antialiased=False)
    ax.set_xlabel("alloc ph1")
    ax.set_ylabel("alloc ph2")
    ax.set_zlabel("Risk")
    fig.colorbar(surf, shrink=0.5, aspect=5)
    plt.savefig("risk-surface.pdf", bbox_inches='tight')
    plt.close()

    fig = plt.figure()
    ax = fig.gca(projection='3d')
    surf = ax.plot_surface(X,
                           Y,
                           Z2,
                           rstride=1,
                           cstride=1,
                           cmap=cm.Greys_r,
                           linewidth=0,
                           antialiased=False)
    ax.set_xlabel("alloc ph1")
    ax.set_ylabel("alloc ph2")
    ax.set_zlabel("peak power")
    # print(ax.azim)
    ax.view_init(azim=-30)
    fig.colorbar(surf, shrink=0.5, aspect=5)
    plt.savefig("pkp-surface.pdf", bbox_inches='tight')
    plt.close()
Exemplo n.º 2
0
def evaluate_all_points():
    """
        Assuming NPH = 5
    """
    start_time = timeit.default_timer()
    mua, vra = pgen.get_pdf()
    slack = ptsl.D

    all_alloc = list(itertools.product(range(1, ptsl.M + 1), repeat=ptsl.NPH))
    riska = []
    f2 = open("risk-file-D216-NPH5.csv", "w")
    f2.write("alloc1,alloc2,alloc3,alloc4,alloc5,risk,util\n")
    count = 0
    for a in all_alloc:
        a1, a2, a3, a4, a5 = a
        r = compute_risk(mua, vra, a, slack)

        if r > 0.00001 and r < 1 - 0.00001:
            riska.append(r)
            util = a1 * mua[a1 - 1] + a2 * mua[a2 - 1] + a3 * mua[
                a3 - 1] + a4 * mua[a4 - 1] + a5 * mua[a5 - 1]
            f2.write("%d,%d,%d,%d,%d,%f,%f\n" % (a1, a2, a3, a4, a5, r, util))
            count = count + 1
    f2.close()
    np.save("stored_risk", riska)
    elapsed = timeit.default_timer() - start_time
    print("Brute Force Evaluation Time for %d points : %fs" % (count, elapsed))
Exemplo n.º 3
0
def main():
    # Load the Source Distribution
    mua, vra = pgen.get_pdf()

    # Creating the allocation vector
    alloc = list(itertools.product(range(1, 17), repeat=ptsl.NPH))
    slack = ptsl.D
    #print(alloc)

    risk = []
    n = 1
    alloc2 = alloc
    alloc2.reverse()
    for a in alloc2:
        mu = 0
        var = 0
        for sa in a:
            mu = mu + mua[sa - 1]
            var = var + vra[sa - 1]
        dist = stats.norm(loc=mu, scale=np.sqrt(var))
        r = dist.sf(slack)

        # Store only if risk is below a threshold
        if r < 1 - 1e-5:
            print("complete allocation %d," % n + " alloc : " + str(a) +
                  ",risk %f" % r)
            print("mu : %f, std : %f" % (mu, np.sqrt(var)))
            print("\n")
            risk.append(r)
        # else :
        #     print("complete allocation %d,"%n+" alloc : "+str(a))

        n = n + 1

    #risk2 = [r2 for r2 in risk if r2 < 0.999]
    # Histogram
    plt.hist(risk)
    np.save("dmr-saved", risk)
    plt.savefig("dmr-hist.pdf")
Exemplo n.º 4
0
def execute_1_ue(ns,dmr2,constrain=False,expshrink=False,introduce_slack=True):
    """ Main Execution program """

    # Generate a list of input
    dmr = dmr2 
    num_subframes = ns
    crnti1 = 2386
    crnti2 = 9983
    crnti3 = 9128
    crnti4 = 4451
    ue_list1 = [dummy_ue(i,dmr,crnti1) for i in range(0,num_subframes)]
    ue_list2 = [] #[dummy_ue(i,dmr,crnti2) for i in range(0,num_subframes)]
    ue_list3 = [] #[dummy_ue(i,dmr,crnti3) for i in range(0,num_subframes)]
    ue_list4 = [] #[dummy_ue(i,dmr,crnti4) for i in range(0,num_subframes)]
    
    ue_list  = ue_list1 + ue_list2 + ue_list3 + ue_list4
    heapq.heapify(ue_list)

    # Initialize the state variables
    NZ          = 100*num_subframes
    s           = np.zeros(NZ) # Start of n-th phase (irrespective of the UE/SF)
    f           = np.zeros(NZ) # Finish of the n-th phase
    m           = [0 for i in range(NZ)] # Total cores busy at beginning of time step n
    d           = [0 for i in range(NZ)] # demanded cores for the n-th phase
    a           = [0 for i in range(NZ)] # Allocated cores at beginning of time step n
    u           = [0 for i in range(NZ)] # Available/Free Cores 
    u[0]        = ptsl.M
    infq        = queue.Queue(maxsize=0) # Stores the number of computations that are inflight
    
    # Construct the distributions (For now assume all phases are balanced)
    marray,varray     = pgen.get_pdf()
    distarry          = pgen.gen_hist(ptsl.NUMBINS)
    approx2           = []
    for idx in range(len(marray)) :
        approx2.append(stats.norm(loc=marray[idx],scale=np.sqrt(varray[idx])))
    print("Offline Profiling Complete\n\n")
    
  

    # "Global" Variables, whose state is maintained across subframe instances
    start_time  = timeit.default_timer()
    missed1      = 0
    missed2      = 0
    missed3      = 0
    missed4      = 0
    n            = 0   # The n-th phase
    while len(ue_list) > 0:
        ue = heapq.heappop(ue_list)

        # Execute
        if expshrink :
            ins_slack, d[n] = ue.get_demand(marray,varray,introduce_slack)
        else :
            d[n] = 11 # Statically Allocate the cores
            ins_slack = 0
        s[n] = ue.get_curr_tick()
        m[n] = 0

        
        # Constrain the number of cores available
        num_inflight = infq.qsize()
        
        # Compute the number of inflight instructions
        while num_inflight > 0:
            f2,a2 = infq.get(block=False)
            if (s[n] <= f2) :
                m[n] = m[n] + a2   # Decrement the number of available cores
                infq.put((f2,a2))
            num_inflight = num_inflight-1
    
        # The number of cores that are free
        u[n]    = ptsl.M - m[n] + ue.alloc 

        # Cap the number of demanded cores to the total available (in a constrained system)
        if constrain :
            if not expshrink :
                if d[n] > u[n] :
                    a[n] = 0      # No cores to be allocated when demand is greater than is available
                else :
                    a[n] = d[n]
            else :
                a[n] = np.min([d[n],u[n]])
        else :
            a[n] = d[n]    

        # print("UE(%d,%d,%d) - d[%d]:%d,u[%d]:%d,m[%d]:%d,a[%d]:%d,ue_alloc:%d"%(ue.subframe,ue.crnti,ue.state,n,d[n],n,u[n],n,m[n],n,a[n],ue.alloc))
        try :
            
            #_,f[n]  = ue.execute(a[n],distarry[a[n]-1])  #distarry is zero indexed
            if ins_slack == 0 :
                _,f[n]  = ue.execute(a[n],ptsl.NW,approx2[a[n]-1])
            else :
                _,f[n]  = ue.execute(a[n],ins_slack,approx2[a[n]-1])

        except IndexError :
            print("n:%d,a[n]:%d,NZ:%d"%(n,a[n],NZ))
            exit
        infq.put((f[n],a[n])) # Enque the (potentially) inflight computation
        # print("UE(%d,%d,%d) - s[%d]:%f,f[%d]:%f,a[%d]:%d,ue_alloc:%d"%(ue.subframe,ue.crnti,ue.state,n,s[n],n,f[n],n,a[n],ue.alloc))
        # print("\n")

        # Store it back or discard it.
        if (ue.state == ptsl.NPH or ue.state == -1):
            if (ue.state == -1):
                if ue.crnti == crnti1 :
                    missed1 = missed1 + 1
                elif ue.crnti == crnti2 :
                    missed2 = missed2 + 1
                elif ue.crnti == crnti3 :
                    missed3 = missed3 + 1
                if ue.crnti == crnti4 :
                    missed4 = missed4 + 1
        
            print(ue)
            print("-------------------------------------")
            print("\n\n\n")
        else :
            heapq.heappush(ue_list,ue)
        n = n+1
    
    elapsed = timeit.default_timer() - start_time
    print("\n")
    print("Simulation Time : %fs,DMR-App1(observed) : %f"%(elapsed,missed1/num_subframes))
    # print("Simulation Time : %fs,DMR-App2(observed) : %f"%(elapsed,missed2/num_subframes))
    # print("Simulation Time : %fs,DMR-App3(observed) : %f"%(elapsed,missed3/num_subframes))
    # print("Simulation Time : %fs,DMR-App4(observed) : %f"%(elapsed,missed4/num_subframes))
    odmr = missed1/num_subframes
    return (s,f,m,n,a,odmr,a[n-1])
Exemplo n.º 5
0
import ptss_utils as ptsl
import ptss_synthpdf as psyn
import ptss_dfspdf as pgen
import ptss_risksteepness as porc
import heapq
import queue
import timeit
from pprint import pprint
import itertools
from pylab import meshgrid
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
from scipy import stats
import pandas as pd

mua, vra, _ = pgen.get_pdf()


def alg4():
    """
        Find an allocation using 
        greedy state-space search
        as discussed on 03/12/2018
    """
    greedyalloc = [1, 1]
    dmrexp = 0.30
    deadline = ptsl.D

    greedyutil = 1.0
    minutil = 1.0