| | |
| | | logo.Infoln(os.Args) |
| | | ctx, cancel := context.WithCancel(context.Background()) |
| | | |
| | | ret := false |
| | | if role == single { |
| | | proc.SingleRole(ctx, runType, id, gpu, shm) |
| | | ret = proc.SingleRole(ctx, runType, id, gpu, shm) |
| | | } else if role == master { |
| | | setParamters() |
| | | proc.MasterRole(ctx) |
| | | ret = proc.MasterRole(ctx) |
| | | } else if role == slave { |
| | | proc.SingleRole(ctx, runType, id, gpu, shm) |
| | | ret = proc.SingleRole(ctx, runType, id, gpu, shm) |
| | | } |
| | | |
| | | if ret { |
| | | c := make(chan os.Signal, 1) |
| | | signal.Notify(c, os.Interrupt, os.Kill, unix.SIGTERM) |
| | | <-c |
| | | } |
| | | |
| | | cancel() |
| | | |
| | |
| | | } |
| | | |
| | | // MasterRole master |
| | | func MasterRole(ctx context.Context) { |
| | | func MasterRole(ctx context.Context) bool { |
| | | reaper(ctx) |
| | | |
| | | util.InitDBAPI() |
| | |
| | | } |
| | | logo.Infof("START %d PROC %d SDK %s ID %s\n", k, pid, v.IpcId, v.SdkType) |
| | | } |
| | | return true |
| | | } |
| | |
| | | "analysis/util" |
| | | "analysis/work" |
| | | "context" |
| | | "strings" |
| | | ) |
| | | |
| | | // SingleRole 单进程 |
| | | func SingleRole(ctx context.Context, typ string, ipcID string, gpu int, shm bool) { |
| | | 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 |
| | | |
| | | allProc(ctx, gpu, shm) |
| | | ret = allProc(ctx, gpu, shm) |
| | | } else if typ == util.FeatFace || typ == util.FeatYolo { // run all face sdk |
| | | |
| | | sdkProc(ctx, typ, gpu, shm) |
| | | ret = sdkProc(ctx, typ, gpu, shm) |
| | | } else { // run one sdk per proc, typ is facedetect/yolodetect/facecompare etc. id is ipc |
| | | slaveProc(ctx, typ, ipcID, gpu, shm) |
| | | ret = slaveProc(ctx, typ, ipcID, gpu, shm) |
| | | } |
| | | return ret |
| | | } |
| | | |
| | | } |
| | | |
| | | func sdkProc(ctx context.Context, typ string, gpu int, shm bool) { |
| | | 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) |
| | | } |
| | |
| | | for k, v := range res { |
| | | if !v { |
| | | logo.Errorln(k, " type proc failed to init") |
| | | return |
| | | return false |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | runAll(ctx) |
| | | return true |
| | | } |
| | | |
| | | func allProc(ctx context.Context, gpu int, shm bool) { |
| | | func allProc(ctx context.Context, gpu int, shm bool) bool { |
| | | var res []bool |
| | | |
| | | for _, v := range work.SDK { |
| | |
| | | for k, v := range res { |
| | | if !v { |
| | | logo.Errorln(k, " ALL PROC FAILED TO INIT") |
| | | return |
| | | return false |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | runAll(ctx) |
| | | |
| | | return true |
| | | } |