Skip to content

Commit

Permalink
fix(brokerage): replace use of pickle by dill
Browse files Browse the repository at this point in the history
  • Loading branch information
rayanht committed May 15, 2022
1 parent 56afd6a commit 68e122d
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 15 deletions.
17 changes: 16 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ GitPython = "^3.1.27"
pyadl = "^0.1"
pandas = "^1.4.2"
db-dtypes = "^1.0.1"
dill = "^0.3.4"

[tool.poetry.dev-dependencies]
black = {version = "^22.3", allow-prereleases = true}
Expand Down
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class FuzzingStrategyConfig:
)

# P(generating a statement at step t + 1 | a statement was generated at step t)
p_statement: float = 0.997
p_statement: float = 0.995

# Number of optimiser fuzzing iterations
optimiser_fuzzing_iterations: int = 20
Expand Down
5 changes: 2 additions & 3 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import hashlib
import inspect
import pickle
import time
from abc import ABC
from dataclasses import field
from dataclasses import fields
Expand All @@ -10,6 +8,7 @@
from typing import TYPE_CHECKING
from typing import TypeVar

import dill
from typing_extensions import Self


Expand Down Expand Up @@ -64,7 +63,7 @@ def __eq__(self, other) -> bool:
def __hash__(self) -> int:
return int(
hashlib.sha224(
pickle.dumps(
dill.dumps(
tuple([hash(getattr(self, attr)) for attr in self.members()])
)
).hexdigest(),
Expand Down
4 changes: 2 additions & 2 deletions src/fuzzing_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def start(self):
thread_pool_executor.submit(
BQ_insert_new_shader, shader, self.generator_id
)
if paused:
Monitor(self.config).info(event=Event.PAUSED)
if paused:
Monitor(self.config).info(event=Event.PAUSED)

if random.SystemRandom().random() <= self.config.strategy.mutation_rate:
old_strategy = copy.deepcopy(self.config.strategy)
Expand Down
1 change: 0 additions & 1 deletion src/optimiser_fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
if TYPE_CHECKING:
from src.fuzzing_server import SPIRVShader
from src.monitor import Event, Monitor
from src.shader_utils import validate_spv_file

SPIRV_OPTIMISER_FLAGS = [
"--amd-ext-to-khr",
Expand Down
13 changes: 7 additions & 6 deletions src/shader_brokerage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pickle
from typing import TYPE_CHECKING

import dill

from src.execution_platform import ExecutionPlatform
from src.utils import get_spirvsmith_version

Expand All @@ -21,15 +22,15 @@


def GCS_upload_shader(shader: "SPIRVShader") -> None:
pickled_shader: bytes = pickle.dumps(shader, protocol=pickle.HIGHEST_PROTOCOL)
pickled_shader: bytes = dill.dumps(shader, protocol=dill.HIGHEST_PROTOCOL)
blob = BUCKET.blob(f"{shader.id}.pkl")
blob.upload_from_string(pickled_shader)


def GCS_download_shader(shader_id: str) -> "SPIRVShader":
blob = BUCKET.blob(f"{shader_id}.pkl")
pickled_shader: bytes = blob.download_as_bytes()
return pickle.loads(pickled_shader)
return dill.loads(pickled_shader)


def BQ_insert_new_shader(
Expand All @@ -39,7 +40,7 @@ def BQ_insert_new_shader(
INSERT INTO `spirvsmith.spirv.shader_data`
VALUES (
"{shader.id}",
{"1" if high_priority else "0"},
{1 if high_priority else 0},
"{generator_id}",
"{shader.context.config.misc.version}",
{len(shader.context.get_storage_buffers())},
Expand All @@ -50,7 +51,7 @@ def BQ_insert_new_shader(
NULL,
NULL,
NULL,
AUTO()
CURRENT_TIMESTAMP()
)
"""
BQ_CLIENT.query(insert_query).result()
Expand All @@ -77,7 +78,7 @@ def BQ_update_shader_with_buffer_dumps(
"{execution_platform.get_active_hardware().hardware_model}",
"{execution_platform.get_active_hardware().driver_version}",
"{execution_platform.vulkan_backend.value}",
"AUTO",
CURRENT_TIMESTAMP(),
)
"""
delete_query = f"""
Expand Down
2 changes: 1 addition & 1 deletion src/shader_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def create_amber_file(shader: SPIRVShader, filename: str) -> None:
fw.write("#!amber\n")
fw.write(f"SHADER compute {'shader'} SPIRV-ASM TARGET_ENV spv1.3\n")
with tempfile.NamedTemporaryFile(suffix=".spasm") as fr:
shader.generate_assembly_file(filename=fr.name)
shader.generate_assembly_file(fr.name)
lines = fr.readlines()
for line in lines:
fw.write(line.decode("utf-8"))
Expand Down

0 comments on commit 68e122d

Please sign in to comment.