Commit 8154b9bb by Weihao KONG

Remove non-parallel old script

parent 66978061
......@@ -8,6 +8,7 @@ parser.add_argument('--gpu',dest='gpu',action='store_true',help='Whether to use
parser.add_argument('--dla1',dest='dla1',action='store_true', help='Whether to use DLA core 1 for inference')
parser.add_argument('--dla2',dest='dla2',action='store_true', help='Whether to use DLA core 2 for inference')
parser.add_argument('--bs',dest='bs',type=int,default=1, help='Batch size of inference')
parser.add_argument('--parallelruns',dest='parallelruns',type=int,default=1, help='Processes launched in parallel for each device')
args=parser.parse_args()
......@@ -39,113 +40,114 @@ def gen_command(onnx_path, engine_path, useDLACore):
return run_command
processes = {
'gpu':None,
'dla1':None,
'dla2':None
'gpu':[],
'dla1':[],
'dla2':[]
}
logfiles = {
'gpu':None,
'dla1':None,
'dla2':None
'gpu':[],
'dla1':[],
'dla2':[]
}
if args.gpu:
print('Launching GPU process')
fname_stdout = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_gpu.stdout'
fname_stderr = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_gpu.stderr'
f_stdout = open(fname_stdout,'w+')
f_stderr = open(fname_stderr,'w+')
bs_dir = 'bs'+str(args.bs)
command = gen_command(
onnx_path=os.path.join(bs_dir, 'model.onnx'),
engine_path=os.path.join(bs_dir, 'gpu.engine'),
useDLACore=None
)
processes['gpu']=subprocess.Popen(command,shell=False, stdout=f_stdout,stderr=f_stderr)
logfiles['gpu']=(f_stdout,f_stderr)
if args.dla1:
print('Launching DLA1 process')
fname_stdout = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_dla1.stdout'
fname_stderr = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_dla1.stderr'
f_stdout = open(fname_stdout,'w+')
f_stderr = open(fname_stderr,'w+')
bs_dir = 'bs'+str(args.bs)
command = gen_command(
onnx_path=os.path.join(bs_dir, 'model.onnx'),
engine_path=os.path.join(bs_dir, 'dla1.engine'),
useDLACore=0
)
processes['dla1']=subprocess.Popen(command,shell=False, stdout=f_stdout,stderr=f_stderr)
logfiles['dla1']=(f_stdout,f_stderr)
if args.dla2:
print('Launching DLA2 process')
fname_stdout = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_dla2.stdout'
fname_stderr = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_dla2.stderr'
f_stdout = open(fname_stdout,'w+')
f_stderr = open(fname_stderr,'w+')
bs_dir = 'bs'+str(args.bs)
command = gen_command(
onnx_path=os.path.join(bs_dir, 'model.onnx'),
engine_path=os.path.join(bs_dir, 'dla2.engine'),
useDLACore=1
)
processes['dla2']=subprocess.Popen(command,shell=False, stdout=f_stdout,stderr=f_stderr)
logfiles['dla2']=(f_stdout,f_stderr)
for process in processes.values():
if process == None:
for i in range(args.parallelruns):
if args.gpu:
print('Launching GPU process {:d}'.format(i))
fname_stdout = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_gpu.stdout.{:d}'.format(i)
fname_stderr = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_gpu.stderr.{:d}'.format(i)
f_stdout = open(fname_stdout,'w+')
f_stderr = open(fname_stderr,'w+')
bs_dir = 'bs'+str(args.bs)
command = gen_command(
onnx_path=os.path.join(bs_dir, 'model.onnx'),
engine_path=os.path.join(bs_dir, 'gpu.engine'),
useDLACore=None
)
processes['gpu'].append(subprocess.Popen(command,shell=False, stdout=f_stdout,stderr=f_stderr))
logfiles['gpu'].append((f_stdout,f_stderr))
if args.dla1:
print('Launching DLA1 process {:d}'.format(i))
fname_stdout = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_dla1.stdout.{:d}'.format(i)
fname_stderr = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_dla1.stderr.{:d}'.format(i)
f_stdout = open(fname_stdout,'w+')
f_stderr = open(fname_stderr,'w+')
bs_dir = 'bs'+str(args.bs)
command = gen_command(
onnx_path=os.path.join(bs_dir, 'model.onnx'),
engine_path=os.path.join(bs_dir, 'dla1.engine'),
useDLACore=0
)
processes['dla1'].append(subprocess.Popen(command,shell=False, stdout=f_stdout,stderr=f_stderr))
logfiles['dla1'].append((f_stdout,f_stderr))
if args.dla2:
print('Launching DLA2 process {:d}'.format(i))
fname_stdout = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_dla2.stdout.{:d}'.format(i)
fname_stderr = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_dla2.stderr.{:d}'.format(i)
f_stdout = open(fname_stdout,'w+')
f_stderr = open(fname_stderr,'w+')
bs_dir = 'bs'+str(args.bs)
command = gen_command(
onnx_path=os.path.join(bs_dir, 'model.onnx'),
engine_path=os.path.join(bs_dir, 'dla2.engine'),
useDLACore=1
)
processes['dla2'].append(subprocess.Popen(command,shell=False, stdout=f_stdout,stderr=f_stderr))
logfiles['dla2'].append((f_stdout,f_stderr))
for process_list in processes.values():
if process_list == []:
continue
process.wait()
for p in process_list:
p.wait()
for key,value in logfiles.items():
if value == None:
for key,file_pair_list in logfiles.items():
if file_pair_list == []:
continue
value[0].seek(0, 0)
print('-'*40+'STDOUT of '+key+'-'*40, file=sys.stdout, end='\n')
print(value[0].read(), file=sys.stdout, end='\n')
print('-'*40+'------end------'+'-'*40, file=sys.stdout, end='\n')
value[1].seek(0, 0)
print('-'*40+'STDERR of '+key+'-'*40, file=sys.stderr, end='\n')
print(value[1].read(), file=sys.stderr, end='\n')
print('-'*40+'------end------'+'-'*40, file=sys.stderr, end='\n')
for files in logfiles.values():
if files == None:
for i,pair in enumerate(file_pair_list):
pair[0].seek(0, 0)
print('-'*40+'STDOUT of '+key+'-'*40, file=sys.stdout, end='\n')
print(pair[0].read(), file=sys.stdout, end='\n')
print('-'*40+'------end------'+'-'*40, file=sys.stdout, end='\n')
pair[1].seek(0, 0)
print('-'*40+'STDERR of '+key+'-'*40, file=sys.stderr, end='\n')
print(pair[1].read(), file=sys.stderr, end='\n')
print('-'*40+'------end------'+'-'*40, file=sys.stderr, end='\n')
for key,file_pair_list in logfiles.items():
if file_pair_list == []:
continue
files[0].close()
files[1].close()
os.remove(files[0].name)
os.remove(files[1].name)
for i,pair in enumerate(file_pair_list):
pair[0].close()
pair[1].close()
os.remove(pair[0].name)
os.remove(pair[1].name)
import subprocess
import argparse
import os
import sys
parser = argparse.ArgumentParser(description='')
parser.add_argument('--gpu',dest='gpu',action='store_true',help='Whether to use GPU for inference')
parser.add_argument('--dla1',dest='dla1',action='store_true', help='Whether to use DLA core 1 for inference')
parser.add_argument('--dla2',dest='dla2',action='store_true', help='Whether to use DLA core 2 for inference')
parser.add_argument('--bs',dest='bs',type=int,default=1, help='Batch size of inference')
parser.add_argument('--parallelruns',dest='parallelruns',type=int,default=1, help='Processes launched in parallel for each device')
args=parser.parse_args()
def gen_command(onnx_path, engine_path, useDLACore):
onnx_path_arg = "--onnx=" + onnx_path
engine_path_arg = "--loadEngine=" + engine_path
useDLACore_arg = None if useDLACore==None else ("--useDLACore="+str(useDLACore))
run_command = ["/usr/src/tensorrt/bin/trtexec"]
run_command += [onnx_path_arg]
run_command += \
["--explicitBatch",
"--int8",
"--allowGPUFallback"]
if useDLACore_arg:
run_command += [useDLACore_arg]
run_command += \
["--workspace=2048",
"--iterations=1000",
"--avgRuns=100",
"--duration=180",]
run_command += [engine_path_arg]
return run_command
processes = {
'gpu':[],
'dla1':[],
'dla2':[]
}
logfiles = {
'gpu':[],
'dla1':[],
'dla2':[]
}
for i in range(args.parallelruns):
if args.gpu:
print('Launching GPU process {:d}'.format(i))
fname_stdout = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_gpu.stdout.{:d}'.format(i)
fname_stderr = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_gpu.stderr.{:d}'.format(i)
f_stdout = open(fname_stdout,'w+')
f_stderr = open(fname_stderr,'w+')
bs_dir = 'bs'+str(args.bs)
command = gen_command(
onnx_path=os.path.join(bs_dir, 'model.onnx'),
engine_path=os.path.join(bs_dir, 'gpu.engine'),
useDLACore=None
)
processes['gpu'].append(subprocess.Popen(command,shell=False, stdout=f_stdout,stderr=f_stderr))
logfiles['gpu'].append((f_stdout,f_stderr))
if args.dla1:
print('Launching DLA1 process {:d}'.format(i))
fname_stdout = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_dla1.stdout.{:d}'.format(i)
fname_stderr = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_dla1.stderr.{:d}'.format(i)
f_stdout = open(fname_stdout,'w+')
f_stderr = open(fname_stderr,'w+')
bs_dir = 'bs'+str(args.bs)
command = gen_command(
onnx_path=os.path.join(bs_dir, 'model.onnx'),
engine_path=os.path.join(bs_dir, 'dla1.engine'),
useDLACore=0
)
processes['dla1'].append(subprocess.Popen(command,shell=False, stdout=f_stdout,stderr=f_stderr))
logfiles['dla1'].append((f_stdout,f_stderr))
if args.dla2:
print('Launching DLA2 process {:d}'.format(i))
fname_stdout = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_dla2.stdout.{:d}'.format(i)
fname_stderr = 'gpu_'+str(args.gpu)+\
'_dla1_'+str(args.dla1)+\
'_dla2_'+str(args.dla2)+\
'_bs'+str(args.bs)+\
'_dla2.stderr.{:d}'.format(i)
f_stdout = open(fname_stdout,'w+')
f_stderr = open(fname_stderr,'w+')
bs_dir = 'bs'+str(args.bs)
command = gen_command(
onnx_path=os.path.join(bs_dir, 'model.onnx'),
engine_path=os.path.join(bs_dir, 'dla2.engine'),
useDLACore=1
)
processes['dla2'].append(subprocess.Popen(command,shell=False, stdout=f_stdout,stderr=f_stderr))
logfiles['dla2'].append((f_stdout,f_stderr))
for process_list in processes.values():
if process_list == []:
continue
for p in process_list:
p.wait()
for key,file_pair_list in logfiles.items():
if file_pair_list == []:
continue
for i,pair in enumerate(file_pair_list):
pair[0].seek(0, 0)
print('-'*40+'STDOUT of '+key+'-'*40, file=sys.stdout, end='\n')
print(pair[0].read(), file=sys.stdout, end='\n')
print('-'*40+'------end------'+'-'*40, file=sys.stdout, end='\n')
pair[1].seek(0, 0)
print('-'*40+'STDERR of '+key+'-'*40, file=sys.stderr, end='\n')
print(pair[1].read(), file=sys.stderr, end='\n')
print('-'*40+'------end------'+'-'*40, file=sys.stderr, end='\n')
for key,file_pair_list in logfiles.items():
if file_pair_list == []:
continue
for i,pair in enumerate(file_pair_list):
pair[0].close()
pair[1].close()
os.remove(pair[0].name)
os.remove(pair[1].name)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment