zhangmeng
2019-12-13 2d25b62b60da018412ed164b6fd29470498cea17
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package proc
 
import (
    "analysis/logo"
    "analysis/util"
    "context"
    "strings"
)
 
func slaveProc(ctx context.Context, typ string, id string, gpu int, shm bool) bool {
    name, ok := prepare(typ, gpu)
    if !ok {
        logo.Errorln("SLAVEPROC ERROR: ", name)
        return false
    }
 
    if id != util.FakeSdkID {
        build(name, id, shm)
        runAll(ctx)
    } else {
 
        util.InitDBAPI()
 
        sdks := util.SDKInfo()
        // 首先运行yolo
        for k, v := range sdks {
            if strings.EqualFold(typ, v.SdkType) {
                build(v.SdkType, v.IpcId, shm)
                logo.Infof("SINGLE PROC ID %s TYPE %s\n", k, v.IpcId, v.SdkType)
            }
        }
 
        runAll(ctx)
    }
    return true
}
 
// SingleRole 单进程
func SingleRole(ctx context.Context, typ string, ipcID string, gpu int, shm bool) bool {
    util.InitDBAPI()
 
    ret := false
    if typ == util.FeatAll { // run all proc per proc
 
        ret = allProc(ctx, gpu, shm)
    } else if typ == util.FeatFace || typ == util.FeatYolo { // run all face sdk
 
        ret = sdkProc(ctx, typ, gpu, shm)
    } else { // run one sdk per proc, typ is facedetect/yolodetect/facecompare etc. id is ipc
        ret = slaveProc(ctx, typ, ipcID, gpu, shm)
    }
    return ret
}
 
func sdkProc(ctx context.Context, typ string, gpu int, shm bool) bool {
    if typ != util.FeatYolo && typ != util.FeatFace {
        logo.Errorf("NO THIS SDK PROC SDKPROC : ", typ)
    }
    rSDK := []string{
        FDetect,
        FCompare,
    }
    if typ == util.FeatYolo {
        rSDK = rSDK[0:0]
        rSDK = append(rSDK, YDetect)
    }
    var res []bool
    for _, v := range rSDK {
        _, f := prepare(v, gpu)
        res = append(res, f)
    }
    for k, v := range res {
        if !v {
            logo.Errorln(k, " type proc failed to init")
            return false
        }
    }
 
    sdks := util.SDKInfo()
 
    for k, v := range sdks {
        for _, s := range rSDK {
            if s == v.SdkType {
                build(v.SdkType, v.IpcId, shm)
                logo.Infof("TYPE PROC ID %s TYPE %s\n", k, v.IpcId, v.SdkType)
            }
        }
    }
 
    runAll(ctx)
    return true
}
 
func allProc(ctx context.Context, gpu int, shm bool) bool {
    var res []bool
 
    for _, v := range SDK {
        _, f := prepare(v, gpu)
        res = append(res, f)
    }
 
    for k, v := range res {
        if !v {
            logo.Errorln(k, " ALL PROC FAILED TO INIT")
            return false
        }
    }
 
    sdks := util.SDKInfo()
    // 首先运行yolo
    for k, v := range sdks {
        if v.SdkType != "Yolo" {
            continue
        }
        build(v.SdkType, v.IpcId, shm)
        logo.Infof("all proc %d sdk id %s run sdk %s\n", k, v.IpcId, v.SdkType)
    }
    for k, v := range sdks {
        if v.SdkType == "Yolo" {
            continue
        }
        build(v.SdkType, v.IpcId, shm)
        logo.Infof("all proc %d sdk id %s run sdk %s\n", k, v.IpcId, v.SdkType)
    }
 
    runAll(ctx)
 
    return true
}