|
3 | 3 | import dataclasses |
4 | 4 | import logging |
5 | 5 | import os |
6 | | -import threading |
7 | 6 | import time |
8 | 7 | from typing import TYPE_CHECKING |
9 | 8 | from typing import Literal |
|
20 | 19 | from .ref_mode import RefMode |
21 | 20 |
|
22 | 21 | if TYPE_CHECKING: |
23 | | - from contextlib import AbstractContextManager |
24 | | - |
25 | 22 | from ..autotuner.base_search import BaseAutotuner |
26 | 23 | from .kernel import BoundKernel |
27 | 24 |
|
28 | | - class _TLS(Protocol): |
29 | | - default_settings: Settings | None |
30 | | - |
31 | 25 | class AutotunerFunction(Protocol): |
32 | 26 | def __call__( |
33 | 27 | self, bound_kernel: BoundKernel, args: Sequence[object], **kwargs: object |
34 | 28 | ) -> BaseAutotuner: ... |
35 | 29 |
|
36 | 30 |
|
37 | | -_tls: _TLS = cast("_TLS", threading.local()) |
38 | | - |
39 | | - |
40 | | -def set_default_settings(settings: Settings) -> AbstractContextManager[None, None]: |
41 | | - """ |
42 | | - Set the default settings for the current thread and return a context manager |
43 | | - that restores the previous settings upon exit. |
44 | | -
|
45 | | - Args: |
46 | | - settings: The Settings object to set as the default. |
47 | | -
|
48 | | - Returns: |
49 | | - AbstractContextManager[None, None]: A context manager that restores the previous settings upon exit. |
50 | | - """ |
51 | | - prior = getattr(_tls, "default_settings", None) |
52 | | - _tls.default_settings = settings |
53 | | - |
54 | | - class _RestoreContext: |
55 | | - def __enter__(self) -> None: |
56 | | - pass |
57 | | - |
58 | | - def __exit__(self, *args: object) -> None: |
59 | | - _tls.default_settings = prior |
60 | | - |
61 | | - return _RestoreContext() |
62 | | - |
63 | | - |
64 | 31 | def default_autotuner_fn( |
65 | 32 | bound_kernel: BoundKernel, args: Sequence[object], **kwargs: object |
66 | 33 | ) -> BaseAutotuner: |
@@ -254,15 +221,8 @@ class Settings(_Settings): |
254 | 221 | def __init__(self, **settings: object) -> None: |
255 | 222 | """ |
256 | 223 | Initialize the Settings object with the provided dictionary of settings. |
257 | | - If no settings are provided, the default settings are used (see `set_default_settings`). |
258 | | -
|
259 | | - Args: |
260 | | - settings: Keyword arguments representing various settings. |
261 | 224 | """ |
262 | 225 |
|
263 | | - if defaults := getattr(_tls, "default_settings", None): |
264 | | - settings = {**defaults.to_dict(), **settings} |
265 | | - |
266 | 226 | super().__init__(**settings) # pyright: ignore[reportArgumentType] |
267 | 227 |
|
268 | 228 | self._check_ref_eager_mode_before_print_output_code() |
@@ -323,16 +283,3 @@ def _check_ref_eager_mode_before_print_output_code(self) -> None: |
323 | 283 | """ |
324 | 284 | if self.ref_mode == RefMode.EAGER and self.print_output_code: |
325 | 285 | raise exc.RefEagerModeCodePrintError |
326 | | - |
327 | | - @staticmethod |
328 | | - def default() -> Settings: |
329 | | - """ |
330 | | - Get the default Settings object. If no default settings are set, create a new one. |
331 | | -
|
332 | | - Returns: |
333 | | - Settings: The default Settings object. |
334 | | - """ |
335 | | - result = getattr(_tls, "default_settings", None) |
336 | | - if result is None: |
337 | | - _tls.default_settings = result = Settings() |
338 | | - return result |
0 commit comments