Skip to content

Commit

Permalink
#43 add batch size to benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
tomskikh committed Jan 31, 2023
1 parent 2b2c51d commit dc8b672
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
27 changes: 13 additions & 14 deletions gpumat/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,12 @@ def pad_buffer_probe(
for _ in range(RECT_N)
]
gst_buffer: Gst.Buffer = info.get_buffer()
ts1 = time.time()
nvds_batch_meta = pyds.gst_buffer_get_nvds_batch_meta(hash(gst_buffer))
for nvds_frame_meta in nvds_frame_meta_iterator(nvds_batch_meta):
ts1 = time.time()
benchmark_func(gst_buffer, nvds_frame_meta, data)
ts2 = time.time()
measurements.append((ts2 - ts1) * scale)
ts2 = time.time()
measurements.append((ts2 - ts1) * scale)

return Gst.PadProbeReturn.OK

Expand All @@ -253,7 +253,7 @@ def bus_call(bus, message, loop):
def main(args):
assert (
len(args) > 2
), 'Usage: ./benchmark.py <benchmark-name> <cpu|gpu> [n-frames] [output-filename]'
), 'Usage: ./benchmark.py <benchmark-name> <cpu|gpu> [n-frames] [batch-size] [output-filename]'
benchmark_name = args[1]
is_gpu = args[2] == 'gpu'
assert (
Expand All @@ -263,18 +263,19 @@ def main(args):
assert benchmark_func is not None, 'Benchmark not implemented'

output_filename = None
n_frames = 1
batch_size = 1
if len(args) > 3:
n_frames = int(args[3])
if len(args) > 4:
output_filename = args[4]
else:
n_frames = 1
if len(args) > 4:
batch_size = int(args[4])
if len(args) > 5:
output_filename = args[5]

Gst.init(None)

print("Creating Pipeline")
pipeline = Gst.Pipeline()
is_live = False

print("Creating streammux")
streammux = Gst.ElementFactory.make("nvstreammux", "streammux")
Expand Down Expand Up @@ -331,11 +332,9 @@ def main(args):

source.set_property('num-buffers', n_frames)

if is_live:
streammux.set_property('live-source', 1)
streammux.set_property('width', 1920)
streammux.set_property('height', 1080)
streammux.set_property('batch-size', 1)
streammux.set_property('batch-size', batch_size)
streammux.set_property('batched-push-timeout', 4000000)

sink.set_property("sync", 0)
Expand Down Expand Up @@ -451,12 +450,12 @@ def main(args):
('stdev', statistics.stdev(measurements)),
]
for name, val in metrics:
print(f'{name}: {val:.3f}')
print(f'{name}: {val:.3f} ({val / batch_size:.3f} per frame)')
device_name = "gpu" if is_gpu else "cpu"
with open('metrics.csv', 'a') as f:
f.write(
','.join(
[benchmark_name, device_name, str(n_frames)]
[benchmark_name, device_name, str(n_frames), str(batch_size)]
+ [f'{val:.3f}' for _, val in metrics]
)
)
Expand Down
12 changes: 9 additions & 3 deletions gpumat/run_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ else
FRAME_NUM=1000
fi

if [[ -n "${2}" ]]; then
BATCH_SIZE="${2}"
else
BATCH_SIZE=1
fi

if [[ "$(uname -m)" == "aarch64" ]]; then
DOCKER_IMAGE="savant-deepstream-l4t:0.1.1-6.1.1-base"
else
Expand All @@ -28,7 +34,7 @@ CPU_BENCHMARK_NAMES=(
"blur-faces"
)

echo "name,device,frame_num,min,max,mean,median,80%,90%,95%,99%,stdev" >metrics.csv
echo "name,device,frame_num,batch_size,min,max,mean,median,80%,90%,95%,99%,stdev" >metrics.csv

for BENCHMARK_NAME in "${GPU_BENCHMARK_NAMES[@]}"; do
echo
Expand All @@ -44,7 +50,7 @@ for BENCHMARK_NAME in "${GPU_BENCHMARK_NAMES[@]}"; do
--workdir /gpumat \
--entrypoint ./benchmark.py \
-v "$(pwd):/gpumat" \
"${DOCKER_IMAGE}" "${BENCHMARK_NAME}" "gpu" "${FRAME_NUM}"
"${DOCKER_IMAGE}" "${BENCHMARK_NAME}" "gpu" "${FRAME_NUM}" "${BATCH_SIZE}"
done

for BENCHMARK_NAME in "${CPU_BENCHMARK_NAMES[@]}"; do
Expand All @@ -61,6 +67,6 @@ for BENCHMARK_NAME in "${CPU_BENCHMARK_NAMES[@]}"; do
--workdir /gpumat \
--entrypoint ./benchmark.py \
-v "$(pwd):/gpumat" \
"${DOCKER_IMAGE}" "${BENCHMARK_NAME}" "cpu" "${FRAME_NUM}"
"${DOCKER_IMAGE}" "${BENCHMARK_NAME}" "cpu" "${FRAME_NUM}" "${BATCH_SIZE}"
done
date

0 comments on commit dc8b672

Please sign in to comment.