当前位置: 首页 > 工具软件 > PISA > 使用案例 >

PISA 架构芯片资源排布问题算法实现II

霍永年
2023-12-01

剪枝之后,我们可以根据控制依赖关系得到一个初始的层级,我们记为floor。例如,终点为floor的第一层,由终点生成的前继节点为floor的第二层,以此类推。

按照题意,仅满足控制依赖关系是可以放在同层的,因此我们不妨先将所有的节点放在同一层。然后再根据数据依赖关系和资源约束关系对节点的层级进行调整。调整后的层级我们记为cellar。例如,floor的第二层中有某个元素Q与它在第一层中的后继节点P有数据依赖关系,且必须调整层级,下放一层,若P在cellar的100层,则Q需要放到cellar的99层,以此类推。

另外,由于生成所有floor后,再根据数据依赖和资源约束关系对floor总体排cellar会非常不方便,所以我们调整算法,每生成一次floor,就生成一次cellar。

以解决问题1为例:

##算法实现

%generate cellar and solve problem1
cellar = 607;       %设初始cellar层为607层(因为共有607个节点,最多也只会有607个流水级层数)
for i=3:total_floor
    [IFMT,preIDs,alpha,SIZE]=generate_pID(IFMT,alpha,i,G,preIDs,SIZE);      %generate floor
    [preIDs,number]=d_re_1(i,preIDs,number);            %delete repetition
    [A]=WandR_cellar(A,i,preIDs,IFMT,B);                %solve cellar by Write&Read
    [A]=THAQ_cellarI(A,i,preIDs,IFMT,B);                %solve cellar by THAQ resource1
end

#WandR_cellar

%Cellars which need to ADjust(AD) or donot need to ADjust(DAD)
Q = [];
DAD = [];
for t=1:20000
    if preIDs(which_floor,t)~=0
        q = preIDs(which_floor,t);
        Q = [Q,q];
    end
end
sigma = size(Q,2);
delta = size(AD,2);
for a=1:sigma
    for b=1:delta
        if Q(1,a)~=AD(1,b)
            dad = Q(1,a);
            DAD = [DAD,dad];
        end
    end
end

%Solve Cellar
beta = size(DAD,2);
for c=1:beta
    e = DAD(1,c);
    A(e,1) = Cel;
end
for d=1:delta
    f = AD(1,d);
    Cel = CL(1,d);
    A(f,1) = Cel-1;
end

#THAQ_cellar

function [A]=THAQ_cellarI(A,which_floor,preIDs,IFMT,B)
    [total_T,total_H,total_A,total_Q] = cal_total(A,cellar);
    [resR1,resR2,resR3,resR4,A]=restrict1(total_T,total_H,total_A,total_Q);
end

#cal_total

function [total_T,total_H,total_A,total_Q] = cal_total(A,cellar)
P = [];
for i=1:607
    if A(i,1)==96
        P = [P,i];
    end
end
beta = size(P,2);
    total_T = 0;
    total_H = 0;
    total_A = 0;
    total_Q = 0;
for i=1:beta
    p =  P(1,i);
    total_T = total_T+A(p,15);
    total_H = total_H+A(p,16);
    total_A = total_A+A(p,17);
    total_Q = total_Q+A(p,18);
end

#restrict1

function [resR1,resR2,resR3,resR4]=restrict1(total_T,total_H,total_A,total_Q)
if total_T<=1
    resR1 = 1;
else
    resR1 = 0;
    fprint('TCAM isnot satisfied\n');
end
if total_H<=2
    resR2 = 1;
else
    resR2 = 0;
    fprint('HASH isnot satisfied\n');
end
if total_A<=56
    resR3 = 1;
else
    resR3 = 0;
    fprint('ALU isnot satisfied\n');
end
if total_Q<=64
    resR4 = 1;
else
    resR4 = 0;
    fprint('QUALIFY isnot satisfied\n');
end
end

分享就到这里了~欢迎补充和指正~

 类似资料: