xobjects 0.4.5__tar.gz → 0.4.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.4.5 → xobjects-0.4.7}/PKG-INFO +1 -1
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_struct.py +87 -0
- xobjects-0.4.7/xobjects/_version.py +1 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/context_cpu.py +2 -1
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/test_helpers.py +24 -2
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects.egg-info/PKG-INFO +1 -1
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects.egg-info/SOURCES.txt +0 -42
- xobjects-0.4.5/.github/workflows/black.yml +0 -10
- xobjects-0.4.5/.gitignore +0 -11
- xobjects-0.4.5/.pre-commit-config.yaml +0 -12
- xobjects-0.4.5/.readthedocs.yaml +0 -20
- xobjects-0.4.5/Architecture.md +0 -202
- xobjects-0.4.5/Readme.md +0 -10
- xobjects-0.4.5/contributors_and_credits.txt +0 -7
- xobjects-0.4.5/docs/Makefile +0 -20
- xobjects-0.4.5/docs/architecture/contexts.rst +0 -164
- xobjects-0.4.5/docs/architecture/types.rst +0 -179
- xobjects-0.4.5/docs/architecture.rst +0 -16
- xobjects-0.4.5/docs/conf.py +0 -278
- xobjects-0.4.5/docs/index.rst +0 -79
- xobjects-0.4.5/docs/make.bat +0 -35
- xobjects-0.4.5/docs/quickstart.rst +0 -2
- xobjects-0.4.5/docs/reference.rst +0 -8
- xobjects-0.4.5/examples/api_def.py +0 -28
- xobjects-0.4.5/examples/api_init.py +0 -101
- xobjects-0.4.5/examples/capi_example.c +0 -100
- xobjects-0.4.5/examples/check_assembly.c +0 -101
- xobjects-0.4.5/examples/ex_array_init_perf.py +0 -42
- xobjects-0.4.5/examples/ex_cpugpu.py +0 -46
- xobjects-0.4.5/examples/ex_nested_ref.py +0 -49
- xobjects-0.4.5/examples/ex_ref_cpu.py +0 -52
- xobjects-0.4.5/examples/ex_struct_cpu.py +0 -39
- xobjects-0.4.5/examples/ex_unionref_cpu.py +0 -49
- xobjects-0.4.5/examples/ex_unionref_method.py +0 -126
- xobjects-0.4.5/examples/init_soa.py +0 -67
- xobjects-0.4.5/examples/issue_with_two_pyopencl_contexts.py +0 -18
- xobjects-0.4.5/examples/kernel_basics/kernel_cffi.py +0 -56
- xobjects-0.4.5/examples/kernel_basics/kernel_cupy.py +0 -42
- xobjects-0.4.5/examples/kernel_basics/kernel_pyopencl.py +0 -48
- xobjects-0.4.5/examples/opencl_offsets.py +0 -38
- xobjects-0.4.5/examples/simple_kernel.py +0 -59
- xobjects-0.4.5/examples/sixtracklib.py +0 -81
- xobjects-0.4.5/mktest +0 -1
- xobjects-0.4.5/release.sh +0 -20
- xobjects-0.4.5/requirements.txt +0 -3
- xobjects-0.4.5/tests/__init__.py +0 -4
- xobjects-0.4.5/tests/__pycache__/test_context.cpython-37-pytest-6.2.1.pyc +0 -0
- xobjects-0.4.5/tests/notest_capi.py +0 -217
- xobjects-0.4.5/update_cprght_statement.py +0 -49
- xobjects-0.4.5/xobjects/_version.py +0 -1
- {xobjects-0.4.5 → xobjects-0.4.7}/LICENSE +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/pyproject.toml +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/setup.cfg +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/setup.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_align.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_array.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_buffer.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_capi.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_chunk.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_context_opencl.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_hybrid_class.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_kernel.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_linked_array.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_nplike_arrays.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_ref.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_scalars.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_shared_memory.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_strides.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_string.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_to_json.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_typeutils.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/tests/test_unionref.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/__init__.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/_patch_pyopencl_array.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/array.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/capi.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/context.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/context_cupy.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/context_pyopencl.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/general.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/hybrid_class.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/linkedarray.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/ref.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/scalar.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/specialize_source.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/string.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/struct.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/typeutils.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects/union.py +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects.egg-info/dependency_links.txt +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects.egg-info/requires.txt +0 -0
- {xobjects-0.4.5 → xobjects-0.4.7}/xobjects.egg-info/top_level.txt +0 -0
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# Copyright (c) CERN, 2021. #
|
|
4
4
|
# ########################################### #
|
|
5
5
|
import cffi
|
|
6
|
+
import numpy as np
|
|
6
7
|
|
|
7
8
|
import xobjects as xo
|
|
8
9
|
from xobjects.test_helpers import for_all_test_contexts, requires_context
|
|
@@ -213,6 +214,92 @@ def test_copy_dynamic():
|
|
|
213
214
|
assert s2.b[1] == 4
|
|
214
215
|
|
|
215
216
|
|
|
217
|
+
def test_kernel_namings():
|
|
218
|
+
class MyStruct(xo.Struct):
|
|
219
|
+
n = xo.Int32
|
|
220
|
+
var_mult_1 = xo.Float64[:]
|
|
221
|
+
var_mult_2 = xo.Float64[:]
|
|
222
|
+
var_mult_3 = xo.Float64[:]
|
|
223
|
+
var_mult_4 = xo.Float64[:]
|
|
224
|
+
|
|
225
|
+
_extra_c_sources = [
|
|
226
|
+
r"""
|
|
227
|
+
double mul(MyStruct stru) {
|
|
228
|
+
int32_t n = MyStruct_get_n(stru);
|
|
229
|
+
double* var_mult_1 = MyStruct_getp1_var_mult_1(stru, 0);
|
|
230
|
+
double* var_mult_2 = MyStruct_getp1_var_mult_2(stru, 0);
|
|
231
|
+
double y = 0;
|
|
232
|
+
for (int32_t tid=0; tid<n; tid++){
|
|
233
|
+
y+= var_mult_1[tid] * var_mult_2[tid];
|
|
234
|
+
}
|
|
235
|
+
return y;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
double mult(MyStruct stru) {
|
|
239
|
+
int32_t n = MyStruct_get_n(stru);
|
|
240
|
+
double* var_mult_1 = MyStruct_getp1_var_mult_1(stru, 0);
|
|
241
|
+
double* var_mult_2 = MyStruct_getp1_var_mult_2(stru, 0);
|
|
242
|
+
double* var_mult_3 = MyStruct_getp1_var_mult_3(stru, 0);
|
|
243
|
+
double y = 0;
|
|
244
|
+
for (int32_t tid=0; tid<n; tid++){
|
|
245
|
+
y+= var_mult_1[tid] * var_mult_2[tid] * var_mult_3[tid];
|
|
246
|
+
}
|
|
247
|
+
return y;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
double mult_four(MyStruct stru) {
|
|
251
|
+
int32_t n = MyStruct_get_n(stru);
|
|
252
|
+
double* var_mult_1 = MyStruct_getp1_var_mult_1(stru, 0);
|
|
253
|
+
double* var_mult_2 = MyStruct_getp1_var_mult_2(stru, 0);
|
|
254
|
+
double* var_mult_3 = MyStruct_getp1_var_mult_3(stru, 0);
|
|
255
|
+
double* var_mult_4 = MyStruct_getp1_var_mult_4(stru, 0);
|
|
256
|
+
double y = 0;
|
|
257
|
+
for (int32_t tid=0; tid<n; tid++){
|
|
258
|
+
y+= var_mult_1[tid] * var_mult_2[tid] * var_mult_3[tid] * var_mult_4[tid];
|
|
259
|
+
}
|
|
260
|
+
return y;
|
|
261
|
+
}"""
|
|
262
|
+
]
|
|
263
|
+
|
|
264
|
+
kernel_descriptions = {
|
|
265
|
+
"mul": xo.Kernel(
|
|
266
|
+
args=[xo.Arg(MyStruct, name="stru")],
|
|
267
|
+
ret=xo.Arg(xo.Float64),
|
|
268
|
+
),
|
|
269
|
+
"mult": xo.Kernel(
|
|
270
|
+
c_name="mult",
|
|
271
|
+
args=[xo.Arg(MyStruct, name="stru")],
|
|
272
|
+
ret=xo.Arg(xo.Float64),
|
|
273
|
+
),
|
|
274
|
+
"pyname_mul": xo.Kernel(
|
|
275
|
+
c_name="mult_four",
|
|
276
|
+
args=[xo.Arg(MyStruct, name="stru")],
|
|
277
|
+
ret=xo.Arg(xo.Float64),
|
|
278
|
+
),
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
a1 = np.arange(10.0)
|
|
282
|
+
a2 = np.arange(10.0)
|
|
283
|
+
a3 = np.arange(10.0)
|
|
284
|
+
a4 = np.arange(10.0)
|
|
285
|
+
stru = MyStruct(
|
|
286
|
+
n=10, var_mult_1=a1, var_mult_2=a2, var_mult_3=a3, var_mult_4=a4
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
ctx = stru._context
|
|
290
|
+
ctx.add_kernels(kernels=kernel_descriptions)
|
|
291
|
+
assert "mul" in ctx.kernels
|
|
292
|
+
# assert "mult" in ctx.kernels
|
|
293
|
+
assert "pyname_mul" in ctx.kernels
|
|
294
|
+
|
|
295
|
+
y = ctx.kernels.mul(stru=stru)
|
|
296
|
+
assert y == 285.0
|
|
297
|
+
y = ctx.kernels.mult(stru=stru)
|
|
298
|
+
assert y == 2025.0
|
|
299
|
+
y = ctx.kernels.pyname_mul(stru=stru)
|
|
300
|
+
assert y == 15333.0
|
|
301
|
+
|
|
302
|
+
|
|
216
303
|
@requires_context("ContextCpu")
|
|
217
304
|
def test_compile_kernels_only_if_needed(tmp_path, mocker):
|
|
218
305
|
"""Test the use case of xtrack.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.4.7"
|
|
@@ -398,7 +398,8 @@ class ContextCpu(XContext):
|
|
|
398
398
|
_print("Compiling ContextCpu kernels...")
|
|
399
399
|
|
|
400
400
|
for pyname, kernel in kernel_descriptions.items():
|
|
401
|
-
|
|
401
|
+
# check if kernel not already declared
|
|
402
|
+
if f" {kernel.c_name}(" not in cdefs:
|
|
402
403
|
signature = cdef_from_kernel(kernel, pyname)
|
|
403
404
|
ffi_interface.cdef(signature)
|
|
404
405
|
log.debug(f"cffi def {pyname} {signature}")
|
|
@@ -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,6 +82,26 @@ 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.")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def fix_random_seed(seed: int):
|
|
91
|
+
"""Decorator to fix the random seed for a test."""
|
|
92
|
+
|
|
93
|
+
def decorator(test_function):
|
|
94
|
+
@wraps(test_function)
|
|
95
|
+
def wrapper(*args, **kwargs):
|
|
96
|
+
import numpy as np
|
|
97
|
+
|
|
98
|
+
rng_state = np.random.get_state()
|
|
99
|
+
try:
|
|
100
|
+
np.random.seed(seed)
|
|
101
|
+
test_function(*args, **kwargs)
|
|
102
|
+
finally:
|
|
103
|
+
np.random.set_state(rng_state)
|
|
104
|
+
|
|
105
|
+
return wrapper
|
|
106
|
+
|
|
107
|
+
return decorator
|
|
@@ -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.5/.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.5/.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.5/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.5/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.5/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)
|