Beispiel #1
0
    def __init__(self, model_defs, finish_reward=100, dim_size=6,n_action_steps=2, resource_size=2,  dataflow="dla"):
        super(MaestroEnvironment,self).__init__()
        dst_path = "../../cost_model/maestro"

        maestro = dst_path
        self._executable = "{}".format(maestro)
        random_file_name = random.randint(0, 2 ** 31)
        self.random_file_name = "{}".format(random_file_name)


        global action_space, action_bound, action_bottom
        action_space, action_bound, action_bottom = get_action_space()
        self.state = np.array([0.5]*8)
        self.last_runtime = 2 ** 64
        self.last_energy = 2**64
        self.last_throughput = 1
        self.observation = [0,0, 0,0,0,0]
        self.resource_state = [0, 0]
        self.consecutive_fail = 0
        self.max_fail = 0
        self.total_resources = action_bound
        self.action_bound = action_bound[:n_action_steps]
        self.total_step = len(model_defs)
        self.model_defs = model_defs
        self.model_defs_saved = copy.deepcopy(model_defs)
        model_bound = np.max(model_defs, axis=0, keepdims=True)
        self.model_defs_norm = model_defs/model_bound
        self.model_defs_norm_saved = copy.deepcopy(self.model_defs_norm)
        self.best_reward_whole = float("-inf")
        self.best_rewards = []
        self.best_sol = None
        self.reward = 0
        self.mae_reward = 0
        self.finish_reward = finish_reward
        self.mae_reward_decay = 0.
        self.worst_reward = None
        self.best_reward = None
        self.reward_scale = 0
        self.n_action_steps = n_action_steps
        self.emptyinfo =  [-1] * (len(self.observation) + len(self.resource_state))
        self.resource_size = resource_size
        self.reward_whole_eps = 0
        self.dim_size = dim_size
        self.reward_rec = []
        self.min_reward = None
        self.running_ave_reward = None
        self.worst_reward_list = [None for _ in range(self.total_step)]

        self.sig = 1
        self.mac_rec = []
        self.epoch = 0
        self.sol_record = []
        self.sol_reward_record = []
        self.dataflow = dataflow
        self.constraint_value = 2**63
        self.constraint = "area"
        self.prev_reward_whole_eps = 0
        self.exp_table = {}
        self.draw = np.arange(0, self.total_step)
        self.is_gemm = False
Beispiel #2
0
    os.makedirs(outdir_exp, exist_ok=True)
    chkpt_file_t = os.path.join(outdir_exp, "{}".format("result"))

    outfile = chkpt_file_t + "_o.plt"
    chkpt_file = chkpt_file_t + "_c.plt"
    img_file = chkpt_file_t + ".png"
    log_file = chkpt_file_t + ".csv"
    expLog_file = chkpt_file_t + ".log"
    m_file_path = "../../data/model/"
    m_file = os.path.join(m_file_path, opt.model + ".csv")
    df = pd.read_csv(m_file)
    model_defs = df.to_numpy()
    _, dim_size = model_defs.shape
    # fd = open(expLog_file, "w")

    action_space, action_bound, action_bottom = get_action_space()
    env = MaestroEnvironment(model_defs=model_defs,
                             dim_size=dim_size,
                             dataflow=opt.df)
    env.set_fitness(opt.fitness)
    env.set_constraint(opt.cstr)
    constraint_temp = [
        env.get_ref_constraint([action_bound[0], action_bound[1]]),
        env.get_ref_constraint([action_bottom[0], action_bottom[1]]),
        env.get_ref_constraint([action_bound[0], action_bottom[1]]),
        env.get_ref_constraint([action_bottom[0], action_bound[1]])
    ]
    max_constraint, min_constraint = max(constraint_temp), min(constraint_temp)
    print("Max constraint: {}".format(max_constraint))
    print("Min constraint: {}".format(min_constraint))
    set_constraint = min_constraint + (max_constraint - min_constraint) * ratio
    def __init__(self,
                 model_defs,
                 finish_reward=100,
                 dim_size=6,
                 n_action_steps=2,
                 resource_size=2,
                 dataflow="dla",
                 is_discrete=True,
                 true_continuous=False,
                 chkpt_file="./chkpt.plt"):
        super(MaestroEnvironment, self).__init__()
        dst_path = "../../cost_model/maestro"

        maestro = dst_path
        self._executable = "{}".format(maestro)
        random.seed()
        random_file_name = random.randint(0, 2**31)
        self.random_file_name = "{}".format(random_file_name)

        self.chkpt_file = chkpt_file
        self.is_gemm = False
        global action_space, action_bound, action_bottom
        action_space, action_bound, action_bottom = get_action_space()
        self.action_bottom = action_bound
        self.state = np.array([0.5] * 8)
        self.last_runtime = 2**64
        self.last_energy = 2**64
        self.last_throughput = 1
        self.observation = [0, 0, 0, 0, 0, 0]
        self.resource_state = [0, 0]
        self.consecutive_fail = 0
        self.max_fail = 0
        self.total_resources = action_bound
        self.action_bound = action_bound[:n_action_steps]
        self.total_step = len(model_defs)
        self.model_defs = model_defs
        self.model_defs_saved = copy.deepcopy(model_defs)
        model_bound = np.max(model_defs, axis=0, keepdims=True)
        self.model_defs_norm = model_defs / model_bound
        self.model_defs_norm_saved = copy.deepcopy(self.model_defs_norm)
        self.best_reward_whole = float("-inf")
        self.best_rewards = []
        self.best_sol = None
        self.reward = 0
        self.mae_reward = 0
        self.finish_reward = finish_reward
        self.mae_reward_decay = 0.
        self.worst_reward = None
        self.best_reward = None
        self.reward_scale = 0
        self.n_action_steps = n_action_steps
        self.emptyinfo = [-1] * (len(self.observation) +
                                 len(self.resource_state))
        self.resource_size = resource_size
        self.reward_whole_eps = 0
        self.dim_size = dim_size
        self.reward_rec = []
        self.min_reward = None
        self.running_ave_reward = None
        self.worst_reward_list = [None for _ in range(self.total_step)]
        self.sig = 1
        self.mac_rec = []

        self.epoch = 0
        self.sol_record = []
        self.sol_reward_record = []
        self.dataflow = dataflow
        self.constraint_value = 2**63
        self.constraint = "area"
        self.prev_reward_whole_eps = 0
        self.exp_table = {}
        self.draw = np.arange(0, self.total_step)
        self.is_discrete = is_discrete
        self.true_contiunous = true_continuous and not is_discrete
        self.state_size = len(self.model_defs_norm[0]) + 3
        if self.is_discrete:
            self.N_DISCRETE_ACTIONS = len(action_space[0])
            self.action_space = spaces.MultiDiscrete(
                [self.N_DISCRETE_ACTIONS, self.N_DISCRETE_ACTIONS])

        else:
            self.action_space = spaces.Box(low=0,
                                           high=1,
                                           shape=(self.n_action_steps, ),
                                           dtype=np.float32)
        self.observation_space = spaces.Box(low=0,
                                            high=1,
                                            shape=(self.state_size, ),
                                            dtype=np.float32)
        self.metadata = {'render.modes': []}
        self.reward_range = (-float('inf'), float('inf'))
        self.resources_denorm = np.zeros((self.resource_size, ))