Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change hasing from md5 to SHA256 #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions dnnlib/tflib/custom_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ def get_plugin(cuda_file):
print('Setting up TensorFlow plugin "%s": ' % cuda_file_base, end='', flush=True)
try:
# Hash CUDA source.
md5 = hashlib.md5()
sha256 = hashlib.sha256()
with open(cuda_file, 'rb') as f:
md5.update(f.read())
md5.update(b'\n')
sha256.update(f.read())
sha256.update(b'\n')

# Hash headers included by the CUDA code by running it through the preprocessor.
if not do_not_hash_included_headers:
Expand All @@ -115,8 +115,8 @@ def get_plugin(cuda_file):
for ln in f:
if not ln.startswith(b'# ') and not ln.startswith(b'#line '): # ignore line number pragmas
ln = ln.replace(bad_file_str, good_file_str)
md5.update(ln)
md5.update(b'\n')
sha256.update(ln)
sha256.update(b'\n')

# Select compiler options.
compile_opts = ''
Expand All @@ -132,13 +132,13 @@ def get_plugin(cuda_file):
nvcc_cmd = _prepare_nvcc_cli(compile_opts)

# Hash build configuration.
md5.update(('nvcc_cmd: ' + nvcc_cmd).encode('utf-8') + b'\n')
md5.update(('tf.VERSION: ' + tf.VERSION).encode('utf-8') + b'\n')
md5.update(('cuda_cache_version_tag: ' + cuda_cache_version_tag).encode('utf-8') + b'\n')
sha256.update(('nvcc_cmd: ' + nvcc_cmd).encode('utf-8') + b'\n')
sha256.update(('tf.VERSION: ' + tf.VERSION).encode('utf-8') + b'\n')
sha256.update(('cuda_cache_version_tag: ' + cuda_cache_version_tag).encode('utf-8') + b'\n')

# Compile if not already compiled.
bin_file_ext = '.dll' if os.name == 'nt' else '.so'
bin_file = os.path.join(cuda_cache_path, cuda_file_name + '_' + md5.hexdigest() + bin_file_ext)
bin_file = os.path.join(cuda_cache_path, cuda_file_name + '_' + sha256.hexdigest() + bin_file_ext)
if not os.path.isfile(bin_file):
if verbose:
print('Compiling... ', end='', flush=True)
Expand Down