Skip to content

Commit 6dace6a

Browse files
committed
Update
1 parent b0c5250 commit 6dace6a

1 file changed

Lines changed: 0 additions & 92 deletions

File tree

python/common.py

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
# limitations under the License.
1919
#
2020

21-
import argparse
22-
import os
2321
import ctypes
2422
from typing import Optional, List
2523

@@ -59,96 +57,6 @@ def GiB(val):
5957
return val * 1 << 30
6058

6159

62-
def add_help(description):
63-
parser = argparse.ArgumentParser(
64-
description=description,
65-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
66-
args, _ = parser.parse_known_args()
67-
68-
69-
def find_sample_data(description="Runs a TensorRT Python sample",
70-
subfolder="",
71-
find_files=[],
72-
err_msg=""):
73-
"""
74-
Parses sample arguments.
75-
76-
Args:
77-
description (str): Description of the sample.
78-
subfolder (str): The subfolder containing data relevant to this sample
79-
find_files (str): A list of filenames to find. Each filename will be replaced with an absolute path.
80-
81-
Returns:
82-
str: Path of data directory.
83-
"""
84-
85-
# Standard command-line arguments for all samples.
86-
kDEFAULT_DATA_ROOT = os.path.join(os.sep, "usr", "src", "tensorrt", "data")
87-
parser = argparse.ArgumentParser(
88-
description=description,
89-
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
90-
parser.add_argument(
91-
"-d",
92-
"--datadir",
93-
help=
94-
"Location of the TensorRT sample data directory, and any additional data directories.",
95-
action="append",
96-
default=[kDEFAULT_DATA_ROOT],
97-
)
98-
args, _ = parser.parse_known_args()
99-
100-
def get_data_path(data_dir):
101-
# If the subfolder exists, append it to the path, otherwise use the provided path as-is.
102-
data_path = os.path.join(data_dir, subfolder)
103-
if not os.path.exists(data_path):
104-
if data_dir != kDEFAULT_DATA_ROOT:
105-
print("WARNING: " + data_path + " does not exist. Trying " +
106-
data_dir + " instead.")
107-
data_path = data_dir
108-
# Make sure data directory exists.
109-
if not (os.path.exists(data_path)) and data_dir != kDEFAULT_DATA_ROOT:
110-
print(
111-
"WARNING: {:} does not exist. Please provide the correct data path with the -d option."
112-
.format(data_path))
113-
return data_path
114-
115-
data_paths = [get_data_path(data_dir) for data_dir in args.datadir]
116-
return data_paths, locate_files(data_paths, find_files, err_msg)
117-
118-
119-
def locate_files(data_paths, filenames, err_msg=""):
120-
"""
121-
Locates the specified files in the specified data directories.
122-
If a file exists in multiple data directories, the first directory is used.
123-
124-
Args:
125-
data_paths (List[str]): The data directories.
126-
filename (List[str]): The names of the files to find.
127-
128-
Returns:
129-
List[str]: The absolute paths of the files.
130-
131-
Raises:
132-
FileNotFoundError if a file could not be located.
133-
"""
134-
found_files = [None] * len(filenames)
135-
for data_path in data_paths:
136-
# Find all requested files.
137-
for index, (found, filename) in enumerate(zip(found_files, filenames)):
138-
if not found:
139-
file_path = os.path.abspath(os.path.join(data_path, filename))
140-
if os.path.exists(file_path):
141-
found_files[index] = file_path
142-
143-
# Check that all files were found
144-
for f, filename in zip(found_files, filenames):
145-
if not f or not os.path.exists(f):
146-
raise FileNotFoundError(
147-
"Could not find {:}. Searched in data paths: {:}\n{:}".format(
148-
filename, data_paths, err_msg))
149-
return found_files
150-
151-
15260
class HostDeviceMem:
15361
"""Pair of host and device memory, where the host memory is wrapped in a numpy array"""
15462

0 commit comments

Comments
 (0)