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 ...@@ -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('--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('--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('--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() args=parser.parse_args()
...@@ -39,113 +40,114 @@ def gen_command(onnx_path, engine_path, useDLACore): ...@@ -39,113 +40,114 @@ def gen_command(onnx_path, engine_path, useDLACore):
return run_command return run_command
processes = { processes = {
'gpu':None, 'gpu':[],
'dla1':None, 'dla1':[],
'dla2':None 'dla2':[]
} }
logfiles = { logfiles = {
'gpu':None, 'gpu':[],
'dla1':None, 'dla1':[],
'dla2':None 'dla2':[]
} }
if args.gpu: for i in range(args.parallelruns):
print('Launching GPU process') if args.gpu:
fname_stdout = 'gpu_'+str(args.gpu)+\ print('Launching GPU process {:d}'.format(i))
'_dla1_'+str(args.dla1)+\ fname_stdout = 'gpu_'+str(args.gpu)+\
'_dla2_'+str(args.dla2)+\ '_dla1_'+str(args.dla1)+\
'_bs'+str(args.bs)+\ '_dla2_'+str(args.dla2)+\
'_gpu.stdout' '_bs'+str(args.bs)+\
fname_stderr = 'gpu_'+str(args.gpu)+\ '_gpu.stdout.{:d}'.format(i)
'_dla1_'+str(args.dla1)+\ fname_stderr = 'gpu_'+str(args.gpu)+\
'_dla2_'+str(args.dla2)+\ '_dla1_'+str(args.dla1)+\
'_bs'+str(args.bs)+\ '_dla2_'+str(args.dla2)+\
'_gpu.stderr' '_bs'+str(args.bs)+\
f_stdout = open(fname_stdout,'w+') '_gpu.stderr.{:d}'.format(i)
f_stderr = open(fname_stderr,'w+') f_stdout = open(fname_stdout,'w+')
bs_dir = 'bs'+str(args.bs) f_stderr = open(fname_stderr,'w+')
command = gen_command( bs_dir = 'bs'+str(args.bs)
onnx_path=os.path.join(bs_dir, 'model.onnx'), command = gen_command(
engine_path=os.path.join(bs_dir, 'gpu.engine'), onnx_path=os.path.join(bs_dir, 'model.onnx'),
useDLACore=None 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) 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') if args.dla1:
fname_stdout = 'gpu_'+str(args.gpu)+\ print('Launching DLA1 process {:d}'.format(i))
'_dla1_'+str(args.dla1)+\ fname_stdout = 'gpu_'+str(args.gpu)+\
'_dla2_'+str(args.dla2)+\ '_dla1_'+str(args.dla1)+\
'_bs'+str(args.bs)+\ '_dla2_'+str(args.dla2)+\
'_dla1.stdout' '_bs'+str(args.bs)+\
fname_stderr = 'gpu_'+str(args.gpu)+\ '_dla1.stdout.{:d}'.format(i)
'_dla1_'+str(args.dla1)+\ fname_stderr = 'gpu_'+str(args.gpu)+\
'_dla2_'+str(args.dla2)+\ '_dla1_'+str(args.dla1)+\
'_bs'+str(args.bs)+\ '_dla2_'+str(args.dla2)+\
'_dla1.stderr' '_bs'+str(args.bs)+\
f_stdout = open(fname_stdout,'w+') '_dla1.stderr.{:d}'.format(i)
f_stderr = open(fname_stderr,'w+') f_stdout = open(fname_stdout,'w+')
bs_dir = 'bs'+str(args.bs) f_stderr = open(fname_stderr,'w+')
command = gen_command( bs_dir = 'bs'+str(args.bs)
onnx_path=os.path.join(bs_dir, 'model.onnx'), command = gen_command(
engine_path=os.path.join(bs_dir, 'dla1.engine'), onnx_path=os.path.join(bs_dir, 'model.onnx'),
useDLACore=0 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) 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') if args.dla2:
fname_stdout = 'gpu_'+str(args.gpu)+\ print('Launching DLA2 process {:d}'.format(i))
'_dla1_'+str(args.dla1)+\ fname_stdout = 'gpu_'+str(args.gpu)+\
'_dla2_'+str(args.dla2)+\ '_dla1_'+str(args.dla1)+\
'_bs'+str(args.bs)+\ '_dla2_'+str(args.dla2)+\
'_dla2.stdout' '_bs'+str(args.bs)+\
fname_stderr = 'gpu_'+str(args.gpu)+\ '_dla2.stdout.{:d}'.format(i)
'_dla1_'+str(args.dla1)+\ fname_stderr = 'gpu_'+str(args.gpu)+\
'_dla2_'+str(args.dla2)+\ '_dla1_'+str(args.dla1)+\
'_bs'+str(args.bs)+\ '_dla2_'+str(args.dla2)+\
'_dla2.stderr' '_bs'+str(args.bs)+\
f_stdout = open(fname_stdout,'w+') '_dla2.stderr.{:d}'.format(i)
f_stderr = open(fname_stderr,'w+') f_stdout = open(fname_stdout,'w+')
bs_dir = 'bs'+str(args.bs) f_stderr = open(fname_stderr,'w+')
command = gen_command( bs_dir = 'bs'+str(args.bs)
onnx_path=os.path.join(bs_dir, 'model.onnx'), command = gen_command(
engine_path=os.path.join(bs_dir, 'dla2.engine'), onnx_path=os.path.join(bs_dir, 'model.onnx'),
useDLACore=1 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) processes['dla2'].append(subprocess.Popen(command,shell=False, stdout=f_stdout,stderr=f_stderr))
logfiles['dla2'].append((f_stdout,f_stderr))
for process in processes.values():
if process == None: for process_list in processes.values():
if process_list == []:
continue continue
process.wait() for p in process_list:
p.wait()
for key,value in logfiles.items(): for key,file_pair_list in logfiles.items():
if value == None: if file_pair_list == []:
continue continue
value[0].seek(0, 0) for i,pair in enumerate(file_pair_list):
print('-'*40+'STDOUT of '+key+'-'*40, file=sys.stdout, end='\n') pair[0].seek(0, 0)
print(value[0].read(), file=sys.stdout, end='\n') print('-'*40+'STDOUT of '+key+'-'*40, file=sys.stdout, end='\n')
print('-'*40+'------end------'+'-'*40, file=sys.stdout, end='\n') print(pair[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') pair[1].seek(0, 0)
print(value[1].read(), file=sys.stderr, end='\n') print('-'*40+'STDERR of '+key+'-'*40, file=sys.stderr, end='\n')
print('-'*40+'------end------'+'-'*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 == []:
for files in logfiles.values():
if files == None:
continue continue
files[0].close() for i,pair in enumerate(file_pair_list):
files[1].close() pair[0].close()
os.remove(files[0].name) pair[1].close()
os.remove(files[1].name) 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