xobjects 0.4.6__tar.gz → 0.5.0__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.4.6 → xobjects-0.5.0}/PKG-INFO +1 -1
- xobjects-0.5.0/xobjects/_version.py +1 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/context.py +3 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/context_cpu.py +14 -6
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/context_cupy.py +5 -1
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/context_pyopencl.py +7 -1
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/hybrid_class.py +1 -1
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/struct.py +4 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/test_helpers.py +4 -2
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects.egg-info/PKG-INFO +1 -1
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects.egg-info/SOURCES.txt +0 -42
- xobjects-0.4.6/.github/workflows/black.yml +0 -10
- xobjects-0.4.6/.gitignore +0 -11
- xobjects-0.4.6/.pre-commit-config.yaml +0 -12
- xobjects-0.4.6/.readthedocs.yaml +0 -20
- xobjects-0.4.6/Architecture.md +0 -202
- xobjects-0.4.6/Readme.md +0 -10
- xobjects-0.4.6/contributors_and_credits.txt +0 -7
- xobjects-0.4.6/docs/Makefile +0 -20
- xobjects-0.4.6/docs/architecture/contexts.rst +0 -164
- xobjects-0.4.6/docs/architecture/types.rst +0 -179
- xobjects-0.4.6/docs/architecture.rst +0 -16
- xobjects-0.4.6/docs/conf.py +0 -278
- xobjects-0.4.6/docs/index.rst +0 -79
- xobjects-0.4.6/docs/make.bat +0 -35
- xobjects-0.4.6/docs/quickstart.rst +0 -2
- xobjects-0.4.6/docs/reference.rst +0 -8
- xobjects-0.4.6/examples/api_def.py +0 -28
- xobjects-0.4.6/examples/api_init.py +0 -101
- xobjects-0.4.6/examples/capi_example.c +0 -100
- xobjects-0.4.6/examples/check_assembly.c +0 -101
- xobjects-0.4.6/examples/ex_array_init_perf.py +0 -42
- xobjects-0.4.6/examples/ex_cpugpu.py +0 -46
- xobjects-0.4.6/examples/ex_nested_ref.py +0 -49
- xobjects-0.4.6/examples/ex_ref_cpu.py +0 -52
- xobjects-0.4.6/examples/ex_struct_cpu.py +0 -39
- xobjects-0.4.6/examples/ex_unionref_cpu.py +0 -49
- xobjects-0.4.6/examples/ex_unionref_method.py +0 -126
- xobjects-0.4.6/examples/init_soa.py +0 -67
- xobjects-0.4.6/examples/issue_with_two_pyopencl_contexts.py +0 -18
- xobjects-0.4.6/examples/kernel_basics/kernel_cffi.py +0 -56
- xobjects-0.4.6/examples/kernel_basics/kernel_cupy.py +0 -42
- xobjects-0.4.6/examples/kernel_basics/kernel_pyopencl.py +0 -48
- xobjects-0.4.6/examples/opencl_offsets.py +0 -38
- xobjects-0.4.6/examples/simple_kernel.py +0 -59
- xobjects-0.4.6/examples/sixtracklib.py +0 -81
- xobjects-0.4.6/mktest +0 -1
- xobjects-0.4.6/release.sh +0 -20
- xobjects-0.4.6/requirements.txt +0 -3
- xobjects-0.4.6/tests/__init__.py +0 -4
- xobjects-0.4.6/tests/__pycache__/test_context.cpython-37-pytest-6.2.1.pyc +0 -0
- xobjects-0.4.6/tests/notest_capi.py +0 -217
- xobjects-0.4.6/update_cprght_statement.py +0 -49
- xobjects-0.4.6/xobjects/_version.py +0 -1
- {xobjects-0.4.6 → xobjects-0.5.0}/LICENSE +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/pyproject.toml +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/setup.cfg +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/setup.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_align.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_array.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_buffer.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_capi.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_chunk.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_context_opencl.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_hybrid_class.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_kernel.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_linked_array.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_nplike_arrays.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_ref.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_scalars.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_shared_memory.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_strides.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_string.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_struct.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_to_json.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_typeutils.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/tests/test_unionref.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/__init__.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/_patch_pyopencl_array.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/array.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/capi.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/general.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/linkedarray.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/ref.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/scalar.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/specialize_source.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/string.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/typeutils.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects/union.py +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects.egg-info/dependency_links.txt +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects.egg-info/requires.txt +0 -0
- {xobjects-0.4.6 → xobjects-0.5.0}/xobjects.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.5.0"
|
|
@@ -254,6 +254,7 @@ class XContext(ABC):
|
|
|
254
254
|
extra_classes: Sequence[Type] = (),
|
|
255
255
|
extra_headers: Sequence[SourceType] = (),
|
|
256
256
|
compile: bool = True, # noqa
|
|
257
|
+
extra_compile_args: Sequence[str] = (),
|
|
257
258
|
):
|
|
258
259
|
"""
|
|
259
260
|
Adds user-defined kernels to the context. The kernel source
|
|
@@ -333,6 +334,7 @@ class XContext(ABC):
|
|
|
333
334
|
extra_classes=extra_classes,
|
|
334
335
|
extra_headers=extra_headers,
|
|
335
336
|
compile=compile,
|
|
337
|
+
extra_compile_args=extra_compile_args,
|
|
336
338
|
)
|
|
337
339
|
self.kernels.update(generated_kernels)
|
|
338
340
|
|
|
@@ -348,6 +350,7 @@ class XContext(ABC):
|
|
|
348
350
|
extra_classes: Sequence[Type],
|
|
349
351
|
extra_headers: Sequence[SourceType],
|
|
350
352
|
compile: bool,
|
|
353
|
+
extra_compile_args: Sequence[str],
|
|
351
354
|
) -> Dict[Tuple[str, tuple], KernelType]:
|
|
352
355
|
pass
|
|
353
356
|
|
|
@@ -169,8 +169,8 @@ class ContextCpu(XContext):
|
|
|
169
169
|
specialize=True,
|
|
170
170
|
apply_to_source=(),
|
|
171
171
|
save_source_as=None,
|
|
172
|
-
extra_compile_args: Sequence[str] = (
|
|
173
|
-
extra_link_args: Sequence[str] = (
|
|
172
|
+
extra_compile_args: Sequence[str] = (),
|
|
173
|
+
extra_link_args: Sequence[str] = (),
|
|
174
174
|
extra_cdef="",
|
|
175
175
|
extra_classes=(),
|
|
176
176
|
extra_headers=(),
|
|
@@ -271,13 +271,16 @@ class ContextCpu(XContext):
|
|
|
271
271
|
specialize=True,
|
|
272
272
|
apply_to_source=(),
|
|
273
273
|
save_source_as=None,
|
|
274
|
-
extra_compile_args=(
|
|
275
|
-
extra_link_args=(
|
|
274
|
+
extra_compile_args=(),
|
|
275
|
+
extra_link_args=(),
|
|
276
276
|
extra_cdef="",
|
|
277
277
|
extra_classes=(),
|
|
278
278
|
extra_headers=(),
|
|
279
279
|
compile=True, # noqa
|
|
280
280
|
) -> Dict[Tuple[str, tuple], "KernelCpu"]:
|
|
281
|
+
extra_compile_args += ("-O3", "-Wno-unused-function")
|
|
282
|
+
extra_link_args += ("-O3",)
|
|
283
|
+
|
|
281
284
|
# Determine names and paths
|
|
282
285
|
clean_up_so = not module_name
|
|
283
286
|
module_name = module_name or str(uuid.uuid4().hex)
|
|
@@ -409,20 +412,25 @@ class ContextCpu(XContext):
|
|
|
409
412
|
ffi_interface.cdef("int omp_get_max_threads();")
|
|
410
413
|
|
|
411
414
|
# Compile
|
|
412
|
-
xtr_compile_args = ["-std=c99"]
|
|
413
|
-
xtr_link_args = ["-std=c99"]
|
|
415
|
+
xtr_compile_args = ["-std=c99", "-DXO_CONTEXT_CPU"]
|
|
416
|
+
xtr_link_args = ["-std=c99", "-DXO_CONTEXT_CPU"]
|
|
414
417
|
xtr_compile_args += extra_compile_args
|
|
415
418
|
xtr_link_args += extra_link_args
|
|
416
419
|
|
|
417
420
|
if self.openmp_enabled:
|
|
418
421
|
xtr_compile_args.append("-fopenmp")
|
|
419
422
|
xtr_link_args.append("-fopenmp")
|
|
423
|
+
xtr_compile_args.append("-DXO_CONTEXT_CPU_OPENMP")
|
|
424
|
+
xtr_link_args.append("-DXO_CONTEXT_CPU_OPENMP")
|
|
420
425
|
|
|
421
426
|
# https://mac.r-project.org/openmp/
|
|
422
427
|
# on macos comment the above and uncomment the below flags to compile OpenMP with Xcode clang:
|
|
423
428
|
# xtr_compile_args.append("-Xclang")
|
|
424
429
|
# xtr_compile_args.append("-fopenmp")
|
|
425
430
|
# xtr_link_args.append("-lomp")
|
|
431
|
+
else:
|
|
432
|
+
xtr_compile_args.append("-DXO_CONTEXT_CPU_SERIAL")
|
|
433
|
+
xtr_link_args.append("-DXO_CONTEXT_CPU_SERIAL")
|
|
426
434
|
|
|
427
435
|
if os.name == "nt": # windows
|
|
428
436
|
# TODO: to be handled properly
|
|
@@ -416,6 +416,7 @@ class ContextCupy(XContext):
|
|
|
416
416
|
specialize=True,
|
|
417
417
|
apply_to_source=(),
|
|
418
418
|
save_source_as=None,
|
|
419
|
+
extra_compile_args=(),
|
|
419
420
|
extra_cdef=None,
|
|
420
421
|
extra_classes=(),
|
|
421
422
|
extra_headers=(),
|
|
@@ -454,7 +455,10 @@ class ContextCupy(XContext):
|
|
|
454
455
|
with open(save_source_as, "w") as fid:
|
|
455
456
|
fid.write(specialized_source)
|
|
456
457
|
|
|
457
|
-
|
|
458
|
+
extra_compile_args = (*extra_compile_args, "-DXO_CONTEXT_CUDA")
|
|
459
|
+
module = cupy.RawModule(
|
|
460
|
+
code=specialized_source, options=extra_compile_args
|
|
461
|
+
)
|
|
458
462
|
|
|
459
463
|
out_kernels = {}
|
|
460
464
|
for pyname, kernel in kernel_descriptions.items():
|
|
@@ -180,6 +180,7 @@ class ContextPyopencl(XContext):
|
|
|
180
180
|
specialize=True,
|
|
181
181
|
apply_to_source=(),
|
|
182
182
|
save_source_as=None,
|
|
183
|
+
extra_compile_args=(),
|
|
183
184
|
extra_cdef=None,
|
|
184
185
|
extra_classes=(),
|
|
185
186
|
extra_headers=(),
|
|
@@ -218,8 +219,13 @@ class ContextPyopencl(XContext):
|
|
|
218
219
|
with open(save_source_as, "w") as fid:
|
|
219
220
|
fid.write(specialized_source)
|
|
220
221
|
|
|
222
|
+
extra_compile_args = (
|
|
223
|
+
*extra_compile_args,
|
|
224
|
+
"-cl-std=CL2.0",
|
|
225
|
+
"-DXO_CONTEXT_CL",
|
|
226
|
+
)
|
|
221
227
|
prg = cl.Program(self.context, specialized_source).build(
|
|
222
|
-
options=
|
|
228
|
+
options=extra_compile_args,
|
|
223
229
|
)
|
|
224
230
|
|
|
225
231
|
out_kernels = {}
|
|
@@ -96,7 +96,7 @@ class JEncoder(json.JSONEncoder):
|
|
|
96
96
|
def _build_xofields_dict(bases, data):
|
|
97
97
|
if "_xofields" in data.keys():
|
|
98
98
|
xofields = data["_xofields"].copy()
|
|
99
|
-
elif any(
|
|
99
|
+
elif any(hasattr(b, "_xofields") for b in bases):
|
|
100
100
|
n_filled = 0
|
|
101
101
|
for bb in bases:
|
|
102
102
|
if hasattr(bb, "_xofields") and len(bb._xofields.keys()) > 0:
|
|
@@ -473,6 +473,7 @@ class Struct(metaclass=MetaStruct):
|
|
|
473
473
|
apply_to_source=(),
|
|
474
474
|
save_source_as=None,
|
|
475
475
|
extra_classes=(),
|
|
476
|
+
extra_compile_args=(),
|
|
476
477
|
):
|
|
477
478
|
if only_if_needed:
|
|
478
479
|
all_found = True
|
|
@@ -489,6 +490,7 @@ class Struct(metaclass=MetaStruct):
|
|
|
489
490
|
extra_classes=[cls] + list(extra_classes),
|
|
490
491
|
apply_to_source=apply_to_source,
|
|
491
492
|
save_source_as=save_source_as,
|
|
493
|
+
extra_compile_args=extra_compile_args,
|
|
492
494
|
)
|
|
493
495
|
|
|
494
496
|
def compile_kernels(
|
|
@@ -497,6 +499,7 @@ class Struct(metaclass=MetaStruct):
|
|
|
497
499
|
apply_to_source=(),
|
|
498
500
|
save_source_as=None,
|
|
499
501
|
extra_classes=(),
|
|
502
|
+
extra_compile_args=(),
|
|
500
503
|
):
|
|
501
504
|
self.compile_class_kernels(
|
|
502
505
|
context=self._context,
|
|
@@ -504,6 +507,7 @@ class Struct(metaclass=MetaStruct):
|
|
|
504
507
|
apply_to_source=apply_to_source,
|
|
505
508
|
save_source_as=save_source_as,
|
|
506
509
|
extra_classes=extra_classes,
|
|
510
|
+
extra_compile_args=extra_compile_args,
|
|
507
511
|
)
|
|
508
512
|
|
|
509
513
|
|
|
@@ -39,11 +39,13 @@ def _for_all_test_contexts_excluding(
|
|
|
39
39
|
f"this test: {excluding}."
|
|
40
40
|
)(actual_test)
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
test = pytest.mark.parametrize(
|
|
43
43
|
"test_context",
|
|
44
44
|
test_context_names,
|
|
45
45
|
)(actual_test)
|
|
46
46
|
|
|
47
|
+
return pytest.mark.context_dependent(test)
|
|
48
|
+
|
|
47
49
|
|
|
48
50
|
def for_all_test_contexts(*args, **kwargs):
|
|
49
51
|
"""Parametrize the decorated test over all test contexts with the argument
|
|
@@ -80,7 +82,7 @@ def requires_context(context_name: str):
|
|
|
80
82
|
ctx_names = (type(ctx).__name__ for ctx in get_test_contexts())
|
|
81
83
|
|
|
82
84
|
if {context_name} & set(ctx_names): # proceed as normal
|
|
83
|
-
return
|
|
85
|
+
return pytest.mark.context_dependent
|
|
84
86
|
|
|
85
87
|
return pytest.mark.skip(f"{context_name} is unavailable on this platform.")
|
|
86
88
|
|
|
@@ -1,48 +1,7 @@
|
|
|
1
|
-
.gitignore
|
|
2
|
-
.pre-commit-config.yaml
|
|
3
|
-
.readthedocs.yaml
|
|
4
|
-
Architecture.md
|
|
5
1
|
LICENSE
|
|
6
|
-
Readme.md
|
|
7
|
-
contributors_and_credits.txt
|
|
8
|
-
mktest
|
|
9
2
|
pyproject.toml
|
|
10
|
-
release.sh
|
|
11
|
-
requirements.txt
|
|
12
3
|
setup.cfg
|
|
13
4
|
setup.py
|
|
14
|
-
update_cprght_statement.py
|
|
15
|
-
.github/workflows/black.yml
|
|
16
|
-
docs/Makefile
|
|
17
|
-
docs/architecture.rst
|
|
18
|
-
docs/conf.py
|
|
19
|
-
docs/index.rst
|
|
20
|
-
docs/make.bat
|
|
21
|
-
docs/quickstart.rst
|
|
22
|
-
docs/reference.rst
|
|
23
|
-
docs/architecture/contexts.rst
|
|
24
|
-
docs/architecture/types.rst
|
|
25
|
-
examples/api_def.py
|
|
26
|
-
examples/api_init.py
|
|
27
|
-
examples/capi_example.c
|
|
28
|
-
examples/check_assembly.c
|
|
29
|
-
examples/ex_array_init_perf.py
|
|
30
|
-
examples/ex_cpugpu.py
|
|
31
|
-
examples/ex_nested_ref.py
|
|
32
|
-
examples/ex_ref_cpu.py
|
|
33
|
-
examples/ex_struct_cpu.py
|
|
34
|
-
examples/ex_unionref_cpu.py
|
|
35
|
-
examples/ex_unionref_method.py
|
|
36
|
-
examples/init_soa.py
|
|
37
|
-
examples/issue_with_two_pyopencl_contexts.py
|
|
38
|
-
examples/opencl_offsets.py
|
|
39
|
-
examples/simple_kernel.py
|
|
40
|
-
examples/sixtracklib.py
|
|
41
|
-
examples/kernel_basics/kernel_cffi.py
|
|
42
|
-
examples/kernel_basics/kernel_cupy.py
|
|
43
|
-
examples/kernel_basics/kernel_pyopencl.py
|
|
44
|
-
tests/__init__.py
|
|
45
|
-
tests/notest_capi.py
|
|
46
5
|
tests/test_align.py
|
|
47
6
|
tests/test_array.py
|
|
48
7
|
tests/test_buffer.py
|
|
@@ -62,7 +21,6 @@ tests/test_struct.py
|
|
|
62
21
|
tests/test_to_json.py
|
|
63
22
|
tests/test_typeutils.py
|
|
64
23
|
tests/test_unionref.py
|
|
65
|
-
tests/__pycache__/test_context.cpython-37-pytest-6.2.1.pyc
|
|
66
24
|
xobjects/__init__.py
|
|
67
25
|
xobjects/_patch_pyopencl_array.py
|
|
68
26
|
xobjects/_version.py
|
xobjects-0.4.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.4.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.4.6/Architecture.md
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
# Architecture
|
|
2
|
-
|
|
3
|
-
## Introduction
|
|
4
|
-
|
|
5
|
-
The library is based on:
|
|
6
|
-
- Buffers: manage chunck of bytes on CPU and GPU (Cuda and OpenCL) memory using different backends
|
|
7
|
-
- Contexts: keep track of buffers, launch functions operating on buffers
|
|
8
|
-
- Basic types: a set of basic types that allow to describe structured data. Basic types are scalars, strings, structs, arrays and unions. User defined classes, composed with basic types, allow to interact with data on buffers and generate C functions to operate with data.
|
|
9
|
-
- C-API generation: The type information allows to write C functions that can be interact with data. The C functions are specialized for CPU, OpenCL and Cuda. Also loops described by annotation in comments are automatically generated for CPU, OpenCL and Cuda.
|
|
10
|
-
|
|
11
|
-
When a user defined class is created, Python methods and additional metadeta is attached to the class.
|
|
12
|
-
When an instance of a user defined class is instantiated, memory is written to a buffer and a Python object is created to interact with the data.
|
|
13
|
-
The size of an instance may not be known at class defintion time, but it cannot be changed after initialization.
|
|
14
|
-
|
|
15
|
-
## Contexts and Buffers
|
|
16
|
-
|
|
17
|
-
A context contain:
|
|
18
|
-
|
|
19
|
-
- `new_buffer(capacity)`: create new buffer of initial capacity
|
|
20
|
-
- `buffers`: list of weakref to buffers
|
|
21
|
-
- kernels : Object containing compiled code from sources/
|
|
22
|
-
|
|
23
|
-
Buffer:
|
|
24
|
-
- `buffer`: low level buffer
|
|
25
|
-
- `allocate(self,size)`: return the offset of the first free memory chunk of given size and grows the buffer if necessary
|
|
26
|
-
- `free(self,offset,size)`: free a chuck of memory of a given size
|
|
27
|
-
- `grow(self,capacity)`: increase the size of a buffer
|
|
28
|
-
- `_new_buffer(capacity)`: creae lowlevel buffer
|
|
29
|
-
- `update_from_native(...)`: Copy data from native buffer into self.buffer starting from offset
|
|
30
|
-
- `update_from_buffer(...)`: Copy data from python buffer such as bytearray, bytes, memoryview, numpy array.data
|
|
31
|
-
- `update_from_nplike(...)`: Copy data from nplike matching dest_dtype
|
|
32
|
-
- `update_from_xbuffer(...)`: Copy data from any xbuffer, don't pass through cpu if possible
|
|
33
|
-
- `copy_to_native(...)`: Copy data from self.buffer into dest
|
|
34
|
-
- `to_native(...)`: Return native data with content at from offset and nbytes
|
|
35
|
-
- `to_nplike(...)`: Return a view in of an nplike
|
|
36
|
-
- `to_bytearray(...)`: Return a byte array: used in update_from_xbuffer
|
|
37
|
-
- `to_pointer_arg(...)`: Return data that can be used as argument in kernel
|
|
38
|
-
|
|
39
|
-
## Types
|
|
40
|
-
|
|
41
|
-
Types can be composed of:
|
|
42
|
-
- scalar: numbers, String
|
|
43
|
-
- compound: Struct, Array, Ref, UnionRef
|
|
44
|
-
|
|
45
|
-
### Scalars
|
|
46
|
-
- examples: Float64, Int64, ...
|
|
47
|
-
- create: Float64(3.14)
|
|
48
|
-
- memory layout
|
|
49
|
-
- data
|
|
50
|
-
|
|
51
|
-
### String:
|
|
52
|
-
- create: String(string_or_int)
|
|
53
|
-
- memory layout
|
|
54
|
-
- size
|
|
55
|
-
- data
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
### Struct
|
|
59
|
-
- example: struct MyStruct field1 field2 ...
|
|
60
|
-
- create: Struct(dict), Struct(**args)
|
|
61
|
-
- memory layout:
|
|
62
|
-
- [ instance size ]
|
|
63
|
-
- static-field1
|
|
64
|
-
- ..
|
|
65
|
-
- static-fieldn
|
|
66
|
-
- [ offset field 2 ]
|
|
67
|
-
- [ offset ... ]
|
|
68
|
-
- [ offset field n ]
|
|
69
|
-
- [ dynamic-field1 ]
|
|
70
|
-
- [ ... ]
|
|
71
|
-
- [ dynamic-fieldn ]
|
|
72
|
-
|
|
73
|
-
### Array:
|
|
74
|
-
- example: 'array' 'f64' d1 d2 d3 'C' ; 'array' 'i64' d1 ':' d3 'F' ;
|
|
75
|
-
- where:
|
|
76
|
-
- 'C'/'F' is C-contiguos or F-contiguous
|
|
77
|
-
- d1, d2, .. are the dimensions for each axis and ':' means not specified
|
|
78
|
-
- create: Array(d1,d2,...) or Array([...]) or Array(np-array)
|
|
79
|
-
- memory layout:
|
|
80
|
-
- [size] if not _is_static_shape or not _is_static_type
|
|
81
|
-
- [dims ... ] len(_dynamic_shape)
|
|
82
|
-
- [strides...] if nd>1 and dynamic shapes
|
|
83
|
-
- [offsets] if not _is_static_type
|
|
84
|
-
- data
|
|
85
|
-
|
|
86
|
-
### Union:
|
|
87
|
-
- create: Union(obj), Union( (typename,args) )
|
|
88
|
-
- memory layout
|
|
89
|
-
- typeid
|
|
90
|
-
- data
|
|
91
|
-
|
|
92
|
-
### UnionRef:
|
|
93
|
-
- create: UnionRef(obj), UnionRef( (typename,args) )
|
|
94
|
-
- memory layout
|
|
95
|
-
- typeid
|
|
96
|
-
- offset
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
### Ref:
|
|
100
|
-
- memory layout
|
|
101
|
-
- offset
|
|
102
|
-
|
|
103
|
-
## Implementation details
|
|
104
|
-
|
|
105
|
-
Assumptions:
|
|
106
|
-
- Python user API cannot change the internal structure of the object but only the content
|
|
107
|
-
- Python object caches the structure information to avoid round trips to access data
|
|
108
|
-
- C user API does not manipulate structures
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
Operation:
|
|
112
|
-
|
|
113
|
-
- _inspect_args(*args, **args) -> info: Info
|
|
114
|
-
- check value and calculate size, offsets and dimensions from arguments, recursively
|
|
115
|
-
- returns at least `size` for `_get_a_buffer` and `value` for `_to_buffer`
|
|
116
|
-
|
|
117
|
-
- _get_a_buffer(size, _context, _buffer, _offset):
|
|
118
|
-
- make sure a valid buffer and offset is created
|
|
119
|
-
|
|
120
|
-
- _to_buffer(buffer, offset, value, info, size?):
|
|
121
|
-
- set data on buffer with offset from pyhon value, using info and implicitely respecting size
|
|
122
|
-
- if value same class -> binary copy (passing from context if needed)
|
|
123
|
-
|
|
124
|
-
- _from_buffer(buffer, offset) -> value:
|
|
125
|
-
- create python object from data on buffer. Can be a native type (scalar or string) or another XObject (struct, array)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
- __init__(self,*args,_context=None, _buffer=None, _offset=None,*nargs)
|
|
129
|
-
- initialize object data on buffer from args and create python object:
|
|
130
|
-
- use _pre_init(*args,**nargs) -> return args, nargs standard initialization value
|
|
131
|
-
- check values and calculate size using `_inspect_args`, return info object containing size, offsets and values to be later used by _to_buffer
|
|
132
|
-
- allocate using `_get_a_buffer`
|
|
133
|
-
- write data using `_to_buffer`
|
|
134
|
-
- use `_post_init` to complete object
|
|
135
|
-
`
|
|
136
|
-
- _update(self, value, size=None):
|
|
137
|
-
- Optional update object content using value, in case respecting size for string
|
|
138
|
-
|
|
139
|
-
- __get__(field,instance) or __getitem__(self,index...)
|
|
140
|
-
- if return instance._cache[field.index] else #should implement item caching for struct and array
|
|
141
|
-
- else return _from_buffer
|
|
142
|
-
|
|
143
|
-
- __set__(..., value) or __setitem__(...,value)
|
|
144
|
-
- if hasattr(self.ftype._update) get object and update in place
|
|
145
|
-
else call _to_buffer
|
|
146
|
-
|
|
147
|
-
- json enconding
|
|
148
|
-
nested object can be initialized using a json enconding
|
|
149
|
-
d:dict -> type(**d)
|
|
150
|
-
t:tuple -> type(*t)
|
|
151
|
-
a:other -> type(a)
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
Class content:
|
|
156
|
-
|
|
157
|
-
- _inspect_args(cls, *args, **nargs) -> size, offsets
|
|
158
|
-
compute size and sizes and offsets from arguments
|
|
159
|
-
|
|
160
|
-
- _to_buffer(cls, buffer, offset, value, offsets=None):
|
|
161
|
-
initialize object on buffer
|
|
162
|
-
|
|
163
|
-
- _from_buffer(cls, buffer,offset):
|
|
164
|
-
create python object from initlialized object on buffer,offset
|
|
165
|
-
|
|
166
|
-
- _size: object size
|
|
167
|
-
None if dynamic
|
|
168
|
-
|
|
169
|
-
Instance content:
|
|
170
|
-
|
|
171
|
-
- _get_size(self) -> size
|
|
172
|
-
|
|
173
|
-
## C-API
|
|
174
|
-
|
|
175
|
-
Access
|
|
176
|
-
- `<Class>_get<_attrs>(obj, <indexes>)` -> scalar or object pointer
|
|
177
|
-
- `<Class>_set<_attrs>(obj, <indexes>, scalar)`
|
|
178
|
-
|
|
179
|
-
e.g. Multipole_get_field_normal(3)
|
|
180
|
-
|
|
181
|
-
Kernel convention:
|
|
182
|
-
|
|
183
|
-
```
|
|
184
|
-
<fun>(void **refs){
|
|
185
|
-
Type0 arg0 = (Type0) refs[0];
|
|
186
|
-
....
|
|
187
|
-
Type1 argN = (TypeN) refs[N];
|
|
188
|
-
...
|
|
189
|
-
}
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
``` <fun>(buffer1, offset, ..., offset3){
|
|
193
|
-
Type0 arg0 = (Type0) refs[offset0];
|
|
194
|
-
,,,
|
|
195
|
-
TypeN argN = (TypeN) refs[offsetN];
|
|
196
|
-
}
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
## TODO
|
|
200
|
-
|
|
201
|
-
- add free methods to delete data from buffer
|
|
202
|
-
- implement SOA types
|
xobjects-0.4.6/Readme.md
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# XObjects
|
|
2
|
-
|
|
3
|
-
Library to create and manipulate serialized object in CPU and GPU memory efficiently.
|
|
4
|
-
|
|
5
|
-
The library defines:
|
|
6
|
-
- Contexts: create buffers and manage computations e.g. BytearrayContext, CLContext, ...
|
|
7
|
-
- Buffers: reference to internal memory buffer with an allocator e.g.
|
|
8
|
-
BytearrayContext, CLBuffer, ...
|
|
9
|
-
- Data types: define users define types to create and manipulate objects on
|
|
10
|
-
buffers and generate C api, e.g. Float64, Int64, String, Struct, Array, Union
|
xobjects-0.4.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)
|