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

daisytuner / docc / 25436733018

06 May 2026 12:59PM UTC coverage: 65.227% (+0.004%) from 65.223%
25436733018

Pull #681

github

web-flow
Merge e31167aa2 into 84dc11a09
Pull Request #681: Target specific expand

55 of 59 new or added lines in 3 files covered. (93.22%)

27 existing lines in 2 files now uncovered.

31624 of 48483 relevant lines covered (65.23%)

2351.88 hits per line

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

73.64
/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
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
)
19

20

21
def _cuda_expand_fn(sdfg, category: str, kwargs: Dict[str, Any]) -> None:
4✔
22
    sdfg.expand_cuda()
4✔
23
    sdfg.expand()
4✔
24

25

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

39

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

43

44
def _is_debug_compile(flags: dict[str, str]) -> bool:
4✔
45
    return "build" in flags
4✔
46

47

48
def _get_build_thread_count(flags: dict[str, str]) -> int:
4✔
49
    return int(flags.get("build_threads", "0"))
4✔
50

51

52
class DoccProgram(ABC):
4✔
53

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

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

90
        self.instrumentation_mode = instrumentation_mode
4✔
91
        self.capture_args = capture_args
4✔
92

93
        if target == "cuda":
4✔
94
            from docc.python import register_target_overrides
4✔
95

96
            register_target_overrides(
4✔
97
                "cuda",
98
                schedule_fn=None,
99
                compile_fn=None,
100
                expand_fn=_cuda_expand_fn,
101
            )
102

103
    @abstractmethod
4✔
104
    def __call__(self, *args: Any) -> Any:
4✔
105
        pass
×
106

107
    @abstractmethod
4✔
108
    def compile(self, *args: Any, output_folder: Optional[str] = None) -> CompiledSDFG:
4✔
109
        pass
×
110

111
    def sdfg_pipe(
4✔
112
        self,
113
        sdfg: StructuredSDFG,
114
        output_folder: Optional[str],
115
        instrumentation_mode: str,
116
        capture_args: bool,
117
    ) -> str:
118

119
        if self.debug_dump:
4✔
UNCOV
120
            sdfg.dump(output_folder, "py0.parsed", dump_dot=True)
×
121

122
        # Enable statistics if envvar is set
123
        if _statistics_enabled_by_env():
4✔
UNCOV
124
            _enable_statistics()
×
125

126
        sdfg.validate()
4✔
127

128
        # Tensor targets keep tensor nodes
129
        custom_expand_fn = get_target_expand_fn(self.target)
4✔
130
        if custom_expand_fn is not None:
4✔
131
            custom_expand_fn(sdfg, self.category, {})
4✔
132
        else:
133
            sdfg.expand()
4✔
134
        if self.debug_dump:
4✔
UNCOV
135
            sdfg.dump(output_folder, "py1.expanded", dump_dot=True)
×
136

137
        # Simplify pipelines
138
        sdfg.simplify()
4✔
139
        if self.debug_dump:
4✔
UNCOV
140
            sdfg.dump(output_folder, "py2.opt", dump_dot=True)
×
141

142
        # Normalization for scheduling
143
        if self.target != "none":
4✔
144
            sdfg.normalize()
4✔
145

146
        if self.debug_dump or instrumentation_mode or capture_args:
4✔
147
            sdfg.dump(
4✔
148
                output_folder,
149
                "py3.norm",
150
                dump_dot=self.debug_dump,
151
                dump_json=True,
152
                record_for_instrumentation=True,
153
            )
154

155
        # Schedule if target is specified
156

157
        if self.target != "none":
4✔
158
            # Check for custom registered target first
159
            custom_schedule_fn = get_target_schedule_fn(self.target)
4✔
160
            if custom_schedule_fn is not None:
4✔
161
                custom_schedule_fn(
4✔
162
                    sdfg, self.category, {"remote_tuning": self.remote_tuning}
163
                )
164
            else:
165
                sdfg.schedule(self.target, self.category, self.remote_tuning)
4✔
166

167
            if self.debug_dump:
4✔
UNCOV
168
                sdfg.dump(output_folder, "py4.post_sched", dump_dot=True)
×
169

170
        self.last_sdfg = sdfg
4✔
171

172
        custom_compile_fn = get_target_compile_fn(self.target)
4✔
173
        if custom_compile_fn is not None:
4✔
174
            lib_path = custom_compile_fn(
4✔
175
                sdfg,
176
                output_folder,
177
                instrumentation_mode,
178
                capture_args,
179
                {"debug_build": self.debug_build, "threads": self.build_thread_count},
180
            )
181
        else:
182
            lib_path = sdfg._compile(
4✔
183
                output_folder=output_folder,
184
                target=self.target,
185
                instrumentation_mode=instrumentation_mode,
186
                capture_args=capture_args,
187
                debug_build=self.debug_build,
188
                threads=self.build_thread_count,
189
            )
190

191
        # Dump statistics after compile
192
        if _statistics_enabled_by_env():
4✔
UNCOV
193
            print(_statistics_summary(), file=sys.stderr)
×
194

195
        return lib_path
4✔
196

197
    @abstractmethod
4✔
198
    def to_sdfg(self, *args: Any) -> StructuredSDFG:
4✔
UNCOV
199
        pass
×
200

201
    @abstractmethod
4✔
202
    def _convert_inputs(self, args: tuple) -> tuple:
4✔
UNCOV
203
        pass
×
204

205
    @abstractmethod
4✔
206
    def _convert_outputs(self, result: Any, original_args: tuple) -> Any:
4✔
207
        pass
×
208

209
    def _get_cache_key(self, *args: Any) -> str:
4✔
UNCOV
210
        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