assassinlike commited on
Commit
67a2c62
·
verified ·
1 Parent(s): a235caa

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. data/conda_envs/abstr/lib/python3.11/site-packages/torch/_dynamo/repro/after_aot.py +1281 -0
  2. data/conda_envs/abstr/lib/python3.11/site-packages/torch/_prims/__pycache__/__init__.cpython-311.pyc +0 -0
  3. data/conda_envs/abstr/lib/python3.11/site-packages/torch/_prims/__pycache__/context.cpython-311.pyc +0 -0
  4. data/conda_envs/abstr/lib/python3.11/site-packages/torch/_prims/__pycache__/debug_prims.cpython-311.pyc +0 -0
  5. data/conda_envs/abstr/lib/python3.11/site-packages/torch/_prims/__pycache__/executor.cpython-311.pyc +0 -0
  6. data/conda_envs/abstr/lib/python3.11/site-packages/torch/_prims/__pycache__/rng_prims.cpython-311.pyc +0 -0
  7. data/conda_envs/abstr/lib/python3.11/site-packages/torch/compiler/__pycache__/__init__.cpython-311.pyc +0 -0
  8. data/conda_envs/abstr/lib/python3.11/site-packages/torch/compiler/__pycache__/_cache.cpython-311.pyc +0 -0
  9. data/conda_envs/abstr/lib/python3.11/site-packages/torch/compiler/__pycache__/config.cpython-311.pyc +0 -0
  10. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl.h +0 -0
  11. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl.hpp +0 -0
  12. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_common.h +180 -0
  13. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_common.hpp +484 -0
  14. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_common_types.h +268 -0
  15. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_config.h +237 -0
  16. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_debug.h +66 -0
  17. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph.h +777 -0
  18. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph.hpp +1639 -0
  19. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph_ocl.h +154 -0
  20. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph_ocl.hpp +161 -0
  21. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph_sycl.h +104 -0
  22. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph_sycl.hpp +136 -0
  23. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph_types.h +480 -0
  24. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_ocl.h +281 -0
  25. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_ocl.hpp +450 -0
  26. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_ocl_types.h +56 -0
  27. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_sycl.h +204 -0
  28. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_sycl.hpp +389 -0
  29. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_sycl_types.h +56 -0
  30. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_threadpool.h +123 -0
  31. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_threadpool.hpp +118 -0
  32. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_threadpool_iface.hpp +78 -0
  33. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_types.h +0 -0
  34. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_ukernel.h +342 -0
  35. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_ukernel.hpp +470 -0
  36. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_ukernel_types.h +98 -0
  37. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_version.h +38 -0
  38. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_version_hash.h +36 -0
  39. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/basic/factory.h +28 -0
  40. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/cma/factory.h +28 -0
  41. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/context.h +113 -0
  42. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/cuda_basic/factory.h +28 -0
  43. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/cuda_gdr/error.h +38 -0
  44. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/cuda_gdr/factory.h +31 -0
  45. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/cuda_ipc/factory.h +28 -0
  46. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/cuda_xth/factory.h +28 -0
  47. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/error.h +45 -0
  48. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/mpt/factory.h +32 -0
  49. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/xth/factory.h +28 -0
  50. data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/common/buffer.h +140 -0
data/conda_envs/abstr/lib/python3.11/site-packages/torch/_dynamo/repro/after_aot.py ADDED
@@ -0,0 +1,1281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Utilities for reproducing and debugging issues in PyTorch's Dynamo AOT compilation.
3
+
4
+ This module provides tools and infrastructure for:
5
+ 1. Generating minimal reproducible test cases ("repros") from failing compilations
6
+ 2. Analyzing accuracy issues between eager and compiled execution
7
+ 3. Minifying large models/inputs to isolate problematic patterns
8
+ 4. Debugging compiler errors and accuracy divergences
9
+
10
+ The main components include:
11
+ - Repro generation: Creates standalone Python files that reproduce compiler issues
12
+ - Minification: Reduces large graphs to minimal failing examples
13
+ - Accuracy analysis: Compares compiled vs eager execution, with fp64 reference
14
+ - Debug tools: Dumps graph state, tracks intermediates, analyzes divergences
15
+
16
+ This is primarily used by PyTorch developers and researchers to debug issues in
17
+ the Dynamo AOT compilation pipeline, particularly for the Inductor backend.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import argparse
23
+ import copy
24
+ import functools
25
+ import io
26
+ import logging
27
+ import os
28
+ import shutil
29
+ import subprocess
30
+ import sys
31
+ import textwrap
32
+ import uuid
33
+ from importlib import import_module
34
+ from tempfile import TemporaryFile
35
+ from typing import Any, IO, Optional, TYPE_CHECKING, Union
36
+ from typing_extensions import Unpack
37
+
38
+ import sympy
39
+
40
+
41
+ try:
42
+ from triton.runtime.autotuner import Autotuner, Heuristics
43
+ from triton.runtime.jit import JITFunction
44
+ except ImportError:
45
+
46
+ class Autotuner: # type: ignore[no-redef]
47
+ pass
48
+
49
+ class JITFunction: # type: ignore[no-redef]
50
+ pass
51
+
52
+ class Heuristics: # type: ignore[no-redef]
53
+ pass
54
+
55
+
56
+ import torch
57
+ import torch.fx as fx
58
+ import torch.nn as nn
59
+ from torch._dynamo.debug_utils import (
60
+ _cuda_system_info_comment,
61
+ AccuracyError,
62
+ backend_accuracy_fails,
63
+ BuckTargetWriter,
64
+ cast_to_fp64,
65
+ extra_deps,
66
+ extra_imports,
67
+ generate_config_string,
68
+ generate_env_vars_string,
69
+ helper_for_dump_minify,
70
+ InputReader,
71
+ InputWriter,
72
+ MAX_CONSTANT_NUMEL_INLINE,
73
+ minifier_dir,
74
+ NNModuleToString,
75
+ NopInputReader,
76
+ same_two_models,
77
+ )
78
+ from torch._dynamo.utils import clone_inputs, counters, same
79
+ from torch._environment import is_fbcode
80
+ from torch._higher_order_ops.triton_kernel_wrap import kernel_side_table
81
+ from torch._inductor.cpp_builder import normalize_path_separator
82
+ from torch._library.fake_class_registry import FakeScriptObject
83
+ from torch._ops import OpOverload
84
+ from torch.fx.experimental.proxy_tensor import make_fx
85
+ from torch.fx.experimental.symbolic_shapes import (
86
+ fx_placeholder_targets,
87
+ has_free_symbols,
88
+ )
89
+ from torch.hub import tqdm
90
+
91
+ from .. import config
92
+
93
+
94
+ if TYPE_CHECKING:
95
+ from collections.abc import Callable, Sequence
96
+
97
+ from torch._inductor.compile_fx import _CompileFxCallable, _CompileFxKwargs
98
+ from torch._inductor.output_code import OutputCode
99
+ from torch._inductor.utils import InputType
100
+
101
+
102
+ log = logging.getLogger(__name__)
103
+
104
+
105
+ inductor_config = import_module("torch._inductor.config")
106
+ use_buck = is_fbcode()
107
+
108
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
109
+ # MAIN ENTRY POINT
110
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
111
+
112
+
113
+ def wrap_compiler_debug(
114
+ unconfigured_compiler_fn: _CompileFxCallable,
115
+ compiler_name: str,
116
+ ) -> _CompileFxCallable:
117
+ """
118
+ Minifier for Fx Graph modules after Aot Autograd has finished. We wrap both
119
+ forward and backward call separately with the backend compiler_fn - like
120
+ inductor or nvfuser. Intercepting after Aot Autograd presents neat
121
+ abstraction, where all the params are lifted as graph inputs, making it easy
122
+ to save the graph as a string.
123
+ """
124
+
125
+ @functools.wraps(unconfigured_compiler_fn)
126
+ def debug_wrapper(
127
+ gm: torch.fx.GraphModule,
128
+ example_inputs: Sequence[InputType],
129
+ **kwargs: Unpack[_CompileFxKwargs],
130
+ ) -> OutputCode:
131
+ from torch._subclasses import FakeTensorMode
132
+
133
+ compiler_fn = functools.partial(unconfigured_compiler_fn, **kwargs)
134
+
135
+ from torch._functorch.aot_autograd import get_aot_graph_name
136
+
137
+ graph_name = get_aot_graph_name()
138
+
139
+ # TODO: why do we need to deepcopy the original graph?
140
+ orig_graph = copy.deepcopy(gm.graph)
141
+ assert config.repro_after in ("dynamo", "aot", None)
142
+
143
+ try:
144
+ # Call the compiler_fn - which is either aot_autograd or inductor
145
+ # with fake inputs
146
+ inner_compiled_fn = compiler_fn(gm, example_inputs)
147
+ except Exception:
148
+ # TODO: Failures here are troublesome because no real inputs,
149
+ # need a different serialization strategy
150
+ if config.repro_after == "aot":
151
+ if config.repro_level == 1:
152
+ dump_compiler_graph_state(
153
+ fx.GraphModule(gm, orig_graph),
154
+ example_inputs,
155
+ compiler_name,
156
+ )
157
+ elif config.repro_level == 2:
158
+ dump_to_minify(
159
+ fx.GraphModule(gm, orig_graph),
160
+ example_inputs,
161
+ compiler_name,
162
+ )
163
+ log.error("CompilerError")
164
+ raise
165
+
166
+ # We may run regular PyTorch compute that may trigger Dynamo, do NOT
167
+ # recursively attempt to accuracy minify in that case!
168
+ def deferred_for_real_inputs(
169
+ real_inputs: Sequence[InputType], **_kwargs: object
170
+ ) -> Any:
171
+ # This is a bit obscure: if we recursively try to accuracy minify
172
+ # the SAME function, this would trigger. But most of the time
173
+ # we should never hit this branch
174
+ assert not _kwargs
175
+ if config.repro_after != "aot":
176
+ assert not isinstance(inner_compiled_fn, str)
177
+ return inner_compiled_fn(real_inputs)
178
+ with config.patch(repro_after=None):
179
+ return inner_debug_fn(real_inputs)
180
+
181
+ def inner_debug_fn(real_inputs: Sequence[InputType]) -> Any:
182
+ """
183
+ Aot Autograd fw_compiler and bw_compiler can have fake tensors. So,
184
+ example_inputs can be fake tensors. We can call compiler_fn (which is
185
+ inductor or nvfuser) with fake tensors but the actually compiled_fn
186
+ should be called with real tensors. Therefore, the actual invocation
187
+ is deferred.
188
+ """
189
+ # Copy the tensor attrs like shape, stride etc by converting to Fake Tensor
190
+ # because inductor clears the tensor list in its codegen. And example_inputs
191
+ # are available only for the first invocation.
192
+ fake_mode = FakeTensorMode()
193
+ copy_tensor_attrs = [
194
+ fake_mode.from_tensor(x) if isinstance(x, torch.Tensor) else x
195
+ for x in real_inputs
196
+ ]
197
+ if config.repro_level == 3:
198
+ # Always dump the original module in case we have segfaults
199
+ dump_to_minify(
200
+ fx.GraphModule(gm, orig_graph), real_inputs, compiler_name
201
+ )
202
+
203
+ if config.repro_level == 4:
204
+ if compiler_name != "inductor":
205
+ raise NotImplementedError(
206
+ "Accuracy minification is supported for inductor only"
207
+ )
208
+ failed = not same_two_models(
209
+ gm,
210
+ inner_compiled_fn, # type: ignore[arg-type]
211
+ real_inputs,
212
+ only_fwd=True,
213
+ ignore_non_fp=config.repro_ignore_non_fp,
214
+ )
215
+
216
+ if failed:
217
+ log.warning(
218
+ "Accuracy failed for the AOT Autograd graph %s", graph_name
219
+ )
220
+ dump_compiler_graph_state(
221
+ fx.GraphModule(gm, orig_graph),
222
+ real_inputs,
223
+ f"{compiler_name}_accuracy",
224
+ )
225
+ dump_to_minify(
226
+ fx.GraphModule(gm, orig_graph),
227
+ real_inputs,
228
+ f"{compiler_name}_accuracy",
229
+ )
230
+ raise AccuracyError("Bad accuracy detected")
231
+ else:
232
+ # Call the compiled function with real inputs
233
+ return inner_compiled_fn(real_inputs) # type: ignore[operator]
234
+ else:
235
+ try:
236
+ # Call the compiled function with real inputs
237
+ out = inner_compiled_fn(real_inputs) # type: ignore[operator]
238
+ # sync cuda kernels to ensure IMA detection
239
+ for arg in example_inputs:
240
+ if isinstance(arg, torch.Tensor) and arg.is_cuda:
241
+ torch.cuda.synchronize()
242
+ break
243
+ return out
244
+ except Exception:
245
+ if config.repro_level == 1:
246
+ dump_compiler_graph_state(
247
+ fx.GraphModule(gm, orig_graph),
248
+ copy_tensor_attrs,
249
+ compiler_name,
250
+ )
251
+ elif config.repro_level == 2:
252
+ dump_to_minify(
253
+ fx.GraphModule(gm, orig_graph),
254
+ copy_tensor_attrs,
255
+ compiler_name,
256
+ )
257
+ raise
258
+
259
+ if config.repro_after == "aot":
260
+ compiled_fn = deferred_for_real_inputs
261
+ compiled_fn._boxed_call = True # type: ignore[attr-defined]
262
+ return compiled_fn # type: ignore[return-value]
263
+ else:
264
+ return inner_compiled_fn
265
+
266
+ return debug_wrapper
267
+
268
+
269
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
270
+ # DUMP REPROS
271
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
272
+
273
+
274
+ def maybe_fbcode_instructions() -> str:
275
+ if is_fbcode():
276
+ extra_deps_formatted = "\n".join([f' "{dep}",' for dep in extra_deps])
277
+ if len(extra_deps_formatted) > 0:
278
+ extra_deps_formatted = "\n" + extra_deps_formatted
279
+ return f"""\
280
+ \"\"\"
281
+ To run this script in fbcode:
282
+ - Create a directory (//scripts/{{your_unixname}}/repro)
283
+ - Put this file in scripts/{{your_unixname}}/repro/fx_graph_runnable.py
284
+ - Add a TARGETS file that looks like the following
285
+ - `buck2 run //scripts/{{your_unixname}}/repro:repro`
286
+
287
+ NOTE: you may need additional deps to actually be able to run the script.
288
+ ```
289
+ # Contents of TARGETS file
290
+ load("@fbcode_macros//build_defs:python_binary.bzl", "python_binary")
291
+
292
+ python_binary(
293
+ name = "repro",
294
+ main_src = "fx_graph_runnable.py",
295
+ deps = [
296
+ "//caffe2:torch",{extra_deps_formatted}
297
+ ],
298
+ )
299
+ ```
300
+ \"\"\"
301
+ """
302
+ else:
303
+ return ""
304
+
305
+
306
+ def generate_compiler_repro_string(
307
+ gm: torch.fx.GraphModule,
308
+ args: Sequence[Any],
309
+ *,
310
+ stable_output: bool = False,
311
+ save_dir: Optional[str] = None,
312
+ stable_hash: bool = False,
313
+ has_distributed_ops: bool = False,
314
+ ) -> str:
315
+ if save_dir is not None:
316
+ save_dir = normalize_path_separator(save_dir)
317
+ # Add distributed imports if needed
318
+ distributed_imports = ""
319
+ if has_distributed_ops:
320
+ distributed_imports = textwrap.dedent(
321
+ """
322
+ import torch.distributed as dist
323
+ from torch.testing._internal.distributed.fake_pg import FakeStore
324
+ """
325
+ ).strip()
326
+
327
+ triton_imports = ""
328
+
329
+ if len(kernel_side_table.id_to_kernel) > 0:
330
+ triton_imports = textwrap.dedent(
331
+ """
332
+ import triton
333
+ import triton.language as tl
334
+ """
335
+ ).strip()
336
+
337
+ model_str = textwrap.dedent(
338
+ f"""
339
+ {generate_env_vars_string(stable_output=stable_output)}
340
+ import torch
341
+ from torch import tensor, device
342
+ import torch.fx as fx
343
+ from torch._dynamo.testing import rand_strided
344
+ from math import inf
345
+ import torch._inductor.inductor_prims
346
+ {distributed_imports}
347
+ {triton_imports}
348
+
349
+ {generate_config_string(stable_output=stable_output)}
350
+
351
+ isolate_fails_code_str = None
352
+
353
+ {extra_imports}
354
+
355
+ {maybe_fbcode_instructions()}
356
+ """
357
+ )
358
+ model_str += textwrap.dedent(
359
+ """
360
+ if "__compile_source__" in globals():
361
+ import inspect as __after_aot_inspect
362
+ import linecache as __after_aot_linecache
363
+ __after_aot_filename = __after_aot_inspect.currentframe().f_code.co_filename
364
+ __after_aot_linecache.cache[__after_aot_filename] = (
365
+ len(__compile_source__),
366
+ None,
367
+ __compile_source__.splitlines(True),
368
+ __after_aot_filename,
369
+ )
370
+ """
371
+ )
372
+ if not stable_output:
373
+ model_str += f"# torch version: {torch.version.__version__}\n"
374
+ if hasattr(torch.version, "cuda"):
375
+ model_str += f"# torch cuda version: {torch.version.cuda}\n"
376
+ if hasattr(torch.version, "git_version"):
377
+ model_str += f"# torch git version: {torch.version.git_version}\n\n\n"
378
+ model_str += _cuda_system_info_comment()
379
+
380
+ kernel_side_table_prefix = (
381
+ "torch._higher_order_ops.triton_kernel_wrap.kernel_side_table"
382
+ )
383
+ # Track which grid entry corresponds to the best config
384
+ for id in kernel_side_table.id_to_kernel:
385
+ kernel = kernel_side_table.get_kernel(id)
386
+
387
+ try:
388
+ if isinstance(kernel, Autotuner):
389
+ # pyrefly: ignore [missing-attribute]
390
+ if isinstance(kernel.fn, Heuristics):
391
+ model_str += "ERROR: Repro will not work as intended, "
392
+ model_str += "triton.runtime.autotuner.Heuristics is not currently supported\n"
393
+ break
394
+
395
+ config_strs = []
396
+ # pyrefly: ignore [missing-attribute]
397
+ for kernel_config in kernel.configs:
398
+ # pyrefly: ignore [bad-argument-type]
399
+ config_strs.append(f"""triton.Config(
400
+ {str(kernel_config.kwargs)},
401
+ num_warps={kernel_config.num_warps},
402
+ num_stages={kernel_config.num_stages},
403
+ )""")
404
+
405
+ config_str = ",".join(config_strs)
406
+ model_str += textwrap.dedent(f"""
407
+ @triton.autotune(
408
+ configs=[
409
+ {config_str}
410
+ ],
411
+ key=[]
412
+ )
413
+ """).strip()
414
+
415
+ model_str += "\n@triton.jit\n"
416
+ # pyrefly: ignore [missing-attribute]
417
+ src_code = kernel.src if isinstance(kernel, JITFunction) else kernel.fn.src
418
+ fn_name = (
419
+ # pyrefly: ignore [missing-attribute]
420
+ kernel._fn_name
421
+ if isinstance(kernel, JITFunction)
422
+ # pyrefly: ignore # missing-attribute
423
+ else kernel.fn._fn_name
424
+ )
425
+ fn_name = fn_name.split(".")[-1]
426
+
427
+ model_str += src_code
428
+ model_str += "\n"
429
+ model_str += f"{kernel_side_table_prefix}.add_kernel({fn_name})\n"
430
+ except AttributeError as e:
431
+ model_str += "ERROR: Repro will not work as intended, "
432
+ model_str += f"User defined triton kernel exception: {e}\n"
433
+
434
+ # pyrefly: ignore [unbound-name]
435
+ if len(kernel_side_table.constant_args) > 0:
436
+ # pyrefly: ignore [unbound-name]
437
+ model_str += f"{kernel_side_table_prefix}.constant_args={kernel_side_table.constant_args}\n"
438
+
439
+ model_str += NNModuleToString.convert(gm)
440
+
441
+ writer = InputWriter(save_dir, stable_hash=stable_hash)
442
+ used_syms = {}
443
+
444
+ # Extract from graph placeholders and their corresponding arguments
445
+ placeholder_targets = fx_placeholder_targets(gm)
446
+ for placeholder, arg in zip(placeholder_targets, args):
447
+ # pyrefly: ignore [unbound-name]
448
+ if isinstance(arg, (int, torch.SymInt)):
449
+ writer.symint(placeholder, arg)
450
+ # pyrefly: ignore [unbound-name]
451
+ elif isinstance(arg, torch.Tensor):
452
+ # TODO: improve these names with FQN
453
+ writer.tensor(placeholder, arg)
454
+ elif arg is None:
455
+ writer.const(placeholder)
456
+ else:
457
+ writer.unsupported(placeholder, arg)
458
+
459
+ # Extract symbolic variables from the same arguments
460
+ # pyrefly: ignore [unbound-name]
461
+ if (
462
+ # pyrefly: ignore [unbound-name]
463
+ isinstance(arg, torch.SymInt)
464
+ # By checking sympy.Symbol, we are excluding any symbolic expressions.
465
+ # TODO: we may need to solve expressions to extract symbol definitions.
466
+ and isinstance(arg.node.expr, sympy.Symbol)
467
+ and arg.node.hint is not None
468
+ ):
469
+ used_syms[str(arg.node)] = arg.node.hint
470
+ # pyrefly: ignore [unbound-name]
471
+ elif isinstance(arg, torch.Tensor):
472
+ # Extract symbolic variables from tensor shapes and strides
473
+ for dim in arg.shape:
474
+ # pyrefly: ignore [unbound-name]
475
+ if (
476
+ # pyrefly: ignore [unbound-name]
477
+ isinstance(dim, torch.SymInt)
478
+ and isinstance(dim.node.expr, sympy.Symbol)
479
+ and dim.node.hint is not None
480
+ ):
481
+ used_syms[str(dim.node)] = dim.node.hint
482
+ for stride in arg.stride():
483
+ # pyrefly: ignore [unbound-name]
484
+ if (
485
+ # pyrefly: ignore [unbound-name]
486
+ isinstance(stride, torch.SymInt)
487
+ and isinstance(stride.node.expr, sympy.Symbol)
488
+ and stride.node.hint is not None
489
+ ):
490
+ used_syms[str(stride.node)] = stride.node.hint
491
+ # Add symbolic variable definitions to the top of the generated code
492
+ if used_syms:
493
+ hint_lines = "\n".join(
494
+ f"{name} = {hint}" for name, hint in sorted(used_syms.items())
495
+ )
496
+ model_str = f"{hint_lines}\n\n{model_str}"
497
+
498
+ load_args_lines = writer.lines()
499
+ load_args_code = "\n".join(load_args_lines)
500
+ model_str += load_args_code + "\n"
501
+
502
+ model_str += "mod = Repro()\n"
503
+ return model_str
504
+
505
+
506
+ def save_graph_repro(
507
+ fd: IO[Any],
508
+ gm: torch.fx.GraphModule,
509
+ args: Sequence[Any],
510
+ compiler_name: str,
511
+ *,
512
+ stable_output: bool = False,
513
+ save_dir: Optional[str] = None,
514
+ command: str = "run",
515
+ accuracy: Optional[Union[str, bool]] = None,
516
+ tracing_mode: Optional[str] = None,
517
+ check_str: Optional[str] = None,
518
+ stable_hash: bool = False,
519
+ ) -> None:
520
+ if any(
521
+ isinstance(arg, torch.fx.experimental._backward_state.BackwardState)
522
+ for arg in args
523
+ ):
524
+ fd.write(
525
+ "Repro is not generated due to existence of BackwardState in graph input"
526
+ )
527
+ return
528
+
529
+ if save_dir is not None:
530
+ save_dir = normalize_path_separator(save_dir)
531
+
532
+ # Check if the graph contains distributed operations
533
+ has_distributed_ops = any(
534
+ node.op == "call_function"
535
+ and isinstance(node.target, OpOverload)
536
+ and node.target.namespace in {"_c10d_functional", "c10d_functional"}
537
+ for node in gm.graph.nodes
538
+ )
539
+
540
+ fd.write(
541
+ generate_compiler_repro_string(
542
+ gm,
543
+ args,
544
+ stable_output=stable_output,
545
+ save_dir=save_dir,
546
+ stable_hash=stable_hash,
547
+ has_distributed_ops=has_distributed_ops,
548
+ )
549
+ )
550
+ if accuracy is None:
551
+ accuracy = "_accuracy" in compiler_name
552
+ if tracing_mode is None:
553
+ tracing_mode = "real"
554
+ if any(
555
+ has_free_symbols(a) for a in args if not isinstance(a, FakeScriptObject)
556
+ ):
557
+ tracing_mode = "symbolic"
558
+ fd.write("if __name__ == '__main__':\n")
559
+ fd.write(" from torch._dynamo.repro.after_aot import run_repro\n")
560
+
561
+ # Add distributed initialization before run_repro if needed
562
+ if has_distributed_ops:
563
+ fd.write(
564
+ " # Initialize FakeProcessGroup for distributed operations\n"
565
+ " store = FakeStore()\n"
566
+ " dist.init_process_group(\n"
567
+ ' backend="fake",\n'
568
+ " rank=0,\n"
569
+ " world_size=2,\n"
570
+ " store=store\n"
571
+ " )\n"
572
+ )
573
+
574
+ fd.write(
575
+ f" with torch.no_grad():\n"
576
+ f" run_repro(mod, load_args, accuracy={accuracy!r}, command={command!r}, "
577
+ f"save_dir={save_dir!r}, tracing_mode={tracing_mode!r}, check_str={check_str!r})\n"
578
+ f" # To run it separately, do \n"
579
+ f" # mod, args = run_repro(mod, load_args, accuracy={accuracy!r}, command='get_args', "
580
+ f"save_dir={save_dir!r}, tracing_mode={tracing_mode!r}, check_str={check_str!r})\n"
581
+ f" # mod(*args)"
582
+ )
583
+
584
+ # Add distributed cleanup after run_repro
585
+ if has_distributed_ops:
586
+ fd.write("\n dist.destroy_process_group()\n")
587
+
588
+
589
+ def dump_compiler_graph_state(
590
+ gm: torch.fx.GraphModule,
591
+ args: Sequence[Any],
592
+ compiler_name: str,
593
+ *,
594
+ accuracy: Optional[Union[str, bool]] = None,
595
+ ) -> None:
596
+ subdir = os.path.join(minifier_dir(), "checkpoints")
597
+ if not os.path.exists(subdir):
598
+ os.makedirs(subdir, exist_ok=True)
599
+ file_name = os.path.join(subdir, f"{len(gm.graph.nodes)}.py")
600
+ log.warning(
601
+ "Writing checkpoint with %s nodes to %s", len(gm.graph.nodes), file_name
602
+ )
603
+ with open(file_name, "w") as fd:
604
+ save_graph_repro(
605
+ fd, gm, args, compiler_name, save_dir=subdir, accuracy=accuracy
606
+ )
607
+ curdir = os.getcwd()
608
+ repro_path = os.path.join(curdir, "repro.py")
609
+ try:
610
+ shutil.copyfile(file_name, repro_path)
611
+ log.warning("Copying repro file for convenience to %s", repro_path)
612
+ if use_buck:
613
+ BuckTargetWriter(file_name).write()
614
+ except OSError:
615
+ log.warning("No write permissions for %s", repro_path)
616
+
617
+
618
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
619
+ # DUMP MINIFIER
620
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
621
+
622
+
623
+ def dump_to_minify(
624
+ gm: torch.fx.GraphModule, args: Sequence[Any], compiler_name: str
625
+ ) -> None:
626
+ out = io.StringIO()
627
+ # TODO: factor this out
628
+ subdir = os.path.join(minifier_dir(), "checkpoints")
629
+ if not os.path.exists(subdir):
630
+ os.makedirs(subdir, exist_ok=True)
631
+ save_graph_repro(out, gm, args, compiler_name, save_dir=subdir, command="minify")
632
+ return helper_for_dump_minify(out.getvalue())
633
+
634
+
635
+ def isolate_fails(
636
+ fx_g: torch.fx.GraphModule,
637
+ args: Sequence[Any],
638
+ compiler_name: str,
639
+ env: Optional[dict[str, Any]] = None,
640
+ save_dir: Optional[str] = None,
641
+ accuracy: Optional[Union[bool, str]] = None,
642
+ tracing_mode: Optional[str] = None,
643
+ check_str: Optional[str] = None,
644
+ ) -> bool:
645
+ if env is None:
646
+ env = {}
647
+ subdir = os.path.join(os.getcwd(), "isolate")
648
+ if not os.path.exists(subdir):
649
+ os.makedirs(subdir, exist_ok=True)
650
+ file_name = os.path.join(subdir, f"{str(uuid.uuid4())[:5]}.py")
651
+ with open(file_name, "w") as fd:
652
+ save_graph_repro(
653
+ fd,
654
+ fx_g,
655
+ args,
656
+ compiler_name,
657
+ save_dir=save_dir,
658
+ command="minifier-query",
659
+ accuracy=accuracy,
660
+ tracing_mode=tracing_mode,
661
+ check_str=check_str,
662
+ )
663
+ # with open(file_name, "r") as fd:
664
+ # print(fd.read())
665
+ new_env = os.environ.copy()
666
+ new_env = {**new_env, **env}
667
+ if use_buck:
668
+ cmd = BuckTargetWriter(file_name).write(print_msg=False)
669
+ else:
670
+ cmd = [sys.executable, file_name]
671
+ with (
672
+ TemporaryFile() as stdout,
673
+ TemporaryFile() as stderr,
674
+ subprocess.Popen(
675
+ cmd,
676
+ cwd=subdir,
677
+ stdout=stdout,
678
+ stderr=stderr,
679
+ env=new_env,
680
+ ) as p,
681
+ ):
682
+ p.wait()
683
+
684
+ stdout.seek(0)
685
+ stderr.seek(0)
686
+ print(
687
+ textwrap.indent(stdout.read().decode("utf-8"), prefix=">> "),
688
+ file=sys.stdout,
689
+ )
690
+ print(
691
+ textwrap.indent(stderr.read().decode("utf-8"), prefix=">> "),
692
+ file=sys.stderr,
693
+ )
694
+ # print(f"Isolated test failed - {file_name}")
695
+ return p.returncode != 0
696
+
697
+
698
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
699
+ # MINIFIER TOOLS
700
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
701
+
702
+
703
+ def inductor_fails(
704
+ fx_g: torch.fx.GraphModule, args: Sequence[Any], check_str: Optional[str] = None
705
+ ) -> bool:
706
+ has_cuda = False
707
+ for arg in args:
708
+ if isinstance(arg, torch.Tensor) and arg.is_cuda:
709
+ has_cuda = True
710
+ break
711
+
712
+ def sync() -> None:
713
+ if has_cuda:
714
+ # Ensures that segfaults are surfaced
715
+ torch.cuda.synchronize()
716
+
717
+ from torch._inductor.compile_fx import compile_fx_inner
718
+
719
+ try:
720
+ result = fx_g(*args)
721
+ assert isinstance(result, (tuple, list))
722
+ assert not any(isinstance(x, (tuple, list)) for x in result)
723
+ except Exception:
724
+ return False
725
+
726
+ sync()
727
+
728
+ try:
729
+ compile_mod = compile_fx_inner(fx_g, args)
730
+ assert not isinstance(compile_mod, str)
731
+ compile_mod(args)
732
+ sync()
733
+ except Exception as e:
734
+ if check_str is not None and check_str not in repr(e):
735
+ return False
736
+ print(repr(e))
737
+ return True
738
+ return False
739
+
740
+
741
+ def inductor_accuracy_fails(
742
+ fx_g: torch.fx.GraphModule,
743
+ args: Sequence[Any],
744
+ check_str: Optional[str] = None,
745
+ *,
746
+ require_fp64: bool = False,
747
+ ignore_non_fp: bool = False,
748
+ ) -> bool:
749
+ from torch._inductor.compile_fx import compile_fx_inner
750
+
751
+ return backend_aot_accuracy_fails(
752
+ fx_g,
753
+ args, # type: ignore[arg-type]
754
+ compile_fx_inner, # type: ignore[arg-type]
755
+ require_fp64=require_fp64,
756
+ ignore_non_fp=ignore_non_fp,
757
+ )
758
+
759
+
760
+ backend_aot_accuracy_fails = functools.partial(backend_accuracy_fails, only_fwd=True)
761
+
762
+
763
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
764
+ # REPRO MAIN
765
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
766
+
767
+
768
+ def repro_common(
769
+ options: Any, mod: nn.Module, load_args: Any
770
+ ) -> tuple[torch.fx.GraphModule, Sequence[Any]]:
771
+ # Invariant for graphs we generate with the repro script
772
+ assert not any(mod.named_parameters())
773
+ for n, b in mod.named_buffers():
774
+ if b.numel() > MAX_CONSTANT_NUMEL_INLINE:
775
+ log.warning(
776
+ "Constant %s was not serialized, generated random data instead. "
777
+ "If you think this is affecting you, please comment on "
778
+ "https://github.com/pytorch/pytorch/issues/100468",
779
+ n,
780
+ )
781
+
782
+ if not hasattr(load_args, "_version"):
783
+ log.warning(
784
+ "load_args does not have a _version attribute, please file a bug to PyTorch "
785
+ "and describe how you generate this repro script"
786
+ )
787
+ else:
788
+ if load_args._version > 0:
789
+ log.warning(
790
+ "load_args is version %s, but this version of PyTorch only supports "
791
+ "version 0. We will try to run it anyway but there may be an incompatibility; "
792
+ "if so, try upgrading your version of PyTorch.",
793
+ load_args._version,
794
+ )
795
+
796
+ nop_reader = NopInputReader()
797
+ load_args(nop_reader)
798
+
799
+ with tqdm(desc="Loading inputs", total=nop_reader.total) as pbar:
800
+ input_reader = InputReader(save_dir=options.save_dir, pbar=pbar)
801
+ load_args(input_reader)
802
+ args = input_reader.args
803
+
804
+ # Turn mod into a GraphModule the slow way
805
+ # TODO: speed this up
806
+ mod = make_fx(mod, tracing_mode=options.tracing_mode)(*args)
807
+
808
+ # pyrefly: ignore [bad-assignment]
809
+ torch._inductor.config.generate_intermediate_hooks = True
810
+
811
+ return mod, args
812
+
813
+
814
+ ACCURACY_FAILS: dict[str, Callable[[torch.fx.GraphModule, Any], bool]] = {
815
+ "": inductor_fails,
816
+ # This might look inverted but it's not. strict_accuracy means "we will
817
+ # minify any time we see anything that diverges", whereas accuracy is more
818
+ # conservative, and will only minify if there is a meaningful fp64
819
+ # divergence
820
+ "accuracy": functools.partial(
821
+ inductor_accuracy_fails, require_fp64=True, ignore_non_fp=True
822
+ ),
823
+ "strict_accuracy": inductor_accuracy_fails,
824
+ }
825
+
826
+
827
+ def repro_minifier_query(options: Any, mod: nn.Module, load_args: Any) -> None:
828
+ mod, args = repro_common(options, mod, load_args)
829
+ fail_fn = functools.partial(
830
+ ACCURACY_FAILS[options.accuracy],
831
+ check_str=options.check_str, # type: ignore[call-arg]
832
+ )
833
+ if fail_fn(mod, args):
834
+ sys.exit(1)
835
+ else:
836
+ sys.exit(0)
837
+
838
+
839
+ def repro_minify(options: Any, mod: nn.Module, load_args: Any) -> None:
840
+ from functorch.compile import minifier
841
+
842
+ mod, args = repro_common(options, mod, load_args)
843
+ compiler_name = "inductor_accuracy" if options.accuracy != "" else "inductor"
844
+
845
+ favored_device = 1 if torch.cuda.device_count() >= 2 else 0
846
+ env_variables = {"CUDA_VISIBLE_DEVICES": str(favored_device)}
847
+
848
+ module_fails: Any
849
+ if options.isolate:
850
+ module_fails = functools.partial(
851
+ isolate_fails,
852
+ env=env_variables,
853
+ compiler_name=compiler_name,
854
+ save_dir=options.save_dir,
855
+ accuracy=options.accuracy,
856
+ tracing_mode=options.tracing_mode,
857
+ )
858
+ else:
859
+ module_fails = ACCURACY_FAILS[options.accuracy]
860
+
861
+ minifier(
862
+ mod,
863
+ args,
864
+ module_fails=functools.partial(module_fails, check_str=options.check_str),
865
+ dump_state=functools.partial(
866
+ dump_compiler_graph_state, compiler_name=compiler_name
867
+ ),
868
+ save_dir=options.save_dir,
869
+ offload_to_disk=options.offload_to_disk,
870
+ skip_offload=options.skip_saving_eager_intermediates,
871
+ skip_sanity=options.skip_sanity,
872
+ max_granularity=options.max_granularity,
873
+ )
874
+
875
+
876
+ def repro_analyze(options: Any, mod: nn.Module, load_args: Any) -> None:
877
+ from torch._inductor.compile_fx import compile_fx_inner
878
+ from torch._inductor.hooks import intermediate_hook
879
+
880
+ mod, args = repro_common(options, mod, load_args)
881
+
882
+ # TODO: The logic for cloning inputs/models here is intentionally
883
+ # modeled off of run_fwd_maybe_bwd, but arguably it is better not to
884
+ # clone inputs (as you are doubling your effective GPU memory usage).
885
+ # It is certainly faster though! It probably makes sense to let the
886
+ # user specify the offload strategy.
887
+
888
+ with tqdm(desc="Compiling"):
889
+ compiled = compile_fx_inner(mod, args)
890
+ total = counters["inductor"]["intermediate_hooks"]
891
+
892
+ known_names = set()
893
+
894
+ def save_hook(name: str, val: Any) -> None:
895
+ known_names.add(name)
896
+ if not options.skip_saving_inductor_intermediates:
897
+ writer.write_tensor(os.path.join("inductor", name), val)
898
+ pbar.update(1) # type: ignore[has-type]
899
+
900
+ writer = torch.utils._content_store.ContentStoreWriter(
901
+ options.save_dir, stable_hash=options.stable_hash
902
+ )
903
+ reader = torch.utils._content_store.ContentStoreReader(options.save_dir)
904
+
905
+ new_args = clone_inputs(args)
906
+ with (
907
+ intermediate_hook(save_hook),
908
+ tqdm(desc="Saving inductor intermediates", total=total) as pbar,
909
+ ):
910
+ assert not isinstance(compiled, str)
911
+ compiled(new_args) # type: ignore[arg-type]
912
+ assert not new_args
913
+
914
+ def compare_tuples(tuple1: tuple[Any], tuple2: tuple[Any]) -> Optional[str]:
915
+ diff_indices = [i for i in range(len(tuple1)) if tuple1[i] != tuple2[i]]
916
+ diff_values = [(tuple1[i], tuple2[i]) for i in diff_indices]
917
+
918
+ if not diff_values:
919
+ return None
920
+ else:
921
+ return " and ".join(f"{a} != {b}" for a, b in diff_values)
922
+
923
+ def check_hook(name: str, val: Any) -> None:
924
+ meta = writer.compute_tensor_metadata(val)
925
+ meta2 = reader.read_tensor_metadata(os.path.join("inductor", name))
926
+ reason = compare_tuples(meta, meta2)
927
+ if reason is not None:
928
+ pbar.write(f"NONDETERMINISTIC INDUCTOR at {name} ({reason})")
929
+ pbar.update(1)
930
+
931
+ if not options.skip_check_deterministic:
932
+ new_args = clone_inputs(args)
933
+ with (
934
+ intermediate_hook(check_hook),
935
+ tqdm(desc="Checking inductor determinism", total=total) as pbar,
936
+ ):
937
+ compiled(new_args) # type: ignore[arg-type]
938
+ assert not new_args
939
+
940
+ class WriterInterp(fx.Interpreter):
941
+ def __init__(self, mod: torch.nn.Module, subdir: str) -> None:
942
+ super().__init__(mod)
943
+ self.subdir = subdir
944
+
945
+ def run_node(self, n: torch.fx.Node) -> Any:
946
+ r = super().run_node(n)
947
+ name = n.name
948
+ if name in known_names:
949
+ pbar.update(1)
950
+ writer.write_tensor(os.path.join(self.subdir, name), r)
951
+ return r
952
+
953
+ # NB: the module cast doesn't actually do anything, since there are no
954
+ # parameters/buffers on the module
955
+ if not options.skip_saving_float64_intermediates:
956
+ new_mod, new_args = cast_to_fp64(copy.deepcopy(mod), clone_inputs(args)) # type: ignore[arg-type]
957
+ with tqdm(desc="Saving float64 intermediates", total=total) as pbar:
958
+ WriterInterp(new_mod, "float64").boxed_run(new_args)
959
+ assert not new_args
960
+
961
+ class ExactReaderInterp(fx.Interpreter):
962
+ def run_node(self, n: torch.fx.Node) -> Any:
963
+ r = super().run_node(n)
964
+ name = n.name
965
+ if name in known_names:
966
+ meta = writer.compute_tensor_metadata(r)
967
+ meta2 = reader.read_tensor_metadata(os.path.join("float64", name))
968
+ reason = compare_tuples(meta, meta2)
969
+ if reason is not None:
970
+ pbar.write(f"NONDETERMINISTIC FLOAT64 at {name} ({reason})")
971
+ pbar.update(1)
972
+ return r
973
+
974
+ # TODO: check eager determinism
975
+
976
+ if not options.skip_check_deterministic:
977
+ new_mod, new_args = cast_to_fp64(copy.deepcopy(mod), clone_inputs(args)) # type: ignore[arg-type]
978
+ with tqdm(desc="Checking float64 determinism", total=total) as pbar:
979
+ ExactReaderInterp(new_mod).boxed_run(new_args)
980
+ assert not new_args
981
+
982
+ # Now that we've saved everything, interp through the eager graph
983
+ # and do comparisons
984
+ class ReaderInterp(fx.Interpreter):
985
+ def run_node(self, n: torch.fx.Node) -> Any:
986
+ r = super().run_node(n)
987
+ name = n.name
988
+ if name in known_names:
989
+ inductor = reader.read_tensor(os.path.join("inductor", name))
990
+ float64 = reader.read_tensor(os.path.join("float64", name))
991
+ logged = False
992
+
993
+ def log_error(msg: str, *args: Any) -> None:
994
+ nonlocal logged
995
+ logged = True
996
+ pbar.write(f"DIVERGED at {name}: {msg % args}")
997
+
998
+ if not same(
999
+ r,
1000
+ inductor,
1001
+ float64,
1002
+ tol=torch._dynamo.config.repro_tolerance,
1003
+ equal_nan=True,
1004
+ log_error=log_error,
1005
+ ):
1006
+ assert logged
1007
+ pbar.update(1)
1008
+ return r
1009
+
1010
+ with tqdm(desc="Checking divergence", total=total) as pbar:
1011
+ ReaderInterp(mod).boxed_run(args)
1012
+ assert not args
1013
+
1014
+
1015
+ def repro_get_args(
1016
+ options: Any, mod: nn.Module, load_args: Any
1017
+ ) -> tuple[torch.fx.GraphModule, list[Any]]:
1018
+ mod, args = repro_common(options, mod, load_args)
1019
+ return mod, args # type: ignore[return-value]
1020
+
1021
+
1022
+ def repro_run(options: Any, mod: nn.Module, load_args: Any) -> None:
1023
+ from torch._inductor.compile_fx import compile_fx_inner
1024
+
1025
+ mod, args = repro_common(options, mod, load_args)
1026
+
1027
+ from torch.cuda import synchronize
1028
+
1029
+ compiled = compile_fx_inner(mod, args)
1030
+ assert not isinstance(compiled, str)
1031
+
1032
+ if options.accuracy != "":
1033
+ # We don't really respect --accuracy vs --strict-accuracy here, it
1034
+ # seems counterintuitive
1035
+ if not same_two_models(
1036
+ mod,
1037
+ compiled, # type: ignore[arg-type]
1038
+ args,
1039
+ only_fwd=True,
1040
+ ignore_non_fp=config.repro_ignore_non_fp,
1041
+ ):
1042
+ raise AccuracyError("Bad accuracy detected")
1043
+ else:
1044
+ need_sync = False
1045
+
1046
+ for arg in args:
1047
+ if isinstance(arg, torch.Tensor) and arg.is_cuda:
1048
+ need_sync = True
1049
+ break
1050
+
1051
+ compiled(list(args))
1052
+
1053
+ if need_sync:
1054
+ synchronize() # ensure segfaults are surfaced
1055
+
1056
+
1057
+ # TODO: lazily load the inputs or something, rather than cloning them
1058
+ def run_repro(
1059
+ mod: nn.Module,
1060
+ load_args: Any,
1061
+ *,
1062
+ command: str = "run",
1063
+ accuracy: Union[bool, str] = "",
1064
+ save_dir: Optional[str] = None,
1065
+ tracing_mode: Optional[str] = None,
1066
+ patch_code: Optional[str] = None,
1067
+ check_str: Optional[str] = None,
1068
+ **kwargs: Any,
1069
+ ) -> Any:
1070
+ for k in kwargs:
1071
+ log.warning(
1072
+ "Unrecognized kwarg %s; perhaps this repro was made on a newer version of PyTorch",
1073
+ k,
1074
+ )
1075
+
1076
+ if accuracy is True:
1077
+ accuracy = "accuracy"
1078
+ elif accuracy is False:
1079
+ accuracy = ""
1080
+
1081
+ if patch_code is not None:
1082
+ log.warning(
1083
+ "patch_code no longer works on this version of PyTorch, silently ignoring"
1084
+ )
1085
+
1086
+ parser = argparse.ArgumentParser(
1087
+ description=f"""\
1088
+ An after_aot repro script, typically triggering a bug in PyTorch Inductor.
1089
+ When run with no arguments, this script defaults to running '{command}'.
1090
+ Extra flags may be available; to find out more, try '{command} --help'.
1091
+ There are also alternate subcommands available, see below.
1092
+
1093
+ default settings on this script:
1094
+ {accuracy=}
1095
+ {tracing_mode=}
1096
+ {save_dir=}
1097
+ {check_str=}
1098
+ """,
1099
+ formatter_class=argparse.RawTextHelpFormatter,
1100
+ )
1101
+
1102
+ def common_flags(parser: argparse.ArgumentParser) -> None:
1103
+ accuracy_group = parser.add_mutually_exclusive_group()
1104
+ accuracy_group.add_argument(
1105
+ "--no-accuracy",
1106
+ dest="accuracy",
1107
+ action="store_const",
1108
+ const="",
1109
+ default=accuracy,
1110
+ help="do not test accuracy, just run the module and see if it errors",
1111
+ )
1112
+ accuracy_group.add_argument(
1113
+ "--accuracy",
1114
+ action="store_const",
1115
+ const="accuracy",
1116
+ default=accuracy,
1117
+ help="""\
1118
+ test if the RMSE between the compiled module and the fp64 reference is greater
1119
+ than eager and the fp64 reference. This is usually more reliable than the
1120
+ standard allclose test, as we expect numeric differences from compiling, often
1121
+ improving accuracy over eager. RMSE test allows for compiled module to
1122
+ diverge greatly from eager, as long as this divergence moves it closer to the
1123
+ 'true' mathematical value of the network. Caveats: (1) double precision can
1124
+ still suffer from rounding error, so it is not a perfect reference (see for
1125
+ example 'Herbie: Automatically Improving Floating Point Accuracy') for
1126
+ approaches that detect the necessary working precision and compute it in
1127
+ arbitrary precision floating point; unfortunately, this is not practical for
1128
+ tensor computation; (2) if there are not enough samples in the output being
1129
+ compared, we may get unlucky and have an unlucky greater RMSE than eager; this
1130
+ could be overcome by applying a more rigorous statistical test at some
1131
+ p-value, which we leave for future work.
1132
+ """,
1133
+ )
1134
+ accuracy_group.add_argument(
1135
+ "--strict-accuracy",
1136
+ dest="accuracy",
1137
+ action="store_const",
1138
+ const="strict_accuracy",
1139
+ default=accuracy,
1140
+ help="""\
1141
+ by default, when doing accuracy minification we will reject reductions which
1142
+ change the divergence from a floating point divergence to a integral/boolean
1143
+ divergence. This is because some operations like ReLU involve temporarily
1144
+ sharp boundaries that smooth out again afterwards; without requiring
1145
+ divergence on floating point, the minifier will often fixate on divergent
1146
+ boolean tensor even though this is not the true source of the divergence.
1147
+ However, rejecting these reductions makes it more difficult for the minifier
1148
+ to make process. Using this option will let the minifier progress for ALL
1149
+ divergences--you just might not end up with a useful repro in the end.""",
1150
+ )
1151
+
1152
+ parser.add_argument(
1153
+ "--save-dir",
1154
+ type=str,
1155
+ default=save_dir,
1156
+ metavar="DIR",
1157
+ help="directory where saved inputs live",
1158
+ )
1159
+ parser.add_argument(
1160
+ "--no-save-dir",
1161
+ dest="save_dir",
1162
+ action="store_const",
1163
+ const=None,
1164
+ help="don't use any directory for saved inputs",
1165
+ )
1166
+ parser.add_argument(
1167
+ "--tracing-mode",
1168
+ type=str,
1169
+ metavar="{real,fake,symbolic}",
1170
+ default=tracing_mode,
1171
+ help="how to trace the repro module into a GraphModule with metadata",
1172
+ )
1173
+
1174
+ subparsers = parser.add_subparsers(
1175
+ dest="command", metavar="{run,minify,analyze}", required=True
1176
+ )
1177
+
1178
+ parser_run = subparsers.add_parser(
1179
+ "run",
1180
+ help="just run the repro",
1181
+ )
1182
+ common_flags(parser_run)
1183
+
1184
+ parser_minify = subparsers.add_parser(
1185
+ "minify", help="run the minifier on the repro"
1186
+ )
1187
+ common_flags(parser_minify)
1188
+ parser_get_args = subparsers.add_parser("get_args", help="get the args")
1189
+ common_flags(parser_get_args)
1190
+ parser_minify_isolate = parser_minify.add_mutually_exclusive_group()
1191
+ parser_minify_isolate.add_argument(
1192
+ "--isolate",
1193
+ action="store_true",
1194
+ default=True,
1195
+ help="run in separate processes to avoid interference (default)",
1196
+ )
1197
+ parser_minify_isolate.add_argument(
1198
+ "--no-isolate",
1199
+ dest="isolate",
1200
+ action="store_false",
1201
+ help="speed up by running all compilation in same process",
1202
+ )
1203
+ parser_minify.add_argument(
1204
+ "--skip-saving-eager-intermediates",
1205
+ action="store_true",
1206
+ help="skip saving eager intermediates on --minify",
1207
+ )
1208
+ # TODO: make this an option for --analyze too
1209
+ parser_minify.add_argument(
1210
+ "--offload-to-disk",
1211
+ action="store_true",
1212
+ help="during minification, offload delta debugging intermediates to disk. Use if you're OOMing",
1213
+ )
1214
+ parser_minify.add_argument(
1215
+ "--skip-sanity",
1216
+ action="store_true",
1217
+ help="skip sanity check at beginning of minification on original graph",
1218
+ )
1219
+ parser_minify.add_argument(
1220
+ "--max-granularity",
1221
+ type=int,
1222
+ default=None,
1223
+ help="start at this granularity and work down; must be power of 2",
1224
+ )
1225
+ parser_minify.add_argument(
1226
+ "--check-str",
1227
+ type=str,
1228
+ default=check_str,
1229
+ help="require minified program to fail with error containing this string",
1230
+ )
1231
+
1232
+ parser_analyze = subparsers.add_parser(
1233
+ "analyze", help="run the accuracy analyzer on the repro"
1234
+ )
1235
+ common_flags(parser_analyze)
1236
+ parser_analyze.add_argument(
1237
+ "--skip-saving-inductor-intermediates",
1238
+ action="store_true",
1239
+ help="skip saving inductor intermediates on --analyze",
1240
+ )
1241
+ parser_analyze.add_argument(
1242
+ "--skip-saving-float64-intermediates",
1243
+ action="store_true",
1244
+ help="skip saving float64 intermediates",
1245
+ )
1246
+ parser_analyze.add_argument(
1247
+ "--skip-check-deterministic",
1248
+ action="store_true",
1249
+ help="skip checking that the network is deterministic",
1250
+ )
1251
+ parser_analyze.add_argument(
1252
+ "--stable-hash",
1253
+ action="store_true",
1254
+ help="use SHA-1 checksum instead of fast (but possibly unsound) hash",
1255
+ )
1256
+
1257
+ # Run the repro in the context of minification, inverting exit code meaning
1258
+ parser_minifier_query = subparsers.add_parser(
1259
+ "minifier-query",
1260
+ )
1261
+ common_flags(parser_minifier_query)
1262
+ parser_minifier_query.add_argument(
1263
+ "--check-str",
1264
+ type=str,
1265
+ default=check_str,
1266
+ help="require minified program to fail with error containing this string",
1267
+ )
1268
+
1269
+ args = None
1270
+ if len(sys.argv) <= 1:
1271
+ args = [command, *sys.argv[1:]]
1272
+
1273
+ options = parser.parse_args(args)
1274
+ COMMAND_FNS = {
1275
+ "minify": repro_minify,
1276
+ "analyze": repro_analyze,
1277
+ "minifier-query": repro_minifier_query,
1278
+ "run": repro_run,
1279
+ "get_args": repro_get_args,
1280
+ }
1281
+ return COMMAND_FNS[options.command](options, mod, load_args)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/_prims/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (95 kB). View file
 
data/conda_envs/abstr/lib/python3.11/site-packages/torch/_prims/__pycache__/context.cpython-311.pyc ADDED
Binary file (9.23 kB). View file
 
data/conda_envs/abstr/lib/python3.11/site-packages/torch/_prims/__pycache__/debug_prims.cpython-311.pyc ADDED
Binary file (2.95 kB). View file
 
data/conda_envs/abstr/lib/python3.11/site-packages/torch/_prims/__pycache__/executor.cpython-311.pyc ADDED
Binary file (3.25 kB). View file
 
data/conda_envs/abstr/lib/python3.11/site-packages/torch/_prims/__pycache__/rng_prims.cpython-311.pyc ADDED
Binary file (25.9 kB). View file
 
data/conda_envs/abstr/lib/python3.11/site-packages/torch/compiler/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (28.9 kB). View file
 
data/conda_envs/abstr/lib/python3.11/site-packages/torch/compiler/__pycache__/_cache.cpython-311.pyc ADDED
Binary file (17.9 kB). View file
 
data/conda_envs/abstr/lib/python3.11/site-packages/torch/compiler/__pycache__/config.cpython-311.pyc ADDED
Binary file (4.87 kB). View file
 
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl.h ADDED
The diff for this file is too large to render. See raw diff
 
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl.hpp ADDED
The diff for this file is too large to render. See raw diff
 
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_common.h ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2022-2023 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ /// @file
19
+ /// C common API
20
+
21
+ #ifndef ONEAPI_DNNL_DNNL_COMMON_H
22
+ #define ONEAPI_DNNL_DNNL_COMMON_H
23
+
24
+ #include "oneapi/dnnl/dnnl_common_types.h"
25
+ #include "oneapi/dnnl/dnnl_config.h"
26
+ #include "oneapi/dnnl/dnnl_version.h"
27
+
28
+ #ifdef __cplusplus
29
+ extern "C" {
30
+ #endif
31
+
32
+ /// @addtogroup dnnl_api oneDNN API
33
+ /// @{
34
+
35
+ /// @addtogroup dnnl_api_common Common API
36
+ /// @{
37
+
38
+ /// @addtogroup dnnl_api_engine Engine
39
+ /// @{
40
+
41
+ /// Returns the number of engines of a particular kind.
42
+ ///
43
+ /// @param kind Kind of engines to count.
44
+ /// @returns Count of the engines.
45
+ size_t DNNL_API dnnl_engine_get_count(dnnl_engine_kind_t kind);
46
+
47
+ /// Creates an engine.
48
+ ///
49
+ /// @param engine Output engine.
50
+ /// @param kind Engine kind.
51
+ /// @param index Engine index that should be between 0 and the count of
52
+ /// engines of the requested kind.
53
+ /// @returns #dnnl_success on success and a status describing the error
54
+ /// otherwise.
55
+ dnnl_status_t DNNL_API dnnl_engine_create(
56
+ dnnl_engine_t *engine, dnnl_engine_kind_t kind, size_t index);
57
+
58
+ /// Returns the kind of an engine.
59
+ ///
60
+ /// @param engine Engine to query.
61
+ /// @param kind Output engine kind.
62
+ /// @returns #dnnl_success on success and a status describing the error
63
+ /// otherwise.
64
+ dnnl_status_t DNNL_API dnnl_engine_get_kind(
65
+ dnnl_engine_t engine, dnnl_engine_kind_t *kind);
66
+
67
+ /// Destroys an engine.
68
+ ///
69
+ /// @param engine Engine to destroy.
70
+ /// @returns #dnnl_success on success and a status describing the error
71
+ /// otherwise.
72
+ dnnl_status_t DNNL_API dnnl_engine_destroy(dnnl_engine_t engine);
73
+
74
+ /// @} dnnl_api_engine
75
+
76
+ /// @addtogroup dnnl_api_stream Stream
77
+ /// @{
78
+
79
+ /// Creates an execution stream.
80
+ ///
81
+ /// @param stream Output execution stream.
82
+ /// @param engine Engine to create the execution stream on.
83
+ /// @param flags Stream behavior flags (@sa dnnl_stream_flags_t).
84
+ /// @returns #dnnl_success on success and a status describing the error
85
+ /// otherwise.
86
+ dnnl_status_t DNNL_API dnnl_stream_create(
87
+ dnnl_stream_t *stream, dnnl_engine_t engine, unsigned flags);
88
+
89
+ /// Returns the engine of a stream object.
90
+ ///
91
+ /// @param stream Stream object.
92
+ /// @param engine Output engine on which the stream is created.
93
+ /// @returns #dnnl_success on success and a status describing the error
94
+ /// otherwise.
95
+ dnnl_status_t DNNL_API dnnl_stream_get_engine(
96
+ const_dnnl_stream_t stream, dnnl_engine_t *engine);
97
+
98
+ /// Waits for all primitives in the execution stream to finish computations.
99
+ ///
100
+ /// @param stream Execution stream.
101
+ /// @returns #dnnl_success on success and a status describing the error
102
+ /// otherwise.
103
+ dnnl_status_t DNNL_API dnnl_stream_wait(dnnl_stream_t stream);
104
+
105
+ /// Destroys an execution stream.
106
+ ///
107
+ /// @param stream Execution stream to destroy.
108
+ /// @returns #dnnl_success on success and a status describing the error
109
+ /// otherwise.
110
+ dnnl_status_t DNNL_API dnnl_stream_destroy(dnnl_stream_t stream);
111
+
112
+ /// @} dnnl_api_stream
113
+
114
+ /// @addtogroup dnnl_api_fpmath_mode Floating-point Math Mode
115
+ /// @{
116
+
117
+ /// Returns the floating-point math mode that will be used by default
118
+ /// for all subsequently created primitives.
119
+ ///
120
+ /// @param mode Output FP math mode.
121
+ /// @returns #dnnl_success on success and a status describing the error
122
+ /// otherwise.
123
+ dnnl_status_t DNNL_API dnnl_get_default_fpmath_mode(dnnl_fpmath_mode_t *mode);
124
+
125
+ /// Sets the floating-point math mode that will be used by default
126
+ /// for all subsequently created primitives.
127
+ ///
128
+ /// @param mode FP math mode. The possible values are:
129
+ /// #dnnl_fpmath_mode_strict,
130
+ /// #dnnl_fpmath_mode_bf16,
131
+ /// #dnnl_fpmath_mode_f16,
132
+ /// #dnnl_fpmath_mode_tf32,
133
+ /// #dnnl_fpmath_mode_any.
134
+ /// @returns #dnnl_success on success and a status describing the error
135
+ /// otherwise.
136
+ dnnl_status_t DNNL_API dnnl_set_default_fpmath_mode(dnnl_fpmath_mode_t mode);
137
+
138
+ /// @} dnnl_api_fpmath_mode
139
+
140
+ /// @addtogroup dnnl_api_service
141
+ /// @{
142
+
143
+ /// Configures verbose output to stdout.
144
+ ///
145
+ /// @note
146
+ /// Enabling verbose output affects performance.
147
+ /// This setting overrides the ONEDNN_VERBOSE environment variable.
148
+ ///
149
+ /// @param level Verbosity level:
150
+ /// - 0: no verbose output (default),
151
+ /// - 1: primitive and graph information at execution,
152
+ /// - 2: primitive and graph information at creation/compilation and execution.
153
+ /// @returns #dnnl_invalid_arguments/#dnnl::status::invalid_arguments if the
154
+ /// @p level value is invalid, and #dnnl_success/#dnnl::status::success on
155
+ /// success.
156
+ dnnl_status_t DNNL_API dnnl_set_verbose(int level);
157
+
158
+ /// Returns library version information.
159
+ /// @returns Pointer to a constant structure containing
160
+ /// - major: major version number,
161
+ /// - minor: minor version number,
162
+ /// - patch: patch release number,
163
+ /// - hash: git commit hash.
164
+ const dnnl_version_t DNNL_API *dnnl_version(void);
165
+
166
+ /// @} dnnl_api_service
167
+
168
+ /// @} dnnl_api_common
169
+
170
+ /// @} dnnl_api
171
+
172
+ #ifdef __cplusplus
173
+ }
174
+ #endif
175
+
176
+ #endif /* ONEAPI_DNNL_DNNL_COMMON_H */
177
+
178
+ #else
179
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
180
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_common.hpp ADDED
@@ -0,0 +1,484 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2022-2025 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ /// @file
19
+ /// C++ common API
20
+
21
+ #ifndef ONEAPI_DNNL_DNNL_COMMON_HPP
22
+ #define ONEAPI_DNNL_DNNL_COMMON_HPP
23
+
24
+ /// @cond DO_NOT_DOCUMENT_THIS
25
+ #include <algorithm>
26
+ #include <cstdlib>
27
+ #include <iterator>
28
+ #include <memory>
29
+ #include <string>
30
+ #include <vector>
31
+ #include <unordered_map>
32
+
33
+ #include "oneapi/dnnl/dnnl_common.h"
34
+
35
+ /// @endcond
36
+
37
+ // __cpp_exceptions is referred from
38
+ // https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html
39
+ // gcc < 5 does not define __cpp_exceptions but __EXCEPTIONS,
40
+ // Microsoft C++ Compiler does not provide an option to disable exceptions
41
+ #ifndef DNNL_ENABLE_EXCEPTIONS
42
+ #if __cpp_exceptions || __EXCEPTIONS \
43
+ || (defined(_MSC_VER) && !defined(__clang__))
44
+ #define DNNL_ENABLE_EXCEPTIONS 1
45
+ #else
46
+ #define DNNL_ENABLE_EXCEPTIONS 0
47
+ #endif
48
+ #endif
49
+
50
+ #if defined(__GNUC__) || defined(__clang__)
51
+ #define DNNL_TRAP() __builtin_trap()
52
+ #elif defined(__INTEL_COMPILER) || defined(_MSC_VER)
53
+ #define DNNL_TRAP() __debugbreak()
54
+ #else
55
+ #error "unknown compiler"
56
+ #endif
57
+
58
+ #if DNNL_ENABLE_EXCEPTIONS
59
+ #define DNNL_THROW_ERROR(status, msg) throw error(status, msg)
60
+ #else
61
+ #include <cstdio>
62
+ #define DNNL_THROW_ERROR(status, msg) \
63
+ do { \
64
+ fputs(msg, stderr); \
65
+ DNNL_TRAP(); \
66
+ } while (0)
67
+ #endif
68
+
69
+ /// @addtogroup dnnl_api oneDNN API
70
+ /// @{
71
+
72
+ /// oneDNN namespace
73
+ namespace dnnl {
74
+
75
+ /// @addtogroup dnnl_api_common Common API
76
+ /// @{
77
+
78
+ /// @addtogroup dnnl_api_utils Utilities
79
+ /// Utility types and definitions.
80
+ /// @{
81
+
82
+ /// oneDNN exception class.
83
+ ///
84
+ /// This class captures the status returned by a failed C API function and
85
+ /// the error message from the call site.
86
+ struct error : public std::exception {
87
+ dnnl_status_t status;
88
+ const char *message;
89
+
90
+ /// Constructs an instance of an exception class.
91
+ ///
92
+ /// @param status The error status returned by a C API function.
93
+ /// @param message The error message.
94
+ error(dnnl_status_t status, const char *message)
95
+ : status(status), message(message) {}
96
+
97
+ /// Returns the explanatory string.
98
+ const char *what() const noexcept override { return message; }
99
+
100
+ /// A convenience function for wrapping calls to C API functions. Checks
101
+ /// the return status and throws an dnnl::error in case of failure.
102
+ ///
103
+ /// @param status The error status returned by a C API function.
104
+ /// @param message The error message.
105
+ static void wrap_c_api(dnnl_status_t status, const char *message) {
106
+ if (status != dnnl_success) DNNL_THROW_ERROR(status, message);
107
+ }
108
+ };
109
+
110
+ /// A class that provides the destructor for a oneDNN C API handle.
111
+ template <typename T>
112
+ struct handle_traits {};
113
+
114
+ /// oneDNN C API handle wrapper class.
115
+ ///
116
+ /// This class is used as the base class for primitive (dnnl::primitive),
117
+ /// engine (dnnl::engine), and stream (dnnl::stream) classes, as well as
118
+ /// others. An object of the dnnl::handle class can be passed by value.
119
+ ///
120
+ /// A handle can be weak, in which case it follows std::weak_ptr semantics.
121
+ /// Otherwise, it follows `std::shared_ptr` semantics.
122
+ ///
123
+ /// @note
124
+ /// The implementation stores oneDNN C API handles in a `std::shared_ptr`
125
+ /// with deleter set to a dummy function in the weak mode.
126
+ ///
127
+ template <typename T, typename traits = handle_traits<T>>
128
+ struct handle {
129
+ private:
130
+ static dnnl_status_t dummy_destructor(T) { return dnnl_success; }
131
+ std::shared_ptr<typename std::remove_pointer<T>::type> data_ {0};
132
+
133
+ protected:
134
+ bool operator==(const T other) const { return other == data_.get(); }
135
+ bool operator!=(const T other) const { return !(*this == other); }
136
+
137
+ public:
138
+ /// Constructs an empty handle object.
139
+ ///
140
+ /// @warning
141
+ /// Uninitialized object cannot be used in most library calls and is
142
+ /// equivalent to a null pointer. Any attempt to use its methods, or
143
+ /// passing it to the other library function, will cause an exception
144
+ /// to be thrown.
145
+ handle() = default;
146
+
147
+ /// Copy constructor.
148
+ handle(const handle<T, traits> &) = default;
149
+ /// Assignment operator.
150
+ handle<T, traits> &operator=(const handle<T, traits> &) = default;
151
+ /// Move constructor.
152
+ handle(handle<T, traits> &&) = default;
153
+ /// Move assignment operator.
154
+ handle<T, traits> &operator=(handle<T, traits> &&) = default;
155
+
156
+ /// Constructs a handle wrapper object from a C API handle.
157
+ ///
158
+ /// @param t The C API handle to wrap.
159
+ /// @param weak A flag specifying whether to construct a weak wrapper;
160
+ /// defaults to @c false.
161
+ explicit handle(T t, bool weak = false) { reset(t, weak); }
162
+
163
+ /// Resets the handle wrapper objects to wrap a new C API handle.
164
+ ///
165
+ /// @param t The new value of the C API handle.
166
+ /// @param weak A flag specifying whether the wrapper should be weak;
167
+ /// defaults to @c false.
168
+ void reset(T t, bool weak = false) {
169
+ data_.reset(t, weak ? &dummy_destructor : traits::destructor);
170
+ }
171
+
172
+ /// Returns the underlying C API handle.
173
+ ///
174
+ /// @param allow_empty A flag signifying whether the method is allowed to
175
+ /// return an empty (null) object without throwing an exception.
176
+ /// @returns The underlying C API handle.
177
+ T get(bool allow_empty = false) const {
178
+ T result = data_.get();
179
+ if (allow_empty == false && result == nullptr)
180
+ DNNL_THROW_ERROR(
181
+ dnnl_invalid_arguments, "object is not initialized");
182
+ return result;
183
+ }
184
+
185
+ /// Converts a handle to the underlying C API handle type. Does not throw
186
+ /// and returns `nullptr` if the object is empty.
187
+ ///
188
+ /// @returns The underlying C API handle.
189
+ explicit operator T() const { return get(true); }
190
+
191
+ /// Checks whether the object is not empty.
192
+ ///
193
+ /// @returns Whether the object is not empty.
194
+ explicit operator bool() const { return get(true) != nullptr; }
195
+
196
+ /// Equality operator.
197
+ ///
198
+ /// @param other Another handle wrapper.
199
+ /// @returns @c true if this and the other handle wrapper manage the same
200
+ /// underlying C API handle, and @c false otherwise. Empty handle
201
+ /// objects are considered to be equal.
202
+ bool operator==(const handle<T, traits> &other) const {
203
+ return other.data_.get() == data_.get();
204
+ }
205
+
206
+ /// Inequality operator.
207
+ ///
208
+ /// @param other Another handle wrapper.
209
+ /// @returns @c true if this and the other handle wrapper manage different
210
+ /// underlying C API handles, and @c false otherwise. Empty handle
211
+ /// objects are considered to be equal.
212
+ bool operator!=(const handle &other) const { return !(*this == other); }
213
+ };
214
+
215
+ /// @} dnnl_api_utils
216
+
217
+ /// @addtogroup dnnl_api_engine Engine
218
+ ///
219
+ /// An abstraction of a computational device: a CPU, a specific GPU
220
+ /// card in the system, etc. Most primitives are created to execute
221
+ /// computations on one specific engine. The only exceptions are reorder
222
+ /// primitives that transfer data between two different engines.
223
+ ///
224
+ /// @sa @ref dev_guide_basic_concepts
225
+ ///
226
+ /// @{
227
+
228
+ /// @cond DO_NOT_DOCUMENT_THIS
229
+ template <>
230
+ struct handle_traits<dnnl_engine_t> {
231
+ static dnnl_status_t destructor(dnnl_engine_t p) {
232
+ return dnnl_engine_destroy(p);
233
+ }
234
+ };
235
+ /// @endcond
236
+
237
+ /// An execution engine.
238
+ struct engine : public handle<dnnl_engine_t> {
239
+ friend struct primitive;
240
+ friend struct reorder;
241
+
242
+ /// Kinds of engines.
243
+ enum class kind {
244
+ /// An unspecified engine
245
+ any = dnnl_any_engine,
246
+ /// CPU engine
247
+ cpu = dnnl_cpu,
248
+ /// GPU engine
249
+ gpu = dnnl_gpu,
250
+ };
251
+
252
+ using handle::handle;
253
+
254
+ /// Constructs an empty engine. An empty engine cannot be used in any
255
+ /// operations.
256
+ engine() = default;
257
+
258
+ /// Returns the number of engines of a certain kind.
259
+ ///
260
+ /// @param akind The kind of engines to count.
261
+ /// @returns The number of engines of the specified kind.
262
+ static size_t get_count(kind akind) {
263
+ return dnnl_engine_get_count(convert_to_c(akind));
264
+ }
265
+
266
+ /// Constructs an engine.
267
+ ///
268
+ /// @param akind The kind of engine to construct.
269
+ /// @param index The index of the engine. Must be less than the value
270
+ /// returned by #get_count() for this particular kind of engine.
271
+ engine(kind akind, size_t index) {
272
+ dnnl_engine_t engine;
273
+ error::wrap_c_api(
274
+ dnnl_engine_create(&engine, convert_to_c(akind), index),
275
+ "could not create an engine");
276
+ reset(engine);
277
+ }
278
+
279
+ /// Returns the kind of the engine.
280
+ /// @returns The kind of the engine.
281
+ kind get_kind() const {
282
+ dnnl_engine_kind_t kind;
283
+ error::wrap_c_api(dnnl_engine_get_kind(get(), &kind),
284
+ "could not get kind of an engine");
285
+ return static_cast<engine::kind>(kind);
286
+ }
287
+
288
+ private:
289
+ static dnnl_engine_kind_t convert_to_c(kind akind) {
290
+ return static_cast<dnnl_engine_kind_t>(akind);
291
+ }
292
+ };
293
+
294
+ /// Converts engine kind enum value from C++ API to C API type.
295
+ ///
296
+ /// @param akind C++ API engine kind enum value.
297
+ /// @returns Corresponding C API engine kind enum value.
298
+ inline dnnl_engine_kind_t convert_to_c(engine::kind akind) {
299
+ return static_cast<dnnl_engine_kind_t>(akind);
300
+ }
301
+
302
+ /// @} dnnl_api_engine
303
+
304
+ /// @addtogroup dnnl_api_stream Stream
305
+ ///
306
+ /// An encapsulation of execution context tied to a particular engine.
307
+ ///
308
+ /// @sa @ref dev_guide_basic_concepts
309
+ ///
310
+ /// @{
311
+
312
+ /// @cond DO_NOT_DOCUMENT_THIS
313
+ template <>
314
+ struct handle_traits<dnnl_stream_t> {
315
+ static dnnl_status_t destructor(dnnl_stream_t p) {
316
+ return dnnl_stream_destroy(p);
317
+ }
318
+ };
319
+ /// @endcond
320
+
321
+ /// An execution stream.
322
+ struct stream : public handle<dnnl_stream_t> {
323
+ using handle::handle;
324
+
325
+ /// Stream flags. Can be combined using the bitwise OR operator.
326
+ enum class flags : unsigned {
327
+ /// In-order execution.
328
+ in_order = dnnl_stream_in_order,
329
+ /// Out-of-order execution.
330
+ out_of_order = dnnl_stream_out_of_order,
331
+ /// Default stream configuration.
332
+ default_flags = dnnl_stream_default_flags,
333
+ #ifdef DNNL_EXPERIMENTAL_PROFILING
334
+ /// Enables profiling capabilities.
335
+ profiling = dnnl_stream_profiling,
336
+ #endif
337
+ };
338
+
339
+ /// Constructs an empty stream. An empty stream cannot be used in any
340
+ /// operations.
341
+ stream() = default;
342
+
343
+ /// Constructs a stream for the specified engine and with behavior
344
+ /// controlled by the specified flags.
345
+ ///
346
+ /// @param aengine Engine to create the stream on.
347
+ /// @param aflags Flags controlling stream behavior.
348
+ explicit stream(
349
+ const engine &aengine, flags aflags = flags::default_flags) {
350
+ dnnl_stream_t stream;
351
+ error::wrap_c_api(dnnl_stream_create(&stream, aengine.get(),
352
+ static_cast<dnnl_stream_flags_t>(aflags)),
353
+ "could not create a stream");
354
+ reset(stream);
355
+ }
356
+
357
+ /// Returns the associated engine.
358
+ engine get_engine() const {
359
+ dnnl_engine_t c_engine;
360
+ error::wrap_c_api(dnnl_stream_get_engine(get(), &c_engine),
361
+ "could not get an engine from a stream object");
362
+ return engine(c_engine, true);
363
+ }
364
+
365
+ /// Waits for all primitives executing in the stream to finish.
366
+ /// @returns The stream itself.
367
+ stream &wait() {
368
+ error::wrap_c_api(
369
+ dnnl_stream_wait(get()), "could not wait on a stream");
370
+ return *this;
371
+ }
372
+ };
373
+
374
+ #define DNNL_DEFINE_BITMASK_OPS(enum_name) \
375
+ inline enum_name operator|(enum_name lhs, enum_name rhs) { \
376
+ return static_cast<enum_name>( \
377
+ static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); \
378
+ } \
379
+ \
380
+ inline enum_name operator&(enum_name lhs, enum_name rhs) { \
381
+ return static_cast<enum_name>( \
382
+ static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); \
383
+ } \
384
+ \
385
+ inline enum_name operator^(enum_name lhs, enum_name rhs) { \
386
+ return static_cast<enum_name>( \
387
+ static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); \
388
+ } \
389
+ \
390
+ inline enum_name &operator|=(enum_name &lhs, enum_name rhs) { \
391
+ lhs = static_cast<enum_name>( \
392
+ static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); \
393
+ return lhs; \
394
+ } \
395
+ \
396
+ inline enum_name &operator&=(enum_name &lhs, enum_name rhs) { \
397
+ lhs = static_cast<enum_name>( \
398
+ static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); \
399
+ return lhs; \
400
+ } \
401
+ \
402
+ inline enum_name &operator^=(enum_name &lhs, enum_name rhs) { \
403
+ lhs = static_cast<enum_name>( \
404
+ static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); \
405
+ return lhs; \
406
+ } \
407
+ \
408
+ inline enum_name operator~(enum_name rhs) { \
409
+ return static_cast<enum_name>(~static_cast<unsigned>(rhs)); \
410
+ }
411
+
412
+ DNNL_DEFINE_BITMASK_OPS(stream::flags)
413
+
414
+ /// @} dnnl_api_stream
415
+
416
+ /// @addtogroup dnnl_api_fpmath_mode Floating-point Math Mode
417
+ /// @{
418
+
419
+ /// Floating-point math mode
420
+ enum class fpmath_mode {
421
+ /// Default behavior, no downconversions allowed
422
+ strict = dnnl_fpmath_mode_strict,
423
+ /// Implicit f32->bf16 conversions allowed
424
+ bf16 = dnnl_fpmath_mode_bf16,
425
+ /// Implicit f32->f16 conversions allowed
426
+ f16 = dnnl_fpmath_mode_f16,
427
+ /// Implicit f32->tf32 conversions allowed
428
+ tf32 = dnnl_fpmath_mode_tf32,
429
+ /// Implicit f32->f16, f32->tf32 or f32->bf16 conversions allowed
430
+ any = dnnl_fpmath_mode_any
431
+ };
432
+
433
+ /// Converts an fpmath mode enum value from C++ API to C API type.
434
+ ///
435
+ /// @param mode C++ API fpmath mode enum value.
436
+ /// @returns Corresponding C API fpmath mode enum value.
437
+ inline dnnl_fpmath_mode_t convert_to_c(fpmath_mode mode) {
438
+ return static_cast<dnnl_fpmath_mode_t>(mode);
439
+ }
440
+
441
+ /// @} dnnl_api_fpmath_mode
442
+
443
+ /// @addtogroup dnnl_api_accumulation_mode Accumulation Mode
444
+ /// @{
445
+
446
+ /// Accumulation mode
447
+ enum class accumulation_mode {
448
+ /// Default behavior, f32 for floating point computation, s32 for integer
449
+ strict = dnnl_accumulation_mode_strict,
450
+ /// same as strict except some partial accumulators can be rounded to
451
+ /// src/dst datatype in memory.
452
+ relaxed = dnnl_accumulation_mode_relaxed,
453
+ /// uses fastest implementation, could use src/dst datatype or
454
+ /// wider datatype for accumulators
455
+ any = dnnl_accumulation_mode_any,
456
+ /// use s32 accumulators during computation
457
+ s32 = dnnl_accumulation_mode_s32,
458
+ /// use f32 accumulators during computation
459
+ f32 = dnnl_accumulation_mode_f32,
460
+ /// use f16 accumulators during computation
461
+ f16 = dnnl_accumulation_mode_f16
462
+ };
463
+
464
+ /// Converts an accumulation mode enum value from C++ API to C API type.
465
+ ///
466
+ /// @param mode C++ API accumulation mode enum value.
467
+ /// @returns Corresponding C API accumulation mode enum value.
468
+ inline dnnl_accumulation_mode_t convert_to_c(accumulation_mode mode) {
469
+ return static_cast<dnnl_accumulation_mode_t>(mode);
470
+ }
471
+
472
+ /// @} dnnl_api_accumulation_mode
473
+
474
+ /// @} dnnl_api_common
475
+
476
+ } // namespace dnnl
477
+
478
+ /// @} dnnl_api
479
+
480
+ #endif
481
+
482
+ #else
483
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
484
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_common_types.h ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2022-2024 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ /// @file
19
+ /// C API common types definitions
20
+
21
+ #ifndef ONEAPI_DNNL_DNNL_COMMON_TYPES_H
22
+ #define ONEAPI_DNNL_DNNL_COMMON_TYPES_H
23
+
24
+ #ifdef __cplusplus
25
+ extern "C" {
26
+ #endif
27
+
28
+ /// @cond DO_NOT_DOCUMENT_THIS
29
+ #include <stddef.h>
30
+ #include <stdint.h>
31
+
32
+ #include "oneapi/dnnl/dnnl_config.h"
33
+
34
+ /// @endcond
35
+
36
+ /// @addtogroup dnnl_api oneDNN API
37
+ /// @{
38
+
39
+ /// @addtogroup dnnl_api_common Common API
40
+ /// @{
41
+
42
+ /// @addtogroup dnnl_api_utils
43
+ /// @{
44
+
45
+ /// Status values returned by the library functions.
46
+ typedef enum {
47
+ /// The operation was successful
48
+ dnnl_success = 0,
49
+ /// The operation failed due to an out-of-memory condition
50
+ dnnl_out_of_memory = 1,
51
+ /// The operation failed because of incorrect function arguments
52
+ dnnl_invalid_arguments = 2,
53
+ /// The operation failed because requested functionality is not implemented
54
+ dnnl_unimplemented = 3,
55
+ /// The last available implementation is reached
56
+ dnnl_last_impl_reached = 4,
57
+ /// Primitive or engine failed on execution
58
+ dnnl_runtime_error = 5,
59
+ /// Queried element is not required for given primitive
60
+ dnnl_not_required = 6,
61
+ /// The graph is not legitimate
62
+ dnnl_invalid_graph = 7,
63
+ /// The operation is not legitimate according to op schema
64
+ dnnl_invalid_graph_op = 8,
65
+ /// The shape cannot be inferred or compiled
66
+ dnnl_invalid_shape = 9,
67
+ /// The data type cannot be inferred or compiled
68
+ dnnl_invalid_data_type = 10,
69
+ } dnnl_status_t;
70
+
71
+ /// @} dnnl_api_utils
72
+
73
+ /// @addtogroup dnnl_api_data_types Data types
74
+ /// @{
75
+
76
+ /// Data type specification
77
+ typedef enum {
78
+ /// Undefined data type, used for empty memory descriptors.
79
+ dnnl_data_type_undef = 0,
80
+ /// 16-bit/half-precision floating point.
81
+ dnnl_f16 = 1,
82
+ /// non-standard 16-bit (bfloat16 w/ 7 bit mantissa) floating point.
83
+ dnnl_bf16 = 2,
84
+ /// 32-bit/single-precision floating point.
85
+ dnnl_f32 = 3,
86
+ /// 32-bit signed integer.
87
+ dnnl_s32 = 4,
88
+ /// 8-bit signed integer.
89
+ dnnl_s8 = 5,
90
+ /// 8-bit unsigned integer.
91
+ dnnl_u8 = 6,
92
+ /// 64-bit/double-precision floating point.
93
+ dnnl_f64 = 7,
94
+ /// Boolean data type. Size is C++ implementation defined.
95
+ dnnl_boolean = 8,
96
+ /// [OFP8 standard 8-bit floating-point](https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-06-20-pdf)
97
+ /// with a 5-bit exponent and a 2-bit mantissa.
98
+ dnnl_f8_e5m2 = 9,
99
+ /// [OFP8 standard 8-bit floating-point](https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-06-20-pdf)
100
+ /// with a 4-bit exponent and a 3-bit mantissa.
101
+ dnnl_f8_e4m3 = 10,
102
+ /// 4-bit signed integer.
103
+ dnnl_s4 = 11,
104
+ /// 4-bit unsigned integer.
105
+ dnnl_u4 = 12,
106
+ /// [MX-compliant 8-bit compliant scale data type](https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf) with 8-bit exponent.
107
+ dnnl_e8m0 = 13,
108
+ /// [MX-compliant 4-bit float data type](https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf) with 2-bit exponent and 1 bit mantissa.
109
+ dnnl_f4_e2m1 = 14,
110
+ /// 4-bit float data type with 3-bit exponent and 0 bit mantissa.
111
+ dnnl_f4_e3m0 = 15,
112
+
113
+ /// Parameter to allow internal only data_types without undefined behavior.
114
+ /// This parameter is chosen to be valid for so long as sizeof(int) >= 2.
115
+ dnnl_data_type_max = 0x7fff,
116
+ } dnnl_data_type_t;
117
+
118
+ /// Maximum number of dimensions a tensor can have. Only restricts the amount
119
+ /// of space used for the tensor description. Individual computational
120
+ /// primitives may support only tensors of certain dimensions.
121
+ #define DNNL_MAX_NDIMS 12
122
+
123
+ /// A type to describe tensor dimension.
124
+ typedef int64_t dnnl_dim_t;
125
+
126
+ /// A type to describe tensor dimensions.
127
+ typedef dnnl_dim_t dnnl_dims_t[DNNL_MAX_NDIMS];
128
+
129
+ /// @} dnnl_api_data_types
130
+
131
+ /// @addtogroup dnnl_api_fpmath_mode Floating-point Math Mode
132
+ /// @{
133
+
134
+ /// Floating-point math mode
135
+ typedef enum {
136
+ /// Default behavior, no downconversions allowed
137
+ dnnl_fpmath_mode_strict,
138
+ /// Implicit f32->bf16 conversions allowed
139
+ dnnl_fpmath_mode_bf16,
140
+ /// Implicit f32->f16 conversions allowed
141
+ dnnl_fpmath_mode_f16,
142
+ /// Implicit f32->f16, f32->tf32 or f32->bf16 conversions allowed
143
+ dnnl_fpmath_mode_any,
144
+ /// Implicit f32->tf32 conversions allowed
145
+ dnnl_fpmath_mode_tf32,
146
+ } dnnl_fpmath_mode_t;
147
+
148
+ /// @} dnnl_api_fpmath_mode
149
+
150
+ /// @addtogroup dnnl_api_accumulation_mode Accumulation Mode
151
+ /// @{
152
+
153
+ /// Accumulation mode
154
+ typedef enum {
155
+ /// Default behavior, f32/f64 for floating point computation, s32
156
+ /// for integer
157
+ dnnl_accumulation_mode_strict,
158
+ /// Same as strict but allows some partial accumulators to be
159
+ /// rounded to src/dst datatype in memory.
160
+ dnnl_accumulation_mode_relaxed,
161
+ /// uses fastest implementation, could use src/dst datatype or
162
+ /// wider datatype for accumulators
163
+ dnnl_accumulation_mode_any,
164
+ /// use s32 accumulators during computation
165
+ dnnl_accumulation_mode_s32,
166
+ /// use f32 accumulators during computation
167
+ dnnl_accumulation_mode_f32,
168
+ /// use f16 accumulators during computation
169
+ dnnl_accumulation_mode_f16
170
+ } dnnl_accumulation_mode_t;
171
+
172
+ /// @} dnnl_api_accumulation_mode
173
+
174
+ /// @addtogroup dnnl_api_engine Engine
175
+ /// @{
176
+
177
+ /// @brief Kinds of engines.
178
+ typedef enum {
179
+ /// An unspecified engine.
180
+ dnnl_any_engine,
181
+ /// CPU engine.
182
+ dnnl_cpu,
183
+ /// GPU engine.
184
+ dnnl_gpu,
185
+ } dnnl_engine_kind_t;
186
+
187
+ /// @struct dnnl_engine
188
+ /// @brief An opaque structure to describe an engine.
189
+ struct dnnl_engine;
190
+ /// @brief An engine handle.
191
+ typedef struct dnnl_engine *dnnl_engine_t;
192
+ #if 0
193
+ // FIXME: looks like this never happens
194
+ /// @brief A constant engine handle.
195
+ typedef const struct dnnl_engine *const_dnnl_engine_t;
196
+ #endif
197
+
198
+ /// @} dnnl_api_engine
199
+
200
+ /// @addtogroup dnnl_api_stream Stream
201
+ /// @{
202
+
203
+ /// @brief Stream flags.
204
+ typedef enum {
205
+ // In-order execution.
206
+ dnnl_stream_in_order = 0x1U,
207
+ /// Out-of-order execution.
208
+ dnnl_stream_out_of_order = 0x2U,
209
+ /// Default stream configuration.
210
+ dnnl_stream_default_flags = dnnl_stream_in_order,
211
+ #ifdef DNNL_EXPERIMENTAL_PROFILING
212
+ /// Enables profiling capabilities.
213
+ dnnl_stream_profiling = 0x4U,
214
+ #endif
215
+ } dnnl_stream_flags_t;
216
+
217
+ /// @struct dnnl_stream
218
+ /// An opaque structure to describe an execution stream.
219
+ struct dnnl_stream;
220
+ /// An execution stream handle.
221
+ typedef struct dnnl_stream *dnnl_stream_t;
222
+ /// A constant execution stream handle.
223
+ typedef const struct dnnl_stream *const_dnnl_stream_t;
224
+
225
+ /// @} dnnl_api_stream
226
+
227
+ /// @addtogroup dnnl_api_service
228
+ /// @{
229
+
230
+ /// Structure containing version information as per [Semantic
231
+ /// Versioning](https://semver.org)
232
+ typedef struct {
233
+ int major; ///< Major version
234
+ int minor; ///< Minor version
235
+ int patch; ///< Patch version
236
+ const char *hash; ///< Git hash of the sources (may be absent)
237
+ unsigned cpu_runtime; ///< CPU runtime
238
+ unsigned gpu_runtime; ///< GPU runtime
239
+ } dnnl_version_t;
240
+
241
+ /// @} dnnl_api_service
242
+
243
+ /// @addtogroup dnnl_api_memory
244
+ /// @{
245
+
246
+ /// Special pointer value that indicates that a memory object should not have
247
+ /// an underlying buffer.
248
+ #define DNNL_MEMORY_NONE (NULL)
249
+
250
+ /// Special pointer value that indicates that the library needs to allocate an
251
+ /// underlying buffer for a memory object.
252
+ #define DNNL_MEMORY_ALLOCATE ((void *)(size_t)-1)
253
+
254
+ /// @} dnnl_api_memory
255
+
256
+ /// @} dnnl_api_common
257
+
258
+ /// @} dnnl_api
259
+
260
+ #ifdef __cplusplus
261
+ }
262
+ #endif
263
+
264
+ #endif
265
+
266
+ #else
267
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
268
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_config.h ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2019-2024 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_CONFIG_H
19
+ #define ONEAPI_DNNL_DNNL_CONFIG_H
20
+
21
+ /// @cond DO_NOT_DOCUMENT_THIS
22
+
23
+ // All symbols shall be internal unless marked as DNNL_API
24
+ #if defined _WIN32 || defined __CYGWIN__
25
+ #define DNNL_HELPER_DLL_IMPORT __declspec(dllimport)
26
+ #define DNNL_HELPER_DLL_EXPORT __declspec(dllexport)
27
+ #else
28
+ #if __GNUC__ >= 4
29
+ #define DNNL_HELPER_DLL_IMPORT __attribute__((visibility("default")))
30
+ #define DNNL_HELPER_DLL_EXPORT __attribute__((visibility("default")))
31
+ #else
32
+ #define DNNL_HELPER_DLL_IMPORT
33
+ #define DNNL_HELPER_DLL_EXPORT
34
+ #endif
35
+ #endif
36
+
37
+ #ifdef DNNL_DLL
38
+ #ifdef DNNL_DLL_EXPORTS
39
+ #define DNNL_API DNNL_HELPER_DLL_EXPORT
40
+ #else
41
+ #define DNNL_API DNNL_HELPER_DLL_IMPORT
42
+ #endif
43
+ #else
44
+ #define DNNL_API
45
+ #endif
46
+
47
+ #if defined(__GNUC__)
48
+ #define DNNL_DEPRECATED __attribute__((deprecated))
49
+ #elif defined(_MSC_VER)
50
+ #define DNNL_DEPRECATED __declspec(deprecated)
51
+ #else
52
+ #define DNNL_DEPRECATED
53
+ #endif
54
+
55
+ /// @endcond
56
+
57
+ // clang-format off
58
+
59
+ /// @addtogroup dnnl_api_service
60
+ /// @{
61
+
62
+ /// No runtime (disabled)
63
+ #define DNNL_RUNTIME_NONE 0u
64
+
65
+ /// Sequential runtime (CPU only)
66
+ #define DNNL_RUNTIME_SEQ 1u
67
+
68
+ /// OpenMP runtime (CPU only)
69
+ #define DNNL_RUNTIME_OMP 2u
70
+
71
+ /// TBB runtime (CPU only)
72
+ #define DNNL_RUNTIME_TBB 4u
73
+
74
+ /// Threadpool runtime (CPU only)
75
+ #define DNNL_RUNTIME_THREADPOOL 8u
76
+
77
+ /// OpenCL runtime
78
+ #define DNNL_RUNTIME_OCL 256u
79
+
80
+ /// SYCL runtime
81
+ #define DNNL_RUNTIME_SYCL 512u
82
+
83
+ /// DPC++ runtime
84
+ #define DNNL_RUNTIME_DPCPP DNNL_RUNTIME_SYCL
85
+
86
+ /// No vendor (corresponding runtime is disabled)
87
+ #define DNNL_VENDOR_NONE 0u
88
+
89
+ /// Intel vendor
90
+ #define DNNL_VENDOR_INTEL 1u
91
+
92
+ /// NVIDIA vendor
93
+ #define DNNL_VENDOR_NVIDIA 2u
94
+
95
+ /// AMD vendor
96
+ #define DNNL_VENDOR_AMD 4u
97
+
98
+ /// Generic vendor
99
+ #define DNNL_VENDOR_GENERIC 8u
100
+
101
+ /// @} dnnl_api_service
102
+
103
+ // oneDNN CPU threading runtime
104
+ #define DNNL_CPU_THREADING_RUNTIME DNNL_RUNTIME_OMP
105
+
106
+ // oneDNN CPU engine runtime
107
+ #define DNNL_CPU_RUNTIME DNNL_RUNTIME_OMP
108
+
109
+ // oneDNN GPU engine runtime
110
+ #define DNNL_GPU_RUNTIME DNNL_RUNTIME_NONE
111
+
112
+ // oneDNN GPU vendor
113
+ #define DNNL_GPU_VENDOR DNNL_VENDOR_NONE
114
+
115
+ // clang-format on
116
+
117
+ #if defined(DNNL_CPU_RUNTIME) && defined(DNNL_GPU_RUNTIME)
118
+ #if (DNNL_CPU_RUNTIME == DNNL_RUNTIME_OCL)
119
+ #error "Unexpected DNNL_CPU_RUNTIME"
120
+ #endif
121
+ #if (DNNL_GPU_RUNTIME != DNNL_RUNTIME_NONE) \
122
+ && (DNNL_GPU_RUNTIME != DNNL_RUNTIME_OCL) \
123
+ && (DNNL_GPU_RUNTIME != DNNL_RUNTIME_SYCL)
124
+ #error "Unexpected DNNL_GPU_RUNTIME"
125
+ #endif
126
+ #if (DNNL_CPU_RUNTIME == DNNL_RUNTIME_NONE \
127
+ && DNNL_GPU_RUNTIME == DNNL_RUNTIME_NONE)
128
+ #error "At least one runtime must be specified"
129
+ #endif
130
+ #else
131
+ #error "BOTH DNNL_CPU_RUNTIME and DNNL_GPU_RUNTIME must be defined"
132
+ #endif
133
+
134
+ // For SYCL CPU, a primitive may be created and executed in different threads
135
+ // hence the global scratchpad does not work. This enables concurrent execution
136
+ // when CPU runtime is SYCL to avoid the issue.
137
+ #if DNNL_CPU_RUNTIME == DNNL_RUNTIME_SYCL
138
+ #ifndef DNNL_ENABLE_CONCURRENT_EXEC
139
+ #define DNNL_ENABLE_CONCURRENT_EXEC
140
+ #endif
141
+ #endif
142
+
143
+ // When defined, primitive cache stores runtime objects.
144
+ /* #undef DNNL_USE_RT_OBJECTS_IN_PRIMITIVE_CACHE */
145
+
146
+ // When defined, DPCPP is supported.
147
+ /* #undef DNNL_WITH_SYCL */
148
+
149
+ // When defined, Level Zero is supported.
150
+ /* #undef DNNL_WITH_LEVEL_ZERO */
151
+
152
+ // When defined, SYCL CUDA backend is used.
153
+ /* #undef DNNL_SYCL_CUDA */
154
+
155
+ // When defined, SYCL HIP backend is used.
156
+ /* #undef DNNL_SYCL_HIP */
157
+
158
+ // When defined, SYCL Generic backend is used.
159
+ /* #undef DNNL_SYCL_GENERIC */
160
+
161
+ // When defined, stack checker is enabled.
162
+ /* #undef DNNL_ENABLE_STACK_CHECKER */
163
+
164
+ // When defined, experimental features are enabled.
165
+ /* #undef DNNL_EXPERIMENTAL */
166
+
167
+ // When defined, experimental functionality for sparse domain is enabled.
168
+ /* #undef DNNL_EXPERIMENTAL_SPARSE */
169
+
170
+ // When defined, experimental functionality for ukernels is enabled.
171
+ #define DNNL_EXPERIMENTAL_UKERNEL
172
+
173
+ // When defined, graph component is enabled.
174
+ #define ONEDNN_BUILD_GRAPH
175
+
176
+ // When defined, experimental profiling capabilities are enabled.
177
+ /* #undef DNNL_EXPERIMENTAL_PROFILING */
178
+
179
+ // When defined, experimental logging capabilities are enabled.
180
+ /* #undef DNNL_EXPERIMENTAL_LOGGING */
181
+ // When defined, it disables GPU compute reference kernels.
182
+ /* #undef DNNL_DISABLE_GPU_REF_KERNELS */
183
+
184
+ // List of configurating build controls
185
+ // Workload controls
186
+ #define BUILD_TRAINING 1
187
+ #define BUILD_INFERENCE 0
188
+ // Primitive controls
189
+ #define BUILD_PRIMITIVE_ALL 1
190
+ #define BUILD_BATCH_NORMALIZATION 0
191
+ #define BUILD_BINARY 0
192
+ #define BUILD_CONCAT 0
193
+ #define BUILD_CONVOLUTION 0
194
+ #define BUILD_DECONVOLUTION 0
195
+ #define BUILD_ELTWISE 0
196
+ #define BUILD_GROUP_NORMALIZATION 0
197
+ #define BUILD_INNER_PRODUCT 0
198
+ #define BUILD_LAYER_NORMALIZATION 0
199
+ #define BUILD_LRN 0
200
+ #define BUILD_MATMUL 0
201
+ #define BUILD_POOLING 0
202
+ #define BUILD_PRELU 0
203
+ #define BUILD_REDUCTION 0
204
+ #define BUILD_REORDER 0
205
+ #define BUILD_RESAMPLING 0
206
+ #define BUILD_RNN 0
207
+ #define BUILD_SDPA 0
208
+ #define BUILD_SHUFFLE 0
209
+ #define BUILD_SOFTMAX 0
210
+ #define BUILD_SUM 0
211
+ // Primitives CPU ISA controls
212
+ #define BUILD_PRIMITIVE_CPU_ISA_ALL 1
213
+ #define BUILD_SSE41 0
214
+ #define BUILD_AVX2 0
215
+ #define BUILD_AVX512 0
216
+ #define BUILD_AMX 0
217
+ // Primitives GPU ISA controls
218
+ #define BUILD_PRIMITIVE_GPU_ISA_ALL 1
219
+ #define BUILD_GEN9 0
220
+ #define BUILD_GEN11 0
221
+ #define BUILD_XELP 0
222
+ #define BUILD_XEHP 0
223
+ #define BUILD_XEHPG 0
224
+ #define BUILD_XEHPC 0
225
+ #define BUILD_XE2 0
226
+ #define BUILD_XE3 0
227
+ // GeMM kernels ISA controls
228
+ #define BUILD_GEMM_KERNELS_ALL 1
229
+ #define BUILD_GEMM_KERNELS_NONE 0
230
+ #define BUILD_GEMM_SSE41 0
231
+ #define BUILD_GEMM_AVX2 0
232
+ #define BUILD_GEMM_AVX512 0
233
+ #endif
234
+
235
+ #else
236
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
237
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_debug.h ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2018-2024 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ // DO NOT EDIT, AUTO-GENERATED
19
+ // Use this script to update the file: scripts/generate_dnnl_debug.py
20
+
21
+ // clang-format off
22
+
23
+ #ifndef ONEAPI_DNNL_DNNL_DEBUG_H
24
+ #define ONEAPI_DNNL_DNNL_DEBUG_H
25
+
26
+ /// @file
27
+ /// Debug capabilities
28
+
29
+ #include "oneapi/dnnl/dnnl_config.h"
30
+ #include "oneapi/dnnl/dnnl_types.h"
31
+
32
+ #ifdef __cplusplus
33
+ extern "C" {
34
+ #endif
35
+
36
+ const char DNNL_API *dnnl_status2str(dnnl_status_t v);
37
+ const char DNNL_API *dnnl_dt2str(dnnl_data_type_t v);
38
+ const char DNNL_API *dnnl_fpmath_mode2str(dnnl_fpmath_mode_t v);
39
+ const char DNNL_API *dnnl_accumulation_mode2str(dnnl_accumulation_mode_t v);
40
+ const char DNNL_API *dnnl_engine_kind2str(dnnl_engine_kind_t v);
41
+ #ifdef DNNL_EXPERIMENTAL_SPARSE
42
+ const char DNNL_API *dnnl_sparse_encoding2str(dnnl_sparse_encoding_t v);
43
+ #endif
44
+ const char DNNL_API *dnnl_fmt_tag2str(dnnl_format_tag_t v);
45
+ const char DNNL_API *dnnl_prop_kind2str(dnnl_prop_kind_t v);
46
+ const char DNNL_API *dnnl_prim_kind2str(dnnl_primitive_kind_t v);
47
+ const char DNNL_API *dnnl_alg_kind2str(dnnl_alg_kind_t v);
48
+ const char DNNL_API *dnnl_rnn_flags2str(dnnl_rnn_flags_t v);
49
+ const char DNNL_API *dnnl_rnn_direction2str(dnnl_rnn_direction_t v);
50
+ const char DNNL_API *dnnl_scratchpad_mode2str(dnnl_scratchpad_mode_t v);
51
+ const char DNNL_API *dnnl_rounding_mode2str(dnnl_rounding_mode_t v);
52
+ const char DNNL_API *dnnl_cpu_isa2str(dnnl_cpu_isa_t v);
53
+ const char DNNL_API *dnnl_cpu_isa_hints2str(dnnl_cpu_isa_hints_t v);
54
+
55
+ const char DNNL_API *dnnl_runtime2str(unsigned v);
56
+ const char DNNL_API *dnnl_fmt_kind2str(dnnl_format_kind_t v);
57
+
58
+ #ifdef __cplusplus
59
+ }
60
+ #endif
61
+
62
+ #endif
63
+
64
+ #else
65
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
66
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph.h ADDED
@@ -0,0 +1,777 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2020-2024 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ /// @file
19
+ /// Graph C API
20
+
21
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_H
22
+ #define ONEAPI_DNNL_DNNL_GRAPH_H
23
+
24
+ #include "oneapi/dnnl/dnnl_common.h"
25
+ #include "oneapi/dnnl/dnnl_config.h"
26
+ #include "oneapi/dnnl/dnnl_graph_types.h"
27
+
28
+ #ifdef __cplusplus
29
+ extern "C" {
30
+ #endif
31
+
32
+ /// @addtogroup dnnl_api
33
+ /// @{
34
+
35
+ /// @addtogroup dnnl_graph_api
36
+ /// @{
37
+
38
+ /// @addtogroup dnnl_graph_api_allocator
39
+ /// @{
40
+
41
+ /// Creates a host allocator with the given allocation and deallocation
42
+ /// call-back function pointers.
43
+ ///
44
+ /// @param allocator Output allocator.
45
+ /// @param host_malloc A pointer to malloc function for host.
46
+ /// @param host_free A pointer to free function for host.
47
+ /// @returns #dnnl_success on success or a status describing the error
48
+ /// otherwise.
49
+ dnnl_status_t DNNL_API dnnl_graph_allocator_create(
50
+ dnnl_graph_allocator_t *allocator,
51
+ dnnl_graph_host_allocate_f host_malloc,
52
+ dnnl_graph_host_deallocate_f host_free);
53
+
54
+ /// Destroys an allocator.
55
+ ///
56
+ /// @param allocator The allocator to be destroyed.
57
+ /// @returns #dnnl_success on success or a status describing the error
58
+ /// otherwise.
59
+ dnnl_status_t DNNL_API dnnl_graph_allocator_destroy(
60
+ dnnl_graph_allocator_t allocator);
61
+
62
+ /// @} dnnl_graph_api_allocator
63
+
64
+ /// @addtogroup dnnl_graph_api_engine
65
+ /// @{
66
+
67
+ /// This API is a supplement for existing onednn engine API.
68
+ dnnl_status_t DNNL_API dnnl_graph_make_engine_with_allocator(
69
+ dnnl_engine_t *engine, dnnl_engine_kind_t kind, size_t index,
70
+ const_dnnl_graph_allocator_t alloc);
71
+
72
+ /// @} dnnl_graph_api_engine
73
+
74
+ /// @addtogroup dnnl_graph_api_logical_tensor
75
+ /// @{
76
+
77
+ /// Initializes a logical tensor with id, data type, number of dimensions,
78
+ /// layout type, and property. The logical tensor's dims are unknown with this
79
+ /// interface.
80
+ ///
81
+ /// @param logical_tensor Output logical tensor.
82
+ /// @param tid The unique id of the output logical tensor.
83
+ /// @param dtype Elements data type.
84
+ /// @param ndims Number of dimensions.
85
+ /// @param ltype Layout type of the underlying tensor buffer.
86
+ /// @param ptype Tensor property type.
87
+ /// @returns #dnnl_success on success or a status describing the error
88
+ /// otherwise.
89
+ dnnl_status_t DNNL_API dnnl_graph_logical_tensor_init(
90
+ dnnl_graph_logical_tensor_t *logical_tensor, size_t tid,
91
+ dnnl_data_type_t dtype, int32_t ndims, dnnl_graph_layout_type_t ltype,
92
+ dnnl_graph_tensor_property_t ptype);
93
+
94
+ /// Initializes a logical tensor with basic information and dims. The logical
95
+ /// tensor's dimensions and layout will be initialized according to the input
96
+ /// arguments.
97
+ ///
98
+ /// @note
99
+ /// If dims contains all valid values and layout type is
100
+ /// #dnnl_graph_layout_type_strided. The strides field in
101
+ /// #dnnl_graph_logical_tensor_t will be calculated in a row major and
102
+ /// contiguous way. Otherwise, Accessing the strides field is an undefined
103
+ /// behavior.
104
+ ///
105
+ /// Eg. dims (2, 3, 4, 5) will get strides (60, 20, 5, 1)
106
+ ///
107
+ /// @param logical_tensor Output logical tensor.
108
+ /// @param tid The unique id of output logical tensor.
109
+ /// @param dtype Elements data type.
110
+ /// @param ndims Number of dimensions.
111
+ /// @param dims Array of dimensions.
112
+ /// @param ltype Layout type of the underlying tensor memory.
113
+ /// @param ptype Tensor property type.
114
+ /// @returns #dnnl_success on success or a status describing the error
115
+ /// otherwise.
116
+ dnnl_status_t DNNL_API dnnl_graph_logical_tensor_init_with_dims(
117
+ dnnl_graph_logical_tensor_t *logical_tensor, size_t tid,
118
+ dnnl_data_type_t dtype, int32_t ndims, const dnnl_dims_t dims,
119
+ dnnl_graph_layout_type_t ltype, dnnl_graph_tensor_property_t ptype);
120
+
121
+ /// Initializes a logical tensor with dimensions and strides provided by user.
122
+ ///
123
+ /// @note
124
+ /// Once strides are explicitly provided through the API, the `layout_type`
125
+ /// in #dnnl_graph_logical_tensor_t can only be
126
+ /// #dnnl_graph_layout_type_strided or #dnnl_graph_layout_type_any.
127
+ ///
128
+ /// @param logical_tensor Output logical tensor.
129
+ /// @param tid The unique id of output logical tensor.
130
+ /// @param dtype Elements data type.
131
+ /// @param ndims Number of dimensions.
132
+ /// @param dims Array of dimensions.
133
+ /// @param strides Array of strides.
134
+ /// @param ptype Tensor property type.
135
+ /// @returns #dnnl_success on success or a status describing the error
136
+ /// otherwise.
137
+ dnnl_status_t DNNL_API dnnl_graph_logical_tensor_init_with_strides(
138
+ dnnl_graph_logical_tensor_t *logical_tensor, size_t tid,
139
+ dnnl_data_type_t dtype, int32_t ndims, const dnnl_dims_t dims,
140
+ const dnnl_dims_t strides, dnnl_graph_tensor_property_t ptype);
141
+
142
+ /// Returns the memory size described by the logical tensor. If it's a strided
143
+ /// layout, the size will be calculated by `dims` and `strides`. If it's an
144
+ /// opaque layout, the size will be decided by `layout_id`.
145
+ ///
146
+ /// @param logical_tensor Logical tensor.
147
+ /// @param size Output memory size in bytes.
148
+ /// @returns #dnnl_success on success or a status describing the error
149
+ /// otherwise.
150
+ dnnl_status_t DNNL_API dnnl_graph_logical_tensor_get_mem_size(
151
+ const dnnl_graph_logical_tensor_t *logical_tensor, size_t *size);
152
+
153
+ /// Compares if two logical tenors are equal. Users can decide accordingly
154
+ /// if layout reordering is needed for two logical tensors. The method will
155
+ /// return true for below two circumstances:
156
+ ///
157
+ /// 1. the two logical tensors are equal regarding each field in the struct,
158
+ /// eg. id, ndims, dims, layout type, property, etc.
159
+ /// 2. If all other fields are equal but the layout types in two logical
160
+ /// tensors are different, the method will return true when the underlying
161
+ /// memory layout is the same. For example, one logical tensor has strided
162
+ /// layout type while the other one has opaque layout type, but underneath,
163
+ /// both layouts are NHWC, the method will still return true for this case.
164
+ ///
165
+ /// @param lt1 The handle of first logical tensor.
166
+ /// @param lt2 The handle of second logical tensor.
167
+ /// @param is_equal 1 if these two logical tensors are equal, 0 otherwise.
168
+ /// @returns #dnnl_success on success or a status describing the error
169
+ /// otherwise.
170
+ dnnl_status_t DNNL_API dnnl_graph_logical_tensor_is_equal(
171
+ const dnnl_graph_logical_tensor_t *lt1,
172
+ const dnnl_graph_logical_tensor_t *lt2, uint8_t *is_equal);
173
+
174
+ /// @} dnnl_graph_api_logical_tensor
175
+
176
+ /// @addtogroup dnnl_graph_api_tensor
177
+ /// @{
178
+
179
+ /// Creates a tensor with logical tensor, engine, and data handle.
180
+ ///
181
+ /// @param tensor Output tensor.
182
+ /// @param logical_tensor Description for this tensor.
183
+ /// @param engine Engine to use.
184
+ /// @param handle Handle of the memory buffer to use as an underlying storage.
185
+ /// - A pointer to the user-allocated buffer. In this case the library
186
+ /// doesn't own the buffer.
187
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
188
+ /// allocate the buffer for the tensor. In this case the library
189
+ /// owns the buffer.
190
+ /// - DNNL_MEMORY_NONE to create tensor without an underlying buffer.
191
+ /// @returns #dnnl_success on success or a status describing the error
192
+ /// otherwise.
193
+ dnnl_status_t DNNL_API dnnl_graph_tensor_create(dnnl_graph_tensor_t *tensor,
194
+ const dnnl_graph_logical_tensor_t *logical_tensor, dnnl_engine_t engine,
195
+ void *handle);
196
+
197
+ /// Destroys a tensor.
198
+ ///
199
+ /// @param tensor The tensor to be destroyed.
200
+ /// @returns #dnnl_success on success or a status describing the error
201
+ /// otherwise.
202
+ dnnl_status_t DNNL_API dnnl_graph_tensor_destroy(dnnl_graph_tensor_t tensor);
203
+
204
+ /// Gets the data handle of a tensor.
205
+ ///
206
+ /// @param tensor The input tensor.
207
+ /// @param handle Pointer to the data of input tensor.
208
+ /// @returns #dnnl_success on success or a status describing the error
209
+ /// otherwise.
210
+ dnnl_status_t DNNL_API dnnl_graph_tensor_get_data_handle(
211
+ const_dnnl_graph_tensor_t tensor, void **handle);
212
+
213
+ /// Set data handle for a tensor.
214
+ ///
215
+ /// @param tensor The input tensor.
216
+ /// @param handle New data handle for tensor.
217
+ /// @returns #dnnl_success on success or a status describing the error
218
+ /// otherwise.
219
+ dnnl_status_t DNNL_API dnnl_graph_tensor_set_data_handle(
220
+ dnnl_graph_tensor_t tensor, void *handle);
221
+
222
+ /// Returns the engine of a tensor object.
223
+ ///
224
+ /// @param tensor The input tensor.
225
+ /// @param engine Output engine on which the tensor is located.
226
+ /// @returns #dnnl_success on success or a status describing the error
227
+ /// otherwise.
228
+ dnnl_status_t DNNL_API dnnl_graph_tensor_get_engine(
229
+ const_dnnl_graph_tensor_t tensor, dnnl_engine_t *engine);
230
+
231
+ /// Returns the logical tensor of a tensor object.
232
+ ///
233
+ /// @param tensor The input tensor.
234
+ /// @param logical_tensor Output logical tensor of the tensor object.
235
+ /// @returns #dnnl_success on success or a status describing the error
236
+ /// otherwise.
237
+ dnnl_status_t DNNL_API dnnl_graph_tensor_get_logical_tensor(
238
+ const_dnnl_graph_tensor_t tensor,
239
+ dnnl_graph_logical_tensor_t *logical_tensor);
240
+
241
+ /// @} dnnl_graph_api_tensor
242
+
243
+ /// @addtogroup dnnl_graph_api_op
244
+ /// @{
245
+
246
+ /// Initializes an op with unique id, kind, and name.
247
+ ///
248
+ /// @param op Output op
249
+ /// @param id The unique id of the output op.
250
+ /// @param kind The op kind.
251
+ /// @param verbose_name The string added as the op name.
252
+ /// @returns #dnnl_success on success or a status describing the error
253
+ /// otherwise.
254
+ dnnl_status_t DNNL_API dnnl_graph_op_create(dnnl_graph_op_t *op, size_t id,
255
+ dnnl_graph_op_kind_t kind, const char *verbose_name);
256
+
257
+ /// Destroys an op.
258
+ ///
259
+ /// @param op The op to be destroyed.
260
+ /// @returns #dnnl_success on success or a status describing the error
261
+ /// otherwise.
262
+ dnnl_status_t DNNL_API dnnl_graph_op_destroy(dnnl_graph_op_t op);
263
+
264
+ /// Adds input logical tensor to the op.
265
+ ///
266
+ /// @param op Input op.
267
+ /// @param input The input logical tensor to be added.
268
+ /// @returns #dnnl_success on success or a status describing the error
269
+ /// otherwise.
270
+ dnnl_status_t DNNL_API dnnl_graph_op_add_input(
271
+ dnnl_graph_op_t op, const dnnl_graph_logical_tensor_t *input);
272
+
273
+ /// Adds output logical tensor to the op.
274
+ ///
275
+ /// @param op Input op.
276
+ /// @param output The output logical tensor to be added.
277
+ /// @returns #dnnl_success on success or a status describing the error
278
+ /// otherwise.
279
+ dnnl_status_t DNNL_API dnnl_graph_op_add_output(
280
+ dnnl_graph_op_t op, const dnnl_graph_logical_tensor_t *output);
281
+
282
+ /// Sets floating point attribute to an op.
283
+ ///
284
+ /// @param op Input op.
285
+ /// @param name The attribute's name.
286
+ /// @param value The attribute's value.
287
+ /// @param value_len The number of value element.
288
+ /// @returns #dnnl_success on success or a status describing the error
289
+ /// otherwise.
290
+ dnnl_status_t DNNL_API dnnl_graph_op_set_attr_f32(dnnl_graph_op_t op,
291
+ dnnl_graph_op_attr_t name, const float *value, size_t value_len);
292
+
293
+ /// Sets boolean attribute to an op.
294
+ ///
295
+ /// @param op Input op.
296
+ /// @param name The attribute's name.
297
+ /// @param value The attribute's value.
298
+ /// @param value_len The number of value element.
299
+ /// @returns #dnnl_success on success or a status describing the error
300
+ /// otherwise.
301
+ dnnl_status_t DNNL_API dnnl_graph_op_set_attr_bool(dnnl_graph_op_t op,
302
+ dnnl_graph_op_attr_t name, const uint8_t *value, size_t value_len);
303
+
304
+ /// Sets integer attribute to an op.
305
+ ///
306
+ /// @param op Input op.
307
+ /// @param name The attribute's name.
308
+ /// @param value The attribute's value.
309
+ /// @param value_len The number of value element.
310
+ /// @returns #dnnl_success on success or a status describing the error
311
+ /// otherwise.
312
+ dnnl_status_t DNNL_API dnnl_graph_op_set_attr_s64(dnnl_graph_op_t op,
313
+ dnnl_graph_op_attr_t name, const int64_t *value, size_t value_len);
314
+
315
+ /// Sets string attribute to an op.
316
+ ///
317
+ /// @param op Input op.
318
+ /// @param name The attribute's name.
319
+ /// @param value The attribute's value.
320
+ /// @param value_len The length of the string value.
321
+ /// @returns #dnnl_success on success or a status describing the error
322
+ /// otherwise.
323
+ dnnl_status_t DNNL_API dnnl_graph_op_set_attr_str(dnnl_graph_op_t op,
324
+ dnnl_graph_op_attr_t name, const char *value, size_t value_len);
325
+
326
+ /// Returns the unique id of an op.
327
+ ///
328
+ /// @param op Input op.
329
+ /// @param id Output the unique id.
330
+ /// @returns #dnnl_success on success or a status describing the error
331
+ /// otherwise.
332
+ dnnl_status_t DNNL_API dnnl_graph_op_get_id(
333
+ const_dnnl_graph_op_t op, size_t *id);
334
+
335
+ /// Returns the kind of an op.
336
+ ///
337
+ /// @param op Input op.
338
+ /// @param kind Output op kind.
339
+ /// @returns #dnnl_success on success or a status describing the error
340
+ /// otherwise.
341
+ dnnl_status_t DNNL_API dnnl_graph_op_get_kind(
342
+ const_dnnl_graph_op_t op, dnnl_graph_op_kind_t *kind);
343
+
344
+ /// @} dnnl_graph_api_op
345
+
346
+ /// @addtogroup dnnl_graph_api_partition
347
+ /// @{
348
+
349
+ /// Creates a new partition with a given operator and engine kind. The API is
350
+ /// used to create a partition from an operation directly without creating the
351
+ /// graph and calling `get_partitions()`. The output partition contains only one
352
+ /// operation specified by the parameter. The output partition instance should
353
+ /// be destroyed via #dnnl_graph_partition_destroy after use.
354
+ ///
355
+ /// @param partition The handle of output partition.
356
+ /// @param op The operation used to create partition.
357
+ /// @param ekind The engine kind used to create partition.
358
+ /// @returns #dnnl_success on success or a status describing the error
359
+ /// otherwise.
360
+ dnnl_status_t DNNL_API dnnl_graph_partition_create_with_op(
361
+ dnnl_graph_partition_t *partition, const_dnnl_graph_op_t op,
362
+ dnnl_engine_kind_t ekind);
363
+
364
+ /// Destroys a partition.
365
+ ///
366
+ /// @param partition The partition to be destroyed.
367
+ /// @returns #dnnl_success on success or a status describing the error
368
+ /// otherwise.
369
+ dnnl_status_t DNNL_API dnnl_graph_partition_destroy(
370
+ dnnl_graph_partition_t partition);
371
+
372
+ /// Returns the number of operations in a partition.
373
+ ///
374
+ /// @param partition The target partition.
375
+ /// @param num Output the number of operations.
376
+ /// @returns #dnnl_success on success or a status describing the error
377
+ /// otherwise.
378
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_op_num(
379
+ const_dnnl_graph_partition_t partition, size_t *num);
380
+
381
+ /// Returns the list of op IDs of the partition.
382
+ ///
383
+ /// @param partition The target partition.
384
+ /// @param num The number of ops.
385
+ /// @param ids Output the op IDs.
386
+ /// @returns #dnnl_success on success or a status describing the error
387
+ /// otherwise.
388
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_ops(
389
+ dnnl_graph_partition_t partition, size_t num, size_t *ids);
390
+
391
+ /// Returns the ID of a partition.
392
+ ///
393
+ /// @param partition The target partition.
394
+ /// @param id Output the ID of the partition.
395
+ /// @returns #dnnl_success on success or a status describing the error
396
+ /// otherwise.
397
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_id(
398
+ const_dnnl_graph_partition_t partition, size_t *id);
399
+
400
+ /// Compiles a partition with given input and output logical tensors. The output
401
+ /// logical tensors can contain unknown dimensions. For this case, the
402
+ /// compilation will deduce the output shapes according to input shapes. The
403
+ /// output logical tensors can also have layout type `any`. The compilation will
404
+ /// choose the optimal layout for output tensors. The optimal layout will be
405
+ /// represented as an opaque layout ID saved in the output logical tensor.
406
+ ///
407
+ /// @param partition The target partition.
408
+ /// @param compiled_partition Output compiled partition.
409
+ /// @param in_num The number of input logical tensors.
410
+ /// @param inputs A list of input logical tensors.
411
+ /// @param out_num The number of output logical tensors.
412
+ /// @param outputs A list of output logical tensors.
413
+ /// @param engine The target engine of the compilation.
414
+ /// @returns #dnnl_success on success or a status describing the error
415
+ /// otherwise.
416
+ dnnl_status_t DNNL_API dnnl_graph_partition_compile(
417
+ dnnl_graph_partition_t partition,
418
+ dnnl_graph_compiled_partition_t compiled_partition, size_t in_num,
419
+ const dnnl_graph_logical_tensor_t **inputs, size_t out_num,
420
+ const dnnl_graph_logical_tensor_t **outputs, dnnl_engine_t engine);
421
+
422
+ /// Returns the number of input logical tensors of a partition.
423
+ ///
424
+ /// @param partition The target partition.
425
+ /// @param num Output the number of input logical tensors.
426
+ /// @returns #dnnl_success on success or a status describing the error
427
+ /// otherwise.
428
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_input_ports_num(
429
+ const_dnnl_graph_partition_t partition, size_t *num);
430
+
431
+ /// Returns a list of input logical tensors from a partition.
432
+ ///
433
+ /// @param partition The target partition.
434
+ /// @param num The number of input logical tensors.
435
+ /// @param inputs The list of input logical tensors.
436
+ /// @returns #dnnl_success on success or a status describing the error
437
+ /// otherwise.
438
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_input_ports(
439
+ const_dnnl_graph_partition_t partition, size_t num,
440
+ dnnl_graph_logical_tensor_t *inputs);
441
+
442
+ /// Returns the number of output logical tensors of a partition.
443
+ ///
444
+ /// @param partition The target partition.
445
+ /// @param num Output the number of output logical tensors.
446
+ /// @returns #dnnl_success on success or a status describing the error
447
+ /// otherwise.
448
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_output_ports_num(
449
+ const_dnnl_graph_partition_t partition, size_t *num);
450
+
451
+ /// Returns a list of output logical tensors from a partition.
452
+ ///
453
+ /// @param partition The target partition.
454
+ /// @param num The number of output logical tensors.
455
+ /// @param outputs The list of output logical tensors.
456
+ /// @returns #dnnl_success on success or a status describing the error
457
+ /// otherwise.
458
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_output_ports(
459
+ const_dnnl_graph_partition_t partition, size_t num,
460
+ dnnl_graph_logical_tensor_t *outputs);
461
+
462
+ /// Returns the supporting status of a partition. Some operations may not be
463
+ /// supported by the library under certain circumstances. During partitioning
464
+ /// stage, unsupported partitions will be returned to users with each containing
465
+ /// an unsupported operation. Users should check the supporting status of a
466
+ /// partition before transforming the computation graph or compiling the
467
+ /// partition.
468
+ ///
469
+ /// @param partition The target partition.
470
+ /// @param is_supported Output flag to indicate the supporting status. 0 means
471
+ /// unsupported while 1 means supported.
472
+ /// @returns #dnnl_success on success or a status describing the error
473
+ /// otherwise.
474
+ dnnl_status_t DNNL_API dnnl_graph_partition_is_supported(
475
+ const_dnnl_graph_partition_t partition, uint8_t *is_supported);
476
+
477
+ /// Returns the engine kind of a partition.
478
+ ///
479
+ /// @param partition The target partition.
480
+ /// @param kind The output engine kind.
481
+ /// @returns #dnnl_success on success or a status describing the error
482
+ /// otherwise.
483
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_engine_kind(
484
+ const_dnnl_graph_partition_t partition, dnnl_engine_kind_t *kind);
485
+
486
+ /// @} dnnl_graph_api_partition
487
+
488
+ /// @addtogroup dnnl_graph_api_compiled_partition
489
+ /// @{
490
+
491
+ /// Creates a new compiled partition handle.
492
+ ///
493
+ /// @param compiled_partition The handle of output compiled partition.
494
+ /// @param partition The handle of input partition.
495
+ /// @returns #dnnl_success on success or a status describing the error
496
+ /// otherwise.
497
+ dnnl_status_t DNNL_API dnnl_graph_compiled_partition_create(
498
+ dnnl_graph_compiled_partition_t *compiled_partition,
499
+ dnnl_graph_partition_t partition);
500
+
501
+ /// Executes a compiled partition.
502
+ ///
503
+ /// @param compiled_partition The handle of target compiled partition.
504
+ /// @param stream The stream used for execution.
505
+ /// @param num_inputs The number of input tensors.
506
+ /// @param inputs A list of input tensors.
507
+ /// @param num_outputs The number of output tensors.
508
+ /// @param outputs A non-empty list of output tensors.
509
+ /// @returns #dnnl_success on success or a status describing the error
510
+ /// otherwise.
511
+ dnnl_status_t DNNL_API dnnl_graph_compiled_partition_execute(
512
+ const_dnnl_graph_compiled_partition_t compiled_partition,
513
+ dnnl_stream_t stream, size_t num_inputs,
514
+ const_dnnl_graph_tensor_t *inputs, size_t num_outputs,
515
+ const_dnnl_graph_tensor_t *outputs);
516
+
517
+ /// Destroys a compiled partition.
518
+ ///
519
+ /// @param compiled_partition The compiled partition to be destroyed.
520
+ /// @returns #dnnl_success on success or a status describing the error
521
+ /// otherwise.
522
+ dnnl_status_t DNNL_API dnnl_graph_compiled_partition_destroy(
523
+ dnnl_graph_compiled_partition_t compiled_partition);
524
+
525
+ /// Queries an input or output logical tensor according to tensor ID. If the
526
+ /// tensor ID doesn't belong to any input or output of the compiled partition,
527
+ /// an error status #dnnl_invalid_arguments will be returned by the API.
528
+ ///
529
+ /// @param compiled_partition The handle of target compiled_partition.
530
+ /// @param tid The unique id of required tensor.
531
+ /// @param lt The output logical tensor.
532
+ /// @returns #dnnl_success on success or a status describing the error
533
+ /// otherwise.
534
+ dnnl_status_t DNNL_API dnnl_graph_compiled_partition_query_logical_tensor(
535
+ const_dnnl_graph_compiled_partition_t compiled_partition, size_t tid,
536
+ dnnl_graph_logical_tensor_t *lt);
537
+
538
+ /// Returns the hint of in-place pairs from a compiled partition. It indicates
539
+ /// that an input and an output of the partition can share the same memory
540
+ /// buffer for computation. In-place computation helps to reduce the memory
541
+ /// footprint and improves cache locality. But since the library may not have a
542
+ /// global view of user's application, it's possible that the tensor with
543
+ /// `input_id` is used at other places in user's computation graph. In this
544
+ /// case, the user should take the in-place pair as a hint and pass a different
545
+ /// memory buffer for output tensor to avoid overwriting the input memory buffer
546
+ /// which will probably cause unexpected incorrect results.
547
+ ///
548
+ /// @param compiled_partition The handle of target compiled_partition.
549
+ /// @param num_inplace_pairs The number of in-place pairs.
550
+ /// @param inplace_pairs The handle of in-place pairs.
551
+ /// @returns #dnnl_success on success or a status describing the error
552
+ /// otherwise.
553
+ dnnl_status_t DNNL_API dnnl_graph_compiled_partition_get_inplace_ports(
554
+ const_dnnl_graph_compiled_partition_t compiled_partition,
555
+ size_t *num_inplace_pairs,
556
+ const dnnl_graph_inplace_pair_t **inplace_pairs);
557
+
558
+ /// @} dnnl_graph_api_compiled_partition
559
+
560
+ /// @addtogroup dnnl_graph_api_graph
561
+ /// @{
562
+
563
+ /// Creates a new empty graph. A graph is associated to a specific engine kind.
564
+ /// The partitions returned from the graph will inherit the engine kind of the
565
+ /// graph.
566
+ ///
567
+ /// @param graph The handle of output graph.
568
+ /// @param engine_kind The target engine kind.
569
+ /// @returns #dnnl_success on success or a status describing the error
570
+ /// otherwise.
571
+ dnnl_status_t DNNL_API dnnl_graph_graph_create(
572
+ dnnl_graph_graph_t *graph, dnnl_engine_kind_t engine_kind);
573
+
574
+ /// Creates a new empty graph with an engine kind and a floating-point math
575
+ /// mode. All partitions returned from the graph will inherit the engine kind
576
+ /// and floating-point math mode.
577
+ ///
578
+ /// @param graph The handle of output graph.
579
+ /// @param engine_kind The kind for engine.
580
+ /// @param mode The floating-point math mode.
581
+ /// @returns #dnnl_success on success or a status describing the error
582
+ /// otherwise.
583
+ dnnl_status_t DNNL_API dnnl_graph_graph_create_with_fpmath_mode(
584
+ dnnl_graph_graph_t *graph, dnnl_engine_kind_t engine_kind,
585
+ dnnl_fpmath_mode_t mode);
586
+
587
+ /// Destroys a graph.
588
+ ///
589
+ /// @param graph The graph to be destroyed.
590
+ /// @returns #dnnl_success on success or a status describing the error
591
+ /// otherwise.
592
+ dnnl_status_t DNNL_API dnnl_graph_graph_destroy(dnnl_graph_graph_t graph);
593
+
594
+ /// Set the floating point math mode for a graph.
595
+ ///
596
+ /// @param graph The target graph.
597
+ /// @param mode The floating-point math mode.
598
+ /// @param apply_to_int The flag that controls whether to use floating-point
599
+ /// arithmetic for integral operations.
600
+ /// @returns #dnnl_success on success or a status describing the error
601
+ /// otherwise.
602
+ dnnl_status_t DNNL_API dnnl_graph_graph_set_fpmath_mode(
603
+ dnnl_graph_graph_t graph, dnnl_fpmath_mode_t mode, int apply_to_int);
604
+
605
+ /// Get the floating point math mode for a graph.
606
+ ///
607
+ /// @param graph The target graph.
608
+ /// @param mode The floating-point math mode.
609
+ /// @param apply_to_int The flag that controls whether to use floating-point
610
+ /// arithmetic for integral operations.
611
+ /// @returns #dnnl_success on success or a status describing the error
612
+ /// otherwise.
613
+ dnnl_status_t DNNL_API dnnl_graph_graph_get_fpmath_mode(
614
+ dnnl_graph_graph_t graph, dnnl_fpmath_mode_t *mode, int *apply_to_int);
615
+
616
+ /// Adds an operation into a graph. The API will return failure if the operator
617
+ /// has already been added to the graph or the operation cannot pass the schema
618
+ /// check in the library (eg. input and output numbers and data types, the
619
+ /// attributes of the operation, etc.).
620
+ ///
621
+ /// @param graph The target graph.
622
+ /// @param op The operation to be added.
623
+ /// @returns #dnnl_success on success or a status describing the error
624
+ /// otherwise.
625
+ dnnl_status_t DNNL_API dnnl_graph_add_op(
626
+ dnnl_graph_graph_t graph, dnnl_graph_op_t op);
627
+
628
+ /// Finalizes a graph. It means users have finished adding operations into the
629
+ /// graph and the graph is ready for partitioning. Adding a new operation into a
630
+ /// finalized graph will return failures. Similarly, partitioning on a
631
+ /// un-finalized graph will also return failures.
632
+ ///
633
+ /// @param graph The target graph to be finalized.
634
+ /// @returns #dnnl_success on success or a status describing the error
635
+ /// otherwise.
636
+ dnnl_status_t DNNL_API dnnl_graph_graph_finalize(dnnl_graph_graph_t graph);
637
+
638
+ /// Checks if a graph is finalized.
639
+ ///
640
+ /// @param graph The target graph to be finalized.
641
+ /// @param finalized Output the finalization status. 0 means then graph is not
642
+ /// finalized. Other values means the graph is finalized.
643
+ /// @returns #dnnl_success on success or a status describing the error
644
+ /// otherwise.
645
+ dnnl_status_t DNNL_API dnnl_graph_graph_is_finalized(
646
+ dnnl_graph_graph_t graph, uint8_t *finalized);
647
+
648
+ /// Filters a graph. Partitions will be claimed internally according to the
649
+ /// capability of the library, the engine kind, and the policy.
650
+ ///
651
+ /// @param graph The target graph.
652
+ /// @param policy The partition policy.
653
+ /// @returns #dnnl_success on success or a status describing the error
654
+ /// otherwise.
655
+ dnnl_status_t DNNL_API dnnl_graph_graph_filter(
656
+ dnnl_graph_graph_t graph, dnnl_graph_partition_policy_t policy);
657
+
658
+ /// Returns the number of partitions of a graph. The API should be called after
659
+ /// a partition is already filtered. Otherwise, the output number is zero.
660
+ ///
661
+ /// @param graph The graph.
662
+ /// @param num Output the number of partitions.
663
+ /// @returns #dnnl_success on success or a status describing the error
664
+ /// otherwise.
665
+ dnnl_status_t DNNL_API dnnl_graph_graph_get_partition_num(
666
+ const_dnnl_graph_graph_t graph, size_t *num);
667
+
668
+ /// Returns the partitions from a filtered graph. Output partition instances
669
+ /// will be written into the parameter `partitions`. Users need to make sure
670
+ /// `partitions` is valid and has enough space to accept the partition
671
+ /// instances. Each output partition instance should be destroyed via
672
+ /// #dnnl_graph_partition_destroy explicitly after use.
673
+ ///
674
+ /// @param graph The target graph.
675
+ /// @param num The number of partitions.
676
+ /// @param partitions Output the partitions.
677
+ /// @returns #dnnl_success on success or a status describing the error
678
+ /// otherwise.
679
+ dnnl_status_t DNNL_API dnnl_graph_graph_get_partitions(dnnl_graph_graph_t graph,
680
+ size_t num, dnnl_graph_partition_t *partitions);
681
+
682
+ /// @} dnnl_graph_api_graph
683
+
684
+ /// @addtogroup dnnl_graph_api_compiled_partition_cache
685
+ /// @{
686
+
687
+ /// Returns the number of compiled partitions that can be held in the compiled
688
+ /// partition cache at the same time.
689
+ ///
690
+ /// @param capacity Compiled partition cache capacity to query. Concurrently
691
+ /// accessing @p capacity is safe.
692
+ /// @returns #dnnl_invalid_arguments if the @p capacity value
693
+ /// is invalid, and #dnnl_success on success.
694
+ dnnl_status_t DNNL_API dnnl_graph_get_compiled_partition_cache_capacity(
695
+ int *capacity);
696
+
697
+ /// Sets a number of compiled partitions that can be held in the compiled
698
+ /// partition cache at the same time. The default capacity of compiled partition
699
+ /// cache is 1024.
700
+ ///
701
+ /// @param capacity Compiled partition cache capacity to set. The default cache
702
+ /// capacity is 1024. If a new @p capacity is less than a number of compiled
703
+ /// partition that the compiled partition cache already has, then the excess
704
+ /// entries will be evicted. Setting the @p capacity to 0 clears the compiled
705
+ /// partition cache and disables it. Concurrently modifying @p capacity is safe.
706
+ /// @returns #dnnl_invalid_arguments if the @p capacity value
707
+ /// is invalid, and #dnnl_success on success.
708
+ dnnl_status_t DNNL_API dnnl_graph_set_compiled_partition_cache_capacity(
709
+ int capacity);
710
+
711
+ /// @} dnnl_graph_api_compiled_partition_cache
712
+
713
+ /// @addtogroup dnnl_graph_api_constant_tensor_cache
714
+ /// @{
715
+
716
+ /// Control the enabling or disabling of constant tensor cache. This API must
717
+ /// be called once before compilation stage. By default, constant tensor cache is
718
+ /// disabled in the library.
719
+ ///
720
+ /// @param flag Set to positive value to enable the cache and set to 0 to
721
+ /// disable the cache. Negative values are invalid.
722
+ /// @returns #dnnl_invalid_arguments if the @p flag value is
723
+ /// invalid, and #dnnl_success on success.
724
+ /// @note This API is deprecated and will be removed in future release, please
725
+ /// use the dnnl_graph_set_constant_tensor_cache_capacity API to disable
726
+ /// constant tensor cache by setting it's capacity to zero.
727
+ dnnl_status_t DNNL_API dnnl_graph_set_constant_tensor_cache(int flag);
728
+
729
+ /// Return the enabling or disabling status of constant tensor cache.
730
+ ///
731
+ /// @param flag The constant tensor cache enabling status to query.
732
+ /// @returns #dnnl_invalid_arguments if the @p flag value is
733
+ /// nullptr, and #dnnl_success on success.
734
+ /// @note This API is deprecated and will be removed in future release, please
735
+ /// use the dnnl_graph_get_constant_tensor_cache_capacity API to check the
736
+ /// enabling status by checking it's capacity.
737
+ dnnl_status_t DNNL_API dnnl_graph_get_constant_tensor_cache(int *flag);
738
+
739
+ /// Control the capacity for the constant tensor cache that used for specific
740
+ /// engine kind. This API is thread safe and can be called multiple times at
741
+ /// runtime. The capacity is set to zero by default which means the cache is
742
+ /// disabled. When calling this API, the corresponding cache will be flushed.
743
+ /// Setting capacity to 0 means to clear all cached tensors and disable cache.
744
+ /// Once the capacity limit is reached, no new tensors will be cached. If there
745
+ /// are multiple devices for an engine kind, the capacity set here is for each
746
+ /// device.
747
+ ///
748
+ /// @param eng_kind The engine kind that the constant tensor cache used for.
749
+ /// @param size The constant tensor cache capacity size to set.
750
+ /// @returns #dnnl_invalid_arguments if the @p eng_kind value is invalid, and
751
+ /// #dnnl_success on success.
752
+ dnnl_status_t DNNL_API dnnl_graph_set_constant_tensor_cache_capacity(
753
+ dnnl_engine_kind_t eng_kind, size_t size);
754
+
755
+ /// Return the current capacity of constant tensor cache.
756
+ ///
757
+ /// @param eng_kind The engine kind that the constant tensor cache used for.
758
+ /// @param size The constant tensor cache capacity size to query.
759
+ /// @returns #dnnl_invalid_arguments if the @p eng_kind value is
760
+ /// nullptr or the @p size is nullptr, and #dnnl_success on success.
761
+ dnnl_status_t DNNL_API dnnl_graph_get_constant_tensor_cache_capacity(
762
+ dnnl_engine_kind_t eng_kind, size_t *size);
763
+
764
+ /// @} dnnl_graph_api_constant_tensor_cache
765
+
766
+ /// @} dnnl_graph_api
767
+
768
+ /// @} dnnl_api
769
+
770
+ #ifdef __cplusplus
771
+ }
772
+ #endif
773
+ #endif
774
+
775
+ #else
776
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
777
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph.hpp ADDED
@@ -0,0 +1,1639 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2020-2025 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ /// @file
19
+ /// Graph C++ API
20
+
21
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_HPP
22
+ #define ONEAPI_DNNL_DNNL_GRAPH_HPP
23
+
24
+ #include "oneapi/dnnl/dnnl_common.hpp"
25
+ #include "oneapi/dnnl/dnnl_graph.h"
26
+
27
+ #include <limits>
28
+ #include <memory>
29
+ #include <string>
30
+ #include <utility>
31
+ #include <vector>
32
+
33
+ /// @addtogroup dnnl_api
34
+ /// @{
35
+
36
+ namespace dnnl {
37
+
38
+ /// @addtogroup dnnl_graph_api Graph API
39
+ /// oneDNN Graph API
40
+ /// @{
41
+
42
+ /// oneDNN Graph namespace
43
+ namespace graph {
44
+
45
+ /// @cond DO_NOT_DOCUMENT_THIS
46
+
47
+ // Alias for common engine and stream API.
48
+ using engine = dnnl::engine;
49
+ using stream = dnnl::stream;
50
+ using fpmath_mode = dnnl::fpmath_mode;
51
+
52
+ /// @endcond
53
+
54
+ /// @addtogroup dnnl_graph_api_utils Utilities
55
+ /// Utility types and definitions
56
+ /// @{
57
+
58
+ /// @cond DO_NOT_DOCUMENT_THIS
59
+
60
+ /// A class that provides the destructor for a oneDNN graph C API handle.
61
+ template <typename T>
62
+ struct graph_handle_traits : public dnnl::handle_traits<T> {};
63
+
64
+ template <>
65
+ struct graph_handle_traits<dnnl_graph_op_t> {
66
+ static dnnl_status_t destructor(dnnl_graph_op_t p) {
67
+ return dnnl_graph_op_destroy(p);
68
+ }
69
+ };
70
+
71
+ template <>
72
+ struct graph_handle_traits<dnnl_graph_graph_t> {
73
+ static dnnl_status_t destructor(dnnl_graph_graph_t p) {
74
+ return dnnl_graph_graph_destroy(p);
75
+ }
76
+ };
77
+
78
+ template <>
79
+ struct graph_handle_traits<dnnl_graph_tensor_t> {
80
+ static dnnl_status_t destructor(dnnl_graph_tensor_t p) {
81
+ return dnnl_graph_tensor_destroy(p);
82
+ }
83
+ };
84
+
85
+ template <>
86
+ struct graph_handle_traits<dnnl_graph_partition_t> {
87
+ static dnnl_status_t destructor(dnnl_graph_partition_t p) {
88
+ return dnnl_graph_partition_destroy(p);
89
+ }
90
+ };
91
+
92
+ template <>
93
+ struct graph_handle_traits<dnnl_graph_compiled_partition_t> {
94
+ static dnnl_status_t destructor(dnnl_graph_compiled_partition_t p) {
95
+ return dnnl_graph_compiled_partition_destroy(p);
96
+ }
97
+ };
98
+
99
+ template <>
100
+ struct graph_handle_traits<dnnl_graph_allocator_t> {
101
+ static dnnl_status_t destructor(dnnl_graph_allocator_t p) {
102
+ return dnnl_graph_allocator_destroy(p);
103
+ }
104
+ };
105
+
106
+ #define DNNL_GRAPH_HANDLE_ALIAS(type) \
107
+ using type##_handle = dnnl::handle<dnnl_graph_##type##_t, \
108
+ graph_handle_traits<dnnl_graph_##type##_t>>
109
+
110
+ DNNL_GRAPH_HANDLE_ALIAS(allocator);
111
+ DNNL_GRAPH_HANDLE_ALIAS(graph);
112
+ DNNL_GRAPH_HANDLE_ALIAS(op);
113
+ DNNL_GRAPH_HANDLE_ALIAS(tensor);
114
+ DNNL_GRAPH_HANDLE_ALIAS(compiled_partition);
115
+ DNNL_GRAPH_HANDLE_ALIAS(partition);
116
+
117
+ #undef DNNL_GRAPH_HANDLE_ALIAS
118
+
119
+ template <bool B>
120
+ using req = typename std::enable_if<B, bool>::type;
121
+
122
+ /// @endcond
123
+
124
+ /// @} dnnl_graph_api_utils
125
+
126
+ /// @addtogroup dnnl_graph_api_status Status
127
+ /// Definitions of status values returned by the library functions.
128
+ /// @{
129
+
130
+ /// Status values returned by the library functions.
131
+ enum class status {
132
+ /// The operation was successful
133
+ success = dnnl_success,
134
+ /// The operation failed due to an out-of-memory condition
135
+ out_of_memory = dnnl_out_of_memory,
136
+ /// The operation failed because of incorrect function arguments
137
+ invalid_arguments = dnnl_invalid_arguments,
138
+ /// The operation failed because requested functionality is not implemented
139
+ unimplemented = dnnl_unimplemented,
140
+ /// The last available implementation is reached
141
+ last_impl_reached = dnnl_last_impl_reached,
142
+ /// Primitive or engine failed on execution
143
+ runtime_error = dnnl_runtime_error,
144
+ /// Queried element is not required for given primitive
145
+ not_required = dnnl_not_required,
146
+ /// The graph is not legitimate
147
+ invalid_graph = dnnl_invalid_graph,
148
+ /// The operation is not legitimate according to op schema
149
+ invalid_graph_op = dnnl_invalid_graph_op,
150
+ /// The shape cannot be inferred or compiled
151
+ invalid_shape = dnnl_invalid_shape,
152
+ /// The data type cannot be inferred or compiled
153
+ invalid_data_type = dnnl_invalid_data_type,
154
+ };
155
+
156
+ /// @} dnnl_graph_api_status
157
+
158
+ /// @addtogroup dnnl_graph_api_allocator Allocator
159
+ ///
160
+ /// Definitions of allocator which is used to acquire memory resources in
161
+ /// partition compilation and execution. SYCL allocator
162
+ /// (#dnnl::graph::sycl_interop::make_allocator) should be used for SYCL runtime
163
+ /// and host allocator should be used for non-SYCL.
164
+ ///
165
+ /// @{
166
+
167
+ /// Allocator
168
+ class allocator : public allocator_handle {
169
+ public:
170
+ using allocator_handle::handle;
171
+
172
+ /// Constructs an allocator according to given function pointers
173
+ ///
174
+ /// @param host_malloc A pointer to malloc function for CPU
175
+ /// @param host_free A pointer to free function for CPU
176
+ allocator(dnnl_graph_host_allocate_f host_malloc,
177
+ dnnl_graph_host_deallocate_f host_free) {
178
+ dnnl_graph_allocator_t a = nullptr;
179
+ error::wrap_c_api(
180
+ dnnl_graph_allocator_create(&a, host_malloc, host_free),
181
+ "could not create allocator for cpu");
182
+ reset(a);
183
+ }
184
+
185
+ /// Default constructor
186
+ allocator() {
187
+ dnnl_graph_allocator_t a = nullptr;
188
+ error::wrap_c_api(dnnl_graph_allocator_create(&a, nullptr, nullptr),
189
+ "could not create allocator");
190
+ reset(a);
191
+ }
192
+ };
193
+
194
+ /// @} dnnl_graph_api_allocator
195
+
196
+ /// @addtogroup dnnl_graph_api_engine Engine
197
+ /// @{
198
+
199
+ /// This API is a supplement for existing onednn engine API.
200
+ inline engine make_engine_with_allocator(
201
+ engine::kind kind, size_t index, const allocator &alloc) {
202
+ dnnl_engine_t c_engine;
203
+ error::wrap_c_api(
204
+ dnnl_graph_make_engine_with_allocator(&c_engine,
205
+ static_cast<dnnl_engine_kind_t>(kind), index, alloc.get()),
206
+ "could not make an engine with allocator");
207
+ return engine(c_engine);
208
+ }
209
+
210
+ /// @} dnnl_graph_api_engine
211
+
212
+ /// @addtogroup dnnl_graph_api_logical_tensor Logical Tensor
213
+ ///
214
+ /// Logical tensor describes the meta-data of the input or output tensor, like
215
+ /// elements data type, number of dimensions, size for each dimension (shape),
216
+ /// layout, and the property of the tensor.
217
+ ///
218
+ /// Each logical tensor has an unique ID. The library uses logical tensor IDs to
219
+ /// build up the connections between operations if the output of one operation
220
+ /// has the same ID as the input of another operation. The meta-data in a
221
+ /// logical tensor may be enriched in the framework graph as it progresses
222
+ /// toward final execution. For example, the library doesn't require detailed
223
+ /// shape information at the operation and graph creation stage. But shape
224
+ /// information of input logical tensor will be required at partition
225
+ /// compilation stage. Logical tensor is not mutable. Users must create a new
226
+ /// logical tensor with the same ID to pass any new additional information to
227
+ /// oneDNN Graph API. Please note that the library also has unique IDs for
228
+ /// operations. The ID should be unique among different logical tensors, but it
229
+ /// can have the same value between a logical tensor and an operation.
230
+ ///
231
+ /// @{
232
+
233
+ /// Logical tensor object
234
+ class logical_tensor {
235
+ friend class op;
236
+ friend class tensor;
237
+ friend class partition;
238
+ friend class compiled_partition;
239
+
240
+ dnnl_graph_logical_tensor_t data;
241
+
242
+ public:
243
+ /// Integer type for representing dimension sizes and indices.
244
+ using dim = dnnl_dim_t;
245
+ /// Vector of dimensions. Implementations are free to force a limit on the
246
+ /// vector's length.
247
+ using dims = std::vector<dim>;
248
+
249
+ /// Data Type
250
+ enum class data_type {
251
+ undef = dnnl_data_type_undef,
252
+ /// 16-bit/half-precision floating point.
253
+ f16 = dnnl_f16,
254
+ /// non-standard 16-bit (bfloat16 w/ 7 bit mantissa) floating point.
255
+ bf16 = dnnl_bf16,
256
+ /// 32-bit/single-precision floating point.
257
+ f32 = dnnl_f32,
258
+ /// 32-bit signed integer.
259
+ s32 = dnnl_s32,
260
+ /// 8-bit signed integer.
261
+ s8 = dnnl_s8,
262
+ /// 8-bit unsigned integer.
263
+ u8 = dnnl_u8,
264
+ /// Boolean data type. Size is C++ implementation defined.
265
+ boolean = dnnl_boolean,
266
+ /// [OFP8 standard 8-bit
267
+ /// floating-point](https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-06-20-pdf)
268
+ /// with a 5-bit exponent and a 2-bit mantissa.
269
+ f8_e5m2 = dnnl_f8_e5m2,
270
+ /// [OFP8 standard 8-bit
271
+ /// floating-point](https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-06-20-pdf)
272
+ /// with a 4-bit exponent and a 3-bit mantissa.
273
+ f8_e4m3 = dnnl_f8_e4m3,
274
+ /// 4-bit signed integer.
275
+ s4 = dnnl_s4,
276
+ /// 4-bit unsigned integer.
277
+ u4 = dnnl_u4,
278
+ };
279
+
280
+ /// Layout type
281
+ enum class layout_type {
282
+ /// Undefined layout type.
283
+ undef = dnnl_graph_layout_type_undef,
284
+ /// Any means to let the library to decide the layout for a tensor
285
+ /// during partition compilation.
286
+ any = dnnl_graph_layout_type_any,
287
+ /// Strided means that the layout of a tensor is determined by the
288
+ /// strides field in the logical tensor.
289
+ strided = dnnl_graph_layout_type_strided,
290
+ /// Opaque means that the layout of a tensor is the library specific.
291
+ /// Usually, an opaque layout is generated by a partition which is
292
+ /// compiled with layout type any.
293
+ opaque = dnnl_graph_layout_type_opaque,
294
+ };
295
+
296
+ /// Tensor property
297
+ enum class property_type {
298
+ /// Undefined tensor property.
299
+ undef = dnnl_graph_tensor_property_undef,
300
+ /// Variable means the tensor may be changed during computation or
301
+ /// between different iterations.
302
+ variable = dnnl_graph_tensor_property_variable,
303
+ /// Constant means the tensor will keep unchanged during computation and
304
+ /// between different iterations. It's useful for the library to apply
305
+ /// optimizations for constant tensors or cache constant tensors inside
306
+ /// the library. For example, constant weight tensors in inference
307
+ /// scenarios.
308
+ constant = dnnl_graph_tensor_property_constant,
309
+ };
310
+
311
+ /// default constructor
312
+ /// construct an empty object
313
+ logical_tensor() = default;
314
+
315
+ /// Constructs a logical tensor object
316
+ explicit logical_tensor(const dnnl_graph_logical_tensor_t &c_data)
317
+ : data(c_data) {}
318
+
319
+ /// Copy
320
+ logical_tensor(const logical_tensor &other) = default;
321
+
322
+ /// Assign
323
+ logical_tensor &operator=(const logical_tensor &other) = default;
324
+
325
+ /// Constructs a logical tensor object with ID, data type, ndims, layout
326
+ /// type, and property type.
327
+ ///
328
+ /// @param tid Logical tensor ID.
329
+ /// @param dtype Elements data type.
330
+ /// @param ndims Number of dimensions. -1 means unknown (see
331
+ /// #DNNL_GRAPH_UNKNOWN_NDIMS) and 0 means a scalar tensor.
332
+ /// @param ltype Layout type.
333
+ /// @param ptype Property type.
334
+ logical_tensor(size_t tid, data_type dtype, int32_t ndims,
335
+ layout_type ltype, property_type ptype = property_type::undef) {
336
+ dnnl_graph_logical_tensor_t val;
337
+ error::wrap_c_api(
338
+ dnnl_graph_logical_tensor_init(&val, tid, convert_to_c(dtype),
339
+ ndims, convert_to_c(ltype), convert_to_c(ptype)),
340
+ "could not create logical_tensor with property");
341
+ data = val;
342
+ }
343
+
344
+ /// Delegated constructor.
345
+ ///
346
+ /// @param tid Logical tensor ID.
347
+ /// @param dtype Elements data type.
348
+ /// @param ltype Layout type.
349
+ logical_tensor(
350
+ size_t tid, data_type dtype, layout_type ltype = layout_type::undef)
351
+ : logical_tensor(tid, dtype, DNNL_GRAPH_UNKNOWN_NDIMS, ltype) {}
352
+
353
+ /// Constructs a logical tensor object with basic information and detailed
354
+ /// dims.
355
+ ///
356
+ /// @param tid Logical tensor ID.
357
+ /// @param dtype Elements data type.
358
+ /// @param adims Logical tensor dimensions. #DNNL_GRAPH_UNKNOWN_DIM means
359
+ /// the size of that dimension is unknown. 0 is used to define
360
+ /// zero-dimension tensor.
361
+ /// @param ltype Layout type. If it's strided, the strides field in the
362
+ /// output logical tensor will be deduced accordingly.
363
+ /// @param ptype Property type.
364
+ logical_tensor(size_t tid, data_type dtype, const dims &adims,
365
+ layout_type ltype, property_type ptype = property_type::undef) {
366
+ dnnl_graph_logical_tensor_t val;
367
+ // if dimension size equals to 0, it's a scalar
368
+ if (adims.size() == 0)
369
+ error::wrap_c_api(dnnl_graph_logical_tensor_init(&val, tid,
370
+ convert_to_c(dtype), 0,
371
+ convert_to_c(ltype), convert_to_c(ptype)),
372
+ "could not create logical_tensor with property");
373
+ else
374
+ error::wrap_c_api(
375
+ dnnl_graph_logical_tensor_init_with_dims(&val, tid,
376
+ convert_to_c(dtype),
377
+ static_cast<int32_t>(adims.size()), adims.data(),
378
+ convert_to_c(ltype), convert_to_c(ptype)),
379
+ "could not create logical_tensor with dims and property");
380
+ data = val;
381
+ }
382
+
383
+ /// Constructs a logical tensor object with detailed dims and strides. The
384
+ /// layout_type of the output logical tensor object will always be strided.
385
+ ///
386
+ /// @param tid Logical tensor ID.
387
+ /// @param dtype Elements data type.
388
+ /// @param adims Logical tensor dimensions. #DNNL_GRAPH_UNKNOWN_DIM means
389
+ /// the size of that dimension is unknown. 0 is used to define
390
+ /// zero-dimension tensor.
391
+ /// @param strides Logical tensor strides. #DNNL_GRAPH_UNKNOWN_DIM means
392
+ /// the stride of the dimension is unknown. The library currently
393
+ /// doesn't support other negative stride values.
394
+ /// @param ptype Property type.
395
+ logical_tensor(size_t tid, data_type dtype, const dims &adims,
396
+ const dims &strides, property_type ptype = property_type::undef) {
397
+ dnnl_graph_logical_tensor_t val;
398
+ // TODO(lvtao): check the size of adims and strides.
399
+ // They should be same.
400
+ error::wrap_c_api(
401
+ dnnl_graph_logical_tensor_init_with_strides(&val, tid,
402
+ convert_to_c(dtype), static_cast<int32_t>(adims.size()),
403
+ adims.data(), strides.data(), convert_to_c(ptype)),
404
+ "could not create logical_tensor with strides and property");
405
+ data = val;
406
+ }
407
+
408
+ /// Constructs a logical tensor object with detailed dims and an opaque
409
+ /// layout ID. layout_type of the output logical tensor object will always
410
+ /// be opaque.
411
+ ///
412
+ /// @param tid Logical tensor ID.
413
+ /// @param dtype Elements data type.
414
+ /// @param adims Logical tensor dimensions. #DNNL_GRAPH_UNKNOWN_DIM means
415
+ /// the size of that dimension is unknown. 0 is used to define
416
+ /// zero-dimension tensor.
417
+ /// @param lid Opaque layout id.
418
+ /// @param ptype Property type
419
+ logical_tensor(size_t tid, data_type dtype, const dims &adims, size_t lid,
420
+ property_type ptype = property_type::undef) {
421
+ dnnl_graph_logical_tensor_t val;
422
+
423
+ if (adims.size() == 0) {
424
+ error::wrap_c_api(dnnl_graph_logical_tensor_init(&val, tid,
425
+ convert_to_c(dtype), 0,
426
+ convert_to_c(layout_type::opaque),
427
+ convert_to_c(ptype)),
428
+ "could not create logical_tensor");
429
+ } else {
430
+ error::wrap_c_api(
431
+ dnnl_graph_logical_tensor_init_with_dims(&val, tid,
432
+ convert_to_c(dtype),
433
+ static_cast<int32_t>(adims.size()), adims.data(),
434
+ convert_to_c(layout_type::opaque),
435
+ convert_to_c(ptype)),
436
+ "could not create logical_tensor with dims");
437
+ }
438
+
439
+ val.layout.layout_id = lid;
440
+ data = val;
441
+ }
442
+
443
+ /// Returns dimensions of a logical tensor.
444
+ ///
445
+ /// @returns A vector describing the size of each dimension.
446
+ dims get_dims() const {
447
+ if (data.ndims < 0) {
448
+ error::wrap_c_api(dnnl_invalid_arguments,
449
+ "cannot return dims when ndims < 0");
450
+ }
451
+
452
+ return {data.dims, data.dims + data.ndims};
453
+ }
454
+
455
+ /// Returns the unique id of a logical tensor.
456
+ ///
457
+ /// @returns An integer value describing the ID.
458
+ size_t get_id() const { return data.id; }
459
+
460
+ /// Returns the data type of a logical tensor.
461
+ ///
462
+ /// @returns The data type.
463
+ data_type get_data_type() const {
464
+ return static_cast<data_type>(data.data_type);
465
+ }
466
+
467
+ /// Returns the property type of a logical tensor.
468
+ ///
469
+ /// @returns The property type.
470
+ property_type get_property_type() const {
471
+ return static_cast<property_type>(data.property);
472
+ }
473
+
474
+ /// Returns the layout type of a logical tensor.
475
+ ///
476
+ /// @returns The layout type.
477
+ layout_type get_layout_type() const {
478
+ return static_cast<layout_type>(data.layout_type);
479
+ }
480
+
481
+ /// Returns the layout ID of a logical tensor. The API should be called on a
482
+ /// logical tensor with opaque layout type. Otherwise, an exception will be
483
+ /// raised.
484
+ ///
485
+ /// @returns Layout ID.
486
+ size_t get_layout_id() const {
487
+ if (get_layout_type() != layout_type::opaque) {
488
+ error::wrap_c_api(
489
+ dnnl_invalid_arguments, "layout type should be opaque");
490
+ }
491
+
492
+ return data.layout.layout_id;
493
+ }
494
+
495
+ /// Returns the strides of a logical tensor. The API should be called on a
496
+ /// logical tensor with strided layout type. Otherwise, an exception will be
497
+ /// raised.
498
+ ///
499
+ /// @returns A vector describing the stride size of each dimension.
500
+ dims get_strides() const {
501
+ if (get_layout_type() != layout_type::strided) {
502
+ error::wrap_c_api(
503
+ dnnl_invalid_arguments, "layout type should be strided");
504
+ }
505
+
506
+ if (data.ndims < 0) {
507
+ error::wrap_c_api(dnnl_invalid_arguments,
508
+ "cannot return strides when ndims < 0");
509
+ }
510
+
511
+ return {data.layout.strides, data.layout.strides + data.ndims};
512
+ }
513
+
514
+ /// Returns memory size in bytes required by this logical tensor.
515
+ ///
516
+ /// @returns The memory size in bytes.
517
+ size_t get_mem_size() const {
518
+ size_t size = 0;
519
+ error::wrap_c_api(dnnl_graph_logical_tensor_get_mem_size(&data, &size),
520
+ "could not get memory size from the logical_tensor");
521
+ return size;
522
+ }
523
+
524
+ /// Compares if two logical tenors are equal. Users can decide accordingly
525
+ /// if layout reordering is needed for two logical tensors. The method will
526
+ /// return true for below two circumstances:
527
+ ///
528
+ /// 1. the two logical tensors are equal regarding each field in the struct,
529
+ /// eg. id, ndims, dims, layout type, property, etc.
530
+ /// 2. If all other fields are equal but the layout types in two logical
531
+ /// tensors are different, the method will return true when the underlying
532
+ /// memory layout is the same. For example, one logical tensor has strided
533
+ /// layout type while the other one has opaque layout type, but underneath,
534
+ /// both layouts are NHWC, the method will still return true for this case.
535
+ ///
536
+ /// @param lt The input logical tensor to be compared.
537
+ /// @returns @c true if the two logical tensors are equal. @c false otherwise
538
+ bool is_equal(const logical_tensor &lt) const {
539
+ uint8_t equal = 0;
540
+ error::wrap_c_api(
541
+ dnnl_graph_logical_tensor_is_equal(&data, &lt.data, &equal),
542
+ "could not compare between the two logical tensors");
543
+ return equal != 0;
544
+ }
545
+
546
+ private:
547
+ static dnnl_data_type_t convert_to_c(data_type dtype) {
548
+ return static_cast<dnnl_data_type_t>(dtype);
549
+ }
550
+
551
+ static dnnl_graph_layout_type_t convert_to_c(layout_type ltype) {
552
+ return static_cast<dnnl_graph_layout_type_t>(ltype);
553
+ }
554
+
555
+ static dnnl_graph_tensor_property_t convert_to_c(property_type ptype) {
556
+ return static_cast<dnnl_graph_tensor_property_t>(ptype);
557
+ }
558
+ };
559
+
560
+ /// @} dnnl_graph_api_logical_tensor
561
+
562
+ /// @addtogroup dnnl_graph_api_tensor Tensor
563
+ ///
564
+ /// Tensor is an abstraction for multi-dimensional input and output data needed
565
+ /// in the execution of a compiled partition. A tensor object encapsulates a
566
+ /// handle to a memory buffer allocated on a specific engine and a logical
567
+ /// tensor which describes the dimensions, elements data type, and memory
568
+ /// layout.
569
+ ///
570
+ /// @{
571
+
572
+ /// A tensor object
573
+ class tensor : public tensor_handle {
574
+ public:
575
+ /// Default constructor. Constructs an empty object.
576
+ tensor() = default;
577
+
578
+ /// Constructs a tensor object according to a given logical tensor, an
579
+ /// engine, and a memory handle.
580
+ ///
581
+ /// @param lt The given logical tensor
582
+ /// @param aengine Engine to store the data on.
583
+ /// @param handle Handle of memory buffer to use as an underlying storage.
584
+ /// - A pointer to the user-allocated buffer. In this case the library
585
+ /// doesn't own the buffer.
586
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
587
+ /// allocate the buffer for the tensor. In this case the library
588
+ /// owns the buffer.
589
+ /// - DNNL_MEMORY_NONE to create tensor without an underlying buffer.
590
+ tensor(const logical_tensor &lt, const engine &aengine, void *handle) {
591
+ dnnl_graph_tensor_t t = nullptr;
592
+ error::wrap_c_api(
593
+ dnnl_graph_tensor_create(&t, &(lt.data), aengine.get(), handle),
594
+ "could not create tensor object with the logical_tensor, "
595
+ "engine, and handle");
596
+ reset(t);
597
+ }
598
+
599
+ /// Constructs a tensor object.
600
+ /// The underlying buffer for the memory will be allocated by the library.
601
+ ///
602
+ /// @param lt The given logical tensor
603
+ /// @param aengine Engine to store the data on.
604
+ tensor(const logical_tensor &lt, const engine &aengine)
605
+ : tensor(lt, aengine, DNNL_MEMORY_ALLOCATE) {}
606
+
607
+ /// Returns the underlying memory buffer.
608
+ ///
609
+ /// On the CPU engine, or when using USM, this is a pointer to the
610
+ /// allocated memory.
611
+ void *get_data_handle() const {
612
+ void *handle = nullptr;
613
+ error::wrap_c_api(dnnl_graph_tensor_get_data_handle(get(), &handle),
614
+ "could not get data handle from the tensor");
615
+ return handle;
616
+ }
617
+
618
+ /// Sets the underlying memory handle.
619
+ ///
620
+ /// @param handle Memory handle.
621
+ void set_data_handle(void *handle) {
622
+ error::wrap_c_api(dnnl_graph_tensor_set_data_handle(get(), handle),
623
+ "setting data handle to the tensor failed");
624
+ }
625
+
626
+ /// Returns the associated engine.
627
+ ///
628
+ /// @returns An engine object
629
+ engine get_engine() const {
630
+ dnnl_engine_t c_engine = nullptr;
631
+ error::wrap_c_api(dnnl_graph_tensor_get_engine(get(), &c_engine),
632
+ "could not get an engine from a tensor object");
633
+ return engine(c_engine, true);
634
+ }
635
+
636
+ /// Returns the logical tensor of a tensor object.
637
+ ///
638
+ /// @returns A logical_tensor object.
639
+ logical_tensor get_logical_tensor() const {
640
+ dnnl_graph_logical_tensor_t lt;
641
+ error::wrap_c_api(dnnl_graph_tensor_get_logical_tensor(get(), &lt),
642
+ "could not get logical tensor from a tensor object");
643
+ return logical_tensor(lt);
644
+ }
645
+ };
646
+
647
+ /// @} dnnl_graph_api_tensor
648
+
649
+ /// @addtogroup dnnl_graph_api_compiled_partition Compiled Partition
650
+ ///
651
+ /// A compiled partition represents the generated kernels specialized for a
652
+ /// partition on a target hardware (engine) with input and output information
653
+ /// specified by the logical tensors.
654
+ ///
655
+ /// @{
656
+
657
+ /// A compiled partition object.
658
+ class compiled_partition : public compiled_partition_handle {
659
+ public:
660
+ /// Default constructor. Constructs an empty object.
661
+ compiled_partition() = default;
662
+
663
+ /// Constructs a compiled partition object
664
+ compiled_partition(dnnl_graph_compiled_partition_t compiled_partition) {
665
+ reset(compiled_partition, false);
666
+ }
667
+
668
+ /// Queries an input or output logical tensor according to tensor ID. If the
669
+ /// tensor ID doesn't belong to any input or output of the compiled
670
+ /// partition, an exception will be raised by the API.
671
+ ///
672
+ /// @param tid The unique id of required tensor.
673
+ /// @returns The logical tensor.
674
+ logical_tensor query_logical_tensor(size_t tid) const {
675
+ dnnl_graph_logical_tensor_t lt;
676
+ error::wrap_c_api(dnnl_graph_compiled_partition_query_logical_tensor(
677
+ get(), tid, &lt),
678
+ "query logical tensor from compiled_partition failed");
679
+ return logical_tensor {lt};
680
+ }
681
+
682
+ /// Returns the hint of in-place pairs from a compiled partition. It
683
+ /// indicates that an input and an output of the partition can share the
684
+ /// same memory buffer for computation. In-place computation helps to reduce
685
+ /// the memory footprint and improves cache locality. But since the library
686
+ /// may not have a global view of user's application, it's possible that the
687
+ /// input tensor is used at other places in user's computation graph. In
688
+ /// this case, the user should take the in-place pair as a hint and pass a
689
+ /// different memory buffer for output tensor to avoid overwriting the input
690
+ /// memory buffer which will probably cause unexpected incorrect results.
691
+ ///
692
+ /// @returns A list of pairs of input and output IDs.
693
+ std::vector<std::pair<size_t, size_t>> get_inplace_ports() const {
694
+ size_t num = 0;
695
+ const dnnl_graph_inplace_pair_t *inplace_pairs;
696
+
697
+ error::wrap_c_api(dnnl_graph_compiled_partition_get_inplace_ports(
698
+ get(), &num, &inplace_pairs),
699
+ "could not get the in-place pairs from a compiled partition");
700
+ if (num == 0) return {};
701
+
702
+ std::vector<std::pair<size_t, size_t>> inplace_options;
703
+ inplace_options.reserve(num);
704
+ for (size_t i = 0; i < num; ++i) {
705
+ const dnnl_graph_inplace_pair_t *inplace_pair = inplace_pairs + i;
706
+ inplace_options.emplace_back(
707
+ inplace_pair->input_id, inplace_pair->output_id);
708
+ }
709
+ return inplace_options;
710
+ }
711
+
712
+ /// Execute a compiled partition.
713
+ ///
714
+ /// @param astream Stream object to run over.
715
+ /// @param inputs A list of input tensors.
716
+ /// @param outputs A list of output tensors.
717
+ void execute(stream &astream, const std::vector<tensor> &inputs,
718
+ const std::vector<tensor> &outputs) const {
719
+ std::vector<const_dnnl_graph_tensor_t> c_inputs;
720
+ c_inputs.reserve(inputs.size());
721
+ for (auto &in : inputs) {
722
+ c_inputs.push_back(in.get());
723
+ }
724
+ std::vector<const_dnnl_graph_tensor_t> c_outputs;
725
+ c_outputs.reserve(outputs.size());
726
+ for (auto &out : outputs) {
727
+ c_outputs.push_back(out.get());
728
+ }
729
+
730
+ error::wrap_c_api(
731
+ dnnl_graph_compiled_partition_execute(get(), astream.get(),
732
+ c_inputs.size(), c_inputs.data(), c_outputs.size(),
733
+ c_outputs.data()),
734
+ "could not execute the compiled_partition");
735
+ }
736
+ };
737
+
738
+ /// @} dnnl_graph_api_compiled_partition
739
+
740
+ /// @addtogroup dnnl_graph_api_op Op
741
+ ///
742
+ /// OP is an abstraction of computation logic for deep neural network
743
+ /// operations. An op object encapsulates an operation kind which describes the
744
+ /// computation logic, an unique ID which differentiates operations with the
745
+ /// same kind, and logical tensors which describes the input and output of the
746
+ /// operation and its connections to other operations in the graph.
747
+ ///
748
+ /// @{
749
+
750
+ /// An op object.
751
+ class op : public op_handle {
752
+ public:
753
+ /// Kinds of operations
754
+ enum class kind {
755
+ Abs = dnnl_graph_op_abs,
756
+ AbsBackward = dnnl_graph_op_abs_backward,
757
+ Add = dnnl_graph_op_add,
758
+ AvgPool = dnnl_graph_op_avg_pool,
759
+ AvgPoolBackward = dnnl_graph_op_avg_pool_backward,
760
+ BatchNormForwardTraining = dnnl_graph_op_batch_norm_forward_training,
761
+ BatchNormInference = dnnl_graph_op_batch_norm_inference,
762
+ BatchNormTrainingBackward = dnnl_graph_op_batch_norm_backward,
763
+ BiasAdd = dnnl_graph_op_bias_add,
764
+ BiasAddBackward = dnnl_graph_op_bias_add_backward,
765
+ Clamp = dnnl_graph_op_clamp,
766
+ ClampBackward = dnnl_graph_op_clamp_backward,
767
+ Concat = dnnl_graph_op_concat,
768
+ Convolution = dnnl_graph_op_convolution,
769
+ ConvolutionBackwardData = dnnl_graph_op_convolution_backward_data,
770
+ ConvolutionBackwardWeights = dnnl_graph_op_convolution_backward_weights,
771
+ ConvTranspose = dnnl_graph_op_conv_transpose,
772
+ ConvTransposeBackwardData = dnnl_graph_op_conv_transpose_backward_data,
773
+ ConvTransposeBackwardWeights
774
+ = dnnl_graph_op_conv_transpose_backward_weights,
775
+ Dequantize = dnnl_graph_op_dequantize,
776
+ Divide = dnnl_graph_op_divide,
777
+ DynamicDequantize = dnnl_graph_op_dynamic_dequantize,
778
+ DynamicQuantize = dnnl_graph_op_dynamic_quantize,
779
+ Elu = dnnl_graph_op_elu,
780
+ EluBackward = dnnl_graph_op_elu_backward,
781
+ End = dnnl_graph_op_end,
782
+ Exp = dnnl_graph_op_exp,
783
+ GELU = dnnl_graph_op_gelu,
784
+ GELUBackward = dnnl_graph_op_gelu_backward,
785
+ GroupNorm = dnnl_graph_op_group_norm,
786
+ HardSigmoid = dnnl_graph_op_hard_sigmoid,
787
+ HardSigmoidBackward = dnnl_graph_op_hard_sigmoid_backward,
788
+ HardSwish = dnnl_graph_op_hard_swish,
789
+ HardSwishBackward = dnnl_graph_op_hard_swish_backward,
790
+ Interpolate = dnnl_graph_op_interpolate,
791
+ InterpolateBackward = dnnl_graph_op_interpolate_backward,
792
+ LayerNorm = dnnl_graph_op_layer_norm,
793
+ LayerNormBackward = dnnl_graph_op_layer_norm_backward,
794
+ LeakyReLU = dnnl_graph_op_leaky_relu,
795
+ Log = dnnl_graph_op_log,
796
+ LogSoftmax = dnnl_graph_op_log_softmax,
797
+ LogSoftmaxBackward = dnnl_graph_op_log_softmax_backward,
798
+ MatMul = dnnl_graph_op_matmul,
799
+ Maximum = dnnl_graph_op_maximum,
800
+ MaxPool = dnnl_graph_op_max_pool,
801
+ MaxPoolBackward = dnnl_graph_op_max_pool_backward,
802
+ Minimum = dnnl_graph_op_minimum,
803
+ Mish = dnnl_graph_op_mish,
804
+ MishBackward = dnnl_graph_op_mish_backward,
805
+ Multiply = dnnl_graph_op_multiply,
806
+ Pow = dnnl_graph_op_pow,
807
+ PReLU = dnnl_graph_op_prelu,
808
+ PReLUBackward = dnnl_graph_op_prelu_backward,
809
+ Quantize = dnnl_graph_op_quantize,
810
+ Reciprocal = dnnl_graph_op_reciprocal,
811
+ ReduceL1 = dnnl_graph_op_reduce_l1,
812
+ ReduceL2 = dnnl_graph_op_reduce_l2,
813
+ ReduceMax = dnnl_graph_op_reduce_max,
814
+ ReduceMean = dnnl_graph_op_reduce_mean,
815
+ ReduceMin = dnnl_graph_op_reduce_min,
816
+ ReduceProd = dnnl_graph_op_reduce_prod,
817
+ ReduceSum = dnnl_graph_op_reduce_sum,
818
+ ReLU = dnnl_graph_op_relu,
819
+ ReLUBackward = dnnl_graph_op_relu_backward,
820
+ Reorder = dnnl_graph_op_reorder,
821
+ Round = dnnl_graph_op_round,
822
+ Select = dnnl_graph_op_select,
823
+ Sigmoid = dnnl_graph_op_sigmoid,
824
+ SigmoidBackward = dnnl_graph_op_sigmoid_backward,
825
+ SoftMax = dnnl_graph_op_softmax,
826
+ SoftMaxBackward = dnnl_graph_op_softmax_backward,
827
+ SoftPlus = dnnl_graph_op_softplus,
828
+ SoftPlusBackward = dnnl_graph_op_softplus_backward,
829
+ Sqrt = dnnl_graph_op_sqrt,
830
+ SqrtBackward = dnnl_graph_op_sqrt_backward,
831
+ Square = dnnl_graph_op_square,
832
+ SquaredDifference = dnnl_graph_op_squared_difference,
833
+ StaticReshape = dnnl_graph_op_static_reshape,
834
+ StaticTranspose = dnnl_graph_op_static_transpose,
835
+ Subtract = dnnl_graph_op_subtract,
836
+ Tanh = dnnl_graph_op_tanh,
837
+ TanhBackward = dnnl_graph_op_tanh_backward,
838
+ TypeCast = dnnl_graph_op_type_cast,
839
+ Wildcard = dnnl_graph_op_wildcard,
840
+ GenIndex = dnnl_graph_op_gen_index,
841
+ GreaterEqual = dnnl_graph_op_greater_equal,
842
+ // Sentinel
843
+ LastSymbol = dnnl_graph_op_last_symbol,
844
+ };
845
+
846
+ /// Attributes of operations. Different operations support different
847
+ /// attributes. Check the document of each operation for what attributes are
848
+ /// supported and what are the potential values for them. Missing required
849
+ /// attribute or illegal attribute value may lead to failure when adding the
850
+ /// operation to a graph.
851
+ enum class attr {
852
+ /// Undefined op attribute.
853
+ undef = dnnl_graph_op_attr_undef,
854
+
855
+ // float32 attributes. The value of these attributes can be any single
856
+ // float32 number.
857
+
858
+ /// Specifies an alpha attribute to an op.
859
+ alpha = dnnl_graph_op_attr_alpha,
860
+ /// Specifies an beta attribute to an op.
861
+ beta = dnnl_graph_op_attr_beta,
862
+ /// Specifies an epsilon attribute to an op.
863
+ epsilon = dnnl_graph_op_attr_epsilon,
864
+ /// Specifies a max attribute to an op.
865
+ max = dnnl_graph_op_attr_max,
866
+ /// Specifies a min attribute to an op.
867
+ min = dnnl_graph_op_attr_min,
868
+ /// Specifies a momentum attribute to an op.
869
+ momentum = dnnl_graph_op_attr_momentum,
870
+
871
+ // float32 vector attributes. The value of these attributes can be a
872
+ // vector of float32 numbers.
873
+
874
+ /// Specifies a scales attribute to an op.
875
+ scales = dnnl_graph_op_attr_scales,
876
+
877
+ // int64_t attributes. The value of these attributes can be any single
878
+ // int64 number.
879
+
880
+ /// Specifies an axis attribute to an op.
881
+ axis = dnnl_graph_op_attr_axis,
882
+ /// Specifies a begin_norm_axis attribute to an op.
883
+ begin_norm_axis = dnnl_graph_op_attr_begin_norm_axis,
884
+ /// Specifies a groups attribute to an op.
885
+ groups = dnnl_graph_op_attr_groups,
886
+
887
+ // int64_t vector attributes. The value of these attributes can be a
888
+ // vector of int64 numbers.
889
+
890
+ /// Specifies an axes attribute to an op.
891
+ axes = dnnl_graph_op_attr_axes,
892
+ /// Specifies a dilations attribute to an op.
893
+ dilations = dnnl_graph_op_attr_dilations,
894
+ /// Specifies an dst_shape attribute to an op.
895
+ dst_shape = dnnl_graph_op_attr_dst_shape,
896
+ /// Specifies a kernel attribute to an op.
897
+ kernel = dnnl_graph_op_attr_kernel,
898
+ /// Specifies an order attribute to an op.
899
+ order = dnnl_graph_op_attr_order,
900
+ /// Specifies an output_padding attribute to an op.
901
+ output_padding = dnnl_graph_op_attr_output_padding,
902
+ /// Specifies a pads_begin attribute to an op.
903
+ pads_begin = dnnl_graph_op_attr_pads_begin,
904
+ /// Specifies a pads_end attribute to an op.
905
+ pads_end = dnnl_graph_op_attr_pads_end,
906
+ /// Specifies a shape attribute to an op.
907
+ shape = dnnl_graph_op_attr_shape,
908
+ /// Specifies a sizes attribute to an op.
909
+ sizes = dnnl_graph_op_attr_sizes,
910
+ /// Specifies an src_shape attribute to an op.
911
+ src_shape = dnnl_graph_op_attr_src_shape,
912
+ /// Specifies a strides attribute to an op.
913
+ strides = dnnl_graph_op_attr_strides,
914
+ /// Specifies a weight_shape attribute to an op.
915
+ weights_shape = dnnl_graph_op_attr_weights_shape,
916
+ /// Specifies a zps attribute to an op.
917
+ zps = dnnl_graph_op_attr_zps,
918
+ /// Specifies the group shape of an op. The size of the vector should
919
+ /// match that of the input. For the dimensions where the grouped
920
+ /// quantization occurs, the values should correspond to the group
921
+ /// size, which indicates the number of elements that will share the
922
+ /// same scaling factor.
923
+ group_shape = dnnl_graph_op_attr_group_shape,
924
+
925
+ // bool attributes. The value of these attributes can be any single bool
926
+ // value.
927
+
928
+ /// Specifies an exclude_pad attribute to an op.
929
+ exclude_pad = dnnl_graph_op_attr_exclude_pad,
930
+ /// Specifies a keep_dims attribute to an op.
931
+ keep_dims = dnnl_graph_op_attr_keep_dims,
932
+ /// Specifies a keep_stats attribute to an op.
933
+ keep_stats = dnnl_graph_op_attr_keep_stats,
934
+ /// Specifies a per_channel_broadcast attribute to an op.
935
+ per_channel_broadcast = dnnl_graph_op_attr_per_channel_broadcast,
936
+ /// Specifies a special_zero attribute to an op.
937
+ special_zero = dnnl_graph_op_attr_special_zero,
938
+ /// Specifies a transpose_a attribute to an op.
939
+ transpose_a = dnnl_graph_op_attr_transpose_a,
940
+ /// Specifies a transpose_b attribute to an op.
941
+ transpose_b = dnnl_graph_op_attr_transpose_b,
942
+ /// Specifies an use_affine attribute to an op.
943
+ use_affine = dnnl_graph_op_attr_use_affine,
944
+ /// Specifies an use_dst attribute to an op.
945
+ use_dst = dnnl_graph_op_attr_use_dst,
946
+
947
+ // string attributes. The value of these attributes can be a string.
948
+
949
+ /// Specifies an auto_broadcast attribute to an op. The value can be
950
+ /// "none" or "numpy".
951
+ auto_broadcast = dnnl_graph_op_attr_auto_broadcast,
952
+ /// Specifies an auto_pad attribute to an op. The value can be "none",
953
+ /// "same_upper", "same_lower", or "valid".
954
+ auto_pad = dnnl_graph_op_attr_auto_pad,
955
+ /// Specifies an coordinate_transformation_mode attribute to an op. The
956
+ /// value can be "half_pixel" or "align_corners". The attribute is
957
+ /// defined for Interpolate operations.
958
+ coordinate_transformation_mode
959
+ = dnnl_graph_op_attr_coordinate_transformation_mode,
960
+ /// Specifies a data_format of an op. The value can be "NCX" or "NXC".
961
+ data_format = dnnl_graph_op_attr_data_format,
962
+ /// Specifies a mode attribute of an op. The value can be "nearest",
963
+ /// "linear", "bilinear", or "trilinear". The attribute is defined for
964
+ /// Interpolate operations.
965
+ mode = dnnl_graph_op_attr_mode,
966
+ /// Specifies a qtype attribute to an op. The value can be "per_channel"
967
+ /// or "per_tensor". The attribute is defined for quantization
968
+ /// operations.
969
+ qtype = dnnl_graph_op_attr_qtype,
970
+ /// Specifies a rounding_type attribute to an op. The value can be
971
+ /// "ceil" or "floor".
972
+ rounding_type = dnnl_graph_op_attr_rounding_type,
973
+ /// Specifies a weights_format of an op. The value can be "OIX", "XIO",
974
+ /// "IOX", or "XOI". Different operations may support different values.
975
+ weights_format = dnnl_graph_op_attr_weights_format,
976
+
977
+ /// Specifies the end of all above exteral attributes for check.
978
+ end = dnnl_graph_op_attr_end,
979
+ };
980
+
981
+ /// Constructs an op object with an unique ID, an operation kind, and a name
982
+ /// string.
983
+ ///
984
+ /// @param id The unique ID of the op.
985
+ /// @param akind The op kind specifies which computation is represented by
986
+ /// the op, such as Convolution or ReLU.
987
+ /// @param verbose_name The string added as the op name.
988
+ op(size_t id, kind akind, const std::string &verbose_name = "") {
989
+ dnnl_graph_op_t op = nullptr;
990
+ error::wrap_c_api(dnnl_graph_op_create(&op, id, convert_to_c(akind),
991
+ verbose_name.c_str()),
992
+ "could not create op with id and op kind");
993
+ reset(op);
994
+ }
995
+
996
+ /// Constructs an op object with an unique ID, an operation kind, and
997
+ /// input/output logical tensors.
998
+ ///
999
+ /// @param id The unique ID of this op.
1000
+ /// @param akind The op kind specifies which computation is represented by
1001
+ /// this op, such as Convolution or ReLU.
1002
+ /// @param inputs Input logical tensor to be bound to this op.
1003
+ /// @param outputs Output logical tensor to be bound to this op.
1004
+ /// @param verbose_name The string added as the op name.
1005
+ op(size_t id, kind akind, const std::vector<logical_tensor> &inputs,
1006
+ const std::vector<logical_tensor> &outputs,
1007
+ const std::string &verbose_name = "")
1008
+ : op(id, akind, verbose_name) {
1009
+ for (const auto &input : inputs) {
1010
+ error::wrap_c_api(dnnl_graph_op_add_input(get(), &(input.data)),
1011
+ "adding input to the op failed");
1012
+ }
1013
+ for (const auto &output : outputs) {
1014
+ error::wrap_c_api(dnnl_graph_op_add_output(get(), &(output.data)),
1015
+ "adding output to the op failed");
1016
+ }
1017
+ }
1018
+
1019
+ /// Adds an input logical tensor to the op.
1020
+ ///
1021
+ /// @param t Input logical tensor.
1022
+ void add_input(const logical_tensor &t) {
1023
+ error::wrap_c_api(dnnl_graph_op_add_input(get(), &(t.data)),
1024
+ "adding input to the op failed");
1025
+ }
1026
+
1027
+ /// Adds a vector of input logical tensors to the op.
1028
+ ///
1029
+ /// @param ts The list of input logical tensors.
1030
+ void add_inputs(const std::vector<logical_tensor> &ts) {
1031
+ for (const auto &t : ts) {
1032
+ error::wrap_c_api(dnnl_graph_op_add_input(get(), &(t.data)),
1033
+ "adding input to the op failed");
1034
+ }
1035
+ }
1036
+
1037
+ /// Adds an output logical tensor to the op.
1038
+ ///
1039
+ /// @param t Output logical tensor.
1040
+ void add_output(const logical_tensor &t) {
1041
+ error::wrap_c_api(dnnl_graph_op_add_output(get(), &(t.data)),
1042
+ "adding output to the op failed");
1043
+ }
1044
+
1045
+ /// Adds a vector of output logical tensors to the op.
1046
+ ///
1047
+ /// @param ts The list of output logical tensors.
1048
+ void add_outputs(const std::vector<logical_tensor> &ts) {
1049
+ for (const auto &t : ts) {
1050
+ error::wrap_c_api(dnnl_graph_op_add_output(get(), &(t.data)),
1051
+ "adding output to the op failed");
1052
+ }
1053
+ }
1054
+
1055
+ /// Sets the attribute according to the name and type (int64_t).
1056
+ ///
1057
+ /// @tparam Type_i Attribute's type.
1058
+ /// @param name Attribute's name.
1059
+ /// @param value The attribute's value.
1060
+ /// @returns The Op self.
1061
+ template <typename Type_i, req<std::is_same<Type_i, int64_t>::value> = true>
1062
+ op &set_attr(attr name, const Type_i &value) {
1063
+ dnnl_graph_op_attr_t attr = convert_to_c(name);
1064
+ error::wrap_c_api(dnnl_graph_op_set_attr_s64(get(), attr, &value, 1),
1065
+ "could not set attribute to the op");
1066
+ return *this;
1067
+ }
1068
+
1069
+ /// Sets the attribute according to the name and type (float).
1070
+ ///
1071
+ /// @tparam Type_f Attribute's type.
1072
+ /// @param name Attribute's name.
1073
+ /// @param value The attribute's value.
1074
+ /// @returns The Op self.
1075
+ template <typename Type_f, req<std::is_same<Type_f, float>::value> = true>
1076
+ op &set_attr(attr name, const Type_f &value) {
1077
+ dnnl_graph_op_attr_t attr = convert_to_c(name);
1078
+ error::wrap_c_api(dnnl_graph_op_set_attr_f32(get(), attr, &value, 1),
1079
+ "could not set attribute to the op");
1080
+ return *this;
1081
+ }
1082
+
1083
+ /// Sets the attribute according to the name and type (bool).
1084
+ ///
1085
+ /// @tparam Type_b Attribute's type.
1086
+ /// @param name Attribute's name.
1087
+ /// @param value The attribute's value.
1088
+ /// @returns The Op self.
1089
+ template <typename Type_b, req<std::is_same<Type_b, bool>::value> = true>
1090
+ op &set_attr(attr name, const Type_b &value) {
1091
+ dnnl_graph_op_attr_t attr = convert_to_c(name);
1092
+ const uint8_t val = value;
1093
+ error::wrap_c_api(dnnl_graph_op_set_attr_bool(get(), attr, &val, 1),
1094
+ "could not set attribute to the op");
1095
+ return *this;
1096
+ }
1097
+
1098
+ /// Sets the attribute according to the name and type (string).
1099
+ ///
1100
+ /// @tparam Type_s Attribute's type.
1101
+ /// @param name Attribute's name.
1102
+ /// @param value The attribute's value.
1103
+ /// @returns The Op self.
1104
+ template <typename Type_s,
1105
+ req<std::is_same<Type_s, std::string>::value> = true>
1106
+ op &set_attr(attr name, const Type_s &value) {
1107
+ dnnl_graph_op_attr_t attr = convert_to_c(name);
1108
+ error::wrap_c_api(dnnl_graph_op_set_attr_str(
1109
+ get(), attr, value.c_str(), value.size()),
1110
+ "could not set attribute to the op");
1111
+ return *this;
1112
+ }
1113
+
1114
+ /// Sets the attribute according to the name and type
1115
+ /// (std::vector<int64_t>).
1116
+ ///
1117
+ /// @tparam Type_is Attribute's type.
1118
+ /// @param name Attribute's name.
1119
+ /// @param value The attribute's value.
1120
+ /// @returns The Op self.
1121
+ template <typename Type_is,
1122
+ req<std::is_same<Type_is, std::vector<int64_t>>::value> = true>
1123
+ op &set_attr(attr name, const Type_is &value) {
1124
+ dnnl_graph_op_attr_t attr = convert_to_c(name);
1125
+ error::wrap_c_api(dnnl_graph_op_set_attr_s64(
1126
+ get(), attr, value.data(), value.size()),
1127
+ "could not set attribute to the op");
1128
+ return *this;
1129
+ }
1130
+
1131
+ /// Sets the attribute according to the name and type (std::vector<float>).
1132
+ ///
1133
+ /// @tparam Type_fs Attribute's type.
1134
+ /// @param name Attribute's name.
1135
+ /// @param value The attribute's value.
1136
+ /// @returns The Op self.
1137
+ template <typename Type_fs,
1138
+ req<std::is_same<Type_fs, std::vector<float>>::value> = true>
1139
+ op &set_attr(attr name, const Type_fs &value) {
1140
+ dnnl_graph_op_attr_t attr = convert_to_c(name);
1141
+ error::wrap_c_api(dnnl_graph_op_set_attr_f32(
1142
+ get(), attr, value.data(), value.size()),
1143
+ "could not set attribute to the op");
1144
+ return *this;
1145
+ }
1146
+
1147
+ private:
1148
+ dnnl_graph_op_kind_t convert_to_c(kind akind) {
1149
+ return static_cast<dnnl_graph_op_kind_t>(akind);
1150
+ }
1151
+
1152
+ dnnl_graph_op_attr_t convert_to_c(attr aattr) {
1153
+ return static_cast<dnnl_graph_op_attr_t>(aattr);
1154
+ }
1155
+ };
1156
+
1157
+ /// @} dnnl_graph_api_op
1158
+
1159
+ /// @addtogroup dnnl_graph_api_partition Partition
1160
+ ///
1161
+ /// Partition represents a collection of operations and their input and output
1162
+ /// logical tensors identified by library as the basic unit for compilation and
1163
+ /// execution.
1164
+ ///
1165
+ /// @{
1166
+
1167
+ /// A partition object.
1168
+ class partition : public partition_handle {
1169
+ public:
1170
+ /// Policy specifications for partitioning.
1171
+ enum class policy {
1172
+ /// Fusion policy returns partitions with typical post-op fusions, eg.
1173
+ /// Convolution + ReLU or other element-wise operations or a chian of
1174
+ /// post-ops.
1175
+ fusion = dnnl_graph_partition_policy_fusion,
1176
+ /// Debug policy doesn't not apply any fusions. It returns partitions
1177
+ /// with single operations in each partition. The policy is useful when
1178
+ /// users notice any bug or correctness issue in fusion policy.
1179
+ debug = dnnl_graph_partition_policy_debug,
1180
+ };
1181
+
1182
+ partition() = default;
1183
+
1184
+ /// Constructs a partition object
1185
+ ///
1186
+ /// @param p A raw pointer to the C API handle
1187
+ partition(dnnl_graph_partition_t p) { reset(p, false); }
1188
+
1189
+ /// Creates a new partition with a given operator and engine kind. The API
1190
+ /// is used to create a partition from an operation directly without
1191
+ /// creating the graph and calling `get_partitions()`. The output partition
1192
+ /// contains only one operation.
1193
+ ///
1194
+ /// @param aop An operation used to create the partition.
1195
+ /// @param ekind Engine kind.
1196
+ partition(const op &aop, engine::kind ekind) {
1197
+ dnnl_graph_partition_t p = nullptr;
1198
+ error::wrap_c_api(dnnl_graph_partition_create_with_op(&p, aop.get(),
1199
+ static_cast<dnnl_engine_kind_t>(ekind)),
1200
+ "could not create a partition with the op and engine kind");
1201
+ reset(p);
1202
+ }
1203
+
1204
+ /// Returns the number of operations contained in the partition.
1205
+ ///
1206
+ /// @returns Number of operations.
1207
+ size_t get_ops_num() const {
1208
+ size_t num {0};
1209
+ error::wrap_c_api(dnnl_graph_partition_get_op_num(get(), &num),
1210
+ "could not get number of ops from the partition");
1211
+ return num;
1212
+ }
1213
+
1214
+ /// Returns all operation IDs contained in the partition.
1215
+ ///
1216
+ /// @returns An unordered set of operation IDs.
1217
+ std::vector<size_t> get_ops() const {
1218
+ auto num = get_ops_num();
1219
+ std::vector<size_t> ops(num);
1220
+
1221
+ error::wrap_c_api(dnnl_graph_partition_get_ops(get(), num, ops.data()),
1222
+ "could not get op ids from the partition");
1223
+ return ops;
1224
+ }
1225
+
1226
+ /// Returns the unique ID of the partition. Partition ID is generated by the
1227
+ /// library internally. The ID can be used for debugging purpose or verbose.
1228
+ ///
1229
+ /// @returns ID of the partition.
1230
+ size_t get_id() const {
1231
+ size_t id {};
1232
+ error::wrap_c_api(dnnl_graph_partition_get_id(get(), &id),
1233
+ "could not get id of the partition");
1234
+ return id;
1235
+ }
1236
+
1237
+ /// Compiles a partition with given input and output logical tensors. The
1238
+ /// output logical tensors can contain unknown dimensions. For this case,
1239
+ /// the compilation will deduce the output shapes according to input shapes.
1240
+ /// The output logical tensors can also have layout type `any`. The
1241
+ /// compilation will choose the optimal layout for output tensors. The
1242
+ /// optimal layout will be represented as an opaque layout ID saved in the
1243
+ /// output logical tensor.
1244
+ ///
1245
+ /// @param inputs A list of input logical tensors.
1246
+ /// @param outputs A list of output logical tensors.
1247
+ /// @param e The engine used to compile the partition.
1248
+ /// @returns A compiled partition.
1249
+ compiled_partition compile(const std::vector<logical_tensor> &inputs,
1250
+ const std::vector<logical_tensor> &outputs, const engine &e) const {
1251
+ if (!is_supported()) {
1252
+ error::wrap_c_api(dnnl_invalid_arguments,
1253
+ "could not compile an unsupported partition");
1254
+ }
1255
+
1256
+ return compile_(inputs, outputs, e);
1257
+ }
1258
+
1259
+ /// Returns the supporting status of a partition. Some operations may not be
1260
+ /// supported by the library under certain circumstances. During
1261
+ /// partitioning stage, unsupported partitions will be returned to users
1262
+ /// with each containing an unsupported operation. Users should check the
1263
+ /// supporting status of a partition before transforming the computation
1264
+ /// graph or compiling the partition.
1265
+ ///
1266
+ /// @returns @c true if this partition is supported or @c false if this
1267
+ /// partition isn't supported by the library
1268
+ bool is_supported() const {
1269
+ uint8_t supported {0};
1270
+ error::wrap_c_api(dnnl_graph_partition_is_supported(get(), &supported),
1271
+ "could not get supporting status of the partition");
1272
+ return supported != 0;
1273
+ }
1274
+
1275
+ /// Returns a list of input logical tensors from the partition.
1276
+ ///
1277
+ /// @returns A list of input logical tensors.
1278
+ std::vector<logical_tensor> get_input_ports() const {
1279
+ size_t num = 0;
1280
+ error::wrap_c_api(dnnl_graph_partition_get_input_ports_num(get(), &num),
1281
+ "could not get number of inputs of the partition");
1282
+ if (num == 0) return {};
1283
+
1284
+ std::vector<dnnl_graph_logical_tensor_t> c_inputs(num);
1285
+ error::wrap_c_api(dnnl_graph_partition_get_input_ports(
1286
+ get(), num, c_inputs.data()),
1287
+ "could not get input logical tensors of the partition");
1288
+
1289
+ std::vector<logical_tensor> inputs;
1290
+ inputs.reserve(num);
1291
+ for (auto &c_lt : c_inputs)
1292
+ inputs.emplace_back(c_lt);
1293
+ return inputs;
1294
+ }
1295
+
1296
+ /// Returns a list of output logical tensors from the partition.
1297
+ ///
1298
+ /// @returns A list of output logical tensor.
1299
+ std::vector<logical_tensor> get_output_ports() const {
1300
+ size_t num = 0;
1301
+ error::wrap_c_api(
1302
+ dnnl_graph_partition_get_output_ports_num(get(), &num),
1303
+ "cannot get number of outputs of the partition");
1304
+ if (num == 0) return {};
1305
+
1306
+ std::vector<dnnl_graph_logical_tensor_t> c_outputs(num);
1307
+ error::wrap_c_api(dnnl_graph_partition_get_output_ports(
1308
+ get(), num, c_outputs.data()),
1309
+ "could not get output logical tensors of the partition");
1310
+
1311
+ std::vector<logical_tensor> outputs;
1312
+ outputs.reserve(num);
1313
+ for (auto &c_lt : c_outputs)
1314
+ outputs.emplace_back(c_lt);
1315
+ return outputs;
1316
+ }
1317
+
1318
+ /// Returns the engine kind of the partition
1319
+ ///
1320
+ /// @returns The engine kind
1321
+ engine::kind get_engine_kind() const {
1322
+ dnnl_engine_kind_t akind;
1323
+ error::wrap_c_api(dnnl_graph_partition_get_engine_kind(get(), &akind),
1324
+ "cannot get the engine kind from the partition");
1325
+
1326
+ return static_cast<engine::kind>(akind);
1327
+ }
1328
+
1329
+ private:
1330
+ compiled_partition compile_(const std::vector<logical_tensor> &inputs,
1331
+ const std::vector<logical_tensor> &outputs, const engine &e) const {
1332
+ std::vector<const dnnl_graph_logical_tensor_t *> c_inputs;
1333
+ std::vector<const dnnl_graph_logical_tensor_t *> c_outputs;
1334
+
1335
+ c_inputs.reserve(inputs.size());
1336
+ for (const auto &in : inputs) {
1337
+ c_inputs.push_back(&(in.data));
1338
+ }
1339
+
1340
+ c_outputs.reserve(outputs.size());
1341
+ for (const auto &out : outputs) {
1342
+ c_outputs.push_back(&(out.data));
1343
+ }
1344
+
1345
+ dnnl_graph_compiled_partition_t cpartitions = nullptr;
1346
+ error::wrap_c_api(
1347
+ dnnl_graph_compiled_partition_create(&cpartitions, get()),
1348
+ "could not create compiled_partition");
1349
+ error::wrap_c_api(dnnl_graph_partition_compile(get(), cpartitions,
1350
+ c_inputs.size(), c_inputs.data(),
1351
+ c_outputs.size(), c_outputs.data(), e.get()),
1352
+ "partition compile failed");
1353
+
1354
+ return compiled_partition(cpartitions);
1355
+ }
1356
+ };
1357
+
1358
+ /// @} dnnl_graph_api_partition
1359
+
1360
+ /// @addtogroup dnnl_graph_api_graph Graph
1361
+ ///
1362
+ /// Graph represents a computational DAG with a set of operations.
1363
+ /// #dnnl::graph::graph::add_op() adds an operation and its input and output
1364
+ /// logical tensors into a graph. The library accumulates the operations and
1365
+ /// logical tensors and constructs and validates the graph as an internal state.
1366
+ /// A graph object is associated to a specific engine kind. The partitions
1367
+ /// returned from the graph will inherit the engine kind of the graph.
1368
+ ///
1369
+ /// @{
1370
+
1371
+ /// A graph object.
1372
+ class graph : public graph_handle {
1373
+ public:
1374
+ /// Constructs a graph with an engine kind.
1375
+ ///
1376
+ /// @param engine_kind Engine kind.
1377
+ graph(engine::kind engine_kind) {
1378
+ dnnl_graph_graph_t g = nullptr;
1379
+ error::wrap_c_api(
1380
+ dnnl_graph_graph_create(&g, convert_to_c(engine_kind)),
1381
+ "could not create graph with engine kind");
1382
+ reset(g);
1383
+ }
1384
+
1385
+ /// Creates a new empty graph with an engine kind and a floating-point math
1386
+ /// mode. All partitions returned from the graph will inherit the engine
1387
+ /// kind and floating-point math mode.
1388
+ ///
1389
+ /// Setting the floating-point math mode enables automatic down-conversion
1390
+ /// of inputs for the given graph, promoting speedup by using
1391
+ /// lower-precision data types when available.
1392
+ ///
1393
+ /// @param engine_kind Engine kind.
1394
+ /// @param mode Floating-point math mode.
1395
+ graph(engine::kind engine_kind, fpmath_mode mode) {
1396
+ dnnl_graph_graph_t g = nullptr;
1397
+ error::wrap_c_api(
1398
+ dnnl_graph_graph_create_with_fpmath_mode(
1399
+ &g, convert_to_c(engine_kind), convert_to_c(mode)),
1400
+ "could not create graph with engine kind and math mode");
1401
+ reset(g);
1402
+ }
1403
+
1404
+ /// Set the floating point math mode for a graph. Users can enforce the
1405
+ /// graph to comply with the mode by specifying a boolean flag with the
1406
+ /// setter function.
1407
+ ///
1408
+ /// @param mode The floating-point math mode.
1409
+ /// @param apply_to_int The flag that controls whether to use
1410
+ /// floating-point arithmetic for integral operations.
1411
+ void set_fpmath_mode(fpmath_mode mode, bool apply_to_int = false) {
1412
+ error::wrap_c_api(dnnl_graph_graph_set_fpmath_mode(
1413
+ get(), convert_to_c(mode), apply_to_int),
1414
+ "could not set fpmath mode graph attribute");
1415
+ }
1416
+
1417
+ /// Get the floating point math mode and the boolean flag that specifies
1418
+ /// whether the graph will be enforced to comply the mode.
1419
+ ///
1420
+ /// @param mode The floating-point math mode.
1421
+ /// @param apply_to_int The flag that controls whether to use
1422
+ /// floating-point arithmetic for integral operations.
1423
+ void get_fpmath_mode(fpmath_mode &mode, bool &apply_to_int) const {
1424
+ dnnl_fpmath_mode_t c_mode;
1425
+ int c_apply_to_int;
1426
+
1427
+ error::wrap_c_api(dnnl_graph_graph_get_fpmath_mode(
1428
+ get(), &c_mode, &c_apply_to_int),
1429
+ "could not get fpmath mode graph attribute");
1430
+
1431
+ mode = fpmath_mode(c_mode);
1432
+ apply_to_int = static_cast<bool>(c_apply_to_int);
1433
+ }
1434
+
1435
+ /// Adds an op into the graph to construct a computational DAG. The API will
1436
+ /// return failure if the operator has already been added to the graph or
1437
+ /// the operation cannot pass the schema check in the library (eg. input and
1438
+ /// output numbers and data types, the attributes of the operation, etc.).
1439
+ ///
1440
+ /// @param op An operation to be added.
1441
+ /// @param allow_exception A flag indicating whether the method is allowed
1442
+ /// to throw an exception if it fails to add the op to the graph.
1443
+ /// @returns #status::success or a status describing the error otherwise.
1444
+ status add_op(const op &op, bool allow_exception = true) {
1445
+ dnnl_status_t ret = dnnl_graph_add_op(get(), op.get());
1446
+
1447
+ if (allow_exception) {
1448
+ error::wrap_c_api(ret, "could not add op to the graph");
1449
+ }
1450
+
1451
+ return static_cast<status>(ret);
1452
+ }
1453
+
1454
+ /// Finalizes a graph. It means users have finished adding operations into
1455
+ /// the graph and the graph is ready for partitioning. Adding a new
1456
+ /// operation into a finalized graph will return failures. Similarly,
1457
+ /// partitioning on a un-finalized graph will also return failures.
1458
+ void finalize() {
1459
+ error::wrap_c_api(dnnl_graph_graph_finalize(get()),
1460
+ "could not finalize the graph");
1461
+ }
1462
+
1463
+ /// Checks if a graph is finalized.
1464
+ ///
1465
+ /// @return True if the graph is finalized or false if the graph is not
1466
+ /// finalized.
1467
+ bool is_finalized() const {
1468
+ uint8_t ret = 0;
1469
+ error::wrap_c_api(dnnl_graph_graph_is_finalized(get(), &ret),
1470
+ "could not get the finalization status of the graph");
1471
+
1472
+ return ret != 0;
1473
+ }
1474
+
1475
+ /// Gets filtered partitions from a graph. Partitions will be claimed
1476
+ /// internally according to the capability of the library, the engine kind
1477
+ /// of the graph, and the policy.
1478
+ ///
1479
+ /// @param policy Partition policy, defaults to policy
1480
+ /// #dnnl::graph::partition::policy::fusion.
1481
+ /// @return A vector storing the partitions.
1482
+ std::vector<partition> get_partitions(
1483
+ partition::policy policy = partition::policy::fusion) {
1484
+ if (!is_finalized()) {
1485
+ error::wrap_c_api(
1486
+ dnnl_invalid_graph, "the graph is not finalized yet");
1487
+ }
1488
+
1489
+ error::wrap_c_api(
1490
+ dnnl_graph_graph_filter(get(),
1491
+ static_cast<dnnl_graph_partition_policy_t>(policy)),
1492
+ "could not filter the graph");
1493
+
1494
+ size_t num = 0;
1495
+ error::wrap_c_api(dnnl_graph_graph_get_partition_num(get(), &num),
1496
+ "could not get number of partitions from the graph");
1497
+
1498
+ // return early if there is no partitions in the graph.
1499
+ if (num == 0) return {};
1500
+
1501
+ std::vector<partition> out_list;
1502
+ out_list.reserve(num);
1503
+
1504
+ std::vector<dnnl_graph_partition_t> partitions(num);
1505
+ error::wrap_c_api(
1506
+ dnnl_graph_graph_get_partitions(get(), num, partitions.data()),
1507
+ "could not get partitions from the graph");
1508
+
1509
+ for (auto p : partitions) {
1510
+ out_list.emplace_back(p);
1511
+ }
1512
+
1513
+ return out_list;
1514
+ }
1515
+
1516
+ private:
1517
+ static dnnl_fpmath_mode_t convert_to_c(fpmath_mode mode) {
1518
+ return static_cast<dnnl_fpmath_mode_t>(mode);
1519
+ }
1520
+
1521
+ static dnnl_engine_kind_t convert_to_c(engine::kind akind) {
1522
+ return static_cast<dnnl_engine_kind_t>(akind);
1523
+ }
1524
+ };
1525
+
1526
+ /// @} dnnl_graph_api_graph
1527
+
1528
+ /// @addtogroup dnnl_graph_api_compiled_partition_cache Compiled Partition Cache
1529
+ ///
1530
+ /// A set of functions that provide compiled partition cache control.
1531
+ ///
1532
+ /// @{
1533
+
1534
+ /// Returns the number of compiled partition that can be held in the compiled
1535
+ /// partition cache at the same time.
1536
+ inline int get_compiled_partition_cache_capacity() {
1537
+ int result = 0;
1538
+ error::wrap_c_api(dnnl_graph_get_compiled_partition_cache_capacity(&result),
1539
+ "could not get compiled partition cache capacity");
1540
+ return result;
1541
+ }
1542
+
1543
+ /// @copydoc dnnl_graph_set_compiled_partition_cache_capacity(int capacity)
1544
+ inline void set_compiled_partition_cache_capacity(int capacity) {
1545
+ error::wrap_c_api(
1546
+ dnnl_graph_set_compiled_partition_cache_capacity(capacity),
1547
+ "could not set compiled partition cache capacity");
1548
+ }
1549
+
1550
+ /// @} dnnl_graph_api_compiled_partition_cache
1551
+
1552
+ /// @addtogroup dnnl_graph_api_constant_tensor_cache Constant Tensor Cache
1553
+ ///
1554
+ /// A set of functions that provide constant tensor cache control
1555
+ ///
1556
+ /// @{
1557
+
1558
+ /// Control the enabling or disabling of constant tensor cache. This API must be
1559
+ /// called once before compilation stage. By default, constant tensor cache is
1560
+ /// disabled in the library.
1561
+ /// @note This API is deprecated and will be removed in future release, please
1562
+ /// use the set_constant_tensor_cache_capacity API to disable
1563
+ /// constant tensor cache by setting it's capacity to zero.
1564
+ ///
1565
+ /// @param flag Set to positive value to enable the cache and set to 0 to
1566
+ /// disable the cache. Negative values are invalid.
1567
+ inline void set_constant_tensor_cache(int flag) {
1568
+ error::wrap_c_api(dnnl_graph_set_constant_tensor_cache(flag),
1569
+ "fail to set constant tensor cache");
1570
+ }
1571
+
1572
+ /// Return the enabling status of constant tensor cache.
1573
+ /// @note This API is deprecated and will be removed in future release, please
1574
+ /// use the get_constant_tensor_cache_capacity API to check the
1575
+ /// enabling status by checking it's capacity.
1576
+ inline int get_constant_tensor_cache() {
1577
+ int result = 0;
1578
+ error::wrap_c_api(dnnl_graph_get_constant_tensor_cache(&result),
1579
+ "fail to get constant tensor cache");
1580
+ return result;
1581
+ }
1582
+
1583
+ /// Control the capacity for the constant tensor cache that used for specific
1584
+ /// engine kind. This API is thread safe and can be called multiple times at
1585
+ /// runtime. The capacity is set to zero by default which means the cache is
1586
+ /// disabled. When calling this API, the corresponding cache will be flushed.
1587
+ /// Setting capacity to 0 means to clear all cached tensors and disable cache.
1588
+ /// Once the capacity limit is reached, no new tensors will be cached. If there
1589
+ /// are multiple devices for an engine kind, the capacity set here is for each
1590
+ /// device.
1591
+ ///
1592
+ /// @param kind The engine kind that the constant tensor cache used for.
1593
+ /// @param size The constant tensor cache capacity size to set.
1594
+ inline void set_constant_tensor_cache_capacity(engine::kind kind, size_t size) {
1595
+ error::wrap_c_api(dnnl_graph_set_constant_tensor_cache_capacity(
1596
+ static_cast<dnnl_engine_kind_t>(kind), size),
1597
+ "fail to set constant tensor cache capacity");
1598
+ }
1599
+
1600
+ /// Return the current capacity of constant tensor cache.
1601
+ ///
1602
+ /// @param kind The engine kind that the constant tensor cache used for.
1603
+ inline size_t get_constant_tensor_cache_capacity(engine::kind kind) {
1604
+ size_t size = 0;
1605
+ error::wrap_c_api(dnnl_graph_get_constant_tensor_cache_capacity(
1606
+ static_cast<dnnl_engine_kind_t>(kind), &size),
1607
+ "fail to get constant tensor cache capacity");
1608
+ return size;
1609
+ }
1610
+
1611
+ /// @} dnnl_graph_api_constant_tensor_cache
1612
+
1613
+ } // namespace graph
1614
+
1615
+ /// @} dnnl_graph_api
1616
+
1617
+ } // namespace dnnl
1618
+
1619
+ /// @cond DO_NOT_DOCUMENT_THIS
1620
+
1621
+ /// oneAPI namespace
1622
+ // Contains the oneapi::dnnl namespace as an alias to the ::dnnl namespace.
1623
+ namespace oneapi {
1624
+ // Note: without this guard, doxygen warns of potentially recursive namespace
1625
+ #ifndef DOXYGEN_SHOULD_SKIP_THIS
1626
+ /// oneDNN alias namespace
1627
+ namespace dnnl = ::dnnl;
1628
+ #endif
1629
+ } // namespace oneapi
1630
+
1631
+ /// @endcond
1632
+
1633
+ /// @} dnnl_api
1634
+
1635
+ #endif
1636
+
1637
+ #else
1638
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
1639
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph_ocl.h ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2024 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_OCL_H
19
+ #define ONEAPI_DNNL_DNNL_GRAPH_OCL_H
20
+
21
+ #include "oneapi/dnnl/dnnl_graph.h"
22
+
23
+ /// @cond DO_NOT_DOCUMENT_THIS
24
+ // Set target version for OpenCL explicitly to suppress a compiler warning.
25
+ #ifndef CL_TARGET_OPENCL_VERSION
26
+ #define CL_TARGET_OPENCL_VERSION 120
27
+ #endif
28
+
29
+ #include <CL/cl.h>
30
+ /// @endcond
31
+
32
+ #ifdef __cplusplus
33
+ extern "C" {
34
+ #endif
35
+
36
+ /// @addtogroup dnnl_api
37
+ /// @{
38
+
39
+ /// @addtogroup dnnl_graph_api
40
+ /// @{
41
+
42
+ /// @addtogroup dnnl_graph_api_interop
43
+ /// @{
44
+
45
+ /// @addtogroup dnnl_graph_api_ocl_interop
46
+ /// @{
47
+
48
+ /// Allocation call-back function interface for OpenCL. OpenCL allocator should
49
+ /// be used for OpenCL GPU runtime. The call-back should return a USM device
50
+ /// memory pointer.
51
+ ///
52
+ /// @param size Memory size in bytes for requested allocation
53
+ /// @param alignment The minimum alignment in bytes for the requested allocation
54
+ /// @param device A valid OpenCL device used to allocate
55
+ /// @param context A valid OpenCL context used to allocate
56
+ /// @returns The memory address of the requested USM allocation.
57
+ typedef void *(*dnnl_graph_ocl_allocate_f)(
58
+ size_t size, size_t alignment, cl_device_id device, cl_context context);
59
+
60
+ /// Deallocation call-back function interface for OpenCL. OpenCL allocator
61
+ /// should be used for OpenCL runtime. The call-back should deallocate a USM
62
+ /// device memory returned by #dnnl_graph_ocl_allocate_f. The event should be
63
+ /// completed before deallocate the USM.
64
+ ///
65
+ /// @param buf The USM allocation to be released
66
+ /// @param device A valid OpenCL device the USM associated with
67
+ /// @param context A valid OpenCL context used to free the USM allocation
68
+ /// @param event A event which the USM deallocation depends on
69
+ typedef void (*dnnl_graph_ocl_deallocate_f)(
70
+ void *buf, cl_device_id device, cl_context context, cl_event event);
71
+
72
+ /// Creates an allocator with the given allocation and deallocation call-back
73
+ /// function pointers.
74
+ ///
75
+ /// @param allocator Output allocator
76
+ /// @param ocl_malloc A pointer to OpenCL malloc function
77
+ /// @param ocl_free A pointer to OpenCL free function
78
+ /// @returns #dnnl_success on success and a status describing the
79
+ /// error otherwise.
80
+ dnnl_status_t DNNL_API dnnl_graph_ocl_interop_allocator_create(
81
+ dnnl_graph_allocator_t *allocator, dnnl_graph_ocl_allocate_f ocl_malloc,
82
+ dnnl_graph_ocl_deallocate_f ocl_free);
83
+
84
+ /// This API is a supplement for existing oneDNN engine API:
85
+ /// dnnl_status_t DNNL_API dnnl_ocl_interop_engine_create(
86
+ /// dnnl_engine_t *engine, cl_device_id device, cl_context context);
87
+ ///
88
+ /// @param engine Output engine.
89
+ /// @param device Underlying OpenCL device to use for the engine.
90
+ /// @param context Underlying OpenCL context to use for the engine.
91
+ /// @param alloc Underlying allocator to use for the engine.
92
+ /// @returns #dnnl_success on success and a status describing the error
93
+ /// otherwise.
94
+ dnnl_status_t DNNL_API dnnl_graph_ocl_interop_make_engine_with_allocator(
95
+ dnnl_engine_t *engine, cl_device_id device, cl_context context,
96
+ const_dnnl_graph_allocator_t alloc);
97
+
98
+ /// This API is a supplement for existing oneDNN engine API:
99
+ /// dnnl_status_t DNNL_API dnnl_ocl_interop_engine_create_from_cache_blob(
100
+ /// dnnl_engine_t *engine, cl_device_id device, cl_context context,
101
+ /// size_t size, const uint8_t *cache_blob);
102
+ ///
103
+ /// @param engine Output engine.
104
+ /// @param device The OpenCL device that this engine will encapsulate.
105
+ /// @param context The OpenCL context (containing the device) that this
106
+ /// engine will use for all operations.
107
+ /// @param alloc Underlying allocator to use for the engine.
108
+ /// @param size Size of the cache blob in bytes.
109
+ /// @param cache_blob Cache blob of size @p size.
110
+ /// @returns #dnnl_success on success and a status describing the error
111
+ /// otherwise.
112
+ dnnl_status_t DNNL_API
113
+ dnnl_graph_ocl_interop_make_engine_from_cache_blob_with_allocator(
114
+ dnnl_engine_t *engine, cl_device_id device, cl_context context,
115
+ const_dnnl_graph_allocator_t alloc, size_t size,
116
+ const uint8_t *cache_blob);
117
+
118
+ /// Execute a compiled partition with OpenCL runtime.
119
+ ///
120
+ /// @param compiled_partition The handle of target compiled_partition.
121
+ /// @param stream The stream used for execution
122
+ /// @param num_inputs The number of input tensors
123
+ /// @param inputs A list of input tensors
124
+ /// @param num_outputs The number of output tensors
125
+ /// @param outputs A non-empty list of output tensors
126
+ /// @param deps Optional handle of list with `cl_event` dependencies.
127
+ /// @param ndeps Number of dependencies.
128
+ /// @param return_event The handle of cl_event.
129
+ /// @returns #dnnl_success on success and a status describing the
130
+ /// error otherwise.
131
+ dnnl_status_t DNNL_API dnnl_graph_ocl_interop_compiled_partition_execute(
132
+ const_dnnl_graph_compiled_partition_t compiled_partition,
133
+ dnnl_stream_t stream, size_t num_inputs,
134
+ const_dnnl_graph_tensor_t *inputs, size_t num_outputs,
135
+ const_dnnl_graph_tensor_t *outputs, const cl_event *deps, int ndeps,
136
+ cl_event *return_event);
137
+
138
+ /// @} dnnl_graph_api_ocl_interop
139
+
140
+ /// @} dnnl_graph_api_interop
141
+
142
+ /// @} dnnl_graph_api
143
+
144
+ /// @} dnnl_api
145
+
146
+ #ifdef __cplusplus
147
+ }
148
+ #endif
149
+
150
+ #endif
151
+
152
+ #else
153
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
154
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph_ocl.hpp ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2024-2025 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ /// @file
19
+ /// Graph OpenCL interop API
20
+
21
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_OCL_HPP
22
+ #define ONEAPI_DNNL_DNNL_GRAPH_OCL_HPP
23
+
24
+ /// @cond DO_NOT_DOCUMENT_THIS
25
+ #include <vector>
26
+
27
+ #include <CL/cl.h>
28
+
29
+ #include "oneapi/dnnl/dnnl_graph.hpp"
30
+ #include "oneapi/dnnl/dnnl_graph_ocl.h"
31
+ #include "oneapi/dnnl/dnnl_ocl.hpp"
32
+ /// @endcond
33
+
34
+ /// @addtogroup dnnl_api
35
+ /// @{
36
+
37
+ namespace dnnl {
38
+
39
+ /// @addtogroup dnnl_graph_api
40
+ /// @{
41
+
42
+ namespace graph {
43
+
44
+ /// @addtogroup dnnl_graph_api_interop Runtime interoperability API
45
+ /// API extensions to interact with the underlying run-time.
46
+ /// @{
47
+
48
+ /// @addtogroup dnnl_graph_api_ocl_interop OpenCL interoperability API
49
+ /// API extensions to interact with the underlying OpenCL run-time.
50
+ /// @{
51
+
52
+ /// OpenCL interoperability namespace
53
+ namespace ocl_interop {
54
+
55
+ /// Constructs an allocator from OpenCL malloc and free function pointer. OpenCL
56
+ /// allocator should be used for OpenCL GPU runtime. Currently, only device USM
57
+ /// allocator is supported.
58
+ ///
59
+ /// @param ocl_malloc The pointer to OpenCL malloc function
60
+ /// @param ocl_free The pointer to OpenCL free function
61
+ /// @returns Created allocator
62
+ inline allocator make_allocator(dnnl_graph_ocl_allocate_f ocl_malloc,
63
+ dnnl_graph_ocl_deallocate_f ocl_free) {
64
+ dnnl_graph_allocator_t c_allocator = nullptr;
65
+ error::wrap_c_api(dnnl_graph_ocl_interop_allocator_create(
66
+ &c_allocator, ocl_malloc, ocl_free),
67
+ "could not create allocator for opencl device");
68
+ return allocator(c_allocator);
69
+ }
70
+
71
+ /// Constructs an engine from an OpenCL device, an OpenCL context, and an
72
+ /// allocator.
73
+ ///
74
+ /// @param device A valid OpenCL device to construct the engine
75
+ /// @param context A valid OpenCL context to construct the engine
76
+ /// @param alloc An allocator to associate with the engine
77
+ /// @returns Created engine
78
+ inline engine make_engine_with_allocator(
79
+ cl_device_id device, cl_context context, const allocator &alloc) {
80
+ dnnl_engine_t c_engine;
81
+ error::wrap_c_api(dnnl_graph_ocl_interop_make_engine_with_allocator(
82
+ &c_engine, device, context, alloc.get()),
83
+ "could not make an engine with allocator");
84
+ return engine(c_engine);
85
+ }
86
+
87
+ /// Constructs an engine from an OpenCL device, an OpenCL context, an
88
+ /// allocator, and a serialized engine cache blob.
89
+ ///
90
+ /// @param device A valid OpenCL device to construct the engine
91
+ /// @param context A valid OpenCL context to construct the engine
92
+ /// @param alloc An allocator to associate with the engine
93
+ /// @param cache_blob Cache blob serialized beforehand
94
+ /// @returns Created engine
95
+ inline engine make_engine_with_allocator(cl_device_id device,
96
+ cl_context context, const allocator &alloc,
97
+ const std::vector<uint8_t> &cache_blob) {
98
+ dnnl_engine_t c_engine;
99
+ error::wrap_c_api(
100
+ dnnl_graph_ocl_interop_make_engine_from_cache_blob_with_allocator(
101
+ &c_engine, device, context, alloc.get(), cache_blob.size(),
102
+ cache_blob.data()),
103
+ "could not make an engine with allocator from cache blob");
104
+ return engine(c_engine);
105
+ }
106
+
107
+ /// Executes a compiled partition in a specified stream and returns a OpenCL
108
+ /// event.
109
+ ///
110
+ /// @param c_partition Compiled partition to execute.
111
+ /// @param astream Stream object to run over
112
+ /// @param inputs Arguments map.
113
+ /// @param outputs Arguments map.
114
+ /// @param deps Optional vector with `cl_event` dependencies.
115
+ /// @returns Output event.
116
+ inline cl_event execute(compiled_partition &c_partition, stream &astream,
117
+ const std::vector<tensor> &inputs, std::vector<tensor> &outputs,
118
+ const std::vector<cl_event> &deps = {}) {
119
+ std::vector<const_dnnl_graph_tensor_t> c_inputs;
120
+ c_inputs.reserve(inputs.size());
121
+ for (auto &in : inputs) {
122
+ c_inputs.push_back(in.get());
123
+ }
124
+ std::vector<const_dnnl_graph_tensor_t> c_outputs;
125
+ c_outputs.reserve(outputs.size());
126
+ for (auto &out : outputs) {
127
+ c_outputs.push_back(out.get());
128
+ }
129
+
130
+ const cl_event *c_deps = deps.empty() ? nullptr : deps.data();
131
+
132
+ cl_event ocl_event;
133
+ error::wrap_c_api(
134
+ dnnl_graph_ocl_interop_compiled_partition_execute(c_partition.get(),
135
+ astream.get(), c_inputs.size(), c_inputs.data(),
136
+ c_outputs.size(), c_outputs.data(), c_deps,
137
+ (int)deps.size(), &ocl_event),
138
+ "could not execute the compiled_partition on a specified opencl "
139
+ "stream");
140
+ return ocl_event;
141
+ }
142
+
143
+ } // namespace ocl_interop
144
+
145
+ /// @} dnnl_graph_api_ocl_interop
146
+
147
+ /// @} dnnl_graph_api_interop
148
+
149
+ } // namespace graph
150
+
151
+ /// @} dnnl_graph_api
152
+
153
+ } // namespace dnnl
154
+
155
+ /// @} dnnl_api
156
+
157
+ #endif
158
+
159
+ #else
160
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
161
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph_sycl.h ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2020-2024 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_SYCL_H
19
+ #define ONEAPI_DNNL_DNNL_GRAPH_SYCL_H
20
+
21
+ #include "oneapi/dnnl/dnnl_graph.h"
22
+
23
+ #ifdef __cplusplus
24
+ extern "C" {
25
+ #endif
26
+
27
+ /// @addtogroup dnnl_api
28
+ /// @{
29
+
30
+ /// @addtogroup dnnl_graph_api
31
+ /// @{
32
+
33
+ /// @addtogroup dnnl_graph_api_interop
34
+ /// @{
35
+
36
+ /// @addtogroup dnnl_graph_api_sycl_interop
37
+ /// @{
38
+
39
+ /// Allocation call-back function interface for SYCL. SYCL allocator should be
40
+ /// used for SYCL runtime and host allocator should be used for non-SYCL. The
41
+ /// call-back should return a USM device memory pointer.
42
+ typedef void *(*dnnl_graph_sycl_allocate_f)(
43
+ size_t size, size_t alignment, const void *dev, const void *context);
44
+
45
+ /// Deallocation call-back function interface for SYCL. SYCL allocator should be
46
+ /// used for SYCL runtime and host allocator should be used for non-SYCL. The
47
+ /// call-back should deallocate a USM device memory returned by
48
+ /// #dnnl_graph_sycl_allocate_f.
49
+ typedef void (*dnnl_graph_sycl_deallocate_f)(
50
+ void *buf, const void *dev, const void *context, void *event);
51
+
52
+ /// Creates an allocator with the given allocation and deallocation call-back
53
+ /// function pointers.
54
+ ///
55
+ /// @param allocator Output allocator
56
+ /// @param sycl_malloc A pointer to SYCL malloc function
57
+ /// @param sycl_free A pointer to SYCL free function
58
+ /// @returns #dnnl_success on success and a status describing the
59
+ /// error otherwise.
60
+ dnnl_status_t DNNL_API dnnl_graph_sycl_interop_allocator_create(
61
+ dnnl_graph_allocator_t *allocator,
62
+ dnnl_graph_sycl_allocate_f sycl_malloc,
63
+ dnnl_graph_sycl_deallocate_f sycl_free);
64
+
65
+ /// This API is a supplement for existing onednn engine API.
66
+ dnnl_status_t DNNL_API dnnl_graph_sycl_interop_make_engine_with_allocator(
67
+ dnnl_engine_t *engine, const void *device, const void *context,
68
+ const_dnnl_graph_allocator_t alloc);
69
+
70
+ /// Execute a compiled partition with sycl runtime.
71
+ ///
72
+ /// @param compiled_partition The handle of target compiled_partition.
73
+ /// @param stream The stream used for execution
74
+ /// @param num_inputs The number of input tensors
75
+ /// @param inputs A list of input tensors
76
+ /// @param num_outputs The number of output tensors
77
+ /// @param outputs A non-empty list of output tensors
78
+ /// @param deps Optional handle of list with `sycl::event` dependencies.
79
+ /// @param sycl_event The handle of sycl event.
80
+ /// @returns #dnnl_success on success and a status describing the
81
+ /// error otherwise.
82
+ dnnl_status_t DNNL_API dnnl_graph_sycl_interop_compiled_partition_execute(
83
+ const_dnnl_graph_compiled_partition_t compiled_partition,
84
+ dnnl_stream_t stream, size_t num_inputs,
85
+ const_dnnl_graph_tensor_t *inputs, size_t num_outputs,
86
+ const_dnnl_graph_tensor_t *outputs, const void *deps, void *sycl_event);
87
+
88
+ /// @} dnnl_graph_api_sycl_interop
89
+
90
+ /// @} dnnl_graph_api_interop
91
+
92
+ /// @} dnnl_graph_api
93
+
94
+ /// @} dnnl_api
95
+
96
+ #ifdef __cplusplus
97
+ }
98
+ #endif
99
+
100
+ #endif
101
+
102
+ #else
103
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
104
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph_sycl.hpp ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2020-2025 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ /// @file
19
+ /// Graph SYCL interop API
20
+
21
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_SYCL_HPP
22
+ #define ONEAPI_DNNL_DNNL_GRAPH_SYCL_HPP
23
+
24
+ /// @cond DO_NOT_DOCUMENT_THIS
25
+ #include <vector>
26
+
27
+ #if __has_include(<sycl/sycl.hpp>)
28
+ #include <sycl/sycl.hpp>
29
+ #else
30
+ #error "Unsupported compiler"
31
+ #endif
32
+
33
+ #include "oneapi/dnnl/dnnl_graph.hpp"
34
+ #include "oneapi/dnnl/dnnl_graph_sycl.h"
35
+ /// @endcond
36
+
37
+ /// @addtogroup dnnl_api
38
+ /// @{
39
+
40
+ namespace dnnl {
41
+
42
+ /// @addtogroup dnnl_graph_api
43
+ /// @{
44
+
45
+ namespace graph {
46
+
47
+ /// @addtogroup dnnl_graph_api_interop Runtime interoperability API
48
+ /// API extensions to interact with the underlying run-time.
49
+ /// @{
50
+
51
+ /// @addtogroup dnnl_graph_api_sycl_interop SYCL interoperability API
52
+ /// API extensions to interact with the underlying SYCL run-time.
53
+ /// @{
54
+
55
+ /// SYCL interoperability namespace
56
+ namespace sycl_interop {
57
+
58
+ /// Constructs an allocator from SYCL malloc and free function pointer. SYCL
59
+ /// allocator should be used for SYCL runtime and host allocator should be used
60
+ /// for non-SYCL. Currently, only device USM allocator is supported.
61
+ ///
62
+ /// @param sycl_malloc The pointer to SYCL malloc function
63
+ /// @param sycl_free The pointer to SYCL free function
64
+ /// @returns Created allocator
65
+ inline allocator make_allocator(dnnl_graph_sycl_allocate_f sycl_malloc,
66
+ dnnl_graph_sycl_deallocate_f sycl_free) {
67
+ dnnl_graph_allocator_t c_allocator = nullptr;
68
+ error::wrap_c_api(dnnl_graph_sycl_interop_allocator_create(
69
+ &c_allocator, sycl_malloc, sycl_free),
70
+ "could not create allocator for sycl device");
71
+ return allocator(c_allocator);
72
+ }
73
+
74
+ inline engine make_engine_with_allocator(const sycl::device &adevice,
75
+ const sycl::context &acontext, const allocator &alloc) {
76
+ dnnl_engine_t c_engine;
77
+ error::wrap_c_api(
78
+ dnnl_graph_sycl_interop_make_engine_with_allocator(&c_engine,
79
+ static_cast<const void *>(&adevice),
80
+ static_cast<const void *>(&acontext), alloc.get()),
81
+ "could not make an engine with allocator");
82
+ return engine(c_engine);
83
+ }
84
+
85
+ /// Executes a compiled partition in a specified stream and returns a SYCL
86
+ /// event.
87
+ ///
88
+ /// @param c_partition Compiled partition to execute.
89
+ /// @param astream Stream object to run over
90
+ /// @param inputs Arguments map.
91
+ /// @param outputs Arguments map.
92
+ /// @param deps Optional vector with `sycl::event` dependencies.
93
+ /// @returns Output event.
94
+ inline sycl::event execute(compiled_partition &c_partition, stream &astream,
95
+ const std::vector<tensor> &inputs, std::vector<tensor> &outputs,
96
+ const std::vector<sycl::event> &deps = {}) {
97
+ std::vector<const_dnnl_graph_tensor_t> c_inputs;
98
+ c_inputs.reserve(inputs.size());
99
+ for (auto &in : inputs) {
100
+ c_inputs.push_back(in.get());
101
+ }
102
+ std::vector<const_dnnl_graph_tensor_t> c_outputs;
103
+ c_outputs.reserve(outputs.size());
104
+ for (auto &out : outputs) {
105
+ c_outputs.push_back(out.get());
106
+ }
107
+
108
+ sycl::event sycl_event;
109
+ error::wrap_c_api(dnnl_graph_sycl_interop_compiled_partition_execute(
110
+ c_partition.get(), astream.get(), c_inputs.size(),
111
+ c_inputs.data(), c_outputs.size(),
112
+ c_outputs.data(), &deps, &sycl_event),
113
+ "could not execute the compiled_partition on a specified sycl "
114
+ "stream");
115
+ return sycl_event;
116
+ }
117
+
118
+ } // namespace sycl_interop
119
+
120
+ /// @} dnnl_graph_api_sycl_interop
121
+
122
+ /// @} dnnl_graph_api_interop
123
+
124
+ } // namespace graph
125
+
126
+ /// @} dnnl_graph_api
127
+
128
+ } // namespace dnnl
129
+
130
+ /// @} dnnl_api
131
+
132
+ #endif
133
+
134
+ #else
135
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
136
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_graph_types.h ADDED
@@ -0,0 +1,480 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2020-2025 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ /// @file
19
+ /// C API definitions
20
+
21
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_TYPES_H
22
+ #define ONEAPI_DNNL_DNNL_GRAPH_TYPES_H
23
+
24
+ #ifdef __cplusplus
25
+ extern "C" {
26
+ #endif
27
+
28
+ /// @cond DO_NOT_DOCUMENT_THIS
29
+ #include <limits.h>
30
+ #include <stddef.h>
31
+
32
+ #include "oneapi/dnnl/dnnl_common_types.h"
33
+ /// @endcond
34
+
35
+ /// @addtogroup dnnl_api
36
+ /// @{
37
+
38
+ /// @addtogroup dnnl_graph_api
39
+ /// @{
40
+
41
+ /// @addtogroup dnnl_graph_api_logical_tensor
42
+ /// @{
43
+
44
+ /// A wildcard value for number of dimensions which is unknown at a tensor or
45
+ /// operation creation time.
46
+ #define DNNL_GRAPH_UNKNOWN_NDIMS -1
47
+
48
+ /// A wildcard value for dimensions that are unknown at a tensor or operation
49
+ /// creation time.
50
+ #define DNNL_GRAPH_UNKNOWN_DIM INT64_MIN
51
+
52
+ /// Layout type specification
53
+ typedef enum {
54
+ /// Undefined layout type
55
+ dnnl_graph_layout_type_undef = 0,
56
+ /// Any means to let the library to decide the layout for a tensor during
57
+ /// partition compilation.
58
+ dnnl_graph_layout_type_any = 1,
59
+ /// Strided means that the layout of a tensor is determined by the strides
60
+ /// field in the logical tensor.
61
+ dnnl_graph_layout_type_strided = 2,
62
+ /// Opaque means that the layout of a tensor is the library specific.
63
+ /// Usually, an opaque layout is generated by a partition which is compiled
64
+ /// with layout type any.
65
+ dnnl_graph_layout_type_opaque = 3,
66
+ } dnnl_graph_layout_type_t;
67
+
68
+ /// Logical tensor property
69
+ typedef enum {
70
+ /// Undefined tensor property
71
+ dnnl_graph_tensor_property_undef = 0,
72
+ /// Variable means the tensor may be changed during computation or between
73
+ /// different iterations.
74
+ dnnl_graph_tensor_property_variable = 1,
75
+ /// Constant means the tensor will keep unchanged during computation and
76
+ /// between different iterations. It's useful for the library to apply
77
+ /// optimizations for constant tensors or cache constant tensors inside the
78
+ /// library. For example, constant weight tensors in inference scenarios.
79
+ dnnl_graph_tensor_property_constant = 2,
80
+ } dnnl_graph_tensor_property_t;
81
+
82
+ /// Logical tensor. It is based on an ID, a number of dimensions, dimensions
83
+ /// themselves, element data type, tensor property and tensor memory layout.
84
+ typedef struct {
85
+ /// Unique id of each logical tensor. The library uses logical tensor IDs to
86
+ /// build up the connections between operations if the output of one
87
+ /// operation has the same ID as the input of another operation.
88
+ size_t id;
89
+
90
+ /// Number of dimensions. -1 means unknown (DNNL_GRAPH_UNKNOWN_NDIMS). 0 is
91
+ /// used to define scalar tensor.
92
+ int ndims;
93
+
94
+ /// Size of each dimension. #DNNL_GRAPH_UNKNOWN_DIM means the size of that
95
+ /// dimension is unknown. 0 is used to define zero-dimension tensor. The
96
+ /// library supports to deduce output shapes according to input shapes
97
+ /// during compilation. Unlike memory descriptor in oneDNN primitive API,
98
+ /// the order of dimensions is not defined in logical tensor. It is defined
99
+ /// by the operations which respect the order through the attributes
100
+ /// #dnnl_graph_op_attr_data_format or #dnnl_graph_op_attr_weights_format.
101
+ /// For example, for a Convolution with `data_format=NXC`, it means the
102
+ /// first element of dims of activation tensor is mini-batch size, the last
103
+ /// effective element of dims is channel size, and other elements between
104
+ /// them are spatial dimensions.
105
+ dnnl_dims_t dims;
106
+
107
+ /// Data type of the tensor elements.
108
+ dnnl_data_type_t data_type;
109
+
110
+ /// Property type of the tensor.
111
+ dnnl_graph_tensor_property_t property;
112
+
113
+ /// Layout type of the tensor.
114
+ dnnl_graph_layout_type_t layout_type;
115
+ union {
116
+ /// The field is valid when `layout_type` is
117
+ /// #dnnl_graph_layout_type_strided. #DNNL_GRAPH_UNKNOWN_DIM means the
118
+ /// stride of the dimension is unknown. The library currently doesn't
119
+ /// support other negative stride values.
120
+ dnnl_dims_t strides;
121
+
122
+ /// The field is valid when `layout_type` is
123
+ /// #dnnl_graph_layout_type_opaque. An opaque layout ID is usually
124
+ /// generated by a partition which is compiled with layout type any.
125
+ size_t layout_id;
126
+ } layout;
127
+ } dnnl_graph_logical_tensor_t;
128
+
129
+ /// @} dnnl_graph_api_logical_tensor
130
+
131
+ /// @addtogroup dnnl_graph_api_partition
132
+ /// @{
133
+
134
+ /// Policy specifications for partitioning
135
+ typedef enum {
136
+ /// Fusion policy returns partitions with typical post-op fusions, eg.
137
+ /// Convolution + ReLU or other element-wise operations or a chian of
138
+ /// post-ops.
139
+ dnnl_graph_partition_policy_fusion = 1,
140
+ /// Debug policy doesn't not apply any fusions. It returns partitions with
141
+ /// single operation in each partition. The policy is useful when users
142
+ /// notice any bug or correctness issue in fusion policy.
143
+ dnnl_graph_partition_policy_debug = 2,
144
+ } dnnl_graph_partition_policy_t;
145
+
146
+ /// An opaque structure to describe a partition.
147
+ struct dnnl_graph_partition;
148
+
149
+ /// A partition handle.
150
+ typedef struct dnnl_graph_partition *dnnl_graph_partition_t;
151
+
152
+ /// A constant partition handle.
153
+ typedef const struct dnnl_graph_partition *const_dnnl_graph_partition_t;
154
+
155
+ /// @} dnnl_graph_api_partition
156
+
157
+ /// @addtogroup dnnl_graph_api_graph
158
+ /// @{
159
+
160
+ /// An opaque structure to describe a graph.
161
+ struct dnnl_graph_graph;
162
+
163
+ /// A graph handle.
164
+ typedef struct dnnl_graph_graph *dnnl_graph_graph_t;
165
+
166
+ /// A constant graph handle.
167
+ typedef const struct dnnl_graph_graph *const_dnnl_graph_graph_t;
168
+
169
+ /// @} dnnl_graph_api_graph
170
+
171
+ /// @addtogroup dnnl_graph_api_op
172
+ /// @{
173
+
174
+ /// Kinds of operations
175
+ typedef enum {
176
+ dnnl_graph_op_abs,
177
+ dnnl_graph_op_abs_backward,
178
+ dnnl_graph_op_add,
179
+ dnnl_graph_op_avg_pool,
180
+ dnnl_graph_op_avg_pool_backward,
181
+ dnnl_graph_op_batch_norm_backward,
182
+ dnnl_graph_op_batch_norm_forward_training,
183
+ dnnl_graph_op_batch_norm_inference,
184
+ dnnl_graph_op_bias_add,
185
+ dnnl_graph_op_bias_add_backward,
186
+ dnnl_graph_op_clamp,
187
+ dnnl_graph_op_clamp_backward,
188
+ dnnl_graph_op_concat,
189
+ dnnl_graph_op_convolution,
190
+ dnnl_graph_op_convolution_backward_data,
191
+ dnnl_graph_op_convolution_backward_weights,
192
+ dnnl_graph_op_conv_transpose,
193
+ dnnl_graph_op_conv_transpose_backward_data,
194
+ dnnl_graph_op_conv_transpose_backward_weights,
195
+ dnnl_graph_op_dequantize,
196
+ dnnl_graph_op_divide,
197
+ dnnl_graph_op_dynamic_dequantize,
198
+ dnnl_graph_op_dynamic_quantize,
199
+ dnnl_graph_op_elu,
200
+ dnnl_graph_op_elu_backward,
201
+ dnnl_graph_op_end,
202
+ dnnl_graph_op_exp,
203
+ dnnl_graph_op_gelu,
204
+ dnnl_graph_op_gelu_backward,
205
+ dnnl_graph_op_hard_swish,
206
+ dnnl_graph_op_hard_swish_backward,
207
+ dnnl_graph_op_interpolate,
208
+ dnnl_graph_op_interpolate_backward,
209
+ dnnl_graph_op_layer_norm,
210
+ dnnl_graph_op_layer_norm_backward,
211
+ dnnl_graph_op_leaky_relu,
212
+ dnnl_graph_op_log,
213
+ dnnl_graph_op_log_softmax,
214
+ dnnl_graph_op_log_softmax_backward,
215
+ dnnl_graph_op_matmul,
216
+ dnnl_graph_op_maximum,
217
+ dnnl_graph_op_max_pool,
218
+ dnnl_graph_op_max_pool_backward,
219
+ dnnl_graph_op_minimum,
220
+ dnnl_graph_op_mish,
221
+ dnnl_graph_op_mish_backward,
222
+ dnnl_graph_op_multiply,
223
+ dnnl_graph_op_prelu,
224
+ dnnl_graph_op_prelu_backward,
225
+ dnnl_graph_op_quantize,
226
+ dnnl_graph_op_reciprocal,
227
+ dnnl_graph_op_reduce_l1,
228
+ dnnl_graph_op_reduce_l2,
229
+ dnnl_graph_op_reduce_max,
230
+ dnnl_graph_op_reduce_mean,
231
+ dnnl_graph_op_reduce_min,
232
+ dnnl_graph_op_reduce_prod,
233
+ dnnl_graph_op_reduce_sum,
234
+ dnnl_graph_op_relu,
235
+ dnnl_graph_op_relu_backward,
236
+ dnnl_graph_op_reorder,
237
+ dnnl_graph_op_round,
238
+ dnnl_graph_op_sigmoid,
239
+ dnnl_graph_op_sigmoid_backward,
240
+ dnnl_graph_op_softmax,
241
+ dnnl_graph_op_softmax_backward,
242
+ dnnl_graph_op_softplus,
243
+ dnnl_graph_op_softplus_backward,
244
+ dnnl_graph_op_sqrt,
245
+ dnnl_graph_op_sqrt_backward,
246
+ dnnl_graph_op_square,
247
+ dnnl_graph_op_squared_difference,
248
+ dnnl_graph_op_static_reshape,
249
+ dnnl_graph_op_static_transpose,
250
+ dnnl_graph_op_subtract,
251
+ dnnl_graph_op_tanh,
252
+ dnnl_graph_op_tanh_backward,
253
+ dnnl_graph_op_type_cast,
254
+ dnnl_graph_op_wildcard,
255
+ dnnl_graph_op_hard_sigmoid,
256
+ dnnl_graph_op_hard_sigmoid_backward,
257
+ dnnl_graph_op_select,
258
+ dnnl_graph_op_pow,
259
+ dnnl_graph_op_group_norm,
260
+ dnnl_graph_op_gen_index,
261
+ dnnl_graph_op_greater_equal,
262
+ dnnl_graph_op_last_symbol,
263
+ } dnnl_graph_op_kind_t;
264
+
265
+ /// Attributes of operations
266
+ typedef enum {
267
+ /// Undefined op attribute.
268
+ dnnl_graph_op_attr_undef = 0,
269
+
270
+ // float32 attributes. The value of these attributes can be any single
271
+ // float32 number.
272
+
273
+ /// Specifies an alpha attribute to an op.
274
+ dnnl_graph_op_attr_alpha = 0x1,
275
+ /// Specifies an beta attribute to an op.
276
+ dnnl_graph_op_attr_beta,
277
+ /// Specifies an epsilon attribute to an op.
278
+ dnnl_graph_op_attr_epsilon,
279
+ /// Specifies a max attribute to an op.
280
+ dnnl_graph_op_attr_max,
281
+ ///Specifies a min attribute to an op.
282
+ dnnl_graph_op_attr_min,
283
+ /// Specifies a momentum attribute to an op.
284
+ dnnl_graph_op_attr_momentum,
285
+
286
+ // float32 vector attributes. The value of these attributes can be a vector
287
+ // of float32 numbers.
288
+
289
+ /// Specifies a scales attribute to an op.
290
+ dnnl_graph_op_attr_scales = 0x20,
291
+
292
+ // int64_t attributes. The value of these attributes can be any single int64
293
+ // number.
294
+
295
+ /// Specifies an axis attribute to an op.
296
+ dnnl_graph_op_attr_axis = 0x30,
297
+ /// Specifies a begin_norm_axis attribute to an op.
298
+ dnnl_graph_op_attr_begin_norm_axis,
299
+ /// Specifies a groups attribute to an op.
300
+ dnnl_graph_op_attr_groups,
301
+
302
+ // int64_t vector attributes. The value of these attributes can be a vector
303
+ // of int64 numbers.
304
+
305
+ /// Specifies an axes attribute to an op.
306
+ dnnl_graph_op_attr_axes = 0x40,
307
+ /// Specifies a dilations attribute to an op.
308
+ dnnl_graph_op_attr_dilations,
309
+ /// Specifies an dst_shape attribute to an op.
310
+ dnnl_graph_op_attr_dst_shape,
311
+ /// Specifies a kernel attribute to an op.
312
+ dnnl_graph_op_attr_kernel,
313
+ /// Specifies an order attribute to an op.
314
+ dnnl_graph_op_attr_order,
315
+ /// Specifies an output_padding attribute to an op.
316
+ dnnl_graph_op_attr_output_padding,
317
+ /// Specifies a pads_begin attribute to an op.
318
+ dnnl_graph_op_attr_pads_begin,
319
+ /// Specifies a pads_end attribute to an op.
320
+ dnnl_graph_op_attr_pads_end,
321
+ /// Specifies a shape attribute to an op.
322
+ dnnl_graph_op_attr_shape,
323
+ /// Specifies a sizes attribute to an op.
324
+ dnnl_graph_op_attr_sizes,
325
+ /// Specifies a input_shape attribute to an op.
326
+ dnnl_graph_op_attr_src_shape,
327
+ /// Specifies a strides attribute to an op.
328
+ dnnl_graph_op_attr_strides,
329
+ /// Specifies a weight_shape attribute to an op.
330
+ dnnl_graph_op_attr_weights_shape,
331
+ /// Specifies a zps attribute to an op.
332
+ dnnl_graph_op_attr_zps,
333
+ /// Specifies a group shape attribute to an op.
334
+ dnnl_graph_op_attr_group_shape,
335
+
336
+ // bool attributes. The value of these attributes can be any single bool
337
+ // value.
338
+
339
+ /// Specifies an exclude_pad attribute to an op.
340
+ dnnl_graph_op_attr_exclude_pad = 0x60,
341
+ /// Specifies a keep_dims attribute to an op.
342
+ dnnl_graph_op_attr_keep_dims,
343
+ /// Specifies a keep_stats attribute to an op.
344
+ dnnl_graph_op_attr_keep_stats,
345
+ /// Specifies a per_channel_broadcast attribute to an op.
346
+ dnnl_graph_op_attr_per_channel_broadcast,
347
+ /// Specifies a special_zero attribute to an op.
348
+ dnnl_graph_op_attr_special_zero,
349
+ /// Specifies a transpose_a attribute to an op.
350
+ dnnl_graph_op_attr_transpose_a,
351
+ /// Specifies a transpose_b attribute to an op.
352
+ dnnl_graph_op_attr_transpose_b,
353
+ /// Specifies an use_affine attribute to an op.
354
+ dnnl_graph_op_attr_use_affine,
355
+ /// Specifies an use_dst attribute to an op.
356
+ dnnl_graph_op_attr_use_dst,
357
+
358
+ // string attributes. The value of these attributes can be a string.
359
+
360
+ /// Specifies an auto_broadcast attribute to an op. The value can be "none"
361
+ /// or "numpy".
362
+ dnnl_graph_op_attr_auto_broadcast = 0x80,
363
+ /// Specifies an auto_pad attribute to an op. The value can be "none",
364
+ /// "same_upper", "same_lower", or "valid".
365
+ dnnl_graph_op_attr_auto_pad,
366
+ /// Specifies an coordinate_transformation_mode attribute to an op. The
367
+ /// value can be "half_pixel" or "align_corners". The attribute is defined
368
+ /// for Interpolate operations.
369
+ dnnl_graph_op_attr_coordinate_transformation_mode,
370
+ /// Specifies a data_format of an op. The value can be "NCX" or "NXC".
371
+ dnnl_graph_op_attr_data_format,
372
+ /// Specifies a mode attribute of an op. The value can be "nearest",
373
+ /// "linear", "bilinear", or "trilinear". The attribute is defined for
374
+ /// Interpolate operations.
375
+ dnnl_graph_op_attr_mode,
376
+ /// Specifies a qtype attribute to an op. The value can be "per_channel" or
377
+ /// "per_tensor". The attribute is defined for quantization operations.
378
+ dnnl_graph_op_attr_qtype,
379
+ /// Specifies a rounding_type attribute to an op. The value can be "ceil" or
380
+ /// "floor".
381
+ dnnl_graph_op_attr_rounding_type,
382
+ /// Specifies a weights_format of an op. The value can be "OIX", "XIO",
383
+ /// "IOX", or "XOI". Different operations may support different values.
384
+ dnnl_graph_op_attr_weights_format,
385
+
386
+ /// Specifies the end of all above exteral attributes for check.
387
+ dnnl_graph_op_attr_end = 0xFF,
388
+ } dnnl_graph_op_attr_t;
389
+
390
+ /// An opaque structure to describe an operation.
391
+ struct dnnl_graph_op;
392
+
393
+ /// An operation handle.
394
+ typedef struct dnnl_graph_op *dnnl_graph_op_t;
395
+
396
+ /// A constant operation handle.
397
+ typedef const struct dnnl_graph_op *const_dnnl_graph_op_t;
398
+
399
+ /// @} dnnl_graph_api_op
400
+
401
+ /// @addtogroup dnnl_graph_api_allocator
402
+ /// @{
403
+
404
+ /// Allocation call-back function interface for host. For SYCL allocator, see
405
+ /// #dnnl_graph_sycl_allocate_f.
406
+ typedef void *(*dnnl_graph_host_allocate_f)(size_t size, size_t alignment);
407
+
408
+ /// Deallocation call-back function interface for host. For SYCL allocator, see
409
+ /// #dnnl_graph_sycl_deallocate_f.
410
+ typedef void (*dnnl_graph_host_deallocate_f)(void *);
411
+
412
+ /// An opaque structure to describe an allocator.
413
+ struct dnnl_graph_allocator;
414
+
415
+ /// An allocator handle.
416
+ typedef struct dnnl_graph_allocator *dnnl_graph_allocator_t;
417
+
418
+ /// A constant allocator handle.
419
+ typedef const struct dnnl_graph_allocator *const_dnnl_graph_allocator_t;
420
+
421
+ /// @} dnnl_graph_api_allocator
422
+
423
+ /// @addtogroup dnnl_graph_api_compiled_partition
424
+ /// @{
425
+
426
+ /// In-place pair definition. It can queried from a compiled partition
427
+ /// indicating that an input and an output of the partition can share the same
428
+ /// memory buffer for computation. In-place computation helps to reduce the
429
+ /// memory footprint and improves cache locality. But since the library may not
430
+ /// have a global view of user's application, it's possible that the tensor with
431
+ /// `input_id` is used at other places in user's computation graph. In this
432
+ /// case, the user should take the in-place pair as a hint and pass a different
433
+ /// memory buffer for output tensor to avoid overwriting the input memory buffer
434
+ /// which will probably cause unexpected incorrect results.
435
+ typedef struct {
436
+ /// The id of input tensor
437
+ size_t input_id;
438
+
439
+ /// The id of output tensor
440
+ size_t output_id;
441
+ } dnnl_graph_inplace_pair_t;
442
+
443
+ /// An opaque structure to describe a compiled partition.
444
+ struct dnnl_graph_compiled_partition;
445
+
446
+ /// A compiled partition handle.
447
+ typedef struct dnnl_graph_compiled_partition *dnnl_graph_compiled_partition_t;
448
+
449
+ /// A constant compiled partition handle.
450
+ typedef const struct dnnl_graph_compiled_partition
451
+ *const_dnnl_graph_compiled_partition_t;
452
+
453
+ /// @} dnnl_graph_api_compiled_partition
454
+
455
+ /// @addtogroup dnnl_graph_api_tensor
456
+ /// @{
457
+
458
+ /// An opaque structure to describe a tensor.
459
+ struct dnnl_graph_tensor;
460
+
461
+ /// A tensor handle.
462
+ typedef struct dnnl_graph_tensor *dnnl_graph_tensor_t;
463
+
464
+ /// A constant tensor handle.
465
+ typedef const struct dnnl_graph_tensor *const_dnnl_graph_tensor_t;
466
+
467
+ /// @} dnnl_graph_api_tensor
468
+
469
+ /// @} dnnl_graph_api
470
+
471
+ /// @} dnnl_api
472
+
473
+ #ifdef __cplusplus
474
+ }
475
+ #endif
476
+ #endif
477
+
478
+ #else
479
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
480
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_ocl.h ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2020-2024 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_OCL_H
19
+ #define ONEAPI_DNNL_DNNL_OCL_H
20
+
21
+ #include "oneapi/dnnl/dnnl.h"
22
+
23
+ #include "oneapi/dnnl/dnnl_ocl_types.h"
24
+
25
+ /// @cond DO_NOT_DOCUMENT_THIS
26
+ // Set target version for OpenCL explicitly to suppress a compiler warning.
27
+ #ifndef CL_TARGET_OPENCL_VERSION
28
+ #define CL_TARGET_OPENCL_VERSION 120
29
+ #endif
30
+
31
+ #include <CL/cl.h>
32
+ /// @endcond
33
+
34
+ #ifdef __cplusplus
35
+ extern "C" {
36
+ #endif
37
+
38
+ /// @addtogroup dnnl_api
39
+ /// @{
40
+
41
+ /// @addtogroup dnnl_api_interop
42
+ /// @{
43
+
44
+ /// @addtogroup dnnl_api_ocl_interop
45
+ /// @{
46
+
47
+ /// Creates a memory object.
48
+ ///
49
+ /// Unless @p handle is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the
50
+ /// constructed memory object will have the underlying buffer set. In this
51
+ /// case, the buffer will be initialized as if:
52
+ /// - dnnl_memory_set_data_handle() has been called, if @p memory_kind is equal
53
+ /// to dnnl_ocl_interop_usm, or
54
+ /// - dnnl_ocl_interop_memory_set_mem_object() has been called, if @p memory_kind
55
+ /// is equal to dnnl_ocl_interop_buffer.
56
+ ///
57
+ /// @param memory Output memory object.
58
+ /// @param memory_desc Memory descriptor.
59
+ /// @param engine Engine to use.
60
+ /// @param memory_kind Memory allocation kind to specify the type of handle.
61
+ /// @param handle Handle of the memory buffer to use as an underlying storage.
62
+ /// - A USM pointer to the user-allocated buffer. In this case the library
63
+ /// doesn't own the buffer. Requires @p memory_kind to be equal to
64
+ /// dnnl_ocl_interop_usm.
65
+ /// - An OpenCL buffer. In this case the library doesn't own the buffer.
66
+ /// Requires @p memory_kind be equal to be equal to dnnl_ocl_interop_buffer.
67
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
68
+ /// allocate the buffer that corresponds to the memory allocation kind
69
+ /// @p memory_kind for the memory object. In this case the library
70
+ /// owns the buffer.
71
+ /// - The DNNL_MEMORY_NONE specific value. Instructs the library to
72
+ /// create memory object without an underlying buffer.
73
+ /// @returns #dnnl_success on success and a status describing the error
74
+ /// otherwise.
75
+ dnnl_status_t DNNL_API dnnl_ocl_interop_memory_create(dnnl_memory_t *memory,
76
+ const_dnnl_memory_desc_t memory_desc, dnnl_engine_t engine,
77
+ dnnl_ocl_interop_memory_kind_t memory_kind, void *handle);
78
+
79
+ #ifdef DNNL_EXPERIMENTAL_SPARSE
80
+ /// Creates a memory object with multiple handles.
81
+ ///
82
+ /// @param memory Output memory object.
83
+ /// @param memory_desc Memory descriptor.
84
+ /// @param engine Engine to use.
85
+ /// @param memory_kind Memory allocation kind to specify the type of handles.
86
+ /// @param nhandles Number of handles.
87
+ /// @param handles Handles of the memory buffers to use as underlying storages.
88
+ /// For each element of the @p handles array the following applies:
89
+ /// - A USM pointer to the user-allocated buffer. In this case the library
90
+ /// doesn't own the buffer. Requires @p memory_kind to be equal to
91
+ /// dnnl_ocl_interop_usm.
92
+ /// - An OpenCL buffer. In this case the library doesn't own the buffer.
93
+ /// Requires @p memory_kind be equal to be equal to dnnl_ocl_interop_buffer.
94
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
95
+ /// allocate the buffer that corresponds to the memory allocation kind
96
+ /// @p memory_kind for the memory object. In this case the library
97
+ /// owns the buffer.
98
+ /// - The DNNL_MEMORY_NONE specific value. Instructs the library to
99
+ /// create memory object without an underlying buffer.
100
+ /// @returns #dnnl_success on success and a status describing the error
101
+ /// otherwise.
102
+ dnnl_status_t DNNL_API dnnl_ocl_interop_memory_create_v2(dnnl_memory_t *memory,
103
+ const_dnnl_memory_desc_t memory_desc, dnnl_engine_t engine,
104
+ dnnl_ocl_interop_memory_kind_t memory_kind, int nhandles,
105
+ void **handles);
106
+ #endif
107
+
108
+ /// Returns the memory allocation kind associated with a memory object.
109
+ ///
110
+ /// @param memory Memory to query.
111
+ /// @param memory_kind Output underlying memory allocation kind of the memory
112
+ /// object.
113
+ /// @returns #dnnl_success on success and a status describing the error
114
+ /// otherwise.
115
+ dnnl_status_t DNNL_API dnnl_ocl_interop_memory_get_memory_kind(
116
+ const_dnnl_memory_t memory,
117
+ dnnl_ocl_interop_memory_kind_t *memory_kind);
118
+
119
+ /// Returns an OpenCL memory object associated with a memory object.
120
+ ///
121
+ /// @param memory Memory object.
122
+ /// @param mem_object Output OpenCL memory object.
123
+ /// @returns #dnnl_success on success and a status describing the error
124
+ /// otherwise.
125
+ dnnl_status_t DNNL_API dnnl_ocl_interop_memory_get_mem_object(
126
+ const_dnnl_memory_t memory, cl_mem *mem_object);
127
+
128
+ /// Sets OpenCL memory object associated with a memory object.
129
+ ///
130
+ /// For behavioral details, see dnnl_memory_set_data_handle().
131
+ ///
132
+ /// @param memory Memory object.
133
+ /// @param mem_object OpenCL memory object.
134
+ /// @returns #dnnl_success on success and a status describing the error
135
+ /// otherwise.
136
+ dnnl_status_t DNNL_API dnnl_ocl_interop_memory_set_mem_object(
137
+ dnnl_memory_t memory, cl_mem mem_object);
138
+
139
+ /// Retrieves a cache blob ID for the OpenCL device.
140
+ ///
141
+ /// @warning
142
+ /// This API is intended to be used with
143
+ /// #dnnl_ocl_interop_engine_get_cache_blob() and
144
+ /// #dnnl_ocl_interop_engine_create_from_cache_blob(). The returned cache
145
+ /// blob ID can only be used as an ID of the cache blob returned by
146
+ /// #dnnl_ocl_interop_engine_get_cache_blob().
147
+ ///
148
+ /// @note The cache blob ID can be empty (@p size will be 0 and
149
+ /// @p cache_blob_id will be nullptr) if oneDNN doesn't have anything to
150
+ /// put in the cache blob. (#dnnl_ocl_interop_engine_get_cache_blob will
151
+ /// return an empty cache blob).
152
+ ///
153
+ /// @param device An OpenCL device.
154
+ /// @param size Size of the cache blob ID in bytes.
155
+ /// @param cache_blob_id Cache blob id of size @p size. If
156
+ /// the @p cache_blob_id is nullptr then the size of the cache blob ID is
157
+ /// returned in @p size.
158
+ /// @returns #dnnl_success on success and a status describing the error
159
+ /// otherwise.
160
+ dnnl_status_t DNNL_API dnnl_ocl_interop_engine_get_cache_blob_id(
161
+ cl_device_id device, size_t *size, uint8_t *cache_blob_id);
162
+
163
+ /// Retrieves a cache blob associated with the given engine.
164
+ ///
165
+ /// @note The cache blob can be empty (@p size will be 0 and @p cache_blob
166
+ /// will be nullptr) if oneDNN doesn't have anything to put in the cache
167
+ /// blob. It's the user's responsibility to check whether it's empty
168
+ /// prior to passing it to
169
+ /// #dnnl_ocl_interop_engine_create_from_cache_blob().
170
+ ///
171
+ /// @param engine Engine to query for the cache blob.
172
+ /// @param size Size of the cache blob in bytes.
173
+ /// @param cache_blob Cache blob of size @p size. If the @p cache_blob is
174
+ /// nullptr then the size of the cache blob is returned in @p size.
175
+ /// @returns #dnnl_success on success and a status describing the error
176
+ /// otherwise.
177
+ dnnl_status_t DNNL_API dnnl_ocl_interop_engine_get_cache_blob(
178
+ dnnl_engine_t engine, size_t *size, uint8_t *cache_blob);
179
+
180
+ /// Creates an engine from the given cache blob.
181
+ ///
182
+ /// @param engine Output engine.
183
+ /// @param device The OpenCL device that this engine will encapsulate.
184
+ /// @param context The OpenCL context (containing the device) that this
185
+ /// engine will use for all operations.
186
+ /// @param size Size of the cache blob in bytes.
187
+ /// @param cache_blob Cache blob of size @p size.
188
+ /// @returns #dnnl_success on success and a status describing the error
189
+ /// otherwise.
190
+ dnnl_status_t DNNL_API dnnl_ocl_interop_engine_create_from_cache_blob(
191
+ dnnl_engine_t *engine, cl_device_id device, cl_context context,
192
+ size_t size, const uint8_t *cache_blob);
193
+
194
+ /// Creates an engine associated with an OpenCL device and an OpenCL context.
195
+ ///
196
+ /// @param engine Output engine.
197
+ /// @param device Underlying OpenCL device to use for the engine.
198
+ /// @param context Underlying OpenCL context to use for the engine.
199
+ /// @returns #dnnl_success on success and a status describing the error
200
+ /// otherwise.
201
+ dnnl_status_t DNNL_API dnnl_ocl_interop_engine_create(
202
+ dnnl_engine_t *engine, cl_device_id device, cl_context context);
203
+
204
+ /// Returns the OpenCL context associated with an engine.
205
+ ///
206
+ /// @param engine Engine to query.
207
+ /// @param context Output underlying OpenCL context of the engine.
208
+ /// @returns #dnnl_success on success and a status describing the error
209
+ /// otherwise.
210
+ dnnl_status_t DNNL_API dnnl_ocl_interop_engine_get_context(
211
+ dnnl_engine_t engine, cl_context *context);
212
+
213
+ /// Returns the OpenCL device associated with an engine.
214
+ ///
215
+ /// @param engine Engine to query.
216
+ /// @param device Output underlying OpenCL device of the engine.
217
+ /// @returns #dnnl_success on success and a status describing the error
218
+ /// otherwise.
219
+ dnnl_status_t DNNL_API dnnl_ocl_interop_get_device(
220
+ dnnl_engine_t engine, cl_device_id *device);
221
+
222
+ /// Creates an execution stream for a given engine associated with
223
+ /// an OpenCL command queue.
224
+ ///
225
+ /// @param stream Output execution stream.
226
+ /// @param engine Engine to create the execution stream on.
227
+ /// @param queue OpenCL command queue to use.
228
+ /// @returns #dnnl_success on success and a status describing the error
229
+ /// otherwise.
230
+ dnnl_status_t DNNL_API dnnl_ocl_interop_stream_create(
231
+ dnnl_stream_t *stream, dnnl_engine_t engine, cl_command_queue queue);
232
+
233
+ /// Returns the OpenCL command queue associated with an execution stream.
234
+ ///
235
+ /// @param stream Execution stream to query.
236
+ /// @param queue Output OpenCL command queue.
237
+ /// @returns #dnnl_success on success and a status describing the error
238
+ /// otherwise.
239
+ dnnl_status_t DNNL_API dnnl_ocl_interop_stream_get_command_queue(
240
+ dnnl_stream_t stream, cl_command_queue *queue);
241
+
242
+ /// Executes computations specified by the primitive in a specified stream and
243
+ /// returns an OpenCL event.
244
+ ///
245
+ /// @param primitive Primitive to execute.
246
+ /// @param stream Stream to use.
247
+ /// @param nargs Number of arguments.
248
+ /// @param args Array of arguments. Each argument is an
249
+ /// <index, #dnnl_memory_t> pair. The index is one of the `DNNL_ARG_*`
250
+ /// values such as `DNNL_ARG_SRC`. Unless runtime shapes are used (see
251
+ /// #DNNL_RUNTIME_DIM_VAL), the memory object must have the same memory
252
+ /// descriptor as that returned by
253
+ /// #dnnl_primitive_desc_query_md(#dnnl_query_exec_arg_md, index).
254
+ /// @param deps A pointer to a vector of size @p ndeps that contains
255
+ /// dependencies.
256
+ /// @param ndeps Number of dependencies.
257
+ /// @param return_event Output event. It's the user's responsibility to
258
+ /// manage lifetime of the event. Can be NULL. When @p stream is in-order
259
+ /// NULL will be returned.
260
+ /// @returns #dnnl_success on success and a status describing the error
261
+ /// otherwise.
262
+ dnnl_status_t DNNL_API dnnl_ocl_interop_primitive_execute(
263
+ const_dnnl_primitive_t primitive, dnnl_stream_t stream, int nargs,
264
+ const dnnl_exec_arg_t *args, const cl_event *deps, int ndeps,
265
+ cl_event *return_event);
266
+
267
+ /// @} dnnl_api_ocl_interop
268
+
269
+ /// @} dnnl_api_interop
270
+
271
+ /// @} dnnl_api
272
+
273
+ #ifdef __cplusplus
274
+ }
275
+ #endif
276
+
277
+ #endif
278
+
279
+ #else
280
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
281
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_ocl.hpp ADDED
@@ -0,0 +1,450 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2020-2025 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_OCL_HPP
19
+ #define ONEAPI_DNNL_DNNL_OCL_HPP
20
+
21
+ #include "oneapi/dnnl/dnnl.hpp"
22
+
23
+ /// @cond DO_NOT_DOCUMENT_THIS
24
+ #include <algorithm>
25
+ #include <cstdlib>
26
+ #include <iterator>
27
+ #include <memory>
28
+ #include <string>
29
+ #include <vector>
30
+ #include <unordered_map>
31
+
32
+ #include "oneapi/dnnl/dnnl_ocl.h"
33
+
34
+ #include <CL/cl.h>
35
+ /// @endcond
36
+
37
+ /// @addtogroup dnnl_api
38
+ /// @{
39
+
40
+ namespace dnnl {
41
+
42
+ /// @addtogroup dnnl_api_interop Runtime interoperability API
43
+ /// API extensions to interact with the underlying run-time.
44
+ /// @{
45
+
46
+ /// @addtogroup dnnl_api_ocl_interop OpenCL interoperability API
47
+ /// API extensions to interact with the underlying OpenCL run-time.
48
+ ///
49
+ /// @sa @ref dev_guide_opencl_interoperability in developer guide
50
+ /// @{
51
+
52
+ /// OpenCL interoperability namespace
53
+ namespace ocl_interop {
54
+
55
+ /// Memory allocation kind.
56
+ enum class memory_kind {
57
+ /// USM (device, shared, host, or unknown) memory allocation kind.
58
+ usm = dnnl_ocl_interop_usm,
59
+ /// Buffer memory allocation kind - default.
60
+ buffer = dnnl_ocl_interop_buffer,
61
+ };
62
+
63
+ /// Converts a memory allocation kind enum value from C++ API to C API type.
64
+ ///
65
+ /// @param akind C++ API memory allocation kind enum value.
66
+ /// @returns Corresponding C API memory allocation kind enum value.
67
+ inline dnnl_ocl_interop_memory_kind_t convert_to_c(memory_kind akind) {
68
+ return static_cast<dnnl_ocl_interop_memory_kind_t>(akind);
69
+ }
70
+
71
+ /// Returns the cache blob ID of the OpenCL device.
72
+ ///
73
+ /// @warning
74
+ /// This API is intended to be used with
75
+ /// #dnnl::ocl_interop::get_engine_cache_blob() and
76
+ /// #dnnl::ocl_interop::make_engine(cl_device_id, cl_context, const std::vector<uint8_t> &).
77
+ /// The returned cache blob ID can only be used as an ID of the cache blob
78
+ /// returned by #dnnl::ocl_interop::get_engine_cache_blob().
79
+ ///
80
+ /// @note The cache blob ID can be empty (@p size will be 0 and
81
+ /// @p cache_blob_id will be nullptr) if oneDNN doesn't have anything to
82
+ /// put in the cache blob. (#dnnl_ocl_interop_engine_get_cache_blob will
83
+ /// return an empty cache blob).
84
+ ///
85
+ /// @param device An OpenCL device.
86
+ /// @returns A vector containing the cache blob ID.
87
+ inline std::vector<uint8_t> get_engine_cache_blob_id(cl_device_id device) {
88
+ size_t size = 0;
89
+ error::wrap_c_api(
90
+ dnnl_ocl_interop_engine_get_cache_blob_id(device, &size, nullptr),
91
+ "could not get an engine cache blob id size");
92
+
93
+ std::vector<uint8_t> cache_blob_id(size);
94
+ error::wrap_c_api(dnnl_ocl_interop_engine_get_cache_blob_id(
95
+ device, &size, cache_blob_id.data()),
96
+ "could not get an engine cache blob id");
97
+ return cache_blob_id;
98
+ }
99
+
100
+ /// Returns a cache blob for the engine.
101
+ ///
102
+ /// @note The cache blob vector can be empty if oneDNN doesn't have anything
103
+ /// to put in the cache blob. It's the user's responsibility to check
104
+ /// whether it's empty prior to passing it to
105
+ /// #dnnl::ocl_interop::make_engine(cl_device_id, cl_context, const std::vector<uint8_t> &)
106
+ ///
107
+ /// @param aengine Engine to query for the cache blob.
108
+ /// @returns Vector containing the cache blob.
109
+ inline std::vector<uint8_t> get_engine_cache_blob(const engine &aengine) {
110
+ size_t size = 0;
111
+ error::wrap_c_api(dnnl_ocl_interop_engine_get_cache_blob(
112
+ aengine.get(), &size, nullptr),
113
+ "could not get an engine cache blob size");
114
+
115
+ std::vector<uint8_t> cache_blob(size);
116
+ error::wrap_c_api(dnnl_ocl_interop_engine_get_cache_blob(
117
+ aengine.get(), &size, cache_blob.data()),
118
+ "could not get an engine cache blob");
119
+ return cache_blob;
120
+ }
121
+
122
+ /// Constructs an engine from the given cache blob.
123
+ ///
124
+ /// @param device The OpenCL device that this engine will encapsulate.
125
+ /// @param context The OpenCL context (containing the device) that this
126
+ /// engine will use for all operations.
127
+ /// @param cache_blob Cache blob.
128
+ /// @returns An engine.
129
+ inline engine make_engine(cl_device_id device, cl_context context,
130
+ const std::vector<uint8_t> &cache_blob) {
131
+ dnnl_engine_t c_engine;
132
+ error::wrap_c_api(
133
+ dnnl_ocl_interop_engine_create_from_cache_blob(&c_engine, device,
134
+ context, cache_blob.size(), cache_blob.data()),
135
+ "could not create an engine from cache blob");
136
+ return engine(c_engine);
137
+ }
138
+
139
+ /// Constructs an engine from OpenCL device and context objects.
140
+ ///
141
+ /// @param device The OpenCL device that this engine will encapsulate.
142
+ /// @param context The OpenCL context (containing the device) that this
143
+ /// engine will use for all operations.
144
+ /// @returns An engine.
145
+ inline engine make_engine(cl_device_id device, cl_context context) {
146
+ dnnl_engine_t c_engine;
147
+ error::wrap_c_api(
148
+ dnnl_ocl_interop_engine_create(&c_engine, device, context),
149
+ "could not create an engine");
150
+ return engine(c_engine);
151
+ }
152
+
153
+ /// Returns OpenCL context associated with the engine.
154
+ ///
155
+ /// @param aengine An engine.
156
+ /// @returns Underlying OpenCL context.
157
+ inline cl_context get_context(const engine &aengine) {
158
+ cl_context context = nullptr;
159
+ error::wrap_c_api(
160
+ dnnl_ocl_interop_engine_get_context(aengine.get(), &context),
161
+ "could not get an OpenCL context from an engine");
162
+ return context;
163
+ }
164
+
165
+ /// Returns OpenCL device associated with the engine.
166
+ ///
167
+ /// @param aengine An engine.
168
+ /// @returns Underlying OpenCL device.
169
+ inline cl_device_id get_device(const engine &aengine) {
170
+ cl_device_id device = nullptr;
171
+ error::wrap_c_api(dnnl_ocl_interop_get_device(aengine.get(), &device),
172
+ "could not get an OpenCL device from an engine");
173
+ return device;
174
+ }
175
+
176
+ /// Constructs an execution stream for the specified engine and OpenCL queue.
177
+ ///
178
+ /// @param aengine Engine to create the stream on.
179
+ /// @param queue OpenCL queue to use for the stream.
180
+ /// @returns An execution stream.
181
+ inline stream make_stream(const engine &aengine, cl_command_queue queue) {
182
+ dnnl_stream_t c_stream;
183
+ error::wrap_c_api(
184
+ dnnl_ocl_interop_stream_create(&c_stream, aengine.get(), queue),
185
+ "could not create a stream");
186
+ return stream(c_stream);
187
+ }
188
+
189
+ /// Returns OpenCL queue object associated with the execution stream.
190
+ ///
191
+ /// @param astream An execution stream.
192
+ /// @returns Underlying OpenCL queue.
193
+ inline cl_command_queue get_command_queue(const stream &astream) {
194
+ cl_command_queue queue = nullptr;
195
+ error::wrap_c_api(
196
+ dnnl_ocl_interop_stream_get_command_queue(astream.get(), &queue),
197
+ "could not get an OpenCL command queue from a stream");
198
+ return queue;
199
+ }
200
+
201
+ /// Returns the OpenCL memory object associated with the memory object.
202
+ ///
203
+ /// @param amemory A memory object.
204
+ /// @returns Underlying OpenCL memory object.
205
+ inline cl_mem get_mem_object(const memory &amemory) {
206
+ cl_mem mem_object;
207
+ error::wrap_c_api(
208
+ dnnl_ocl_interop_memory_get_mem_object(amemory.get(), &mem_object),
209
+ "could not get OpenCL buffer object from a memory object");
210
+ return mem_object;
211
+ }
212
+
213
+ /// Sets the OpenCL memory object associated with the memory object.
214
+ ///
215
+ /// For behavioral details see memory::set_data_handle().
216
+ ///
217
+ /// @param amemory A memory object.
218
+ /// @param mem_object OpenCL cl_mem object to use as the underlying
219
+ /// storage. It must have at least get_desc().get_size() bytes
220
+ /// allocated.
221
+ inline void set_mem_object(memory &amemory, cl_mem mem_object) {
222
+ error::wrap_c_api(
223
+ dnnl_ocl_interop_memory_set_mem_object(amemory.get(), mem_object),
224
+ "could not set OpenCL buffer object from a memory object");
225
+ }
226
+
227
+ /// Returns the memory allocation kind associated with a memory object.
228
+ ///
229
+ /// @param amemory A memory object.
230
+ ///
231
+ /// @returns The underlying memory allocation kind of the memory object.
232
+ inline memory_kind get_memory_kind(const memory &amemory) {
233
+ dnnl_ocl_interop_memory_kind_t ckind;
234
+ error::wrap_c_api(
235
+ dnnl_ocl_interop_memory_get_memory_kind(amemory.get(), &ckind),
236
+ "could not get memory kind");
237
+ return static_cast<memory_kind>(ckind);
238
+ }
239
+
240
+ #ifdef DNNL_EXPERIMENTAL_SPARSE
241
+ /// Creates a memory object with multiple handles.
242
+ ///
243
+ /// @param memory_desc Memory descriptor.
244
+ /// @param aengine Engine to use.
245
+ /// @param kind Memory allocation kind to specify the type of handles.
246
+ /// @param handles Handles of the memory buffers to use as underlying storages.
247
+ /// For each element of the @p handles array the following applies:
248
+ /// - A USM pointer to the user-allocated buffer. In this case the library
249
+ /// doesn't own the buffer. Requires @p memory_kind to be equal to
250
+ /// dnnl_ocl_interop_usm.
251
+ /// - An OpenCL buffer. In this case the library doesn't own the buffer.
252
+ /// Requires @p memory_kind be equal to be equal to dnnl_ocl_interop_buffer.
253
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
254
+ /// allocate the buffer that corresponds to the memory allocation kind
255
+ /// @p memory_kind for the memory object. In this case the library
256
+ /// owns the buffer.
257
+ /// - The DNNL_MEMORY_NONE specific value. Instructs the library to
258
+ /// create memory object without an underlying buffer.
259
+ ///
260
+ /// If the @p handles vector is not provided the library will allocate all
261
+ /// buffers as if all handles have the special value DNNL_MEMORY_ALLOCATE.
262
+ ///
263
+ /// @returns #dnnl_success on success and a status describing the error
264
+ /// otherwise.
265
+ inline memory make_memory(const memory::desc &memory_desc,
266
+ const engine &aengine, memory_kind kind,
267
+ std::vector<void *> handles = {}) {
268
+ if (handles.empty()) {
269
+ const int nhandles = memory_desc.get_num_handles();
270
+ handles.resize(nhandles, DNNL_MEMORY_ALLOCATE);
271
+ }
272
+
273
+ dnnl_memory_t c_memory;
274
+ error::wrap_c_api(
275
+ dnnl_ocl_interop_memory_create_v2(&c_memory, memory_desc.get(),
276
+ aengine.get(), convert_to_c(kind), (int)handles.size(),
277
+ handles.data()),
278
+ "could not create a memory");
279
+ return memory(c_memory);
280
+ }
281
+
282
+ /// Constructs a memory object with multiple OpenCL buffers.
283
+ ///
284
+ /// @param memory_desc Memory descriptor.
285
+ /// @param aengine Engine to use.
286
+ /// @param mem_objects A vector of OpenCL buffers to use.
287
+ ///
288
+ /// @returns Created memory object.
289
+ inline memory make_memory(const memory::desc &memory_desc,
290
+ const engine &aengine, std::vector<cl_mem> mem_objects) {
291
+ const int nhandles = memory_desc.get_num_handles();
292
+ std::vector<void *> handles(nhandles, DNNL_MEMORY_NONE);
293
+ memory amemory(memory_desc, aengine, handles);
294
+ for (int i = 0; i < nhandles; i++)
295
+ amemory.set_data_handle(mem_objects[i], i);
296
+ return amemory;
297
+ }
298
+
299
+ /// Creates a memory object.
300
+ ///
301
+ /// Unless @p handle is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the
302
+ /// constructed memory object will have the underlying buffer set. In this
303
+ /// case, the buffer will be initialized as if:
304
+ /// - dnnl::memory::set_data_handle() had been called, if @p memory_kind is
305
+ /// equal to dnnl::ocl_interop::memory_kind::usm, or
306
+ /// - dnnl::ocl_interop::set_mem_object() has been called, if @p memory_kind is
307
+ /// equal to dnnl::ocl_interop::memory_kind::buffer.
308
+ ///
309
+ /// @param memory_desc Memory descriptor.
310
+ /// @param aengine Engine to use.
311
+ /// @param kind Memory allocation kind to specify the type of handle.
312
+ /// @param handle Handle of the memory buffer to use as an underlying storage.
313
+ /// - A USM pointer to the user-allocated buffer. In this case the library
314
+ /// doesn't own the buffer. Requires @p memory_kind to be equal to
315
+ /// dnnl::ocl_interop::memory_kind::usm.
316
+ /// - An OpenCL buffer. In this case the library doesn't own the buffer.
317
+ /// Requires @p memory_kind be equal to be equal to
318
+ /// dnnl::ocl_interop::memory_kind::buffer.
319
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
320
+ /// allocate the buffer that corresponds to the memory allocation kind
321
+ /// @p memory_kind for the memory object. In this case the library
322
+ /// owns the buffer.
323
+ /// - The DNNL_MEMORY_NONE specific value. Instructs the library to
324
+ /// create memory object without an underlying buffer.
325
+ ///
326
+ /// @returns Created memory object.
327
+ inline memory make_memory(const memory::desc &memory_desc,
328
+ const engine &aengine, memory_kind kind, void *handle) {
329
+ return make_memory(
330
+ memory_desc, aengine, kind, std::vector<void *> {handle});
331
+ }
332
+
333
+ /// Constructs a memory object from an OpenCL buffer.
334
+ ///
335
+ /// @param memory_desc Memory descriptor.
336
+ /// @param aengine Engine to use.
337
+ /// @param mem_object An OpenCL buffer to use.
338
+ ///
339
+ /// @returns Created memory object.
340
+ inline memory make_memory(const memory::desc &memory_desc,
341
+ const engine &aengine, cl_mem mem_object) {
342
+ return make_memory(memory_desc, aengine, std::vector<cl_mem> {mem_object});
343
+ }
344
+ #else
345
+
346
+ /// Creates a memory object.
347
+ ///
348
+ /// Unless @p handle is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the
349
+ /// constructed memory object will have the underlying buffer set. In this
350
+ /// case, the buffer will be initialized as if:
351
+ /// - dnnl::memory::set_data_handle() had been called, if @p memory_kind is
352
+ /// equal to dnnl::ocl_interop::memory_kind::usm, or
353
+ /// - dnnl::ocl_interop::set_mem_object() has been called, if @p memory_kind is
354
+ /// equal to dnnl::ocl_interop::memory_kind::buffer.
355
+ ///
356
+ /// @param memory_desc Memory descriptor.
357
+ /// @param aengine Engine to use.
358
+ /// @param kind Memory allocation kind to specify the type of handle.
359
+ /// @param handle Handle of the memory buffer to use as an underlying storage.
360
+ /// - A USM pointer to the user-allocated buffer. In this case the library
361
+ /// doesn't own the buffer. Requires @p memory_kind to be equal to
362
+ /// dnnl::ocl_interop::memory_kind::usm.
363
+ /// - An OpenCL buffer. In this case the library doesn't own the buffer.
364
+ /// Requires @p memory_kind be equal to be equal to
365
+ /// dnnl::ocl_interop::memory_kind::buffer.
366
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
367
+ /// allocate the buffer that corresponds to the memory allocation kind
368
+ /// @p memory_kind for the memory object. In this case the library
369
+ /// owns the buffer.
370
+ /// - The DNNL_MEMORY_NONE specific value. Instructs the library to
371
+ /// create memory object without an underlying buffer.
372
+ ///
373
+ /// @returns Created memory object.
374
+ inline memory make_memory(const memory::desc &memory_desc,
375
+ const engine &aengine, memory_kind kind,
376
+ void *handle = DNNL_MEMORY_ALLOCATE) {
377
+ dnnl_memory_t c_memory;
378
+ error::wrap_c_api(
379
+ dnnl_ocl_interop_memory_create(&c_memory, memory_desc.get(),
380
+ aengine.get(), convert_to_c(kind), handle),
381
+ "could not create a memory");
382
+ return memory(c_memory);
383
+ }
384
+
385
+ /// Constructs a memory object from an OpenCL buffer.
386
+ ///
387
+ /// @param memory_desc Memory descriptor.
388
+ /// @param aengine Engine to use.
389
+ /// @param mem_object An OpenCL buffer to use.
390
+ ///
391
+ /// @returns Created memory object.
392
+ inline memory make_memory(const memory::desc &memory_desc,
393
+ const engine &aengine, cl_mem mem_object) {
394
+ memory amemory(memory_desc, aengine, DNNL_MEMORY_NONE);
395
+ set_mem_object(amemory, mem_object);
396
+ return amemory;
397
+ }
398
+ #endif
399
+
400
+ /// Executes computations specified by the primitive in a specified stream and
401
+ /// returns a SYCL event.
402
+ ///
403
+ /// Arguments are passed via an arguments map containing
404
+ /// <index, memory object> pairs. The index must be one of the `DNNL_ARG_*`
405
+ /// values such as `DNNL_ARG_SRC`, and the memory must have a memory descriptor
406
+ /// matching the one returned by
407
+ /// #dnnl::primitive_desc::query_md(#query::exec_arg_md, index) unless using
408
+ /// dynamic shapes (see #DNNL_RUNTIME_DIM_VAL).
409
+ ///
410
+ /// @param aprimitive Primitive to execute.
411
+ /// @param astream Stream object. The stream must belong to the same engine
412
+ /// as the primitive.
413
+ /// @param args Arguments map.
414
+ /// @param deps Optional vector with `cl_event` dependencies.
415
+ ///
416
+ /// @returns Output event. It's the user's responsibility to manage lifetime
417
+ /// of the event.
418
+ inline cl_event execute(const dnnl::primitive &aprimitive,
419
+ const stream &astream, const std::unordered_map<int, memory> &args,
420
+ const std::vector<cl_event> &deps = {}) {
421
+ std::vector<dnnl_exec_arg_t> c_args;
422
+ c_args.reserve(args.size());
423
+ for (const auto &a : args)
424
+ c_args.push_back({a.first, a.second.get()});
425
+
426
+ const cl_event *c_deps = deps.empty() ? nullptr : deps.data();
427
+
428
+ cl_event return_event;
429
+ error::wrap_c_api(dnnl_ocl_interop_primitive_execute(aprimitive.get(),
430
+ astream.get(), (int)c_args.size(), c_args.data(),
431
+ c_deps, (int)deps.size(), &return_event),
432
+ "could not execute a primitive");
433
+ return return_event;
434
+ }
435
+
436
+ } // namespace ocl_interop
437
+
438
+ /// @} dnnl_api_ocl_interop
439
+
440
+ /// @} dnnl_api_interop
441
+
442
+ } // namespace dnnl
443
+
444
+ /// @} dnnl_api
445
+
446
+ #endif
447
+
448
+ #else
449
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
450
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_ocl_types.h ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2021 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_OCL_TYPES_H
19
+ #define ONEAPI_DNNL_DNNL_OCL_TYPES_H
20
+
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif
24
+
25
+ /// @addtogroup dnnl_api
26
+ /// @{
27
+
28
+ /// @addtogroup dnnl_api_interop
29
+ /// @{
30
+
31
+ /// @addtogroup dnnl_api_ocl_interop
32
+ /// @{
33
+
34
+ /// Memory allocation kind.
35
+ typedef enum {
36
+ /// USM (device, shared, host, or unknown) memory allocation kind.
37
+ dnnl_ocl_interop_usm,
38
+ /// Buffer memory allocation kind - default.
39
+ dnnl_ocl_interop_buffer,
40
+ } dnnl_ocl_interop_memory_kind_t;
41
+
42
+ /// @} dnnl_api_ocl_interop
43
+
44
+ /// @} dnnl_api_interop
45
+
46
+ /// @} dnnl_api
47
+
48
+ #ifdef __cplusplus
49
+ }
50
+ #endif
51
+
52
+ #endif
53
+
54
+ #else
55
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
56
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_sycl.h ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2020-2024 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_SYCL_H
19
+ #define ONEAPI_DNNL_DNNL_SYCL_H
20
+
21
+ #include "oneapi/dnnl/dnnl.h"
22
+
23
+ #include "oneapi/dnnl/dnnl_sycl_types.h"
24
+
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ /// @addtogroup dnnl_api
30
+ /// @{
31
+
32
+ /// @addtogroup dnnl_api_interop
33
+ /// @{
34
+
35
+ /// @addtogroup dnnl_api_sycl_interop
36
+ /// @{
37
+
38
+ /// Creates an engine associated with a SYCL device and a SYCL context.
39
+ ///
40
+ /// @param engine Output engine.
41
+ /// @param device Pointer to the SYCL device to use for the engine.
42
+ /// @param context Pointer to the SYCL context to use for the engine.
43
+ /// @returns #dnnl_success on success and a status describing the error
44
+ /// otherwise.
45
+ dnnl_status_t DNNL_API dnnl_sycl_interop_engine_create(
46
+ dnnl_engine_t *engine, const void *device, const void *context);
47
+
48
+ /// Returns the SYCL context associated with an engine.
49
+ ///
50
+ /// @param engine Engine to query.
51
+ /// @param context Pointer to the underlying SYCL context of the engine.
52
+ /// @returns #dnnl_success on success and a status describing the error
53
+ /// otherwise.
54
+ dnnl_status_t DNNL_API dnnl_sycl_interop_engine_get_context(
55
+ dnnl_engine_t engine, void **context);
56
+
57
+ /// Returns the SYCL device associated with an engine.
58
+ ///
59
+ /// @param engine Engine to query.
60
+ /// @param device Pointer to the underlying SYCL device of the engine.
61
+ /// @returns #dnnl_success on success and a status describing the error
62
+ /// otherwise.
63
+ dnnl_status_t DNNL_API dnnl_sycl_interop_engine_get_device(
64
+ dnnl_engine_t engine, void **device);
65
+
66
+ /// Creates a memory object.
67
+ ///
68
+ /// Unless @p handle is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the
69
+ /// constructed memory object will have the underlying buffer set. In this
70
+ /// case, the buffer will be initialized as if:
71
+ /// - dnnl_memory_set_data_handle() had been called, if @p memory_kind is equal
72
+ /// to dnnl_sycl_interop_usm, or
73
+ /// - dnnl_sycl_interop_memory_set_buffer() has been called, if @p memory_kind
74
+ /// is equal to dnnl_sycl_interop_buffer.
75
+ ///
76
+ /// @param memory Output memory object.
77
+ /// @param memory_desc Memory descriptor.
78
+ /// @param engine Engine to use.
79
+ /// @param memory_kind Memory allocation kind to specify the type of handle.
80
+ /// @param handle Handle of the memory buffer to use as an underlying storage.
81
+ /// - A USM pointer to the user-allocated buffer. In this case the library
82
+ /// doesn't own the buffer. Requires @p memory_kind to be equal to
83
+ /// dnnl_sycl_interop_usm.
84
+ /// - A pointer to SYCL buffer. In this case the library doesn't own the
85
+ /// buffer. Requires @p memory_kind be equal to be equal to
86
+ /// dnnl_sycl_interop_buffer.
87
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
88
+ /// allocate the buffer that corresponds to the memory allocation kind
89
+ /// @p memory_kind for the memory object. In this case the library
90
+ /// owns the buffer.
91
+ /// - The DNNL_MEMORY_NONE specific value. Instructs the library to
92
+ /// create memory object without an underlying buffer.
93
+ /// @returns #dnnl_success on success and a status describing the error
94
+ /// otherwise.
95
+ dnnl_status_t DNNL_API dnnl_sycl_interop_memory_create(dnnl_memory_t *memory,
96
+ const_dnnl_memory_desc_t memory_desc, dnnl_engine_t engine,
97
+ dnnl_sycl_interop_memory_kind_t memory_kind, void *handle);
98
+
99
+ #ifdef DNNL_EXPERIMENTAL_SPARSE
100
+ /// Creates a memory object with multiple handles.
101
+ ///
102
+ /// @param memory Output memory object.
103
+ /// @param memory_desc Memory descriptor.
104
+ /// @param engine Engine to use.
105
+ /// @param memory_kind Memory allocation kind to specify the type of handles.
106
+ /// @param nhandles Number of handles.
107
+ /// @param handles Handles of the memory buffers to use as underlying storages.
108
+ /// For each element of the @p handles array the following applies:
109
+ /// - A USM pointer to the user-allocated buffer. In this case the library
110
+ /// doesn't own the buffer. Requires @p memory_kind to be equal to
111
+ /// dnnl_sycl_interop_usm.
112
+ /// - A pointer to SYCL buffer. In this case the library doesn't own the
113
+ /// buffer. Requires @p memory_kind be equal to be equal to
114
+ /// dnnl_sycl_interop_buffer.
115
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
116
+ /// allocate the buffer that corresponds to the memory allocation kind
117
+ /// @p memory_kind for the memory object. In this case the library
118
+ /// owns the buffer.
119
+ /// - The DNNL_MEMORY_NONE specific value. Instructs the library to
120
+ /// create memory object without an underlying buffer.
121
+ /// @returns #dnnl_success on success and a status describing the error
122
+ /// otherwise.
123
+ dnnl_status_t DNNL_API dnnl_sycl_interop_memory_create_v2(dnnl_memory_t *memory,
124
+ const_dnnl_memory_desc_t memory_desc, dnnl_engine_t engine,
125
+ dnnl_sycl_interop_memory_kind_t memory_kind, int nhandles,
126
+ void **handles);
127
+ #endif
128
+
129
+ /// Returns the memory allocation kind associated with a memory object.
130
+ ///
131
+ /// @param memory Memory to query.
132
+ /// @param memory_kind Output underlying memory allocation kind of the memory
133
+ /// object.
134
+ /// @returns #dnnl_success on success and a status describing the error
135
+ /// otherwise.
136
+ dnnl_status_t DNNL_API dnnl_sycl_interop_memory_get_memory_kind(
137
+ const_dnnl_memory_t memory,
138
+ dnnl_sycl_interop_memory_kind_t *memory_kind);
139
+
140
+ /// Sets a SYCL buffer for a memory object.
141
+ ///
142
+ /// @param memory Memory object.
143
+ /// @param buffer SYCL buffer to be set in the memory object.
144
+ /// @returns #dnnl_success on success and a status describing the error
145
+ /// otherwise.
146
+ dnnl_status_t DNNL_API dnnl_sycl_interop_memory_set_buffer(
147
+ dnnl_memory_t memory, void *buffer);
148
+
149
+ /// Creates an execution stream for a given engine associated with a SYCL
150
+ /// queue.
151
+ ///
152
+ /// @param stream Output execution stream.
153
+ /// @param engine Engine to create the execution stream on.
154
+ /// @param queue SYCL queue to use.
155
+ /// @returns #dnnl_success on success and a status describing the error
156
+ /// otherwise.
157
+ dnnl_status_t DNNL_API dnnl_sycl_interop_stream_create(
158
+ dnnl_stream_t *stream, dnnl_engine_t engine, void *queue);
159
+
160
+ /// Returns the SYCL queue associated with an execution stream.
161
+ ///
162
+ /// @param stream Execution stream to query.
163
+ /// @param queue Output SYCL command queue.
164
+ /// @returns #dnnl_success on success and a status describing the error
165
+ /// otherwise.
166
+ dnnl_status_t DNNL_API dnnl_sycl_interop_stream_get_queue(
167
+ dnnl_stream_t stream, void **queue);
168
+
169
+ /// Executes computations specified by the primitive in a specified stream and
170
+ /// returns a SYCL event.
171
+ ///
172
+ /// @param primitive Primitive to execute.
173
+ /// @param stream Stream to use.
174
+ /// @param nargs Number of arguments.
175
+ /// @param args Array of arguments. Each argument is an
176
+ /// <index, #dnnl_memory_t> pair. The index is one of the `DNNL_ARG_*`
177
+ /// values such as `DNNL_ARG_SRC`. Unless runtime shapes are used (see
178
+ /// #DNNL_RUNTIME_DIM_VAL), the memory object must have the same memory
179
+ /// descriptor as that returned by
180
+ /// #dnnl_primitive_desc_query_md(#dnnl_query_exec_arg_md, index).
181
+ /// @param deps A pointer to std::vector<sycl::event> that contains
182
+ /// dependencies.
183
+ /// @param return_event Output event.
184
+ /// @returns #dnnl_success on success and a status describing the error
185
+ /// otherwise.
186
+ dnnl_status_t DNNL_API dnnl_sycl_interop_primitive_execute(
187
+ const_dnnl_primitive_t primitive, dnnl_stream_t stream, int nargs,
188
+ const dnnl_exec_arg_t *args, const void *deps, void *return_event);
189
+
190
+ /// @} dnnl_api_sycl_interop
191
+
192
+ /// @} dnnl_api_interop
193
+
194
+ /// @} dnnl_api
195
+
196
+ #ifdef __cplusplus
197
+ }
198
+ #endif
199
+
200
+ #endif
201
+
202
+ #else
203
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
204
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_sycl.hpp ADDED
@@ -0,0 +1,389 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2020-2025 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_SYCL_HPP
19
+ #define ONEAPI_DNNL_DNNL_SYCL_HPP
20
+
21
+ /// @cond DO_NOT_DOCUMENT_THIS
22
+ #include <algorithm>
23
+ #include <cstdlib>
24
+ #include <iterator>
25
+ #include <memory>
26
+ #include <string>
27
+ #include <vector>
28
+ #include <unordered_map>
29
+
30
+ #if __has_include(<sycl/sycl.hpp>)
31
+ #include <sycl/sycl.hpp>
32
+ #else
33
+ #error "Unsupported compiler"
34
+ #endif
35
+
36
+ #include "oneapi/dnnl/dnnl.hpp"
37
+ #include "oneapi/dnnl/dnnl_sycl.h"
38
+
39
+ /// @endcond
40
+
41
+ /// @addtogroup dnnl_api
42
+ /// @{
43
+
44
+ namespace dnnl {
45
+
46
+ /// @addtogroup dnnl_api_interop
47
+ /// @{
48
+
49
+ /// @addtogroup dnnl_api_sycl_interop SYCL interoperability API
50
+ /// API extensions to interact with the underlying SYCL run-time.
51
+ ///
52
+ /// @sa @ref dev_guide_dpcpp_interoperability in developer guide
53
+ /// @{
54
+
55
+ /// SYCL interoperability namespace
56
+ namespace sycl_interop {
57
+
58
+ /// Memory allocation kind.
59
+ enum class memory_kind {
60
+ /// USM (device, shared, host, or unknown) memory allocation kind - default.
61
+ usm = dnnl_sycl_interop_usm,
62
+ /// Buffer memory allocation kind.
63
+ buffer = dnnl_sycl_interop_buffer,
64
+ };
65
+
66
+ /// Converts a memory allocation kind enum value from C++ API to C API type.
67
+ ///
68
+ /// @param akind C++ API memory allocation kind enum value.
69
+ /// @returns Corresponding C API memory allocation kind enum value.
70
+ inline dnnl_sycl_interop_memory_kind_t convert_to_c(memory_kind akind) {
71
+ return static_cast<dnnl_sycl_interop_memory_kind_t>(akind);
72
+ }
73
+
74
+ /// Constructs an engine from SYCL device and context objects.
75
+ ///
76
+ /// @param adevice SYCL device.
77
+ /// @param acontext SYCL context.
78
+ ///
79
+ /// @returns Created engine.
80
+ inline engine make_engine(
81
+ const sycl::device &adevice, const sycl::context &acontext) {
82
+ dnnl_engine_t aengine;
83
+ error::wrap_c_api(dnnl_sycl_interop_engine_create(&aengine,
84
+ static_cast<const void *>(&adevice),
85
+ static_cast<const void *>(&acontext)),
86
+ "could not create an engine");
87
+ return engine(aengine);
88
+ }
89
+
90
+ /// Returns the SYCL context associated with an engine.
91
+ ///
92
+ /// @param aengine Engine to query.
93
+ ///
94
+ /// @returns The underlying SYCL device of the engine.
95
+ inline sycl::context get_context(const engine &aengine) {
96
+ void *ctx_ptr;
97
+ error::wrap_c_api(
98
+ dnnl_sycl_interop_engine_get_context(aengine.get(), &ctx_ptr),
99
+ "could not get a context handle");
100
+ auto ctx = *static_cast<sycl::context *>(ctx_ptr);
101
+ return ctx;
102
+ }
103
+
104
+ /// Returns the SYCL device associated with an engine.
105
+ ///
106
+ /// @param aengine Engine to query.
107
+ ///
108
+ /// @returns The underlying SYCL context of the engine.
109
+ inline sycl::device get_device(const engine &aengine) {
110
+ void *dev_ptr;
111
+ error::wrap_c_api(
112
+ dnnl_sycl_interop_engine_get_device(aengine.get(), &dev_ptr),
113
+ "could not get a device handle");
114
+ auto dev = *static_cast<sycl::device *>(dev_ptr);
115
+ return dev;
116
+ }
117
+
118
+ /// Creates an execution stream for a given engine associated with a SYCL
119
+ /// queue.
120
+ ///
121
+ /// @param aengine Engine object to use for the stream.
122
+ /// @param aqueue SYCL queue to use for the stream.
123
+ ///
124
+ /// @returns An execution stream.
125
+ inline stream make_stream(const engine &aengine, sycl::queue &aqueue) {
126
+ dnnl_stream_t astream;
127
+ error::wrap_c_api(
128
+ dnnl_sycl_interop_stream_create(&astream, aengine.get(), &aqueue),
129
+ "could not create a stream");
130
+ return stream(astream);
131
+ }
132
+
133
+ /// Returns the SYCL queue associated with an execution stream.
134
+ ///
135
+ /// @param astream Execution stream to query.
136
+ ///
137
+ /// @returns SYCL queue object.
138
+ inline sycl::queue get_queue(const stream &astream) {
139
+ void *queue_ptr;
140
+ error::wrap_c_api(
141
+ dnnl_sycl_interop_stream_get_queue(astream.get(), &queue_ptr),
142
+ "could not get a stream handle");
143
+ auto queue = *static_cast<sycl::queue *>(queue_ptr);
144
+ return queue;
145
+ }
146
+
147
+ /// Returns the SYCL buffer associated with a memory object.
148
+ ///
149
+ /// Throws an exception if the memory allocation kind associated with the
150
+ /// memory object is not equal to dnnl::sycl_interop::memory_kind::buffer.
151
+ ///
152
+ /// @tparam T Type of the requested buffer.
153
+ /// @tparam ndims Number of dimensions of the requested buffer.
154
+ /// @param amemory Memory object.
155
+ ///
156
+ /// @returns SYCL buffer associated with the memory object.
157
+ template <typename T, int ndims = 1>
158
+ sycl::buffer<T, ndims> get_buffer(const memory &amemory) {
159
+ static_assert(ndims == 1, "only 1D buffers supported");
160
+
161
+ // XXX: workaround: when CPU runtime is not SYCL and amemory was created
162
+ // for CPU engine `get_buffer` should return an error. Use interop API to
163
+ // implement the check.
164
+ dnnl_sycl_interop_memory_kind_t ckind;
165
+ error::wrap_c_api(
166
+ dnnl_sycl_interop_memory_get_memory_kind(amemory.get(), &ckind),
167
+ "could not get SYCL buffer object");
168
+
169
+ void *handle_ptr;
170
+ error::wrap_c_api(dnnl_memory_get_data_handle(amemory.get(), &handle_ptr),
171
+ "could not get SYCL buffer object");
172
+
173
+ // XXX: workaround: zero-range buffer cannot be constructed.
174
+ if (!handle_ptr) return sycl::buffer<T, ndims>(sycl::range<1>(1));
175
+
176
+ auto &buf_u8 = *static_cast<sycl::buffer<uint8_t, 1> *>(handle_ptr);
177
+
178
+ auto range = sycl::range<1>(buf_u8.byte_size() / sizeof(T));
179
+ return buf_u8.reinterpret<T, 1>(range);
180
+ }
181
+
182
+ /// Sets SYCL buffer associated with a memory object.
183
+ ///
184
+ /// @tparam T Type of the buffer.
185
+ /// @tparam ndims Number of dimensions of the buffer.
186
+ /// @param amemory Memory object to change.
187
+ /// @param abuffer SYCL buffer.
188
+ template <typename T, int ndims>
189
+ void set_buffer(memory &amemory, sycl::buffer<T, ndims> &abuffer) {
190
+ auto range = sycl::range<1>(abuffer.byte_size());
191
+ auto buf_u8 = abuffer.template reinterpret<uint8_t, 1>(range);
192
+ error::wrap_c_api(dnnl_sycl_interop_memory_set_buffer(
193
+ amemory.get(), static_cast<void *>(&buf_u8)),
194
+ "could not set SYCL buffer object");
195
+ }
196
+
197
+ /// Returns the memory allocation kind associated with a memory object.
198
+ ///
199
+ /// @param amemory A memory object.
200
+ ///
201
+ /// @returns The underlying memory allocation kind of the memory object.
202
+ inline memory_kind get_memory_kind(const memory &amemory) {
203
+ dnnl_sycl_interop_memory_kind_t ckind;
204
+ error::wrap_c_api(
205
+ dnnl_sycl_interop_memory_get_memory_kind(amemory.get(), &ckind),
206
+ "could not get memory kind");
207
+ return static_cast<memory_kind>(ckind);
208
+ }
209
+
210
+ #ifdef DNNL_EXPERIMENTAL_SPARSE
211
+ /// Creates a memory object with multiple handles.
212
+ ///
213
+ /// @param memory_desc Memory descriptor.
214
+ /// @param aengine Engine to use.
215
+ /// @param kind Memory allocation kind to specify the type of handles.
216
+ /// @param handles Handles of the memory buffers to use as underlying storages.
217
+ /// For each element of the @p handles array the following applies:
218
+ /// - A USM pointer to the user-allocated buffer. In this case the library
219
+ /// doesn't own the buffer. Requires @p memory_kind to be equal to
220
+ /// dnnl::sycl_interop::memory_kind::usm.
221
+ /// - A pointer to SYCL buffer. In this case the library doesn't own the
222
+ /// buffer. Requires @p memory_kind be equal to be equal to
223
+ /// dnnl::sycl_interop::memory_kind::buffer.
224
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
225
+ /// allocate the buffer that corresponds to the memory allocation kind
226
+ /// @p memory_kind for the memory object. In this case the library
227
+ /// owns the buffer.
228
+ /// - The DNNL_MEMORY_NONE specific value. Instructs the library to
229
+ /// create memory object without an underlying buffer.
230
+ ///
231
+ /// If the @p handles vector is not provided the library will allocate all
232
+ /// buffers as if all handles have the special value DNNL_MEMORY_ALLOCATE.
233
+ ///
234
+ /// @returns Created memory object.
235
+ inline memory make_memory(const memory::desc &memory_desc,
236
+ const engine &aengine, memory_kind kind,
237
+ std::vector<void *> handles = {}) {
238
+ if (handles.empty()) {
239
+ const int nhandles = memory_desc.get_num_handles();
240
+ handles.resize(nhandles, DNNL_MEMORY_ALLOCATE);
241
+ }
242
+
243
+ dnnl_memory_t c_memory;
244
+ error::wrap_c_api(
245
+ dnnl_sycl_interop_memory_create_v2(&c_memory, memory_desc.get(),
246
+ aengine.get(), convert_to_c(kind), (int)handles.size(),
247
+ handles.data()),
248
+ "could not create a memory");
249
+ return memory(c_memory);
250
+ }
251
+
252
+ /// Creates a memory object.
253
+ ///
254
+ /// Unless @p handle is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the
255
+ /// constructed memory object will have the underlying buffer set. In this
256
+ /// case, the buffer will be initialized as if:
257
+ /// - dnnl::memory::set_data_handle() had been called, if @p memory_kind is
258
+ /// equal to dnnl::sycl_interop::memory_kind::usm, or
259
+ /// - dnnl::sycl_interop::set_buffer() has been called, if @p memory_kind is
260
+ /// equal to dnnl::sycl_interop::memory_kind::buffer.
261
+ ///
262
+ /// @param memory_desc Memory descriptor.
263
+ /// @param aengine Engine to use.
264
+ /// @param kind Memory allocation kind to specify the type of handle.
265
+ /// @param handle Handle of the memory buffer to use as an underlying storage.
266
+ /// - A USM pointer to the user-allocated buffer. In this case the library
267
+ /// doesn't own the buffer. Requires @p memory_kind to be equal to
268
+ /// dnnl::sycl_interop::memory_kind::usm.
269
+ /// - A pointer to SYCL buffer. In this case the library doesn't own the
270
+ /// buffer. Requires @p memory_kind be equal to be equal to
271
+ /// dnnl::sycl_interop::memory_kind::buffer.
272
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
273
+ /// allocate the buffer that corresponds to the memory allocation kind
274
+ /// @p memory_kind for the memory object. In this case the library
275
+ /// owns the buffer.
276
+ /// - The DNNL_MEMORY_NONE specific value. Instructs the library to
277
+ /// create memory object without an underlying buffer.
278
+ ///
279
+ /// @returns Created memory object.
280
+ inline memory make_memory(const memory::desc &memory_desc,
281
+ const engine &aengine, memory_kind kind, void *handle) {
282
+ return make_memory(
283
+ memory_desc, aengine, kind, std::vector<void *> {handle});
284
+ }
285
+ #else
286
+
287
+ /// Creates a memory object.
288
+ ///
289
+ /// Unless @p handle is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the
290
+ /// constructed memory object will have the underlying buffer set. In this
291
+ /// case, the buffer will be initialized as if:
292
+ /// - dnnl::memory::set_data_handle() had been called, if @p memory_kind is
293
+ /// equal to dnnl::sycl_interop::memory_kind::usm, or
294
+ /// - dnnl::sycl_interop::set_buffer() has been called, if @p memory_kind is
295
+ /// equal to dnnl::sycl_interop::memory_kind::buffer.
296
+ ///
297
+ /// @param memory_desc Memory descriptor.
298
+ /// @param aengine Engine to use.
299
+ /// @param kind Memory allocation kind to specify the type of handle.
300
+ /// @param handle Handle of the memory buffer to use as an underlying storage.
301
+ /// - A USM pointer to the user-allocated buffer. In this case the library
302
+ /// doesn't own the buffer. Requires @p memory_kind to be equal to
303
+ /// dnnl::sycl_interop::memory_kind::usm.
304
+ /// - A pointer to SYCL buffer. In this case the library doesn't own the
305
+ /// buffer. Requires @p memory_kind be equal to be equal to
306
+ /// dnnl::sycl_interop::memory_kind::buffer.
307
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
308
+ /// allocate the buffer that corresponds to the memory allocation kind
309
+ /// @p memory_kind for the memory object. In this case the library
310
+ /// owns the buffer.
311
+ /// - The DNNL_MEMORY_NONE specific value. Instructs the library to
312
+ /// create memory object without an underlying buffer.
313
+ ///
314
+ /// @returns Created memory object.
315
+ inline memory make_memory(const memory::desc &memory_desc,
316
+ const engine &aengine, memory_kind kind,
317
+ void *handle = DNNL_MEMORY_ALLOCATE) {
318
+ dnnl_memory_t c_memory;
319
+ error::wrap_c_api(
320
+ dnnl_sycl_interop_memory_create(&c_memory, memory_desc.get(),
321
+ aengine.get(), convert_to_c(kind), handle),
322
+ "could not create a memory");
323
+ return memory(c_memory);
324
+ }
325
+ #endif
326
+
327
+ /// Constructs a memory object from a SYCL buffer.
328
+ ///
329
+ /// @param memory_desc Memory descriptor.
330
+ /// @param aengine Engine to use.
331
+ /// @param abuffer A SYCL buffer to use.
332
+ ///
333
+ /// @returns Created memory object.
334
+ template <typename T, int ndims = 1>
335
+ memory make_memory(const memory::desc &memory_desc, const engine &aengine,
336
+ sycl::buffer<T, ndims> &abuffer) {
337
+ memory amemory(memory_desc, aengine, DNNL_MEMORY_NONE);
338
+ set_buffer(amemory, abuffer);
339
+ return amemory;
340
+ }
341
+
342
+ /// Executes computations specified by the primitive in a specified stream and
343
+ /// returns a SYCL event.
344
+ ///
345
+ /// Arguments are passed via an arguments map containing
346
+ /// <index, memory object> pairs. The index must be one of the `DNNL_ARG_*`
347
+ /// values such as `DNNL_ARG_SRC`, and the memory must have a memory descriptor
348
+ /// matching the one returned by
349
+ /// #dnnl::primitive_desc::query_md(#query::exec_arg_md, index) unless using
350
+ /// dynamic shapes (see #DNNL_RUNTIME_DIM_VAL).
351
+ ///
352
+ /// @param aprimitive Primitive to execute.
353
+ /// @param astream Stream object. The stream must belong to the same engine
354
+ /// as the primitive.
355
+ /// @param args Arguments map.
356
+ /// @param deps Optional vector with `sycl::event` dependencies.
357
+ ///
358
+ /// @returns Output event.
359
+ inline sycl::event execute(const dnnl::primitive &aprimitive,
360
+ const stream &astream, const std::unordered_map<int, memory> &args,
361
+ const std::vector<sycl::event> &deps = {}) {
362
+ std::vector<dnnl_exec_arg_t> c_args;
363
+ c_args.reserve(args.size());
364
+ for (const auto &a : args)
365
+ c_args.push_back({a.first, a.second.get()});
366
+
367
+ sycl::event return_event;
368
+ error::wrap_c_api(
369
+ dnnl_sycl_interop_primitive_execute(aprimitive.get(), astream.get(),
370
+ (int)c_args.size(), c_args.data(), &deps, &return_event),
371
+ "could not execute a primitive");
372
+ return return_event;
373
+ }
374
+
375
+ } // namespace sycl_interop
376
+
377
+ /// @} dnnl_api_sycl_interop
378
+
379
+ /// @} dnnl_api_interop
380
+
381
+ } // namespace dnnl
382
+
383
+ /// @} dnnl_api
384
+
385
+ #endif // DNNL_SYCL_HPP
386
+
387
+ #else
388
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
389
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_sycl_types.h ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2020-2021 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_SYCL_TYPES_H
19
+ #define ONEAPI_DNNL_DNNL_SYCL_TYPES_H
20
+
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif
24
+
25
+ /// @addtogroup dnnl_api
26
+ /// @{
27
+
28
+ /// @addtogroup dnnl_api_interop
29
+ /// @{
30
+
31
+ /// @addtogroup dnnl_api_sycl_interop
32
+ /// @{
33
+
34
+ /// Memory allocation kind.
35
+ typedef enum {
36
+ /// USM (device, shared, host, or unknown) memory allocation kind - default.
37
+ dnnl_sycl_interop_usm,
38
+ /// Buffer memory allocation kind.
39
+ dnnl_sycl_interop_buffer,
40
+ } dnnl_sycl_interop_memory_kind_t;
41
+
42
+ /// @} dnnl_api_sycl_interop
43
+
44
+ /// @} dnnl_api_interop
45
+
46
+ /// @} dnnl_api
47
+
48
+ #ifdef __cplusplus
49
+ }
50
+ #endif
51
+
52
+ #endif
53
+
54
+ #else
55
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
56
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_threadpool.h ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2020-2022 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_THREADPOOL_H
19
+ #define ONEAPI_DNNL_DNNL_THREADPOOL_H
20
+
21
+ #include "oneapi/dnnl/dnnl_config.h"
22
+ #include "oneapi/dnnl/dnnl_types.h"
23
+
24
+ #ifdef __cplusplus
25
+ extern "C" {
26
+ #endif
27
+
28
+ /// @addtogroup dnnl_api
29
+ /// @{
30
+
31
+ /// @addtogroup dnnl_api_interop
32
+ /// @{
33
+
34
+ /// @addtogroup dnnl_api_threadpool_interop
35
+ /// @{
36
+
37
+ /// Creates an execution stream with specified threadpool.
38
+ ///
39
+ /// @sa @ref dev_guide_threadpool
40
+ ///
41
+ /// @param stream Output execution stream.
42
+ /// @param engine Engine to create the execution stream on.
43
+ /// @param threadpool Pointer to an instance of a C++ class that implements
44
+ /// dnnl::threapdool_iface interface.
45
+ /// @returns #dnnl_success on success and a status describing the error
46
+ /// otherwise.
47
+ dnnl_status_t DNNL_API dnnl_threadpool_interop_stream_create(
48
+ dnnl_stream_t *stream, dnnl_engine_t engine, void *threadpool);
49
+
50
+ /// Returns a threadpool to be used by the execution stream.
51
+ ///
52
+ /// @sa @ref dev_guide_threadpool
53
+ ///
54
+ /// @param astream Execution stream.
55
+ /// @param threadpool Output pointer to an instance of a C++ class that
56
+ /// implements dnnl::threapdool_iface interface. Set to NULL if the
57
+ /// stream was created without threadpool.
58
+ /// @returns #dnnl_success on success and a status describing the error
59
+ /// otherwise.
60
+ dnnl_status_t DNNL_API dnnl_threadpool_interop_stream_get_threadpool(
61
+ dnnl_stream_t astream, void **threadpool);
62
+
63
+ /// Sets the maximum concurrency assumed by oneDNN when outside a
64
+ /// parallel call.
65
+ ///
66
+ /// @param max_concurrency The maximum concurrency assumed by oneDNN
67
+ /// when outside a parallel call. This is a threadlocal setting.
68
+ /// @returns #dnnl_success on success and a status describing the
69
+ /// error otherwise.
70
+ dnnl_status_t DNNL_API dnnl_threadpool_interop_set_max_concurrency(
71
+ int max_concurrency);
72
+
73
+ /// Gets the maximum concurrency assumed by oneDNN when outside a
74
+ /// parallel call.
75
+ ///
76
+ /// @param max_concurrency The maximum concurrency assumed by oneDNN
77
+ /// when outside a parallel call. This is a threadlocal setting.
78
+ /// @returns #dnnl_success on success and a status describing the
79
+ /// error otherwise.
80
+ dnnl_status_t DNNL_API dnnl_threadpool_interop_get_max_concurrency(
81
+ int *max_concurrency);
82
+
83
+ /// @copydoc dnnl_sgemm()
84
+ /// @param threadpool A pointer to a threadpool interface (only when built with
85
+ /// the THREADPOOL CPU runtime).
86
+ dnnl_status_t DNNL_API dnnl_threadpool_interop_sgemm(char transa, char transb,
87
+ dnnl_dim_t M, dnnl_dim_t N, dnnl_dim_t K, float alpha, const float *A,
88
+ dnnl_dim_t lda, const float *B, dnnl_dim_t ldb, float beta, float *C,
89
+ dnnl_dim_t ldc, void *threadpool);
90
+
91
+ /// @copydoc dnnl_gemm_u8s8s32()
92
+ /// @param threadpool A pointer to a threadpool interface (only when built with
93
+ /// the THREADPOOL CPU runtime).
94
+ dnnl_status_t DNNL_API dnnl_threadpool_interop_gemm_u8s8s32(char transa,
95
+ char transb, char offsetc, dnnl_dim_t M, dnnl_dim_t N, dnnl_dim_t K,
96
+ float alpha, const uint8_t *A, dnnl_dim_t lda, uint8_t ao,
97
+ const int8_t *B, dnnl_dim_t ldb, int8_t bo, float beta, int32_t *C,
98
+ dnnl_dim_t ldc, const int32_t *co, void *threadpool);
99
+
100
+ /// @copydoc dnnl_gemm_s8s8s32()
101
+ /// @param threadpool A pointer to a threadpool interface (only when built with
102
+ /// the THREADPOOL CPU runtime).
103
+ dnnl_status_t DNNL_API dnnl_threadpool_interop_gemm_s8s8s32(char transa,
104
+ char transb, char offsetc, dnnl_dim_t M, dnnl_dim_t N, dnnl_dim_t K,
105
+ float alpha, const int8_t *A, dnnl_dim_t lda, int8_t ao,
106
+ const int8_t *B, dnnl_dim_t ldb, int8_t bo, float beta, int32_t *C,
107
+ dnnl_dim_t ldc, const int32_t *co, void *threadpool);
108
+
109
+ /// @} dnnl_api_threadpool_interop
110
+
111
+ /// @} dnnl_api_interop
112
+
113
+ /// @} dnnl_api
114
+
115
+ #ifdef __cplusplus
116
+ }
117
+ #endif
118
+
119
+ #endif
120
+
121
+ #else
122
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
123
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_threadpool.hpp ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2020-2025 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_THREADPOOL_HPP
19
+ #define ONEAPI_DNNL_DNNL_THREADPOOL_HPP
20
+
21
+ #include "oneapi/dnnl/dnnl.hpp"
22
+ #include "oneapi/dnnl/dnnl_threadpool.h"
23
+
24
+ #include "oneapi/dnnl/dnnl_threadpool_iface.hpp"
25
+
26
+ /// @addtogroup dnnl_api
27
+ /// @{
28
+
29
+ namespace dnnl {
30
+
31
+ /// @addtogroup dnnl_api_interop
32
+ /// @{
33
+
34
+ /// @addtogroup dnnl_api_threadpool_interop Threadpool interoperability API
35
+ /// API extensions to interact with the underlying Threadpool run-time.
36
+ /// @{
37
+
38
+ /// Threadpool interoperability namespace
39
+ namespace threadpool_interop {
40
+
41
+ /// Constructs an execution stream for the specified engine and threadpool.
42
+ ///
43
+ /// @sa @ref dev_guide_threadpool
44
+ ///
45
+ /// @param aengine Engine to create the stream on.
46
+ /// @param threadpool Pointer to an instance of a C++ class that implements
47
+ /// dnnl::threapdool_iface interface.
48
+ /// @returns An execution stream.
49
+ inline dnnl::stream make_stream(
50
+ const dnnl::engine &aengine, threadpool_iface *threadpool) {
51
+ dnnl_stream_t c_stream;
52
+ dnnl::error::wrap_c_api(dnnl_threadpool_interop_stream_create(
53
+ &c_stream, aengine.get(), threadpool),
54
+ "could not create stream");
55
+ return dnnl::stream(c_stream);
56
+ }
57
+
58
+ /// Returns the pointer to a threadpool that is used by an execution stream.
59
+ ///
60
+ /// @sa @ref dev_guide_threadpool
61
+ ///
62
+ /// @param astream An execution stream.
63
+ /// @returns Output pointer to an instance of a C++ class that implements
64
+ /// dnnl::threapdool_iface interface or NULL if the stream was created
65
+ /// without threadpool.
66
+ inline threadpool_iface *get_threadpool(const dnnl::stream &astream) {
67
+ void *tp;
68
+ dnnl::error::wrap_c_api(
69
+ dnnl_threadpool_interop_stream_get_threadpool(astream.get(), &tp),
70
+ "could not get stream threadpool");
71
+ return static_cast<threadpool_iface *>(tp);
72
+ }
73
+
74
+ /// @copydoc dnnl_threadpool_interop_sgemm()
75
+ inline status sgemm(char transa, char transb, dnnl_dim_t M, dnnl_dim_t N,
76
+ dnnl_dim_t K, float alpha, const float *A, dnnl_dim_t lda,
77
+ const float *B, dnnl_dim_t ldb, float beta, float *C, dnnl_dim_t ldc,
78
+ threadpool_iface *threadpool) {
79
+ return static_cast<status>(dnnl_threadpool_interop_sgemm(transa, transb, M,
80
+ N, K, alpha, A, lda, B, ldb, beta, C, ldc, threadpool));
81
+ }
82
+ /// @copydoc dnnl_threadpool_interop_gemm_u8s8s32()
83
+ inline status gemm_u8s8s32(char transa, char transb, char offsetc, dnnl_dim_t M,
84
+ dnnl_dim_t N, dnnl_dim_t K, float alpha, const uint8_t *A,
85
+ dnnl_dim_t lda, uint8_t ao, const int8_t *B, dnnl_dim_t ldb, int8_t bo,
86
+ float beta, int32_t *C, dnnl_dim_t ldc, const int32_t *co,
87
+ threadpool_iface *threadpool) {
88
+ return static_cast<status>(dnnl_threadpool_interop_gemm_u8s8s32(transa,
89
+ transb, offsetc, M, N, K, alpha, A, lda, ao, B, ldb, bo, beta, C,
90
+ ldc, co, threadpool));
91
+ }
92
+
93
+ /// @copydoc dnnl_threadpool_interop_gemm_s8s8s32()
94
+ inline status gemm_s8s8s32(char transa, char transb, char offsetc, dnnl_dim_t M,
95
+ dnnl_dim_t N, dnnl_dim_t K, float alpha, const int8_t *A,
96
+ dnnl_dim_t lda, int8_t ao, const int8_t *B, dnnl_dim_t ldb, int8_t bo,
97
+ float beta, int32_t *C, dnnl_dim_t ldc, const int32_t *co,
98
+ threadpool_iface *threadpool) {
99
+ return static_cast<status>(dnnl_threadpool_interop_gemm_s8s8s32(transa,
100
+ transb, offsetc, M, N, K, alpha, A, lda, ao, B, ldb, bo, beta, C,
101
+ ldc, co, threadpool));
102
+ }
103
+
104
+ } // namespace threadpool_interop
105
+
106
+ /// @} dnnl_api_threadpool_interop
107
+
108
+ /// @} dnnl_api_interop
109
+
110
+ } // namespace dnnl
111
+
112
+ /// @} dnnl_api
113
+
114
+ #endif
115
+
116
+ #else
117
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
118
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_threadpool_iface.hpp ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2020-2024 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_THREADPOOL_IFACE_HPP
19
+ #define ONEAPI_DNNL_DNNL_THREADPOOL_IFACE_HPP
20
+
21
+ #include <cstdint>
22
+ #include <functional>
23
+
24
+ /// @addtogroup dnnl_api
25
+ /// @{
26
+
27
+ namespace dnnl {
28
+
29
+ /// @addtogroup dnnl_api_interop
30
+ /// @{
31
+
32
+ /// @addtogroup dnnl_api_threadpool_interop
33
+ /// @{
34
+
35
+ namespace threadpool_interop {
36
+
37
+ /// Abstract threadpool interface. The users are expected to subclass this
38
+ /// interface and pass an object to the library during CPU stream creation or
39
+ /// directly in case of BLAS functions.
40
+ struct threadpool_iface {
41
+ /// Returns the number of worker threads.
42
+ virtual int get_num_threads() const = 0;
43
+
44
+ /// Returns true if the calling thread belongs to this threadpool.
45
+ virtual bool get_in_parallel() const = 0;
46
+
47
+ /// Submits n instances of a closure for execution in parallel:
48
+ ///
49
+ /// for (int i = 0; i < n; i++) fn(i, n);
50
+ ///
51
+ virtual void parallel_for(int n, const std::function<void(int, int)> &fn)
52
+ = 0;
53
+
54
+ /// Returns threadpool behavior flags bit mask (see below).
55
+ virtual uint64_t get_flags() const = 0;
56
+
57
+ /// If set, parallel_for() returns immediately and oneDNN needs implement
58
+ /// waiting for the submitted closures to finish execution on its own.
59
+ static constexpr uint64_t ASYNCHRONOUS = 1;
60
+
61
+ virtual ~threadpool_iface() {}
62
+ };
63
+
64
+ } // namespace threadpool_interop
65
+
66
+ /// @} dnnl_api_threadpool_interop
67
+
68
+ /// @} dnnl_api_interop
69
+
70
+ } // namespace dnnl
71
+
72
+ /// @} dnnl_api
73
+
74
+ #endif
75
+
76
+ #else
77
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
78
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_types.h ADDED
The diff for this file is too large to render. See raw diff
 
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_ukernel.h ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2024 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ /// @file
19
+ /// ukernel C API
20
+
21
+ #ifndef ONEAPI_DNNL_DNNL_UKERNEL_H
22
+ #define ONEAPI_DNNL_DNNL_UKERNEL_H
23
+
24
+ #include "oneapi/dnnl/dnnl.h"
25
+ #include "oneapi/dnnl/dnnl_ukernel_types.h"
26
+
27
+ #ifdef __cplusplus
28
+ extern "C" {
29
+ #endif
30
+
31
+ /// @addtogroup dnnl_api
32
+ /// @{
33
+
34
+ /// @addtogroup dnnl_api_ukernel
35
+ /// @{
36
+
37
+ #ifdef DNNL_EXPERIMENTAL_UKERNEL
38
+
39
+ /// Creates a ukernel attributes memory storage.
40
+ ///
41
+ /// @param attr_params Output ukernel attributes memory storage.
42
+ /// @returns #dnnl_success on success and a status describing the error
43
+ /// otherwise.
44
+ dnnl_status_t DNNL_API dnnl_ukernel_attr_params_create(
45
+ dnnl_ukernel_attr_params_t *attr_params);
46
+
47
+ /// Sets post-operations arguments to a storage.
48
+ ///
49
+ /// @param attr_params Memory pointers storage object.
50
+ /// @param post_ops_args A pointer to pointers of post_ops storages. Expected to
51
+ /// be packed together.
52
+ /// @returns #dnnl_success on success and a status describing the error
53
+ /// otherwise.
54
+ dnnl_status_t DNNL_API dnnl_ukernel_attr_params_set_post_ops_args(
55
+ dnnl_ukernel_attr_params_t attr_params, const void **post_ops_args);
56
+
57
+ /// Sets tensor A scales argument to a storage.
58
+ ///
59
+ /// @param attr_params Memory pointers storage object.
60
+ /// @param a_scales Pointer to the scales storage.
61
+ /// @returns #dnnl_success on success and a status describing the error
62
+ /// otherwise.
63
+ dnnl_status_t DNNL_API dnnl_ukernel_attr_params_set_A_scales(
64
+ dnnl_ukernel_attr_params_t attr_params, const void *a_scales);
65
+
66
+ /// Sets tensor B scales argument to a storage.
67
+ ///
68
+ /// If `dnnl_brgemm_set_B_scales` used mask of 2, then at least N values of
69
+ /// selected data type are expected.
70
+ ///
71
+ /// @param attr_params Memory pointers storage object.
72
+ /// @param b_scales Pointer to the scales storage.
73
+ /// @returns #dnnl_success on success and a status describing the error
74
+ /// otherwise.
75
+ dnnl_status_t DNNL_API dnnl_ukernel_attr_params_set_B_scales(
76
+ dnnl_ukernel_attr_params_t attr_params, const void *b_scales);
77
+
78
+ /// Sets tensor D scales argument to a storage.
79
+ ///
80
+ /// @param attr_params Memory pointers storage object.
81
+ /// @param d_scales Pointer to the scales storage.
82
+ /// @returns #dnnl_success on success and a status describing the error
83
+ /// otherwise.
84
+ dnnl_status_t DNNL_API dnnl_ukernel_attr_params_set_D_scales(
85
+ dnnl_ukernel_attr_params_t attr_params, const void *d_scales);
86
+
87
+ /// Destroys a ukernel attributes memory storage.
88
+ ///
89
+ /// @param attr_params Memory pointers storage object to destroy.
90
+ /// @returns #dnnl_success on success and a status describing the error
91
+ /// otherwise.
92
+ dnnl_status_t DNNL_API dnnl_ukernel_attr_params_destroy(
93
+ dnnl_ukernel_attr_params_t attr_params);
94
+
95
+ /// @addtogroup dnnl_api_ukernel_brgemm
96
+ /// @{
97
+
98
+ /// Creates a BRGeMM ukernel object. Operates by the following formula:
99
+ /// `C = [A x B]`.
100
+ ///
101
+ /// @param brgemm Output BRGeMM ukernel object.
102
+ /// @param M Dimension M of tensor A.
103
+ /// @param N Dimension N of tensor B.
104
+ /// @param K Dimension K of tensors A and B.
105
+ /// @param batch_size Number of batches to process.
106
+ /// @param lda Leading dimension of tensor A.
107
+ /// @param ldb Leading dimension of tensor B.
108
+ /// @param ldc Leading dimension of tensor C.
109
+ /// @param a_dt Data type of tensor A.
110
+ /// @param b_dt Data type of tensor B.
111
+ /// @param c_dt Data type of tensor C. Must be dnnl_f32.
112
+ /// @returns #dnnl_success on success and a status describing the error
113
+ /// otherwise.
114
+ dnnl_status_t DNNL_API dnnl_brgemm_create(dnnl_brgemm_t *brgemm, dnnl_dim_t M,
115
+ dnnl_dim_t N, dnnl_dim_t K, dnnl_dim_t batch_size, dnnl_dim_t lda,
116
+ dnnl_dim_t ldb, dnnl_dim_t ldc, dnnl_data_type_t a_dt,
117
+ dnnl_data_type_t b_dt, dnnl_data_type_t c_dt);
118
+
119
+ /// Sets adding an intermediate result to the output tensor C instead of
120
+ /// writing: `C += [A x B]`.
121
+ ///
122
+ /// @param brgemm BRGeMM ukernel object.
123
+ /// @param add_C Value to indicate addition. Can be `0` to skip addition, and
124
+ /// `1` to apply addition.
125
+ /// @returns #dnnl_success on success and a status describing the error
126
+ /// otherwise.
127
+ dnnl_status_t DNNL_API dnnl_brgemm_set_add_C(dnnl_brgemm_t brgemm, int add_C);
128
+
129
+ /// Sets post-operations to a BRGeMM ukernel object: `D = post-operations(C)`.
130
+ ///
131
+ /// Post-operations applies if one of the following holds:
132
+ /// * Non-empty attributes are specified.
133
+ /// * Output data type `d_dt` is different from accumulation data type `c_dt`.
134
+ ///
135
+ /// If any of conditions happens, the final call of the accumulation chain
136
+ /// must be `dnnl_brgemm_execute_postops`, and `dnnl_brgemm_execute`, otherwise.
137
+ ///
138
+ /// @param brgemm BRGeMM ukernel object.
139
+ /// @param ldd Leading dimension of tensor D.
140
+ /// @param d_dt Data type of tensor D.
141
+ /// @param post_ops Primitive post operations attribute to extend the kernel
142
+ /// operations.
143
+ /// @returns #dnnl_success on success and a status describing the error
144
+ /// otherwise.
145
+ dnnl_status_t DNNL_API dnnl_brgemm_set_post_ops(dnnl_brgemm_t brgemm,
146
+ dnnl_dim_t ldd, dnnl_data_type_t d_dt, const_dnnl_post_ops_t post_ops);
147
+
148
+ /// Sets tensor A scales mask to a BRGeMM ukernel object.
149
+ ///
150
+ /// For quantization flavor tensor A scales apply to accumulation buffer once C
151
+ /// is ready.
152
+ ///
153
+ /// @param brgemm BRGeMM ukernel object.
154
+ /// @param a_scale_mask Tensor A scale mask. Can be `0` only.
155
+ dnnl_status_t DNNL_API dnnl_brgemm_set_A_scales(
156
+ dnnl_brgemm_t brgemm, int a_scale_mask);
157
+
158
+ /// Sets tensor B scales mask to a BRGeMM ukernel object.
159
+ ///
160
+ /// For quantization flavor tensor B scales apply to accumulation buffer once C
161
+ /// is ready.
162
+ ///
163
+ /// @param brgemm BRGeMM ukernel object.
164
+ /// @param b_scale_mask Tensor B scale mask. Can be `0` and `2` only.
165
+ dnnl_status_t DNNL_API dnnl_brgemm_set_B_scales(
166
+ dnnl_brgemm_t brgemm, int b_scale_mask);
167
+
168
+ /// Sets tensor D scales mask to a BRGeMM ukernel object.
169
+ ///
170
+ /// For quantization flavor tensor D scales apply after all post-ops are
171
+ /// applied.
172
+ ///
173
+ /// @param brgemm BRGeMM ukernel object.
174
+ /// @param d_scale_mask Tensor D scale mask. Can be `0` only.
175
+ dnnl_status_t DNNL_API dnnl_brgemm_set_D_scales(
176
+ dnnl_brgemm_t brgemm, int d_scale_mask);
177
+
178
+ /// Finalizes initialization of a BRGeMM ukernel object.
179
+ ///
180
+ /// This step is mandatory to query information from the object.
181
+ ///
182
+ /// @param brgemm Output BRGeMM ukernel object.
183
+ /// @returns #dnnl_success on success and a status describing the error
184
+ /// otherwise.
185
+ dnnl_status_t DNNL_API dnnl_brgemm_finalize(dnnl_brgemm_t brgemm);
186
+
187
+ /// Returns the packing type expected by a tensor B of a BRGeMM ukernel object.
188
+ ///
189
+ /// @param brgemm BRGeMM ukernel object.
190
+ /// @param pack_type Output packing type. Can be `dnnl_brgemm_no_pack` if
191
+ /// packing is not expected, and `dnnl_brgemm_pack_32`, otherwise.
192
+ /// @returns #dnnl_success on success and a status describing the error
193
+ /// otherwise.
194
+ dnnl_status_t DNNL_API dnnl_brgemm_get_B_pack_type(
195
+ const_dnnl_brgemm_t brgemm, dnnl_pack_type_t *pack_type);
196
+
197
+ /// Returns the size of a scratchpad memory needed for the BRGeMM ukernel
198
+ /// object.
199
+ ///
200
+ /// @param brgemm BRGeMM ukernel object.
201
+ /// @param size Output size of a buffer required for the BRGeMM ukernel object.
202
+ /// @returns #dnnl_success on success and a status describing the error
203
+ /// otherwise.
204
+ dnnl_status_t DNNL_API dnnl_brgemm_get_scratchpad_size(
205
+ const_dnnl_brgemm_t brgemm, size_t *size);
206
+
207
+ /// Returns the flag indicating when the call to `dnnl_brgemm_execute_postops`
208
+ /// is valid.
209
+ ///
210
+ /// @param brgemm BRGeMM ukernel object.
211
+ /// @param valid The flag indicating if `dnnl_brgemm_execute_postops` is valid
212
+ /// for a given ukernel object. `1` is for valid and `0`, otherwise.
213
+ /// @returns #dnnl_success on success and a status describing the error
214
+ /// otherwise.
215
+ dnnl_status_t DNNL_API dnnl_brgemm_is_execute_postops_valid(
216
+ const_dnnl_brgemm_t brgemm, int *valid);
217
+
218
+ /// Initializes the hardware-specific context. If no initialization required,
219
+ /// returns the success status.
220
+ ///
221
+ /// @param brgemm BRGeMM ukernel object.
222
+ /// @returns #dnnl_success on success and a status describing the error
223
+ /// otherwise.
224
+ dnnl_status_t DNNL_API dnnl_brgemm_set_hw_context(const_dnnl_brgemm_t brgemm);
225
+
226
+ /// Releases the hardware-specific context. Must be used after all the execution
227
+ /// calls to BRGeMM ukernel objects.
228
+ /// @returns #dnnl_success on success and a status describing the error
229
+ /// otherwise.
230
+ dnnl_status_t DNNL_API dnnl_brgemm_release_hw_context();
231
+
232
+ /// Generates an executable part of BRGeMM ukernel object.
233
+ /// @param brgemm BRGeMM ukernel object.
234
+ /// @returns #dnnl_success on success and a status describing the error
235
+ /// otherwise.
236
+ dnnl_status_t DNNL_API dnnl_brgemm_generate(dnnl_brgemm_t brgemm);
237
+
238
+ /// Executes a BRGeMM ukernel object.
239
+ ///
240
+ /// @param brgemm BRGeMM ukernel object.
241
+ /// @param A_ptr Base pointer to a tensor A.
242
+ /// @param B_ptr Base pointer to a tensor B.
243
+ /// @param A_B_offsets Pointer to the set of tensor A and tensor B offsets for
244
+ /// each batch; the set must be contiguous in memory. Single batch should
245
+ /// supply offsets for both tensors A and B simultaneously. The number of
246
+ /// batches must coincide with the `batch_size` value passed at the creation
247
+ /// stage.
248
+ /// @param C_ptr Pointer to a tensor C (accumulation buffer).
249
+ /// @param scratchpad_ptr Pointer to a scratchpad buffer.
250
+ /// @returns #dnnl_success on success and a status describing the error
251
+ /// otherwise.
252
+ dnnl_status_t DNNL_API dnnl_brgemm_execute(const_dnnl_brgemm_t brgemm,
253
+ const void *A_ptr, const void *B_ptr, const dnnl_dim_t *A_B_offsets,
254
+ void *C_ptr, void *scratchpad_ptr);
255
+
256
+ /// Executes a BRGeMM ukernel object with post operations.
257
+ ///
258
+ /// @param brgemm BRGeMM ukernel object.
259
+ /// @param A Base pointer to a tensor A.
260
+ /// @param B Base pointer to a tensor B.
261
+ /// @param A_B_offsets Pointer to a set of tensor A and tensor B offsets for
262
+ /// each batch. A set must be contiguous in memory. A single batch should
263
+ /// supply offsets for both tensors A and B simultaneously. The number of
264
+ /// batches must coincide with the `batch_size` value passed at the creation
265
+ /// stage.
266
+ /// @param C_ptr Pointer to a tensor C (accumulation buffer).
267
+ /// @param D_ptr Pointer to a tensor D (output buffer).
268
+ /// @param scratchpad_ptr Pointer to a scratchpad buffer.
269
+ /// @param attr_params Ukernel attributes memory storage.
270
+ /// @returns #dnnl_success on success and a status describing the error
271
+ /// otherwise.
272
+ dnnl_status_t DNNL_API dnnl_brgemm_execute_postops(const_dnnl_brgemm_t brgemm,
273
+ const void *A, const void *B, const dnnl_dim_t *A_B_offsets,
274
+ const void *C_ptr, void *D_ptr, void *scratchpad_ptr,
275
+ const_dnnl_ukernel_attr_params_t attr_params);
276
+
277
+ /// Destroys a BRGeMM ukernel object.
278
+ ///
279
+ /// @param brgemm BRGeMM ukernel object to destroy.
280
+ /// @returns #dnnl_success on success and a status describing the error
281
+ /// otherwise.
282
+ dnnl_status_t DNNL_API dnnl_brgemm_destroy(dnnl_brgemm_t brgemm);
283
+
284
+ /// Creates a transform object.
285
+ ///
286
+ /// @param transform Output transform object.
287
+ /// @param K Dimension K.
288
+ /// @param N Dimension N.
289
+ /// @param in_pack_type Input packing type. Must be one of
290
+ /// `dnnl_pack_type_no_trans`, or `dnnl_pack_type_trans`.
291
+ /// @param in_ld Input leading dimension.
292
+ /// @param out_ld Output leading dimension. When packing data, it specifies a
293
+ /// block by N dimension.
294
+ /// @param in_dt Input data type.
295
+ /// @param out_dt Output data type.
296
+ /// @returns #dnnl_success on success and a status describing the error
297
+ /// otherwise.
298
+ dnnl_status_t DNNL_API dnnl_transform_create(dnnl_transform_t *transform,
299
+ dnnl_dim_t K, dnnl_dim_t N, dnnl_pack_type_t in_pack_type,
300
+ dnnl_dim_t in_ld, dnnl_dim_t out_ld, dnnl_data_type_t in_dt,
301
+ dnnl_data_type_t out_dt);
302
+
303
+ /// Generates an executable part of transform object.
304
+ /// @param transform Transform object.
305
+ /// @returns #dnnl_success on success and a status describing the error
306
+ /// otherwise.
307
+ dnnl_status_t DNNL_API dnnl_transform_generate(dnnl_transform_t transform);
308
+
309
+ /// Executes a transform object.
310
+ ///
311
+ /// @param transform Transform object.
312
+ /// @param in_ptr Pointer to an input buffer.
313
+ /// @param out_ptr Pointer to an output buffer.
314
+ /// @returns #dnnl_success on success and a status describing the error
315
+ /// otherwise.
316
+ dnnl_status_t DNNL_API dnnl_transform_execute(
317
+ const_dnnl_transform_t transform, const void *in_ptr, void *out_ptr);
318
+
319
+ /// Destroys a transform object.
320
+ ///
321
+ /// @param transform Transform object.
322
+ /// @returns #dnnl_success on success and a status describing the error
323
+ /// otherwise.
324
+ dnnl_status_t DNNL_API dnnl_transform_destroy(dnnl_transform_t transform);
325
+
326
+ /// @} dnnl_api_ukernel_brgemm
327
+
328
+ #endif
329
+
330
+ /// @} dnnl_api_ukernel
331
+
332
+ /// @} dnnl_api
333
+
334
+ #ifdef __cplusplus
335
+ }
336
+ #endif
337
+
338
+ #endif /* ONEAPI_DNNL_DNNL_UKERNEL_H */
339
+
340
+ #else
341
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
342
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_ukernel.hpp ADDED
@@ -0,0 +1,470 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2024-2025 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ /// @file
19
+ /// ukernel C++ API
20
+
21
+ #ifndef ONEAPI_DNNL_DNNL_UKERNEL_HPP
22
+ #define ONEAPI_DNNL_DNNL_UKERNEL_HPP
23
+
24
+ #include "oneapi/dnnl/dnnl.hpp"
25
+ #include "oneapi/dnnl/dnnl_ukernel.h"
26
+
27
+ /// @addtogroup dnnl_api oneDNN API
28
+ /// @{
29
+
30
+ /// oneDNN namespace
31
+ namespace dnnl {
32
+
33
+ #ifdef DNNL_EXPERIMENTAL_UKERNEL
34
+
35
+ /// @addtogroup dnnl_api_utils
36
+ /// @{
37
+
38
+ /// @cond DO_NOT_DOCUMENT_THIS
39
+
40
+ template <>
41
+ struct handle_traits<dnnl_brgemm_t> {
42
+ static dnnl_status_t destructor(dnnl_brgemm_t p) {
43
+ return dnnl_brgemm_destroy(p);
44
+ }
45
+ };
46
+
47
+ template <>
48
+ struct handle_traits<dnnl_transform_t> {
49
+ static dnnl_status_t destructor(dnnl_transform_t p) {
50
+ return dnnl_transform_destroy(p);
51
+ }
52
+ };
53
+
54
+ template <>
55
+ struct handle_traits<dnnl_ukernel_attr_params_t> {
56
+ static dnnl_status_t destructor(dnnl_ukernel_attr_params_t p) {
57
+ return dnnl_ukernel_attr_params_destroy(p);
58
+ }
59
+ };
60
+
61
+ /// @endcond
62
+
63
+ /// @} dnnl_api_utils
64
+
65
+ #endif
66
+
67
+ /// @addtogroup dnnl_api_ukernel Ukernels
68
+ /// Collection of ukernels
69
+ /// @{
70
+
71
+ /// ukernel namespace
72
+ namespace ukernel {
73
+
74
+ #ifdef DNNL_EXPERIMENTAL_UKERNEL
75
+
76
+ /// @addtogroup dnnl_api_ukernel_utils ukernel utils
77
+ /// ukernel utility functions
78
+ /// @{
79
+
80
+ /// Packing specification
81
+ enum class pack_type {
82
+ /// Undefined pack type. A guard value.
83
+ undef = dnnl_pack_type_undef,
84
+ /// Plain, not transposed layout. Similar to format_tag::ab.
85
+ no_trans = dnnl_pack_type_no_trans,
86
+ /// Plain, transposed layout. Similar to format_tag::ba.
87
+ trans = dnnl_pack_type_trans,
88
+ /// Packed by 32 bits along K dimension layout.
89
+ pack32 = dnnl_pack_type_pack32,
90
+ };
91
+
92
+ /// Ukernel attributes memory storage
93
+ struct attr_params : public handle<dnnl_ukernel_attr_params_t> {
94
+ /// Constructs a ukernel attributes memory storage.
95
+ attr_params() {
96
+ dnnl_ukernel_attr_params_t c_params = nullptr;
97
+ dnnl_status_t status = dnnl_ukernel_attr_params_create(&c_params);
98
+ error::wrap_c_api(
99
+ status, "could not create an attributes memory storage");
100
+ reset(c_params);
101
+ }
102
+
103
+ /// Sets post-operations arguments to a storage.
104
+ ///
105
+ /// @param post_ops_args Pointer to pointers of post_ops storages.
106
+ /// Expected to be packed together.
107
+ void set_post_ops_args(const void **post_ops_args) {
108
+ dnnl_status_t status = dnnl_ukernel_attr_params_set_post_ops_args(
109
+ get(), post_ops_args);
110
+ if (status != dnnl_success)
111
+ error::wrap_c_api(
112
+ status, "could not set post operations arguments");
113
+ }
114
+
115
+ /// Sets tensor A scales arguments to a storage.
116
+ ///
117
+ /// @param a_scales Pointer to scales storage.
118
+ void set_A_scales(const void *a_scales) {
119
+ dnnl_status_t status
120
+ = dnnl_ukernel_attr_params_set_A_scales(get(), a_scales);
121
+ if (status != dnnl_success)
122
+ error::wrap_c_api(status, "could not set A scales argument");
123
+ }
124
+
125
+ /// Sets tensor B scales arguments to a storage.
126
+ ///
127
+ /// If @ref attr_params::set_B_scales used mask of 2, then at
128
+ /// least N values of selected data type are expected.
129
+ ///
130
+ /// @param b_scales Pointer to scales storage.
131
+ void set_B_scales(const void *b_scales) {
132
+ dnnl_status_t status
133
+ = dnnl_ukernel_attr_params_set_B_scales(get(), b_scales);
134
+ if (status != dnnl_success)
135
+ error::wrap_c_api(status, "could not set B scales argument");
136
+ }
137
+
138
+ /// Sets tensor D scales arguments to a storage.
139
+ ///
140
+ /// @param d_scales Pointer to scales storage.
141
+ void set_D_scales(const void *d_scales) {
142
+ dnnl_status_t status
143
+ = dnnl_ukernel_attr_params_set_D_scales(get(), d_scales);
144
+ if (status != dnnl_success)
145
+ error::wrap_c_api(status, "could not set D scales argument");
146
+ }
147
+ };
148
+ /// @} dnnl_api_ukernel_utils
149
+
150
+ /// @addtogroup dnnl_api_ukernel_brgemm BRGeMM ukernel
151
+ /// BRGeMM ukernel routines
152
+ /// @{
153
+
154
+ /// BRGeMM ukernel
155
+ struct brgemm : public handle<dnnl_brgemm_t> {
156
+ /// Default constructor. Produces an empty object.
157
+ brgemm() = default;
158
+
159
+ /// Constructs a BRGeMM ukernel object. Operates by the following formula:
160
+ /// `C = [A x B]`.
161
+ ///
162
+ /// @param M Dimension M of tensor A.
163
+ /// @param N Dimension N of tensor B.
164
+ /// @param K Dimension K of tensors A and B.
165
+ /// @param batch_size Number of batches to process.
166
+ /// @param lda Leading dimension of tensor A.
167
+ /// @param ldb Leading dimension of tensor B.
168
+ /// @param ldc Leading dimension of tensor C.
169
+ /// @param a_dt Data type of tensor A.
170
+ /// @param b_dt Data type of tensor B.
171
+ /// @param c_dt Data type of tensor C.
172
+ /// @param allow_empty A flag signifying whether construction is
173
+ /// allowed to fail without throwing an exception. In this case an
174
+ /// empty object will be produced. This flag is optional and
175
+ /// defaults to false.
176
+ brgemm(memory::dim M, memory::dim N, memory::dim K, memory::dim batch_size,
177
+ memory::dim lda, memory::dim ldb, memory::dim ldc,
178
+ memory::data_type a_dt, memory::data_type b_dt,
179
+ memory::data_type c_dt, bool allow_empty = false) {
180
+
181
+ dnnl_brgemm_t brgemm = nullptr;
182
+ dnnl_status_t status = dnnl_brgemm_create(&brgemm, M, N, K, batch_size,
183
+ lda, ldb, ldc, memory::convert_to_c(a_dt),
184
+ memory::convert_to_c(b_dt), memory::convert_to_c(c_dt));
185
+
186
+ if (!allow_empty)
187
+ error::wrap_c_api(
188
+ status, "could not create a BRGeMM ukernel object");
189
+ reset(brgemm);
190
+ }
191
+
192
+ /// Sets adding an intermediate result to the output tensor C instead of
193
+ /// writing: `C += [A x B]`.
194
+ ///
195
+ /// @param add_C Value to indicate addition. `false` to skip addition, and
196
+ /// `true` to apply addition.
197
+ void set_add_C(bool add_C) {
198
+ dnnl_status_t status
199
+ = dnnl_brgemm_set_add_C(get(), static_cast<int>(add_C));
200
+ if (status != dnnl_success)
201
+ error::wrap_c_api(status, "could not set add_C attribute");
202
+ }
203
+
204
+ /// Sets post-operations to a BRGeMM ukernel object:
205
+ /// `D = post-operations(C)`.
206
+ ///
207
+ /// Post-operations applies if one of the following holds:
208
+ /// * Non-empty post-operations are specified.
209
+ /// * Output data type `d_dt` is different from accumulation data type
210
+ /// `c_dt`.
211
+ ///
212
+ /// @param ldd Leading dimension of tensor D.
213
+ /// @param d_dt Data type of tensor D.
214
+ /// @param po Primitive post-operation attributes to extend the kernel
215
+ /// operations.
216
+ void set_post_ops(memory::dim ldd, memory::data_type d_dt,
217
+ const post_ops &po = default_post_ops()) {
218
+ dnnl_status_t status = dnnl_brgemm_set_post_ops(
219
+ get(), ldd, memory::convert_to_c(d_dt), po.get());
220
+ if (status != dnnl_success)
221
+ error::wrap_c_api(status, "could not set post operations");
222
+ }
223
+
224
+ /// Sets tensor A scales mask to a BRGeMM ukernel object.
225
+ ///
226
+ /// For quantization flavor tensor A scales apply to accumulation buffer
227
+ /// once C is ready.
228
+ ///
229
+ /// @param a_scale_mask Tensor A scale mask. Can be `0` only.
230
+ void set_A_scales(int a_scale_mask) {
231
+ dnnl_status_t status = dnnl_brgemm_set_A_scales(get(), a_scale_mask);
232
+ if (status != dnnl_success)
233
+ error::wrap_c_api(status, "could not set A scales");
234
+ }
235
+
236
+ /// Sets tensor B scales mask to a BRGeMM ukernel object.
237
+ ///
238
+ /// For quantization flavor tensor B scales apply to accumulation buffer
239
+ /// once C is ready.
240
+ ///
241
+ /// @param b_scale_mask Tensor B scale mask. Can be `0` and `2` only.
242
+ void set_B_scales(int b_scale_mask) {
243
+ dnnl_status_t status = dnnl_brgemm_set_B_scales(get(), b_scale_mask);
244
+ if (status != dnnl_success)
245
+ error::wrap_c_api(status, "could not set B scales");
246
+ }
247
+
248
+ /// Sets tensor D scales mask to a BRGeMM ukernel object.
249
+ ///
250
+ /// For quantization flavor tensor D scales apply after all post-ops are
251
+ /// applied.
252
+ ///
253
+ /// @param d_scale_mask Tensor D scale mask. Can be `0` only.
254
+ void set_D_scales(int d_scale_mask) {
255
+ dnnl_status_t status = dnnl_brgemm_set_D_scales(get(), d_scale_mask);
256
+ if (status != dnnl_success)
257
+ error::wrap_c_api(status, "could not set D scales");
258
+ }
259
+
260
+ /// Finalizes initialization of a BRGeMM ukernel object.
261
+ ///
262
+ /// This step must be performed prior to querying information from the
263
+ /// object.
264
+ void finalize() {
265
+ dnnl_status_t status = dnnl_brgemm_finalize(get());
266
+ if (status != dnnl_success)
267
+ error::wrap_c_api(status, "could not finalize an object");
268
+ }
269
+
270
+ /// Returns the packing type expected by a tensor B of a BRGeMM ukernel
271
+ /// object.
272
+ pack_type get_B_pack_type() const {
273
+ dnnl_pack_type_t c_pack_type;
274
+ dnnl_status_t status = dnnl_brgemm_get_B_pack_type(get(), &c_pack_type);
275
+ if (status != dnnl_success)
276
+ error::wrap_c_api(status, "could not query B pack type");
277
+
278
+ return static_cast<pack_type>(c_pack_type);
279
+ }
280
+
281
+ /// Returns the size of a scratchpad memory needed for the BRGeMM ukernel
282
+ /// object.
283
+ size_t get_scratchpad_size() const {
284
+ size_t size;
285
+ dnnl_status_t status = dnnl_brgemm_get_scratchpad_size(get(), &size);
286
+ if (status != dnnl_success)
287
+ error::wrap_c_api(status,
288
+ "could not query a scratchpad size from a BRGeMM ukernel "
289
+ "object");
290
+ return size;
291
+ }
292
+
293
+ /// Returns the flag indicating when the call to execute with post
294
+ /// operations is valid.
295
+ ///
296
+ /// `True` is for a valid call, `false`, otherwise.
297
+ bool is_execute_postops_valid() const {
298
+ int valid;
299
+ dnnl_status_t status
300
+ = dnnl_brgemm_is_execute_postops_valid(get(), &valid);
301
+ if (status != dnnl_success)
302
+ error::wrap_c_api(status,
303
+ "could not query a flag for execute postops from a BRGeMM "
304
+ "ukernel object");
305
+ return static_cast<bool>(valid);
306
+ }
307
+
308
+ /// Initializes the hardware-specific context. Affects the global state for
309
+ /// all BRGeMM ukernel objects. If no initialization required, returns.
310
+ void set_hw_context() const {
311
+ dnnl_status_t status = dnnl_brgemm_set_hw_context(get());
312
+ if (status != dnnl_success)
313
+ error::wrap_c_api(status, "could not set hardware context");
314
+ }
315
+
316
+ /// Releases the hardware-specific context. Affects the global state for
317
+ /// all BRGeMM ukernel objects. Must be used after all the execution calls
318
+ /// to BRGeMM ukernel objects.
319
+ static void release_hw_context() {
320
+ dnnl_status_t status = dnnl_brgemm_release_hw_context();
321
+ if (status != dnnl_success)
322
+ error::wrap_c_api(status, "could not release hardware context");
323
+ }
324
+
325
+ /// Generates an executable part of BRGeMM ukernel object.
326
+ void generate() {
327
+ dnnl_status_t status = dnnl_brgemm_generate(get());
328
+ if (status != dnnl_success)
329
+ error::wrap_c_api(status, "could not generate a kernel");
330
+ }
331
+
332
+ /// Executes a BRGeMM ukernel object.
333
+ ///
334
+ /// @param A Base pointer to a tensor A.
335
+ /// @param B Base pointer to a tensor B.
336
+ /// @param A_B_offsets Vector of pairs of tensors A and B offsets for
337
+ /// each batch. The number of batches must coincide with the
338
+ /// `batch_size` value passed at object construction stage.
339
+ /// @param C Pointer to a tensor C (accumulation buffer).
340
+ /// @param scratchpad Pointer to a scratchpad buffer.
341
+ void execute(const void *A, const void *B,
342
+ const std::vector<std::pair<memory::dim, memory::dim>> &A_B_offsets,
343
+ void *C, void *scratchpad) const {
344
+ // TODO: export batch_element to C API later for user to fill it and
345
+ // pass directly to the call.
346
+ dnnl_status_t status = dnnl_brgemm_execute(get(), A, B,
347
+ (const dnnl_dim_t *)A_B_offsets.data(), C, scratchpad);
348
+ if (status != dnnl_success)
349
+ error::wrap_c_api(
350
+ status, "could not execute a BRGeMM ukernel object");
351
+ }
352
+
353
+ /// Executes a BRGeMM ukernel object with post operations.
354
+ ///
355
+ /// @param A Base pointer to a tensor A.
356
+ /// @param B Base pointer to a tensor B.
357
+ /// @param A_B_offsets Vector of pairs of tensors A and B offsets for
358
+ /// each batch. The number of batches must coincide with the
359
+ /// `batch_size` value passed at object construction stage.
360
+ /// @param C Pointer to a tensor C (accumulation buffer).
361
+ /// @param D Pointer to a tensor D (output buffer).
362
+ /// @param scratchpad Pointer to a scratchpad buffer.
363
+ /// @param params Post-op memory arguments. Must be passed If binary
364
+ /// post-op or scales were set.
365
+ void execute(const void *A, const void *B,
366
+ const std::vector<std::pair<memory::dim, memory::dim>> &A_B_offsets,
367
+ const void *C, void *D, void *scratchpad,
368
+ const attr_params &params = default_attr_params()) const {
369
+ // TODO: export batch_element to C API later for user to fill it and
370
+ // pass directly to the call.
371
+ dnnl_status_t status = dnnl_brgemm_execute_postops(get(), A, B,
372
+ (const dnnl_dim_t *)A_B_offsets.data(), C, D, scratchpad,
373
+ params.get());
374
+ if (status != dnnl_success)
375
+ error::wrap_c_api(
376
+ status, "could not execute a BRGeMM ukernel object");
377
+ }
378
+
379
+ /// Returns a constant reference to a static instance of default constructed
380
+ /// primitive post-operations attribute.
381
+ static const post_ops &default_post_ops() {
382
+ static const post_ops po;
383
+ return po;
384
+ }
385
+
386
+ /// Returns a constant reference to a static instance of default constructed
387
+ /// ukernel attributes parameters.
388
+ static const attr_params &default_attr_params() {
389
+ static const attr_params ap;
390
+ return ap;
391
+ }
392
+ };
393
+ /// @} dnnl_api_ukernel_brgemm
394
+
395
+ /// @addtogroup dnnl_api_ukernel_transform Transform ukernel
396
+ /// Transform routines
397
+ /// @{
398
+
399
+ /// Transform ukernel
400
+ struct transform : public handle<dnnl_transform_t> {
401
+ /// Default constructor. Produces an empty object.
402
+ transform() = default;
403
+
404
+ /// Constructs a transform object.
405
+ ///
406
+ /// @param K Dimension K.
407
+ /// @param N Dimension N.
408
+ /// @param in_pack_type Input packing type. Must be one of
409
+ /// `pack_type::no_trans`, or `pack_type::trans`.
410
+ /// @param in_ld Input leading dimension.
411
+ /// @param out_ld Output leading dimension. Specifies a block by N dimension
412
+ /// during data packing.
413
+ /// @param in_dt Input data type.
414
+ /// @param out_dt Output data type.
415
+ /// @param allow_empty A flag signifying whether construction is
416
+ /// allowed to fail without throwing an exception. In this case an
417
+ /// empty object will be produced. This flag is optional and
418
+ /// defaults to false.
419
+ transform(memory::dim K, memory::dim N, pack_type in_pack_type,
420
+ memory::dim in_ld, memory::dim out_ld, memory::data_type in_dt,
421
+ memory::data_type out_dt, bool allow_empty = false) {
422
+
423
+ dnnl_transform_t transform = nullptr;
424
+ dnnl_status_t status = dnnl_transform_create(&transform, K, N,
425
+ static_cast<dnnl_pack_type_t>(in_pack_type), in_ld, out_ld,
426
+ memory::convert_to_c(in_dt), memory::convert_to_c(out_dt));
427
+
428
+ if (!allow_empty)
429
+ error::wrap_c_api(status,
430
+ "could not create a BRGeMM ukernel packing B object");
431
+ reset(transform);
432
+ }
433
+
434
+ /// Generates an executable part of transform object.
435
+ void generate() {
436
+ dnnl_status_t status = dnnl_transform_generate(get());
437
+ if (status != dnnl_success)
438
+ error::wrap_c_api(status,
439
+ "could not generate a BRGeMM ukernel packing B object");
440
+ }
441
+
442
+ /// Executes a transform object.
443
+ ///
444
+ /// @param in Pointer to an input buffer.
445
+ /// @param out Pointer to an output buffer.
446
+ void execute(const void *in, void *out) const {
447
+ dnnl_status_t status = dnnl_transform_execute(get(), in, out);
448
+ if (status != dnnl_success)
449
+ error::wrap_c_api(status,
450
+ "could not execute a BRGeMM ukernel packing B object");
451
+ }
452
+ };
453
+
454
+ /// @} dnnl_api_ukernel_transform
455
+
456
+ #endif
457
+
458
+ } // namespace ukernel
459
+
460
+ /// @} dnnl_api_ukernel
461
+
462
+ } // namespace dnnl
463
+
464
+ /// @} dnnl_api
465
+
466
+ #endif /* ONEAPI_DNNL_DNNL_UKERNEL_HPP */
467
+
468
+ #else
469
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
470
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_ukernel_types.h ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2024 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ /// @file
19
+ /// ukernel C API types definitions
20
+
21
+ #ifndef ONEAPI_DNNL_DNNL_UKERNEL_TYPES_H
22
+ #define ONEAPI_DNNL_DNNL_UKERNEL_TYPES_H
23
+
24
+ #ifdef __cplusplus
25
+ extern "C" {
26
+ #endif
27
+
28
+ #include "oneapi/dnnl/dnnl_types.h"
29
+
30
+ /// @addtogroup dnnl_api
31
+ /// @{
32
+
33
+ /// @addtogroup dnnl_api_ukernel
34
+ /// @{
35
+
36
+ #ifdef DNNL_EXPERIMENTAL_UKERNEL
37
+
38
+ /// Packing specification
39
+ typedef enum {
40
+ /// Undefined pack type. A guard value.
41
+ dnnl_pack_type_undef = 0,
42
+ /// Plain, not transposed layout. Similar to format_tag::ab.
43
+ dnnl_pack_type_no_trans,
44
+ /// Plain, transposed layout. Similar to format_tag::ba.
45
+ dnnl_pack_type_trans,
46
+ /// Packed by 32 bits along K dimension layout.
47
+ dnnl_pack_type_pack32,
48
+ } dnnl_pack_type_t;
49
+
50
+ /// @struct dnnl_ukernel_attr_params
51
+ /// An opaque structure to describe ukernel attributes memory storage.
52
+ struct dnnl_ukernel_attr_params;
53
+
54
+ /// A ukernel attributes memory storage handle.
55
+ typedef struct dnnl_ukernel_attr_params *dnnl_ukernel_attr_params_t;
56
+
57
+ /// A constant ukernel attributes memory storage handle.
58
+ typedef const struct dnnl_ukernel_attr_params *const_dnnl_ukernel_attr_params_t;
59
+
60
+ /// @addtogroup dnnl_api_ukernel_brgemm
61
+ /// @{
62
+
63
+ /// @struct dnnl_brgemm
64
+ /// An opaque structure to describe a brgemm ukernel.
65
+ struct dnnl_brgemm;
66
+
67
+ /// A brgemm ukernel handle.
68
+ typedef struct dnnl_brgemm *dnnl_brgemm_t;
69
+
70
+ /// A constant brgemm ukernel handle.
71
+ typedef const struct dnnl_brgemm *const_dnnl_brgemm_t;
72
+
73
+ /// @struct dnnl_transform
74
+ /// An opaque structure to describe a transform routine.
75
+ struct dnnl_transform;
76
+
77
+ /// A transform routine handle.
78
+ typedef struct dnnl_transform *dnnl_transform_t;
79
+
80
+ /// A constant transform routine handle.
81
+ typedef const struct dnnl_transform *const_dnnl_transform_t;
82
+
83
+ /// @} dnnl_api_ukernel_brgemm
84
+ #endif
85
+
86
+ /// @} dnnl_api_ukernel
87
+
88
+ /// @} dnnl_api
89
+
90
+ #ifdef __cplusplus
91
+ }
92
+ #endif
93
+
94
+ #endif /* ONEAPI_DNNL_DNNL_UKERNEL_TYPES_H */
95
+
96
+ #else
97
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
98
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_version.h ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2019-2024 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_VERSION_H
19
+ #define ONEAPI_DNNL_DNNL_VERSION_H
20
+
21
+ // clang-format off
22
+
23
+ /// Major version
24
+ #define DNNL_VERSION_MAJOR 3
25
+
26
+ /// Minor version
27
+ #define DNNL_VERSION_MINOR 7
28
+
29
+ /// Patch version
30
+ #define DNNL_VERSION_PATCH 1
31
+
32
+ // clang-format on
33
+
34
+ #endif
35
+
36
+ #else
37
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
38
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/oneapi/dnnl/dnnl_version_hash.h ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*******************************************************************************
3
+ * Copyright 2024 Intel Corporation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *******************************************************************************/
17
+
18
+ #ifndef ONEAPI_DNNL_DNNL_VERSION_HASH_H
19
+ #define ONEAPI_DNNL_DNNL_VERSION_HASH_H
20
+
21
+ // clang-format off
22
+
23
+ /// Note: this macro and header file were moved to a separate instance to avoid
24
+ /// incremental build issues as moving from commit to commit would trigger a
25
+ /// complete library rebuild. Including a generated header file in a single
26
+ /// translation unit makes this problem go away.
27
+ /// Git commit hash
28
+ #define DNNL_VERSION_HASH "8d263e693366ef8db40acc569cc7d8edf644556d"
29
+
30
+ // clang-format on
31
+
32
+ #endif
33
+
34
+ #else
35
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
36
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/basic/factory.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * All rights reserved.
5
+ *
6
+ * This source code is licensed under the BSD-style license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <memory>
13
+
14
+ #include <tensorpipe/channel/context.h>
15
+
16
+ namespace tensorpipe {
17
+ namespace channel {
18
+ namespace basic {
19
+
20
+ std::shared_ptr<Context> create();
21
+
22
+ } // namespace basic
23
+ } // namespace channel
24
+ } // namespace tensorpipe
25
+
26
+ #else
27
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
28
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/cma/factory.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * All rights reserved.
5
+ *
6
+ * This source code is licensed under the BSD-style license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <memory>
13
+
14
+ #include <tensorpipe/channel/context.h>
15
+
16
+ namespace tensorpipe {
17
+ namespace channel {
18
+ namespace cma {
19
+
20
+ std::shared_ptr<Context> create();
21
+
22
+ } // namespace cma
23
+ } // namespace channel
24
+ } // namespace tensorpipe
25
+
26
+ #else
27
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
28
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/context.h ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * All rights reserved.
5
+ *
6
+ * This source code is licensed under the BSD-style license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <memory>
13
+ #include <string>
14
+ #include <unordered_map>
15
+ #include <vector>
16
+
17
+ #include <tensorpipe/common/buffer.h>
18
+ #include <tensorpipe/transport/context.h>
19
+
20
+ namespace tensorpipe {
21
+ namespace channel {
22
+
23
+ enum class Endpoint : bool { kConnect, kListen };
24
+
25
+ class Channel;
26
+
27
+ // Abstract base class for channel context classes.
28
+ //
29
+ // Instances of these classes are expected to be registered with a
30
+ // context. All registered instances are assumed to be eligible
31
+ // channels for all pairs.
32
+ //
33
+ class Context {
34
+ public:
35
+ // Return whether the context is able to operate correctly.
36
+ //
37
+ // Some channel types may be unable to perform as intended under some
38
+ // circumstances (e.g., specialized hardware unavailable, lack of
39
+ // permissions). They can report it through this method in order for
40
+ // the core context to avoid registering them in the first place.
41
+ //
42
+ virtual bool isViable() const = 0;
43
+
44
+ // Return the number of control connections needed to create an instance of
45
+ // this channel.
46
+ //
47
+ // Most channels require only one, but some require more (cuda_basic), and
48
+ // some might require none.
49
+ //
50
+ virtual size_t numConnectionsNeeded() const = 0;
51
+
52
+ // Return a map from supported devices to strings describing the device from
53
+ // the channel's perspective.
54
+ //
55
+ // Two processes with a channel context of the same type can leverage this
56
+ // channel to make two devices communicate if one side's device descriptor is
57
+ // "accepted" by the other one, using the canCommunicateWithRemote method
58
+ // below. That method must be symmetric, and unless overridden defaults to
59
+ // string comparison.
60
+ //
61
+ virtual const std::unordered_map<Device, std::string>& deviceDescriptors()
62
+ const = 0;
63
+
64
+ // Compare local and remote device descriptors for compatibility.
65
+ //
66
+ // Determine whether a channel can be opened between a local device and
67
+ // a remote one that has the given device descriptor. This function
68
+ // needs to be symmetric: if we called this method on the remote
69
+ // context with the local descriptor we should get the same answer.
70
+ // Unless overridden it defaults to string comparison.
71
+ //
72
+ virtual bool canCommunicateWithRemote(
73
+ const std::string& localDeviceDescriptor,
74
+ const std::string& remoteDeviceDescriptor) const = 0;
75
+
76
+ // Return newly created channel using the specified connections.
77
+ //
78
+ // It is up to the channel to either use these connections for further
79
+ // initialization, or use them directly. Either way, the returned
80
+ // channel should be immediately usable. If the channel isn't fully
81
+ // initialized yet, take care to queue these operations to execute
82
+ // as soon as initialization has completed.
83
+ //
84
+ virtual std::shared_ptr<Channel> createChannel(
85
+ std::vector<std::shared_ptr<transport::Connection>>,
86
+ Endpoint) = 0;
87
+
88
+ // Tell the context what its identifier is.
89
+ //
90
+ // This is only supposed to be called from the high-level context. It will
91
+ // only used for logging and debugging purposes.
92
+ virtual void setId(std::string id) = 0;
93
+
94
+ // Put the channel context in a terminal state, in turn closing all of its
95
+ // channels, and release its resources. This may be done asynchronously, in
96
+ // background.
97
+ virtual void close() = 0;
98
+
99
+ // Wait for all resources to be released and all background activity to stop.
100
+ virtual void join() = 0;
101
+
102
+ virtual ~Context() = default;
103
+
104
+ private:
105
+ std::string name_;
106
+ };
107
+
108
+ } // namespace channel
109
+ } // namespace tensorpipe
110
+
111
+ #else
112
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
113
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/cuda_basic/factory.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * All rights reserved.
5
+ *
6
+ * This source code is licensed under the BSD-style license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <memory>
13
+
14
+ #include <tensorpipe/channel/context.h>
15
+
16
+ namespace tensorpipe {
17
+ namespace channel {
18
+ namespace cuda_basic {
19
+
20
+ std::shared_ptr<Context> create(std::shared_ptr<Context> cpuContext);
21
+
22
+ } // namespace cuda_basic
23
+ } // namespace channel
24
+ } // namespace tensorpipe
25
+
26
+ #else
27
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
28
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/cuda_gdr/error.h ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * All rights reserved.
5
+ *
6
+ * This source code is licensed under the BSD-style license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <string>
13
+
14
+ #include <tensorpipe/channel/error.h>
15
+
16
+ namespace tensorpipe {
17
+ namespace channel {
18
+ namespace cuda_gdr {
19
+
20
+ class IbvError final : public BaseError {
21
+ public:
22
+ explicit IbvError(std::string error) : error_(error) {}
23
+
24
+ std::string what() const override {
25
+ return error_;
26
+ }
27
+
28
+ private:
29
+ std::string error_;
30
+ };
31
+
32
+ } // namespace cuda_gdr
33
+ } // namespace channel
34
+ } // namespace tensorpipe
35
+
36
+ #else
37
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
38
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/cuda_gdr/factory.h ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * All rights reserved.
5
+ *
6
+ * This source code is licensed under the BSD-style license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <memory>
13
+ #include <vector>
14
+
15
+ #include <tensorpipe/channel/context.h>
16
+ #include <tensorpipe/common/optional.h>
17
+
18
+ namespace tensorpipe {
19
+ namespace channel {
20
+ namespace cuda_gdr {
21
+
22
+ std::shared_ptr<Context> create(
23
+ optional<std::vector<std::string>> gpuIdxToNicName = nullopt);
24
+
25
+ } // namespace cuda_gdr
26
+ } // namespace channel
27
+ } // namespace tensorpipe
28
+
29
+ #else
30
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
31
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/cuda_ipc/factory.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * All rights reserved.
5
+ *
6
+ * This source code is licensed under the BSD-style license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <memory>
13
+
14
+ #include <tensorpipe/channel/context.h>
15
+
16
+ namespace tensorpipe {
17
+ namespace channel {
18
+ namespace cuda_ipc {
19
+
20
+ std::shared_ptr<Context> create();
21
+
22
+ } // namespace cuda_ipc
23
+ } // namespace channel
24
+ } // namespace tensorpipe
25
+
26
+ #else
27
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
28
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/cuda_xth/factory.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * All rights reserved.
5
+ *
6
+ * This source code is licensed under the BSD-style license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <memory>
13
+
14
+ #include <tensorpipe/channel/context.h>
15
+
16
+ namespace tensorpipe {
17
+ namespace channel {
18
+ namespace cuda_xth {
19
+
20
+ std::shared_ptr<Context> create();
21
+
22
+ } // namespace cuda_xth
23
+ } // namespace channel
24
+ } // namespace tensorpipe
25
+
26
+ #else
27
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
28
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/error.h ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * All rights reserved.
5
+ *
6
+ * This source code is licensed under the BSD-style license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <string>
13
+
14
+ #include <tensorpipe/common/error.h>
15
+
16
+ namespace tensorpipe {
17
+ namespace channel {
18
+
19
+ class ContextClosedError final : public BaseError {
20
+ public:
21
+ ContextClosedError() {}
22
+
23
+ std::string what() const override;
24
+ };
25
+
26
+ class ChannelClosedError final : public BaseError {
27
+ public:
28
+ ChannelClosedError() {}
29
+
30
+ std::string what() const override;
31
+ };
32
+
33
+ class ContextNotViableError final : public BaseError {
34
+ public:
35
+ ContextNotViableError() {}
36
+
37
+ std::string what() const override;
38
+ };
39
+
40
+ } // namespace channel
41
+ } // namespace tensorpipe
42
+
43
+ #else
44
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
45
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/mpt/factory.h ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * All rights reserved.
5
+ *
6
+ * This source code is licensed under the BSD-style license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <memory>
13
+ #include <vector>
14
+
15
+ #include <tensorpipe/channel/context.h>
16
+ #include <tensorpipe/transport/context.h>
17
+
18
+ namespace tensorpipe {
19
+ namespace channel {
20
+ namespace mpt {
21
+
22
+ std::shared_ptr<Context> create(
23
+ std::vector<std::shared_ptr<transport::Context>> contexts,
24
+ std::vector<std::shared_ptr<transport::Listener>> listeners);
25
+
26
+ } // namespace mpt
27
+ } // namespace channel
28
+ } // namespace tensorpipe
29
+
30
+ #else
31
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
32
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/channel/xth/factory.h ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * All rights reserved.
5
+ *
6
+ * This source code is licensed under the BSD-style license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <memory>
13
+
14
+ #include <tensorpipe/channel/context.h>
15
+
16
+ namespace tensorpipe {
17
+ namespace channel {
18
+ namespace xth {
19
+
20
+ std::shared_ptr<Context> create();
21
+
22
+ } // namespace xth
23
+ } // namespace channel
24
+ } // namespace tensorpipe
25
+
26
+ #else
27
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
28
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
data/conda_envs/abstr/lib/python3.11/site-packages/torch/include/tensorpipe/common/buffer.h ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * All rights reserved.
5
+ *
6
+ * This source code is licensed under the BSD-style license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <cstddef>
13
+ #include <stdexcept>
14
+ #include <type_traits>
15
+ #include <utility>
16
+
17
+ #include <tensorpipe/common/cpu_buffer.h>
18
+ #include <tensorpipe/common/device.h>
19
+
20
+ namespace tensorpipe {
21
+
22
+ class Buffer {
23
+ class AbstractBufferWrapper {
24
+ public:
25
+ virtual Device device() const = 0;
26
+ virtual void copyConstructInto(void* ptr) const = 0;
27
+ virtual void moveConstructInto(void* ptr) = 0;
28
+ virtual ~AbstractBufferWrapper() = default;
29
+ };
30
+
31
+ template <typename TBuffer>
32
+ class BufferWrapper : public AbstractBufferWrapper {
33
+ static_assert(
34
+ std::is_trivially_copyable<TBuffer>::value,
35
+ "wrapping non-trivially copyable class");
36
+
37
+ public:
38
+ TBuffer buffer;
39
+
40
+ explicit BufferWrapper(TBuffer buffer) : buffer(std::move(buffer)) {}
41
+
42
+ Device device() const override {
43
+ return buffer.getDevice();
44
+ }
45
+
46
+ void copyConstructInto(void* ptr) const override {
47
+ new (ptr) BufferWrapper(*this);
48
+ }
49
+
50
+ void moveConstructInto(void* ptr) override {
51
+ new (ptr) BufferWrapper(std::move(*this));
52
+ }
53
+ };
54
+
55
+ public:
56
+ template <typename TBuffer>
57
+ /* implicit */ Buffer(TBuffer b) {
58
+ static_assert(
59
+ sizeof(BufferWrapper<TBuffer>) <= kStructSize, "kStructSize too small");
60
+ static_assert(
61
+ alignof(BufferWrapper<TBuffer>) <= kStructAlign,
62
+ "kStructAlign too small");
63
+ new (&raw_) BufferWrapper<TBuffer>(std::move(b));
64
+ }
65
+
66
+ Buffer() : Buffer(CpuBuffer{}) {}
67
+
68
+ Buffer(const Buffer& other) {
69
+ other.ptr()->copyConstructInto(&raw_);
70
+ }
71
+
72
+ Buffer& operator=(const Buffer& other) {
73
+ if (this != &other) {
74
+ ptr()->~AbstractBufferWrapper();
75
+ other.ptr()->copyConstructInto(&raw_);
76
+ }
77
+ return *this;
78
+ }
79
+
80
+ Buffer(Buffer&& other) noexcept {
81
+ other.ptr()->moveConstructInto(&raw_);
82
+ }
83
+
84
+ Buffer& operator=(Buffer&& other) {
85
+ if (this != &other) {
86
+ ptr()->~AbstractBufferWrapper();
87
+ other.ptr()->moveConstructInto(&raw_);
88
+ }
89
+ return *this;
90
+ }
91
+
92
+ ~Buffer() {
93
+ ptr()->~AbstractBufferWrapper();
94
+ }
95
+
96
+ template <typename TBuffer>
97
+ TBuffer& unwrap() {
98
+ BufferWrapper<TBuffer>* wrapperPtr =
99
+ dynamic_cast<BufferWrapper<TBuffer>*>(ptr());
100
+ if (wrapperPtr == nullptr) {
101
+ throw std::runtime_error("Invalid unwrapping of tensorpipe::Buffer");
102
+ }
103
+ return wrapperPtr->buffer;
104
+ }
105
+
106
+ template <typename TBuffer>
107
+ const TBuffer& unwrap() const {
108
+ const BufferWrapper<TBuffer>* wrapperPtr =
109
+ dynamic_cast<const BufferWrapper<TBuffer>*>(ptr());
110
+ if (wrapperPtr == nullptr) {
111
+ throw std::runtime_error("Invalid unwrapping of tensorpipe::Buffer");
112
+ }
113
+ return wrapperPtr->buffer;
114
+ }
115
+
116
+ Device device() const {
117
+ return ptr()->device();
118
+ }
119
+
120
+ private:
121
+ static constexpr int kStructSize = 32;
122
+ static constexpr int kStructAlign = 8;
123
+ std::aligned_storage<kStructSize, kStructAlign>::type raw_{};
124
+
125
+ const AbstractBufferWrapper* ptr() const {
126
+ // FIXME: Once we go C++17, use std::launder on the returned pointer.
127
+ return reinterpret_cast<const AbstractBufferWrapper*>(&raw_);
128
+ }
129
+
130
+ AbstractBufferWrapper* ptr() {
131
+ // FIXME: Once we go C++17, use std::launder on the returned pointer.
132
+ return reinterpret_cast<AbstractBufferWrapper*>(&raw_);
133
+ }
134
+ };
135
+
136
+ } // namespace tensorpipe
137
+
138
+ #else
139
+ #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
140
+ #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)