pyomp 0.5.0__cp314-cp314t-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- numba/openmp/__init__.py +106 -0
- numba/openmp/_version.py +34 -0
- numba/openmp/analysis.py +251 -0
- numba/openmp/compiler.py +402 -0
- numba/openmp/config.py +27 -0
- numba/openmp/decorators.py +27 -0
- numba/openmp/exceptions.py +26 -0
- numba/openmp/ir_utils.py +4 -0
- numba/openmp/libs/openmp/lib/libgomp.1.dylib +0 -0
- numba/openmp/libs/openmp/lib/libgomp.dylib +0 -0
- numba/openmp/libs/openmp/lib/libiomp5.dylib +0 -0
- numba/openmp/libs/openmp/lib/libomp.dylib +0 -0
- numba/openmp/libs/openmp/patches/14.0.6/0001-BACKPORT-Fix-for-CUDA-OpenMP-RTL.patch +39 -0
- numba/openmp/libs/openmp/patches/14.0.6/0002-Fix-missing-includes.patch +12 -0
- numba/openmp/libs/openmp/patches/14.0.6/0003-Link-static-LLVM-libs.patch +13 -0
- numba/openmp/libs/openmp/patches/15.0.7/0001-Fix-missing-includes.patch +14 -0
- numba/openmp/libs/openmp/patches/15.0.7/0002-Link-LLVM-statically.patch +101 -0
- numba/openmp/libs/openmp/patches/15.0.7/0003-Disable-opaque-pointers-DeviceRTL-bitcode.patch +12 -0
- numba/openmp/libs/openmp/patches/16.0.6/0001-Load-plugins-from-install-directory.patch +53 -0
- numba/openmp/libs/openmp/patches/16.0.6/0002-Link-LLVM-statically.patch +218 -0
- numba/openmp/libs/openmp/patches/20.1.8/0001-Enable-standalone-build.patch +13 -0
- numba/openmp/libs/openmp/patches/20.1.8/0002-Link-statically-LLVM.patch +24 -0
- numba/openmp/libs/openmp/patches/20.1.8/0003-Do-not-build-liboffload.patch +12 -0
- numba/openmp/libs/pass/CGIntrinsicsOpenMP.cpp +2939 -0
- numba/openmp/libs/pass/CGIntrinsicsOpenMP.h +606 -0
- numba/openmp/libs/pass/CMakeLists.txt +57 -0
- numba/openmp/libs/pass/DebugOpenMP.cpp +17 -0
- numba/openmp/libs/pass/DebugOpenMP.h +28 -0
- numba/openmp/libs/pass/IntrinsicsOpenMP.cpp +837 -0
- numba/openmp/libs/pass/IntrinsicsOpenMP.h +13 -0
- numba/openmp/libs/pass/IntrinsicsOpenMP_CAPI.h +23 -0
- numba/openmp/libs/pass/libIntrinsicsOpenMP.dylib +0 -0
- numba/openmp/link_utils.py +126 -0
- numba/openmp/llvm_pass.py +48 -0
- numba/openmp/llvmlite_extensions.py +75 -0
- numba/openmp/omp_context.py +242 -0
- numba/openmp/omp_grammar.py +696 -0
- numba/openmp/omp_ir.py +2105 -0
- numba/openmp/omp_lower.py +3125 -0
- numba/openmp/omp_runtime.py +107 -0
- numba/openmp/overloads.py +53 -0
- numba/openmp/parser.py +6 -0
- numba/openmp/tags.py +532 -0
- numba/openmp/tests/test_openmp.py +5056 -0
- pyomp-0.5.0.dist-info/METADATA +193 -0
- pyomp-0.5.0.dist-info/RECORD +52 -0
- pyomp-0.5.0.dist-info/WHEEL +6 -0
- pyomp-0.5.0.dist-info/licenses/LICENSE +25 -0
- pyomp-0.5.0.dist-info/licenses/LICENSE-OPENMP.txt +361 -0
- pyomp-0.5.0.dist-info/top_level.txt +3 -0
- pyomp.dylibs/libc++.1.0.dylib +0 -0
- pyomp.dylibs/libzstd.1.5.7.dylib +0 -0
numba/openmp/__init__.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import llvmlite.binding as ll
|
|
2
|
+
import sys
|
|
3
|
+
from ._version import version as __version__ # noqa: F401
|
|
4
|
+
|
|
5
|
+
from .config import (
|
|
6
|
+
libpath,
|
|
7
|
+
DEBUG_OPENMP,
|
|
8
|
+
)
|
|
9
|
+
from .omp_runtime import ( # noqa F401
|
|
10
|
+
omp_set_num_threads,
|
|
11
|
+
omp_get_thread_num,
|
|
12
|
+
omp_get_num_threads,
|
|
13
|
+
omp_get_wtime,
|
|
14
|
+
omp_set_dynamic,
|
|
15
|
+
omp_set_nested,
|
|
16
|
+
omp_set_max_active_levels,
|
|
17
|
+
omp_get_max_active_levels,
|
|
18
|
+
omp_get_max_threads,
|
|
19
|
+
omp_get_num_procs,
|
|
20
|
+
omp_in_parallel,
|
|
21
|
+
omp_get_thread_limit,
|
|
22
|
+
omp_get_supported_active_levels,
|
|
23
|
+
omp_get_level,
|
|
24
|
+
omp_get_active_level,
|
|
25
|
+
omp_get_ancestor_thread_num,
|
|
26
|
+
omp_get_team_size,
|
|
27
|
+
omp_in_final,
|
|
28
|
+
omp_get_proc_bind,
|
|
29
|
+
omp_get_num_places,
|
|
30
|
+
omp_get_place_num_procs,
|
|
31
|
+
omp_get_place_num,
|
|
32
|
+
omp_set_default_device,
|
|
33
|
+
omp_get_default_device,
|
|
34
|
+
omp_get_num_devices,
|
|
35
|
+
omp_get_device_num,
|
|
36
|
+
omp_get_team_num,
|
|
37
|
+
omp_get_num_teams,
|
|
38
|
+
omp_is_initial_device,
|
|
39
|
+
omp_get_initial_device,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
from .compiler import (
|
|
43
|
+
CustomCompiler,
|
|
44
|
+
CustomFunctionCompiler,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
from .exceptions import ( # noqa: F401
|
|
48
|
+
UnspecifiedVarInDefaultNone,
|
|
49
|
+
ParallelForExtraCode,
|
|
50
|
+
ParallelForWrongLoopCount,
|
|
51
|
+
ParallelForInvalidCollapseCount,
|
|
52
|
+
NonconstantOpenmpSpecification,
|
|
53
|
+
NonStringOpenmpSpecification,
|
|
54
|
+
MultipleNumThreadsClauses,
|
|
55
|
+
)
|
|
56
|
+
from .overloads import omp_shared_array # noqa: F401
|
|
57
|
+
from .omp_context import _OpenmpContextType
|
|
58
|
+
from .decorators import jit, njit # noqa: F401
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _init():
|
|
62
|
+
sys_platform = sys.platform
|
|
63
|
+
from ctypes.util import find_library
|
|
64
|
+
|
|
65
|
+
omplib = (
|
|
66
|
+
libpath
|
|
67
|
+
/ "openmp"
|
|
68
|
+
/ "lib"
|
|
69
|
+
/ f"libomp{'.dylib' if sys_platform == 'darwin' else '.so'}"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# Prefer bundled libomp if it exists.
|
|
73
|
+
if omplib.exists():
|
|
74
|
+
if DEBUG_OPENMP >= 1:
|
|
75
|
+
print("Found bundled OpenMP runtime library at", omplib)
|
|
76
|
+
ll.load_library_permanently(str(omplib))
|
|
77
|
+
else:
|
|
78
|
+
# There is no bundled libomp, try to find it in standard library paths.
|
|
79
|
+
system_omplib = find_library("omp")
|
|
80
|
+
if system_omplib:
|
|
81
|
+
if DEBUG_OPENMP >= 1:
|
|
82
|
+
print(f"Found system OpenMP runtime library: {system_omplib}")
|
|
83
|
+
ll.load_library_permanently(system_omplib)
|
|
84
|
+
else:
|
|
85
|
+
raise RuntimeError(
|
|
86
|
+
f"OpenMP runtime not found. Bundled library missing at {omplib} "
|
|
87
|
+
"and no system libomp found via ctypes.util.find_library('omp'). "
|
|
88
|
+
"Ensure libomp is available in library paths."
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# libomptarget is unavailable on apple, windows, so return.
|
|
92
|
+
if sys_platform.startswith("darwin") or sys_platform.startswith("win32"):
|
|
93
|
+
return
|
|
94
|
+
|
|
95
|
+
omptargetlib = libpath / "openmp" / "lib" / "libomptarget.so"
|
|
96
|
+
if omptargetlib.exists():
|
|
97
|
+
if DEBUG_OPENMP >= 1:
|
|
98
|
+
print("Found OpenMP target runtime library at", omptargetlib)
|
|
99
|
+
ll.load_library_permanently(str(omptargetlib))
|
|
100
|
+
else:
|
|
101
|
+
raise RuntimeError(f"OpenMP target runtime not found at {omptargetlib}")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
_init()
|
|
105
|
+
|
|
106
|
+
openmp_context = _OpenmpContextType()
|
numba/openmp/_version.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
TYPE_CHECKING = False
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from typing import Tuple
|
|
16
|
+
from typing import Union
|
|
17
|
+
|
|
18
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
20
|
+
else:
|
|
21
|
+
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
23
|
+
|
|
24
|
+
version: str
|
|
25
|
+
__version__: str
|
|
26
|
+
__version_tuple__: VERSION_TUPLE
|
|
27
|
+
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
30
|
+
|
|
31
|
+
__version__ = version = '0.5.0'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 5, 0)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = 'g6d955c9a6'
|
numba/openmp/analysis.py
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
from numba.core import ir, types, typing
|
|
2
|
+
from numba.core.analysis import _fix_loop_exit, compute_cfg_from_blocks
|
|
3
|
+
from numba.core.ir_utils import visit_vars
|
|
4
|
+
from numba.extending import intrinsic
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def remove_ssa(var_name, scope, loc):
|
|
8
|
+
# Get the base name of a variable, removing the SSA extension.
|
|
9
|
+
var = ir.Var(scope, var_name, loc)
|
|
10
|
+
return var.unversioned_name
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def user_defined_var(var):
|
|
14
|
+
if not isinstance(var, str):
|
|
15
|
+
return False
|
|
16
|
+
return not var.startswith("$")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def is_dsa(name):
|
|
20
|
+
return (
|
|
21
|
+
name
|
|
22
|
+
in [
|
|
23
|
+
"QUAL.OMP.FIRSTPRIVATE",
|
|
24
|
+
"QUAL.OMP.PRIVATE",
|
|
25
|
+
"QUAL.OMP.SHARED",
|
|
26
|
+
"QUAL.OMP.LASTPRIVATE",
|
|
27
|
+
"QUAL.OMP.TARGET.IMPLICIT",
|
|
28
|
+
]
|
|
29
|
+
or name.startswith("QUAL.OMP.REDUCTION")
|
|
30
|
+
or name.startswith("QUAL.OMP.MAP")
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def is_private(x):
|
|
35
|
+
return x in [
|
|
36
|
+
"QUAL.OMP.PRIVATE",
|
|
37
|
+
"QUAL.OMP.FIRSTPRIVATE",
|
|
38
|
+
"QUAL.OMP.LASTPRIVATE",
|
|
39
|
+
"QUAL.OMP.TARGET.IMPLICIT",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def is_internal_var(var):
|
|
44
|
+
# Determine if a var is a Python var or an internal Numba var.
|
|
45
|
+
if var.is_temp:
|
|
46
|
+
return True
|
|
47
|
+
return var.unversioned_name != var.name
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def has_user_defined_var(the_set):
|
|
51
|
+
for x in the_set:
|
|
52
|
+
if user_defined_var(x):
|
|
53
|
+
return True
|
|
54
|
+
return False
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def get_user_defined_var(the_set):
|
|
58
|
+
ret = set()
|
|
59
|
+
for x in the_set:
|
|
60
|
+
if user_defined_var(x):
|
|
61
|
+
ret.add(x)
|
|
62
|
+
return ret
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def get_enclosing_region(func_ir, cur_block):
|
|
66
|
+
if not hasattr(func_ir, "openmp_enclosing"):
|
|
67
|
+
func_ir.openmp_enclosing = {}
|
|
68
|
+
if cur_block in func_ir.openmp_enclosing:
|
|
69
|
+
return func_ir.openmp_enclosing[cur_block]
|
|
70
|
+
else:
|
|
71
|
+
return None
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def add_enclosing_region(func_ir, blocks, openmp_node):
|
|
75
|
+
if not hasattr(func_ir, "openmp_enclosing"):
|
|
76
|
+
func_ir.openmp_enclosing = {}
|
|
77
|
+
if not hasattr(func_ir, "openmp_regions"):
|
|
78
|
+
func_ir.openmp_regions = {}
|
|
79
|
+
func_ir.openmp_regions[openmp_node] = sorted(blocks)
|
|
80
|
+
for b in blocks:
|
|
81
|
+
if b not in func_ir.openmp_enclosing:
|
|
82
|
+
func_ir.openmp_enclosing[b] = []
|
|
83
|
+
func_ir.openmp_enclosing[b].append(openmp_node)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def filter_nested_loops(cfg, loops):
|
|
87
|
+
blocks_in_loop = set()
|
|
88
|
+
# get loop bodies
|
|
89
|
+
for loop in loops.values():
|
|
90
|
+
insiders = set(loop.body) | set(loop.entries) | set(loop.exits)
|
|
91
|
+
insiders.discard(loop.header)
|
|
92
|
+
blocks_in_loop |= insiders
|
|
93
|
+
# find loop that is not part of other loops
|
|
94
|
+
for loop in loops.values():
|
|
95
|
+
if loop.header not in blocks_in_loop:
|
|
96
|
+
yield _fix_loop_exit(cfg, loop)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def remove_privatized(x):
|
|
100
|
+
if isinstance(x, ir.Var):
|
|
101
|
+
x = x.name
|
|
102
|
+
|
|
103
|
+
if isinstance(x, str) and x.endswith("%privatized"):
|
|
104
|
+
return x[: len(x) - len("%privatized")]
|
|
105
|
+
else:
|
|
106
|
+
return x
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def get_var_from_enclosing(enclosing_regions, var):
|
|
110
|
+
if not enclosing_regions:
|
|
111
|
+
return None
|
|
112
|
+
if len(enclosing_regions) == 0:
|
|
113
|
+
return None
|
|
114
|
+
return enclosing_regions[-1].get_var_dsa(var)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def remove_indirections(clause):
|
|
118
|
+
if not isinstance(clause, list):
|
|
119
|
+
return clause
|
|
120
|
+
while len(clause) == 1 and isinstance(clause[0], list):
|
|
121
|
+
clause = clause[0]
|
|
122
|
+
return clause
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def add_tags_to_enclosing(func_ir, cur_block, tags):
|
|
126
|
+
enclosing_region = get_enclosing_region(func_ir, cur_block)
|
|
127
|
+
if enclosing_region:
|
|
128
|
+
for region in enclosing_region:
|
|
129
|
+
for tag in tags:
|
|
130
|
+
region.add_tag(tag)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def get_blocks_between_start_end(blocks, start_block, end_block):
|
|
134
|
+
cfg = compute_cfg_from_blocks(blocks)
|
|
135
|
+
blocks_in_region = [start_block]
|
|
136
|
+
|
|
137
|
+
def add_in_region(cfg, blk, blocks_in_region, end_block):
|
|
138
|
+
"""For each successor in the CFG of the block we're currently
|
|
139
|
+
adding to blocks_in_region, add that successor to
|
|
140
|
+
blocks_in_region if it isn't the end_block. Then,
|
|
141
|
+
recursively call this routine for the added block to add
|
|
142
|
+
its successors.
|
|
143
|
+
"""
|
|
144
|
+
for out_blk, _ in cfg.successors(blk):
|
|
145
|
+
if out_blk != end_block and out_blk not in blocks_in_region:
|
|
146
|
+
blocks_in_region.append(out_blk)
|
|
147
|
+
add_in_region(cfg, out_blk, blocks_in_region, end_block)
|
|
148
|
+
|
|
149
|
+
# Calculate all the Numba IR blocks in the target region.
|
|
150
|
+
add_in_region(cfg, start_block, blocks_in_region, end_block)
|
|
151
|
+
return blocks_in_region
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
@intrinsic
|
|
155
|
+
def get_itercount(typingctx, it):
|
|
156
|
+
if isinstance(it, types.RangeIteratorType):
|
|
157
|
+
sig = typing.signature(it.yield_type, it)
|
|
158
|
+
|
|
159
|
+
def codegen(context, builder, signature, args):
|
|
160
|
+
assert len(args) == 1
|
|
161
|
+
val = args[0]
|
|
162
|
+
pair = context.make_helper(builder, it, val)
|
|
163
|
+
return builder.load(pair.count)
|
|
164
|
+
|
|
165
|
+
return sig, codegen
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def remove_all_privatized(x):
|
|
169
|
+
new_x = None
|
|
170
|
+
while new_x != x:
|
|
171
|
+
new_x = x
|
|
172
|
+
x = remove_privatized(new_x)
|
|
173
|
+
|
|
174
|
+
return new_x
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def typemap_lookup(typemap, x):
|
|
178
|
+
orig_x = x
|
|
179
|
+
if isinstance(x, ir.Var):
|
|
180
|
+
x = x.name
|
|
181
|
+
|
|
182
|
+
while True:
|
|
183
|
+
if x in typemap:
|
|
184
|
+
return typemap[x]
|
|
185
|
+
new_x = remove_privatized(x)
|
|
186
|
+
if new_x == x:
|
|
187
|
+
break
|
|
188
|
+
else:
|
|
189
|
+
x = new_x
|
|
190
|
+
|
|
191
|
+
tkeys = typemap.keys()
|
|
192
|
+
|
|
193
|
+
# Get basename (without privatized)
|
|
194
|
+
x = remove_all_privatized(x)
|
|
195
|
+
|
|
196
|
+
potential_keys = list(filter(lambda y: y.startswith(x), tkeys))
|
|
197
|
+
|
|
198
|
+
for pkey in potential_keys:
|
|
199
|
+
pkey_base = remove_all_privatized(pkey)
|
|
200
|
+
if pkey_base == x:
|
|
201
|
+
return typemap[pkey]
|
|
202
|
+
|
|
203
|
+
raise KeyError(f"{orig_x} and all of its non-privatized names not found in typemap")
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def is_target_tag(x):
|
|
207
|
+
ret = x.startswith("DIR.OMP.TARGET") and x not in [
|
|
208
|
+
"DIR.OMP.TARGET.DATA",
|
|
209
|
+
"DIR.OMP.TARGET.ENTER.DATA",
|
|
210
|
+
"DIR.OMP.TARGET.EXIT.DATA",
|
|
211
|
+
]
|
|
212
|
+
return ret
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def is_target_arg(name):
|
|
216
|
+
return (
|
|
217
|
+
name in ["QUAL.OMP.FIRSTPRIVATE", "QUAL.OMP.TARGET.IMPLICIT"]
|
|
218
|
+
or name.startswith("QUAL.OMP.MAP")
|
|
219
|
+
or name.startswith("QUAL.OMP.REDUCTION")
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def in_openmp_region(builder):
|
|
224
|
+
if hasattr(builder, "_lowerer_push_alloca_callbacks"):
|
|
225
|
+
return builder._lowerer_push_alloca_callbacks > 0
|
|
226
|
+
else:
|
|
227
|
+
return False
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def get_name_var_table(blocks):
|
|
231
|
+
"""create a mapping from variable names to their ir.Var objects"""
|
|
232
|
+
|
|
233
|
+
def get_name_var_visit(var, namevar):
|
|
234
|
+
namevar[var.name] = var
|
|
235
|
+
return var
|
|
236
|
+
|
|
237
|
+
namevar = {}
|
|
238
|
+
visit_vars(blocks, get_name_var_visit, namevar)
|
|
239
|
+
return namevar
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def is_pointer_target_arg(name, typ):
|
|
243
|
+
if name.startswith("QUAL.OMP.REDUCTION"):
|
|
244
|
+
return True
|
|
245
|
+
if name.startswith("QUAL.OMP.MAP"):
|
|
246
|
+
return True
|
|
247
|
+
if name in ["QUAL.OMP.TARGET.IMPLICIT"]:
|
|
248
|
+
if isinstance(typ, types.npytypes.Array):
|
|
249
|
+
return True
|
|
250
|
+
|
|
251
|
+
return False
|