yaoyaoding commented on code in PR #283:
URL: https://github.com/apache/tvm-ffi/pull/283#discussion_r2561766750
##########
python/tvm_ffi/cpp/extension.py:
##########
@@ -45,35 +46,47 @@ def _hash_sources(
extra_cuda_cflags: Sequence[str],
extra_ldflags: Sequence[str],
extra_include_paths: Sequence[str],
+ embed_cubin: Mapping[str, bytes] | None = None,
) -> str:
"""Generate a unique hash for the given sources and functions."""
m = hashlib.sha256()
- def _maybe_hash_string(source: str | None) -> None:
- if source is not None:
- m.update(source.encode("utf-8"))
-
- def _hash_sequence(seq: Sequence[str]) -> None:
- for item in seq:
- m.update(item.encode("utf-8"))
-
- def _hash_mapping(mapping: Mapping[str, str]) -> None:
- for key in sorted(mapping):
- m.update(key.encode("utf-8"))
- m.update(mapping[key].encode("utf-8"))
-
- _maybe_hash_string(cpp_source)
- _maybe_hash_string(cuda_source)
- _hash_sequence(sorted(cpp_files or []))
- _hash_sequence(sorted(cuda_files or []))
- if isinstance(functions, Mapping):
- _hash_mapping(functions)
- else:
- _hash_sequence(sorted(functions))
- _hash_sequence(extra_cflags)
- _hash_sequence(extra_cuda_cflags)
- _hash_sequence(extra_ldflags)
- _hash_sequence(extra_include_paths)
+ def _hash(obj: Any) -> None:
+ if obj is None:
+ m.update(b"None")
+ elif isinstance(obj, str):
+ m.update(b"str")
+ m.update(obj.encode("utf-8"))
+ elif isinstance(obj, bytes):
+ m.update(b"bytes")
+ m.update(obj)
+ elif isinstance(obj, Mapping):
+ m.update(b"Mapping")
+ for key, item in obj.items():
+ _hash(key)
+ _hash(item)
+ elif isinstance(obj, Sequence):
+ m.update(b"Sequence")
+ for item in obj:
+ _hash(item)
+ else:
+ raise ValueError(f"Unsupported type: {type(obj)}")
+
+ _hash(
+ (
+ cpp_source,
+ cuda_source,
+ cpp_files,
+ cuda_files,
Review Comment:
fixed
##########
python/tvm_ffi/cpp/extension.py:
##########
@@ -45,35 +46,47 @@ def _hash_sources(
extra_cuda_cflags: Sequence[str],
extra_ldflags: Sequence[str],
extra_include_paths: Sequence[str],
+ embed_cubin: Mapping[str, bytes] | None = None,
) -> str:
"""Generate a unique hash for the given sources and functions."""
m = hashlib.sha256()
- def _maybe_hash_string(source: str | None) -> None:
- if source is not None:
- m.update(source.encode("utf-8"))
-
- def _hash_sequence(seq: Sequence[str]) -> None:
- for item in seq:
- m.update(item.encode("utf-8"))
-
- def _hash_mapping(mapping: Mapping[str, str]) -> None:
- for key in sorted(mapping):
- m.update(key.encode("utf-8"))
- m.update(mapping[key].encode("utf-8"))
-
- _maybe_hash_string(cpp_source)
- _maybe_hash_string(cuda_source)
- _hash_sequence(sorted(cpp_files or []))
- _hash_sequence(sorted(cuda_files or []))
- if isinstance(functions, Mapping):
- _hash_mapping(functions)
- else:
- _hash_sequence(sorted(functions))
- _hash_sequence(extra_cflags)
- _hash_sequence(extra_cuda_cflags)
- _hash_sequence(extra_ldflags)
- _hash_sequence(extra_include_paths)
+ def _hash(obj: Any) -> None:
+ if obj is None:
+ m.update(b"None")
+ elif isinstance(obj, str):
+ m.update(b"str")
+ m.update(obj.encode("utf-8"))
+ elif isinstance(obj, bytes):
+ m.update(b"bytes")
+ m.update(obj)
+ elif isinstance(obj, Mapping):
+ m.update(b"Mapping")
+ for key, item in obj.items():
+ _hash(key)
+ _hash(item)
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]