xobjects 0.6.6__tar.gz → 0.6.8__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.egg-info → xobjects-0.6.8}/PKG-INFO +1 -1
- xobjects-0.6.8/xobjects/_version.py +1 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/context.py +61 -11
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/context_cpu.py +8 -4
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/context_cupy.py +41 -4
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/context_pyopencl.py +9 -2
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/headers/atomicadd.h +1 -1
- {xobjects-0.6.6 → xobjects-0.6.8/xobjects.egg-info}/PKG-INFO +1 -1
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects.egg-info/SOURCES.txt +0 -39
- xobjects-0.6.6/.github/workflows/black.yml +0 -10
- xobjects-0.6.6/.gitignore +0 -13
- xobjects-0.6.6/.pre-commit-config.yaml +0 -12
- xobjects-0.6.6/.readthedocs.yaml +0 -20
- xobjects-0.6.6/contributors_and_credits.txt +0 -7
- xobjects-0.6.6/docs/Makefile +0 -20
- xobjects-0.6.6/docs/architecture/contexts.rst +0 -164
- xobjects-0.6.6/docs/architecture/types.rst +0 -179
- xobjects-0.6.6/docs/architecture.rst +0 -16
- xobjects-0.6.6/docs/conf.py +0 -278
- xobjects-0.6.6/docs/index.rst +0 -79
- xobjects-0.6.6/docs/make.bat +0 -35
- xobjects-0.6.6/docs/quickstart.rst +0 -2
- xobjects-0.6.6/docs/reference.rst +0 -8
- xobjects-0.6.6/examples/api_def.py +0 -28
- xobjects-0.6.6/examples/api_init.py +0 -101
- xobjects-0.6.6/examples/capi_example.c +0 -100
- xobjects-0.6.6/examples/check_assembly.c +0 -101
- xobjects-0.6.6/examples/ex_array_init_perf.py +0 -42
- xobjects-0.6.6/examples/ex_cpugpu.py +0 -46
- xobjects-0.6.6/examples/ex_nested_ref.py +0 -49
- xobjects-0.6.6/examples/ex_ref_cpu.py +0 -52
- xobjects-0.6.6/examples/ex_struct_cpu.py +0 -39
- xobjects-0.6.6/examples/ex_unionref_cpu.py +0 -49
- xobjects-0.6.6/examples/ex_unionref_method.py +0 -120
- xobjects-0.6.6/examples/init_soa.py +0 -67
- xobjects-0.6.6/examples/issue_with_two_pyopencl_contexts.py +0 -18
- xobjects-0.6.6/examples/kernel_basics/kernel_cffi.py +0 -54
- xobjects-0.6.6/examples/kernel_basics/kernel_cupy.py +0 -42
- xobjects-0.6.6/examples/kernel_basics/kernel_pyopencl.py +0 -48
- xobjects-0.6.6/examples/opencl_offsets.py +0 -38
- xobjects-0.6.6/examples/simple_kernel.py +0 -59
- xobjects-0.6.6/examples/sixtracklib.py +0 -80
- xobjects-0.6.6/mktest +0 -1
- xobjects-0.6.6/release.sh +0 -20
- xobjects-0.6.6/requirements.txt +0 -3
- xobjects-0.6.6/tests/__init__.py +0 -4
- xobjects-0.6.6/tests/notest_capi.py +0 -208
- xobjects-0.6.6/update_cprght_statement.py +0 -49
- xobjects-0.6.6/xobjects/_version.py +0 -1
- {xobjects-0.6.6 → xobjects-0.6.8}/Architecture.md +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/LICENSE +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/MANIFEST.in +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/README.md +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/pyproject.toml +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/setup.cfg +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/setup.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_align.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_array.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_buffer.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_capi.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_chunk.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_common.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_context_opencl.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_hybrid_class.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_kernel.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_linked_array.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_nplike_arrays.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_ref.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_scalars.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_shared_memory.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_strides.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_string.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_struct.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_to_dict.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_typeutils.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/tests/test_unionref.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/__init__.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/_patch_pyopencl_array.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/array.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/capi.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/general.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/headers/common.h +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/hybrid_class.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/linkedarray.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/ref.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/scalar.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/specialize_source.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/string.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/struct.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/test_helpers.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/typeutils.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects/union.py +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects.egg-info/dependency_links.txt +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects.egg-info/entry_points.txt +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects.egg-info/requires.txt +0 -0
- {xobjects-0.6.6 → xobjects-0.6.8}/xobjects.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.6.8"
|
|
@@ -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,11 +29,24 @@ 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
|
|
34
43
|
import cupyx.scipy.interpolate
|
|
35
|
-
|
|
44
|
+
with warnings.catch_warnings():
|
|
45
|
+
warnings.filterwarnings(
|
|
46
|
+
'ignore',
|
|
47
|
+
message=r'cupyx\.jit\.rawkernel is experimental\.',
|
|
48
|
+
category=FutureWarning)
|
|
49
|
+
import cupyx.scipy.signal
|
|
36
50
|
import cupyx.scipy.special
|
|
37
51
|
import cupyx.scipy.stats
|
|
38
52
|
from cupyx.scipy import fftpack as cufftp
|
|
@@ -385,6 +399,13 @@ class ContextCupy(XContext):
|
|
|
385
399
|
Creates a Cupy Context object, that allows performing the computations
|
|
386
400
|
on nVidia GPUs.
|
|
387
401
|
|
|
402
|
+
The module-level flag ``xobjects.context_cupy.no_fast_compile`` controls
|
|
403
|
+
whether NVRTC fast compile tuning is disabled. By default it is ``False``,
|
|
404
|
+
so CUDA kernels built with NVRTC >= 12.9 use ``--Ofast-compile=min`` to
|
|
405
|
+
reduce compilation time and memory usage, at the cost of some runtime
|
|
406
|
+
performance. Set it to ``True`` to disable this option. The environment
|
|
407
|
+
variable ``XO_CUDA_NO_FAST_COMPILE`` also disables it.
|
|
408
|
+
|
|
388
409
|
Args:
|
|
389
410
|
default_block_size (int): CUDA thread size that is used by default
|
|
390
411
|
for kernel execution in case a block size is not specified
|
|
@@ -477,8 +498,15 @@ class ContextCupy(XContext):
|
|
|
477
498
|
with open(save_source_as, "w") as fid:
|
|
478
499
|
fid.write(specialized_source)
|
|
479
500
|
|
|
480
|
-
|
|
481
|
-
|
|
501
|
+
(
|
|
502
|
+
# TODO: how to deal with CUDA libraries?
|
|
503
|
+
extra_include_paths,
|
|
504
|
+
_,
|
|
505
|
+
_,
|
|
506
|
+
) = self.get_installed_c_source_and_library_paths()
|
|
507
|
+
include_flags = [
|
|
508
|
+
f"-I{path.as_posix()}" for path in extra_include_paths
|
|
509
|
+
]
|
|
482
510
|
extra_compile_args = (
|
|
483
511
|
*extra_compile_args,
|
|
484
512
|
*include_flags,
|
|
@@ -488,11 +516,20 @@ class ContextCupy(XContext):
|
|
|
488
516
|
if self.backend == "nvrtc":
|
|
489
517
|
# NVRTC (default): add NVRTC-specific flags
|
|
490
518
|
nvrtc_args = (*extra_compile_args,)
|
|
519
|
+
fast_compile = not (
|
|
520
|
+
no_fast_compile or os.environ.get("XO_CUDA_NO_FAST_COMPILE")
|
|
521
|
+
)
|
|
491
522
|
if nvrtc and nvrtc.getVersion() >= (12, 9):
|
|
492
523
|
# If supported, skip prohibitively heavy optimisations (e.g.
|
|
493
524
|
# involving cloning). This it at the expense of <20%
|
|
494
525
|
# runtime performance, but gain of a lot of compile time and memory.
|
|
495
|
-
|
|
526
|
+
if fast_compile:
|
|
527
|
+
nvrtc_args += ("--Ofast-compile=min",)
|
|
528
|
+
elif fast_compile:
|
|
529
|
+
warnings.warn(
|
|
530
|
+
"Detected nvrtc version < 12.9, which does not support compile-time optimisation tuning. "
|
|
531
|
+
"Compilation time and memory usage might be high: if this is a problem, please update CUDA nvrtc."
|
|
532
|
+
)
|
|
496
533
|
|
|
497
534
|
module = cupy.RawModule(
|
|
498
535
|
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,49 +1,10 @@
|
|
|
1
|
-
.gitignore
|
|
2
|
-
.pre-commit-config.yaml
|
|
3
|
-
.readthedocs.yaml
|
|
4
1
|
Architecture.md
|
|
5
2
|
LICENSE
|
|
6
3
|
MANIFEST.in
|
|
7
4
|
README.md
|
|
8
|
-
contributors_and_credits.txt
|
|
9
|
-
mktest
|
|
10
5
|
pyproject.toml
|
|
11
|
-
release.sh
|
|
12
|
-
requirements.txt
|
|
13
6
|
setup.cfg
|
|
14
7
|
setup.py
|
|
15
|
-
update_cprght_statement.py
|
|
16
|
-
.github/workflows/black.yml
|
|
17
|
-
docs/Makefile
|
|
18
|
-
docs/architecture.rst
|
|
19
|
-
docs/conf.py
|
|
20
|
-
docs/index.rst
|
|
21
|
-
docs/make.bat
|
|
22
|
-
docs/quickstart.rst
|
|
23
|
-
docs/reference.rst
|
|
24
|
-
docs/architecture/contexts.rst
|
|
25
|
-
docs/architecture/types.rst
|
|
26
|
-
examples/api_def.py
|
|
27
|
-
examples/api_init.py
|
|
28
|
-
examples/capi_example.c
|
|
29
|
-
examples/check_assembly.c
|
|
30
|
-
examples/ex_array_init_perf.py
|
|
31
|
-
examples/ex_cpugpu.py
|
|
32
|
-
examples/ex_nested_ref.py
|
|
33
|
-
examples/ex_ref_cpu.py
|
|
34
|
-
examples/ex_struct_cpu.py
|
|
35
|
-
examples/ex_unionref_cpu.py
|
|
36
|
-
examples/ex_unionref_method.py
|
|
37
|
-
examples/init_soa.py
|
|
38
|
-
examples/issue_with_two_pyopencl_contexts.py
|
|
39
|
-
examples/opencl_offsets.py
|
|
40
|
-
examples/simple_kernel.py
|
|
41
|
-
examples/sixtracklib.py
|
|
42
|
-
examples/kernel_basics/kernel_cffi.py
|
|
43
|
-
examples/kernel_basics/kernel_cupy.py
|
|
44
|
-
examples/kernel_basics/kernel_pyopencl.py
|
|
45
|
-
tests/__init__.py
|
|
46
|
-
tests/notest_capi.py
|
|
47
8
|
tests/test_align.py
|
|
48
9
|
tests/test_array.py
|
|
49
10
|
tests/test_buffer.py
|
xobjects-0.6.6/.gitignore
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
repos:
|
|
2
|
-
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
-
rev: v4.5.0
|
|
4
|
-
hooks:
|
|
5
|
-
- id: check-yaml
|
|
6
|
-
- id: end-of-file-fixer
|
|
7
|
-
- id: trailing-whitespace
|
|
8
|
-
- repo: https://github.com/psf/black
|
|
9
|
-
rev: 23.10.1
|
|
10
|
-
hooks:
|
|
11
|
-
- id: black
|
|
12
|
-
language_version: python3 # Should be a command that runs python3.6+
|
xobjects-0.6.6/.readthedocs.yaml
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# .readthedocs.yaml
|
|
2
|
-
# Read the Docs configuration file
|
|
3
|
-
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
|
4
|
-
|
|
5
|
-
# Required
|
|
6
|
-
version: 2
|
|
7
|
-
|
|
8
|
-
# Build documentation in the docs/ directory with Sphinx
|
|
9
|
-
sphinx:
|
|
10
|
-
configuration: docs/conf.py
|
|
11
|
-
|
|
12
|
-
# Optionally build your docs in additional formats such as PDF
|
|
13
|
-
formats:
|
|
14
|
-
- pdf
|
|
15
|
-
|
|
16
|
-
# Optionally set the version of Python and requirements required to build your docs
|
|
17
|
-
python:
|
|
18
|
-
version: 3.7
|
|
19
|
-
# install:
|
|
20
|
-
# - requirements: docs/requirements.txt
|
xobjects-0.6.6/docs/Makefile
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# Minimal makefile for Sphinx documentation
|
|
2
|
-
#
|
|
3
|
-
|
|
4
|
-
# You can set these variables from the command line, and also
|
|
5
|
-
# from the environment for the first two.
|
|
6
|
-
SPHINXOPTS ?=
|
|
7
|
-
SPHINXBUILD ?= sphinx-build
|
|
8
|
-
SOURCEDIR = .
|
|
9
|
-
BUILDDIR = _build
|
|
10
|
-
|
|
11
|
-
# Put it first so that "make" without argument is like "make help".
|
|
12
|
-
help:
|
|
13
|
-
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
14
|
-
|
|
15
|
-
.PHONY: help Makefile
|
|
16
|
-
|
|
17
|
-
# Catch-all target: route all unknown targets to Sphinx using the new
|
|
18
|
-
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
|
19
|
-
%: Makefile
|
|
20
|
-
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
Contexts
|
|
2
|
-
========
|
|
3
|
-
|
|
4
|
-
Devices
|
|
5
|
-
-------
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Buffers
|
|
9
|
-
-------
|
|
10
|
-
|
|
11
|
-
Buffers are able to store data in the host or device from several object types and return data in device or host.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Instance methods:
|
|
15
|
-
|
|
16
|
-
* write(self, source, offset, nbytes): write nbytes from source that can be a np-like array, bytearray, bytes or another buffer
|
|
17
|
-
* to_nplike(self,dtype,shape,offset): return a view of the data in a np-like arrays
|
|
18
|
-
* to_bytearray(self,offset,count): return
|
|
19
|
-
|
|
20
|
-
.. code::
|
|
21
|
-
|
|
22
|
-
def update_from_xbuffer(self,offset, source, source_offset, nbytes):
|
|
23
|
-
"update from any xbuffer, don't pass through gpu if possible"
|
|
24
|
-
|
|
25
|
-
def update_from_buffer(self, offset, buffer):
|
|
26
|
-
"""source is python buffer such as bytearray, numpy array .data"""
|
|
27
|
-
|
|
28
|
-
def copy_native(self,offset,nbytes):
|
|
29
|
-
"""return native data with content at from offset and nbytes
|
|
30
|
-
return native_data
|
|
31
|
-
|
|
32
|
-
def update_from_native(self, offset, source, source_offset, nbytes):
|
|
33
|
-
"""update native source into buffer usef in update_from_xbuffer"""
|
|
34
|
-
|
|
35
|
-
def to_nplike(self,offset,shape,dtype)
|
|
36
|
-
"""view in nplike"""
|
|
37
|
-
|
|
38
|
-
def to_bytearray(self,offset,nbytes)
|
|
39
|
-
"""copy in byte array: used in update_from_xbuffer"""
|
|
40
|
-
|
|
41
|
-
def to_pointer_arg(self,offset,nbytes):
|
|
42
|
-
return self.data[offset:offset+nbytes] #offset can lead to alignement error in opencl if not multiple of 4 bytes
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
Arguments for kernels:
|
|
47
|
-
|
|
48
|
-
- CPU:
|
|
49
|
-
- numpy array -> ``ffi.cast("double *", ffi.from_buffer(arr))``
|
|
50
|
-
- numpy scalar -> no change
|
|
51
|
-
- s string -> ``ss.decode("utf8")``
|
|
52
|
-
|
|
53
|
-
- PyOpenCL:
|
|
54
|
-
- pyopencl.Buffer: [offset:offset+nbytes] or copy back and fort if needs to be aligned
|
|
55
|
-
- pyopencl.array: arr.base_data[arr.offset:arr.offset+arr.nbytes] or copy back and fort
|
|
56
|
-
|
|
57
|
-
- cuda:
|
|
58
|
-
- pycuda.array: arr or arr.data
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
nparray.data: python buffer pointing to start of the array arrays
|
|
62
|
-
clarray.data: Optional Opencl buffer pointing to the start of the array
|
|
63
|
-
clarray.base_data,clarray.base_data: Optional Opencl buffer and offset from where the pointer start
|
|
64
|
-
cupyaray.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
clarray.base_data[]:
|
|
68
|
-
|
|
69
|
-
Code generation
|
|
70
|
-
---------------
|
|
71
|
-
|
|
72
|
-
Each context is able to compile source code and make available python callable functions.
|
|
73
|
-
|
|
74
|
-
The callable functions can take as arguments Python numbers, strings,
|
|
75
|
-
numpy-like arrays (depending on the context) and xobject allocated in the same
|
|
76
|
-
contexts (if not copies will be done).
|
|
77
|
-
|
|
78
|
-
Source code is optionally pre-processed to adapt it to the context.
|
|
79
|
-
|
|
80
|
-
The callable functions are defined by:
|
|
81
|
-
* the name of the function in the source code
|
|
82
|
-
* the type of parameters
|
|
83
|
-
* how to pass parallalization instruction (threads for openmp, grid for GPU)
|
|
84
|
-
|
|
85
|
-
The callable functions are parametrized by name and argument types.
|
|
86
|
-
|
|
87
|
-
Each xobject type can provide the API source code the ``_get_c_api()`` class method.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
C Api
|
|
92
|
-
^^^^^^^^^^^^^^^^^^^
|
|
93
|
-
|
|
94
|
-
General:
|
|
95
|
-
|
|
96
|
-
- ``<pointer type> <typename>_getp_<field_names>(<typename> obj, <indexes>)``
|
|
97
|
-
- ``<scalar type> <typename>_get_<field_names>(<typename> obj, <indexes>)``
|
|
98
|
-
- ``<typename>_set_<field_names>(<typename> obj, <indexes>, <scalar_type> value)``
|
|
99
|
-
- ``<int64> <typename>_size_<field_names>(<typename> obj,<indexes>)``
|
|
100
|
-
|
|
101
|
-
Array:
|
|
102
|
-
- ``<int64> <typename>_len...(<typename> obj) : number of itemns``
|
|
103
|
-
- ``<int64> <typename>_dim...(<typename> obj, int index): size of dimension``
|
|
104
|
-
- ``<int64> <typename>_ndim...(<typename> obj): number of dimensions``
|
|
105
|
-
- ``void <typename>_strides(int* result)``
|
|
106
|
-
|
|
107
|
-
UnionRef:
|
|
108
|
-
- ``<int64> <typename>_typeid...(<typename> obj) : get member
|
|
109
|
-
- ``void* <typename>_member...(int* result)``
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
Kernels and Functions
|
|
113
|
-
^^^^^^^^^^^^^^^^^^^^^
|
|
114
|
-
|
|
115
|
-
Context can execute:
|
|
116
|
-
|
|
117
|
-
- kernels: no return function and executed on a grid
|
|
118
|
-
- functions: only for cpu kernels
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
.. code:: python
|
|
122
|
-
Kernel(
|
|
123
|
-
cname,
|
|
124
|
-
args=Arg(dtype, name: String, const: Boolean)
|
|
125
|
-
grid=integer, string or list of string or functions of arguments
|
|
126
|
-
ret=None)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
Arg:
|
|
130
|
-
|
|
131
|
-
* atype: argument type:
|
|
132
|
-
- provide validation function: cls._validate(value) or atype(value)
|
|
133
|
-
- provide C-type name: atype._get_ctype() or dtype -> converted to c types,
|
|
134
|
-
- generate raw argument from value .atype._get_carg() for the interface
|
|
135
|
-
* name: optional, String needed for the grid
|
|
136
|
-
* const: boolean (used in case of copy back)
|
|
137
|
-
|
|
138
|
-
Code:
|
|
139
|
-
|
|
140
|
-
* define sources, list of string or files
|
|
141
|
-
* define kernels to expose, list of kernels
|
|
142
|
-
* define preprocessors
|
|
143
|
-
* attach callable kernels to context
|
|
144
|
-
* to be used by CMethod or CProperty
|
|
145
|
-
|
|
146
|
-
.. code::
|
|
147
|
-
double x -> Arg(dtype=xo.Float64,name='x'): takes python scalar and np scalar
|
|
148
|
-
double *restrict x -> Arg(dtype=xo.Float64,pointer=True,const=False,name='x'): takes np.array, xo.Float64 arrays
|
|
149
|
-
const double *restrict x -> Arg(dtype=xo.Float64,pointer=True,const=True,name='x'): takes np.array, xo.Float64 arrays
|
|
150
|
-
const Float64_N -> Arg(dtype=xo.Float64[:],const=True,name='x'): takes xo.Float64[:]
|
|
151
|
-
const Float64_6by6 -> Arg(dtype=xo.Float64[6,6],const=True,name='x'): takes xo.Float64[6,6]
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
* function: general function
|
|
158
|
-
* method: implies first attribute is the instance of the class where it is defined
|
|
159
|
-
* kernel: implies some iteration and no return type
|
|
160
|
-
|
|
161
|
-
The function can be defined using:
|
|
162
|
-
* header
|
|
163
|
-
* source
|
|
164
|
-
* body
|