sq_approach_faster.py 2.37 KB
Newer Older
harry1080ti's avatar
harry1080ti committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from multiprocessing import Pool
from os import cpu_count

import path_constant as pc
import cma_approach_square_size as ap

nets = [
    'FasterRCNN', 
    'mobilenet',
    'yolo_tiny',
    'googlenet',
    'alexnet',
    'AlphaGoZero',
    'ncf_rec',
    'resnet_50_v1']

layers = [
    46, 27, 10, 58, 8, 8, 8, 53
]

max_partitions = [
    23, 14, 9, 29, 8, 8, 8, 27, 13
]

max_res_sizes = [
    1920*9*1, 1920*9*2, 1920*9*3
]

pop_size = [
    100, 200, 500
]

targets = [
    'DRAM_cycle', 'Cycles'
]

seedings = [
    'allzeros', 'allzeros'
]

MAX_TRIAL = 20

def trial(prop):
    trials = 1
    n, part, pop, tar, res, seed = prop
LongChan's avatar
LongChan committed
46
    print(prop)
harry1080ti's avatar
harry1080ti committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    instance = ap.cma_approach(
        path_to_datasrc = n+"_square_mem_bound.csv",
        path_to_topology = n+".csv",
        target_col = tar,

        number_of_partition = part, max_iteration = 10000,
        sigma = 0.5, population_size = pop,

        max_res_unit = res, initial_res = 0,
        res_step = 3,
        penalty_offest = 100000000000,
        seeding_type = seed,
        hybird = True,
        print_to_csv = False
    )

harry1080ti's avatar
harry1080ti committed
63
    process_out = instance.run()
harry1080ti's avatar
harry1080ti committed
64
65
    success, out = instance.report()
    while not success and trials < MAX_TRIAL:
harry1080ti's avatar
harry1080ti committed
66
        process_out = instance.run()
harry1080ti's avatar
harry1080ti committed
67
68
        success, out = instance.report()
        trials += 1
harry1080ti's avatar
harry1080ti committed
69
    process_out.append(out)
LongChan's avatar
LongChan committed
70
    return process_out
harry1080ti's avatar
harry1080ti committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

    topology = sys.argv[1]
    k = int(sys.argv[2])
    population_size = int(sys.argv[3])
    max_res_unit = int(sys.argv[4])
    seeding_type = sys.argv[5]
    target_col = sys.argv[6]

if __name__ == "__main__":
    import sys
    import csv

    MAX_TRIAL = sys.argv[1]
    approaches = []

LongChan's avatar
LongChan committed
86
87
    for idx, n in enumerate(nets):
        for part in range(3, max_partitions[idx] + 1):
harry1080ti's avatar
harry1080ti committed
88
89
90
91
92
93
94
            for seed in seedings:
                for pop in pop_size:
                    for tar in targets:
                        for res in max_res_sizes:
                            # print(n, part, pop, tar, res, seed)
                            approaches.append((n, part, pop, tar, res, seed))

LongChan's avatar
LongChan committed
95
    pool = Pool(processes = cpu_count() - 2)
harry1080ti's avatar
harry1080ti committed
96
    for result in pool.imap_unordered(trial, approaches):
harry1080ti's avatar
harry1080ti committed
97
98
99
100
        with open(pc.RESULT_CSV_PATH+'cma_logmore_sq_full_evo.csv', 'a') as csvFile:
            for evo in result:
                writer = csv.writer(csvFile, delimiter=',', lineterminator="\n")
                writer.writerow(evo)
harry1080ti's avatar
harry1080ti committed
101
    pool.close()
LongChan's avatar
LongChan committed
102
    pool.join()