• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daisytuner / docc / 25931355994

15 May 2026 05:18PM UTC coverage: 60.837%. First build
25931355994

Pull #709

github

web-flow
Merge a3c81527d into df89083a8
Pull Request #709: Add support for tenstorrent backend to python front end

12 of 121 new or added lines in 9 files covered. (9.92%)

34996 of 57524 relevant lines covered (60.84%)

11107.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.9
/python/docc/compiler/docc_program.py
1
from abc import ABC, abstractmethod
4✔
2
import sys
4✔
3
from typing import Any, Dict, Optional
4✔
4
import os
4✔
5
import re
4✔
6

7
from docc.sdfg import StructuredSDFG, TargetOptions
4✔
8
from docc.sdfg._sdfg import (
4✔
9
    _enable_statistics,
10
    _statistics_enabled_by_env,
11
    _statistics_summary,
12
)
13
from docc.compiler.compiled_sdfg import CompiledSDFG
4✔
14
from docc.compiler.target_registry import (
4✔
15
    get_target_schedule_fn,
16
    get_target_compile_fn,
17
    get_target_expand_fn,
18
    register_target_overrides,
19
)
20

21

22
def _parse_docc_debug() -> dict[str, str]:
4✔
23
    debug_env = os.environ.get("DOCC_DEBUG", "")
4✔
24
    debug_dict = {}
4✔
25
    if debug_env:
4✔
26
        for entry in re.split(r"[;:]", debug_env):
×
27
            if not entry:
×
28
                continue
×
29
            parts = entry.split("=", 1)
×
30
            key = parts[0].strip()
×
31
            value = parts[1].strip() if len(parts) > 1 else ""
×
32
            debug_dict[key] = value
×
33
    return debug_dict
4✔
34

35

36
def _is_debug_dump(flags: dict[str, str]) -> bool:
4✔
37
    return "dump" in flags
4✔
38

39

40
def _is_debug_compile(flags: dict[str, str]) -> bool:
4✔
41
    return "build" in flags
4✔
42

43

44
def _get_build_thread_count(flags: dict[str, str]) -> int:
4✔
45
    return int(flags.get("build_threads", "0"))
4✔
46

47

48
class DoccProgram(ABC):
4✔
49

50
    def __init__(
4✔
51
        self,
52
        name: str,
53
        target: str = "none",
54
        category: str = "server",
55
        instrumentation_mode: Optional[str] = None,
56
        capture_args: Optional[bool] = None,
57
        remote_tuning: bool = False,
58
    ):
59
        self.name = name
4✔
60
        self.target = target
4✔
61
        self.category = category
4✔
62
        self.remote_tuning = remote_tuning
4✔
63
        self.last_sdfg: Optional[StructuredSDFG] = None
4✔
64
        self.cache: dict = {}
4✔
65
        debug_flags = _parse_docc_debug()
4✔
66
        self.debug_dump: bool = _is_debug_dump(debug_flags)
4✔
67
        self.debug_build: bool = _is_debug_compile(debug_flags)
4✔
68
        self.build_thread_count: int = _get_build_thread_count(debug_flags)
4✔
69

70
        # Check environment variable DOCC_CI
71
        docc_ci = os.environ.get("DOCC_CI", "")
4✔
72
        if docc_ci:
4✔
73
            if docc_ci == "regions":
×
74
                if instrumentation_mode is None:
×
75
                    instrumentation_mode = "ols"
×
76
            elif docc_ci == "arg-capture":
×
77
                if capture_args is None:
×
78
                    capture_args = True
×
79
            else:
80
                # Full mode (or unknown value treated as full)
81
                if instrumentation_mode is None:
×
82
                    instrumentation_mode = "ols"
×
83
                if capture_args is None:
×
84
                    capture_args = True
×
85

86
        self.instrumentation_mode = instrumentation_mode
4✔
87
        self.capture_args = capture_args
4✔
88

89
    @abstractmethod
4✔
90
    def __call__(self, *args: Any) -> Any:
4✔
91
        pass
×
92

93
    @abstractmethod
4✔
94
    def compile(self, *args: Any, output_folder: Optional[str] = None) -> CompiledSDFG:
4✔
95
        pass
×
96

97
    def sdfg_pipe(
4✔
98
        self,
99
        sdfg: StructuredSDFG,
100
        output_folder: Optional[str],
101
        instrumentation_mode: str,
102
        capture_args: bool,
103
    ) -> str:
104

105
        if self.debug_dump:
4✔
106
            sdfg.dump(output_folder, "py0.parsed", dump_dot=True)
×
107

108
        # Enable statistics if envvar is set
109
        if _statistics_enabled_by_env():
4✔
110
            _enable_statistics()
×
111

112
        sdfg.validate()
4✔
113

114
        target_options = TargetOptions()
4✔
115
        target_options.target = self.target
4✔
116
        target_options.category = self.category
4✔
117
        target_options.remote_tuning = self.remote_tuning
4✔
118

119
        # Tensor targets keep tensor nodes
120
        custom_expand_fn = get_target_expand_fn(self.target)
4✔
121
        if custom_expand_fn is not None:
4✔
122
            custom_expand_fn(sdfg, self.category, {})
4✔
123
        else:
124
            sdfg.expand(target_options)
4✔
125
        if self.debug_dump:
4✔
126
            sdfg.dump(output_folder, "py1.expanded", dump_dot=True)
×
127

128
        # Simplify pipelines
129
        sdfg.simplify()
4✔
130
        if self.debug_dump:
4✔
131
            sdfg.dump(output_folder, "py2.opt", dump_dot=True)
×
132

133
        # Normalization for scheduling
134
        if self.target != "none":
4✔
135
            sdfg.normalize()
4✔
136

137
        if self.debug_dump or instrumentation_mode or capture_args:
4✔
138
            sdfg.dump(
4✔
139
                output_folder,
140
                "py3.norm",
141
                dump_dot=self.debug_dump,
142
                dump_json=True,
143
                record_for_instrumentation=True,
144
            )
145

146
        # Schedule if target is specified
147

148
        custom_schedule_fn = get_target_schedule_fn(self.target)
4✔
149
        if custom_schedule_fn is not None:
4✔
150
            custom_schedule_fn(
4✔
151
                sdfg, self.category, {"remote_tuning": self.remote_tuning}
152
            )
153
        else:
154
            sdfg.schedule(target_options)
4✔
155

156
        if self.debug_dump:
4✔
NEW
157
            sdfg.dump(output_folder, "py4.post_sched", dump_dot=True)
×
158

159
        self.last_sdfg = sdfg
4✔
160

161
        custom_compile_fn = get_target_compile_fn(self.target)
4✔
162
        if custom_compile_fn is not None:
4✔
163
            lib_path = custom_compile_fn(
4✔
164
                sdfg,
165
                output_folder,
166
                instrumentation_mode,
167
                capture_args,
168
                {"debug_build": self.debug_build, "threads": self.build_thread_count},
169
            )
170
        else:
171
            lib_path = sdfg._compile(
4✔
172
                output_folder=output_folder,
173
                target=self.target,
174
                instrumentation_mode=instrumentation_mode,
175
                capture_args=capture_args,
176
                debug_build=self.debug_build,
177
                threads=self.build_thread_count,
178
            )
179

180
        # Dump statistics after compile
181
        if _statistics_enabled_by_env():
4✔
182
            print(_statistics_summary(), file=sys.stderr)
×
183

184
        return lib_path
4✔
185

186
    @abstractmethod
4✔
187
    def to_sdfg(self, *args: Any) -> StructuredSDFG:
4✔
188
        pass
×
189

190
    @abstractmethod
4✔
191
    def _convert_inputs(self, args: tuple) -> tuple:
4✔
192
        pass
×
193

194
    @abstractmethod
4✔
195
    def _convert_outputs(self, result: Any, original_args: tuple) -> Any:
4✔
196
        pass
×
197

198
    def _get_cache_key(self, *args: Any) -> str:
4✔
199
        return ""
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc