MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / benchmark_script

Function benchmark_script

bench/python/benchmark.py:912–1132  ·  view source on GitHub ↗

Main function responsible for running an arbitrary python script and benchmarking it. :param process_idx: The 0-based index of this process. :param device_id: The GPU device id to use. :param output_dir: The output directory to use to store artifacts. :param warmup_batches: The

(
    process_idx,
    device_id,
    output_dir,
    warmup_batches,
    script,
    args,
)

Source from the content-addressed store, hash-verified

910
911
912def benchmark_script(
913 process_idx,
914 device_id,
915 output_dir,
916 warmup_batches,
917 script,
918 args,
919):
920 """
921 Main function responsible for running an arbitrary python script and benchmarking it.
922 :param process_idx: The 0-based index of this process.
923 :param device_id: The GPU device id to use.
924 :param output_dir: The output directory to use to store artifacts.
925 :param warmup_batches: The numbers of batches that should be ignored from benchmarking.
926 :param script: The python script to execute.
927 :param args: Any optional command line arguments that should be passed to the script.
928 """
929
930 # Make a copy of the environment variables and add our own env-vars to it.
931 my_env = os.environ.copy()
932 # Change the CUDA visible devices for this process.
933 my_env["CUDA_VISIBLE_DEVICES"] = str(device_id)
934 # Add the benchmark flag so that perf_utils knows that this is a benchmark run.
935 my_env["BENCHMARK_PY"] = "1"
936
937 # Set a path to store the SQLITE report created by NSYS.
938 out_sqlite_path = os.path.join(output_dir, "perf_report")
939 # Set a path to the benchmark.json created by the script.
940 benchmark_json_path = os.path.join(output_dir, "benchmark.json")
941
942 # Remove any existing benchmark.json files.
943 if os.path.isfile(benchmark_json_path):
944 os.remove(benchmark_json_path)
945
946 # Setup the command that will launch nsys and ask it to benchmark the script
947 # that we were interested in.
948 nsys_root_path = "/opt/nvidia/nsight-systems/2025.5.1/"
949 nsys_binary_path = os.path.join(nsys_root_path, "bin/nsys")
950 nsys_reports_path = os.path.join(nsys_root_path, "target-linux-x64/reports")
951 nsys_gpu_proj_trace_report_path = os.path.join(
952 nsys_reports_path, "nvtx_gpu_proj_trace"
953 )
954 nsys_pushpop_trace_report_path = os.path.join(
955 nsys_reports_path, "nvtx_pushpop_trace"
956 )
957
958 if not os.path.isfile(nsys_binary_path):
959 raise ValueError(
960 "Unable to locate nsys binary at %s. Make sure you have nsight-systems installed."
961 % nsys_binary_path
962 )
963
964 cmd = [
965 nsys_binary_path,
966 "profile",
967 "--export",
968 "sqlite",
969 "-o",

Callers

nothing calls this directly

Calls 9

expand_nvtx_range_namesFunction · 0.85
merge_cpu_and_gpu_rangesFunction · 0.85
calc_mean_rangesFunction · 0.85
removeMethod · 0.80
existsMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected