Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion backends/vulkan/serialization/vulkan_graph_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def convert_to_flatbuffer(vk_graph: VkGraph) -> bytes:
json_path = os.path.join(d, "schema.json")
with open(json_path, "wb") as json_file:
json_file.write(vk_graph_json.encode("ascii"))
_flatc_compile(d, schema_path, json_path)
_flatc_compile(d, schema_path, json_path, ["--force-defaults"])
output_path = os.path.join(d, "schema.bin")
with open(output_path, "rb") as output_file:
return output_file.read()
Expand Down
8 changes: 8 additions & 0 deletions backends/vulkan/test/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ def test_serialize_deserialize_non_finite_scalars(self) -> None:
]
)

def test_serialize_deserialize_signed_zero(self) -> None:
values = [
VkValue(Double(-0.0)),
VkValue(Double(0.0)),
VkValue(DoubleList([-0.0, 0.0])),
]
self.assertEqual(repr(self._round_trip(values).values), repr(values))

def test_serialize_deserialize_non_finite_floats_in_list(self) -> None:
# json only emits a float as a chunk of its own inside an object; in a
# list the chunk carries the delimiter with it, so a rewrite that works
Expand Down
9 changes: 8 additions & 1 deletion exir/_serialize/_flatbuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,12 @@ def convert(value: object) -> object:
return json.dumps(convert(json.loads(content))).encode("utf-8")


def _flatc_compile(output_dir: str, schema_path: str, json_path: str) -> None:
def _flatc_compile(
output_dir: str,
schema_path: str,
json_path: str,
flatc_additional_args: Optional[List[str]] = None,
) -> None:
"""Serializes JSON data to a binary flatbuffer file.

Args:
Expand All @@ -381,6 +386,7 @@ def _flatc_compile(output_dir: str, schema_path: str, json_path: str) -> None:
matches the schema. Rewritten in place if it contains non-finite
floats; flatc derives the output filename from this path, so the
data cannot be sanitized into a differently-named file.
flatc_additional_args: Additional options passed to flatc.
"""
with open(json_path, "rb") as json_file:
content = json_file.read()
Expand All @@ -392,6 +398,7 @@ def _flatc_compile(output_dir: str, schema_path: str, json_path: str) -> None:
_run_flatc(
[
"--binary",
*(flatc_additional_args or []),
"-o",
output_dir,
schema_path,
Expand Down
Loading