xobjects 0.6.6__tar.gz → 0.6.7__tar.gz
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.
- {xobjects-0.6.6 → xobjects-0.6.7}/.github/workflows/black.yml +1 -1
- {xobjects-0.6.6 → xobjects-0.6.7}/.pre-commit-config.yaml +3 -3
- {xobjects-0.6.6/xobjects.egg-info → xobjects-0.6.7}/PKG-INFO +1 -1
- xobjects-0.6.7/xobjects/_version.py +1 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/context.py +61 -11
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/context_cpu.py +8 -4
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/context_cupy.py +35 -3
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/context_pyopencl.py +9 -2
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/headers/atomicadd.h +1 -1
- {xobjects-0.6.6 → xobjects-0.6.7/xobjects.egg-info}/PKG-INFO +1 -1
- xobjects-0.6.6/xobjects/_version.py +0 -1
- {xobjects-0.6.6 → xobjects-0.6.7}/.gitignore +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/.readthedocs.yaml +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/Architecture.md +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/LICENSE +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/MANIFEST.in +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/README.md +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/contributors_and_credits.txt +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/docs/Makefile +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/docs/architecture/contexts.rst +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/docs/architecture/types.rst +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/docs/architecture.rst +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/docs/conf.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/docs/index.rst +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/docs/make.bat +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/docs/quickstart.rst +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/docs/reference.rst +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/api_def.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/api_init.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/capi_example.c +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/check_assembly.c +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/ex_array_init_perf.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/ex_cpugpu.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/ex_nested_ref.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/ex_ref_cpu.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/ex_struct_cpu.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/ex_unionref_cpu.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/ex_unionref_method.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/init_soa.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/issue_with_two_pyopencl_contexts.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/kernel_basics/kernel_cffi.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/kernel_basics/kernel_cupy.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/kernel_basics/kernel_pyopencl.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/opencl_offsets.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/simple_kernel.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/examples/sixtracklib.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/mktest +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/pyproject.toml +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/release.sh +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/requirements.txt +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/setup.cfg +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/setup.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/__init__.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/notest_capi.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_align.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_array.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_buffer.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_capi.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_chunk.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_common.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_context_opencl.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_hybrid_class.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_kernel.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_linked_array.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_nplike_arrays.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_ref.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_scalars.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_shared_memory.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_strides.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_string.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_struct.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_to_dict.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_typeutils.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/tests/test_unionref.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/update_cprght_statement.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/__init__.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/_patch_pyopencl_array.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/array.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/capi.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/general.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/headers/common.h +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/hybrid_class.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/linkedarray.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/ref.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/scalar.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/specialize_source.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/string.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/struct.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/test_helpers.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/typeutils.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects/union.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects.egg-info/SOURCES.txt +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects.egg-info/dependency_links.txt +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects.egg-info/entry_points.txt +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects.egg-info/requires.txt +0 -0
- {xobjects-0.6.6 → xobjects-0.6.7}/xobjects.egg-info/top_level.txt +0 -0
|
@@ -5,8 +5,8 @@ repos:
|
|
|
5
5
|
- id: check-yaml
|
|
6
6
|
- id: end-of-file-fixer
|
|
7
7
|
- id: trailing-whitespace
|
|
8
|
-
- repo: https://github.com/psf/black
|
|
9
|
-
rev:
|
|
8
|
+
- repo: https://github.com/psf/black-pre-commit-mirror
|
|
9
|
+
rev: 26.3.1
|
|
10
10
|
hooks:
|
|
11
11
|
- id: black
|
|
12
|
-
language_version: python3
|
|
12
|
+
language_version: python3
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.6.7"
|
|
@@ -354,25 +354,75 @@ class XContext(ABC):
|
|
|
354
354
|
) -> Dict[Tuple[str, tuple], KernelType]:
|
|
355
355
|
pass
|
|
356
356
|
|
|
357
|
-
def
|
|
358
|
-
|
|
357
|
+
def get_installed_c_source_and_library_paths(
|
|
358
|
+
self,
|
|
359
|
+
) -> tuple[set[Path], set[str], set[Path]]:
|
|
360
|
+
"""Returns a list of C paths registered in dependent packages.
|
|
359
361
|
|
|
360
|
-
In a package that depends on xobjects, you can register C source
|
|
361
|
-
using the entry point `xobjects.
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
``#include <
|
|
362
|
+
In a package that depends on xobjects, you can register C source and
|
|
363
|
+
library paths using the entry point `xobjects.build_info`. These paths
|
|
364
|
+
will be added to the C include path and the library path when building
|
|
365
|
+
kernels. For example, the following will allow to write
|
|
366
|
+
``#include <xcoll/path/to/some/header.h>`` in kernel sources, and
|
|
367
|
+
allow to use functions from the library ``xcoll/lib/libFlukaIO.a``:
|
|
365
368
|
|
|
366
369
|
.. code-block:: toml
|
|
367
370
|
[project.entry-points.xobjects]
|
|
368
|
-
|
|
371
|
+
build_info = "xcoll._xobjects:get_build_info"
|
|
372
|
+
|
|
373
|
+
and in the file ``xcoll/_xobjects.py``:
|
|
374
|
+
|
|
375
|
+
.. code-block:: python
|
|
376
|
+
from ..general import _pkg_root
|
|
377
|
+
def get_build_info():
|
|
378
|
+
return {
|
|
379
|
+
"include_dirs": [_pkg_root.parent],
|
|
380
|
+
"libraries": ["FlukaIO"],
|
|
381
|
+
"library_dirs": [_pkg_root / "lib"],
|
|
382
|
+
}
|
|
369
383
|
"""
|
|
370
|
-
sources =
|
|
384
|
+
sources = set()
|
|
385
|
+
libs = set()
|
|
386
|
+
lib_paths = set()
|
|
387
|
+
|
|
388
|
+
# Old entry point for backward compatibility
|
|
371
389
|
for ep in entry_points(group="xobjects", name="include"):
|
|
372
390
|
module = ep.load()
|
|
373
391
|
path = Path(module.__file__).parents[1]
|
|
374
|
-
sources.
|
|
375
|
-
|
|
392
|
+
sources.add(path)
|
|
393
|
+
|
|
394
|
+
# New entry point
|
|
395
|
+
for ep in entry_points(group="xobjects", name="build_info"):
|
|
396
|
+
get_build_info = ep.load()
|
|
397
|
+
info = get_build_info()
|
|
398
|
+
include_dirs = info.get("include_dirs", [])
|
|
399
|
+
if not hasattr(include_dirs, "__iter__") or isinstance(
|
|
400
|
+
include_dirs, str
|
|
401
|
+
):
|
|
402
|
+
include_dirs = [include_dirs]
|
|
403
|
+
include_dirs = [
|
|
404
|
+
Path(dd).expanduser().resolve() for dd in include_dirs
|
|
405
|
+
]
|
|
406
|
+
sources.update(include_dirs)
|
|
407
|
+
|
|
408
|
+
library_dirs = info.get("library_dirs", [])
|
|
409
|
+
if not hasattr(library_dirs, "__iter__") or isinstance(
|
|
410
|
+
library_dirs, str
|
|
411
|
+
):
|
|
412
|
+
library_dirs = [library_dirs]
|
|
413
|
+
library_dirs = [
|
|
414
|
+
Path(dd).expanduser().resolve() for dd in library_dirs
|
|
415
|
+
]
|
|
416
|
+
lib_paths.update(library_dirs)
|
|
417
|
+
|
|
418
|
+
libraries = info.get("libraries", [])
|
|
419
|
+
if not hasattr(libraries, "__iter__") or isinstance(
|
|
420
|
+
libraries, str
|
|
421
|
+
):
|
|
422
|
+
libraries = [libraries]
|
|
423
|
+
libs.update(libraries)
|
|
424
|
+
|
|
425
|
+
return sources, libs, lib_paths
|
|
376
426
|
|
|
377
427
|
@abstractmethod
|
|
378
428
|
def nparray_to_context_array(self, arr, copy=False):
|
|
@@ -499,10 +499,11 @@ class ContextCpu(XContext):
|
|
|
499
499
|
xtr_compile_args.append("-DXO_CONTEXT_CPU_SERIAL")
|
|
500
500
|
xtr_link_args.append("-DXO_CONTEXT_CPU_SERIAL")
|
|
501
501
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
502
|
+
(
|
|
503
|
+
extra_include_paths,
|
|
504
|
+
extra_libraries,
|
|
505
|
+
extra_library_paths,
|
|
506
|
+
) = self.get_installed_c_source_and_library_paths()
|
|
506
507
|
|
|
507
508
|
if os.name == "nt": # windows
|
|
508
509
|
# TODO: to be handled properly
|
|
@@ -516,6 +517,9 @@ class ContextCpu(XContext):
|
|
|
516
517
|
ffi_interface.set_source(
|
|
517
518
|
module_name,
|
|
518
519
|
specialized_source,
|
|
520
|
+
include_dirs=[path.as_posix() for path in extra_include_paths],
|
|
521
|
+
libraries=list(extra_libraries),
|
|
522
|
+
library_dirs=[path.as_posix() for path in extra_library_paths],
|
|
519
523
|
extra_compile_args=xtr_compile_args,
|
|
520
524
|
extra_link_args=xtr_link_args,
|
|
521
525
|
)
|
|
@@ -8,6 +8,7 @@ import os
|
|
|
8
8
|
import shutil
|
|
9
9
|
import subprocess
|
|
10
10
|
import tempfile
|
|
11
|
+
import warnings
|
|
11
12
|
from typing import Dict, List, Tuple, Literal
|
|
12
13
|
|
|
13
14
|
import numpy as np
|
|
@@ -28,6 +29,14 @@ from .specialize_source import specialize_source
|
|
|
28
29
|
|
|
29
30
|
log = logging.getLogger(__name__)
|
|
30
31
|
|
|
32
|
+
no_fast_compile = False
|
|
33
|
+
"""Disable NVRTC fast compile tuning when building CUDA kernels.
|
|
34
|
+
|
|
35
|
+
When set to ``True``, ``ContextCupy`` does not pass ``--Ofast-compile=min``
|
|
36
|
+
to NVRTC. The ``XO_CUDA_NO_FAST_COMPILE`` environment variable provides the
|
|
37
|
+
same behavior.
|
|
38
|
+
"""
|
|
39
|
+
|
|
31
40
|
try:
|
|
32
41
|
import cupy
|
|
33
42
|
import cupyx.scipy
|
|
@@ -385,6 +394,13 @@ class ContextCupy(XContext):
|
|
|
385
394
|
Creates a Cupy Context object, that allows performing the computations
|
|
386
395
|
on nVidia GPUs.
|
|
387
396
|
|
|
397
|
+
The module-level flag ``xobjects.context_cupy.no_fast_compile`` controls
|
|
398
|
+
whether NVRTC fast compile tuning is disabled. By default it is ``False``,
|
|
399
|
+
so CUDA kernels built with NVRTC >= 12.9 use ``--Ofast-compile=min`` to
|
|
400
|
+
reduce compilation time and memory usage, at the cost of some runtime
|
|
401
|
+
performance. Set it to ``True`` to disable this option. The environment
|
|
402
|
+
variable ``XO_CUDA_NO_FAST_COMPILE`` also disables it.
|
|
403
|
+
|
|
388
404
|
Args:
|
|
389
405
|
default_block_size (int): CUDA thread size that is used by default
|
|
390
406
|
for kernel execution in case a block size is not specified
|
|
@@ -477,8 +493,15 @@ class ContextCupy(XContext):
|
|
|
477
493
|
with open(save_source_as, "w") as fid:
|
|
478
494
|
fid.write(specialized_source)
|
|
479
495
|
|
|
480
|
-
|
|
481
|
-
|
|
496
|
+
(
|
|
497
|
+
# TODO: how to deal with CUDA libraries?
|
|
498
|
+
extra_include_paths,
|
|
499
|
+
_,
|
|
500
|
+
_,
|
|
501
|
+
) = self.get_installed_c_source_and_library_paths()
|
|
502
|
+
include_flags = [
|
|
503
|
+
f"-I{path.as_posix()}" for path in extra_include_paths
|
|
504
|
+
]
|
|
482
505
|
extra_compile_args = (
|
|
483
506
|
*extra_compile_args,
|
|
484
507
|
*include_flags,
|
|
@@ -488,11 +511,20 @@ class ContextCupy(XContext):
|
|
|
488
511
|
if self.backend == "nvrtc":
|
|
489
512
|
# NVRTC (default): add NVRTC-specific flags
|
|
490
513
|
nvrtc_args = (*extra_compile_args,)
|
|
514
|
+
fast_compile = not (
|
|
515
|
+
no_fast_compile or os.environ.get("XO_CUDA_NO_FAST_COMPILE")
|
|
516
|
+
)
|
|
491
517
|
if nvrtc and nvrtc.getVersion() >= (12, 9):
|
|
492
518
|
# If supported, skip prohibitively heavy optimisations (e.g.
|
|
493
519
|
# involving cloning). This it at the expense of <20%
|
|
494
520
|
# runtime performance, but gain of a lot of compile time and memory.
|
|
495
|
-
|
|
521
|
+
if fast_compile:
|
|
522
|
+
nvrtc_args += ("--Ofast-compile=min",)
|
|
523
|
+
elif fast_compile:
|
|
524
|
+
warnings.warn(
|
|
525
|
+
"Detected nvrtc version < 12.9, which does not support compile-time optimisation tuning. "
|
|
526
|
+
"Compilation time and memory usage might be high: if this is a problem, please update CUDA nvrtc."
|
|
527
|
+
)
|
|
496
528
|
|
|
497
529
|
module = cupy.RawModule(
|
|
498
530
|
code=specialized_source, options=nvrtc_args
|
|
@@ -228,8 +228,15 @@ class ContextPyopencl(XContext):
|
|
|
228
228
|
with open(save_source_as, "w") as fid:
|
|
229
229
|
fid.write(specialized_source)
|
|
230
230
|
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
(
|
|
232
|
+
# TODO: how to deal with OpenCL libraries?
|
|
233
|
+
extra_include_paths,
|
|
234
|
+
_,
|
|
235
|
+
_,
|
|
236
|
+
) = self.get_installed_c_source_and_library_paths()
|
|
237
|
+
include_flags = [
|
|
238
|
+
f"-I{path.as_posix()}" for path in extra_include_paths
|
|
239
|
+
]
|
|
233
240
|
|
|
234
241
|
extra_compile_args = (
|
|
235
242
|
*extra_compile_args,
|
|
@@ -102,7 +102,7 @@ DEF_ATOMIC_ADD(double , f64)
|
|
|
102
102
|
#if defined(XO_CONTEXT_CUDA)
|
|
103
103
|
// CUDA compiler may not have <stdint.h>, so define the types if needed.
|
|
104
104
|
#if defined(__CUDACC_RTC__) || defined(__HIPCC_RTC__)
|
|
105
|
-
// NVRTC and HIPRTC (CuPy RawModule default) can’t see <stdint.h>
|
|
105
|
+
// NVRTC and HIPRTC (CuPy RawModule default) can’t see <stdint.h>
|
|
106
106
|
// We detect via __CUDACC_RTC__ (Nvidia) or __HIPCC_RTC__ (ROCm)
|
|
107
107
|
typedef signed char int8_t;
|
|
108
108
|
typedef short int16_t;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.6.6"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|