xobjects 0.4.4__tar.gz → 0.4.6__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.
Files changed (92) hide show
  1. xobjects-0.4.6/.github/workflows/black.yml +10 -0
  2. xobjects-0.4.6/.gitignore +11 -0
  3. xobjects-0.4.6/.pre-commit-config.yaml +12 -0
  4. xobjects-0.4.6/.readthedocs.yaml +20 -0
  5. xobjects-0.4.6/Architecture.md +202 -0
  6. {xobjects-0.4.4/xobjects.egg-info → xobjects-0.4.6}/PKG-INFO +1 -1
  7. xobjects-0.4.6/Readme.md +10 -0
  8. xobjects-0.4.6/contributors_and_credits.txt +7 -0
  9. xobjects-0.4.6/docs/Makefile +20 -0
  10. xobjects-0.4.6/docs/architecture/contexts.rst +164 -0
  11. xobjects-0.4.6/docs/architecture/types.rst +179 -0
  12. xobjects-0.4.6/docs/architecture.rst +16 -0
  13. xobjects-0.4.6/docs/conf.py +278 -0
  14. xobjects-0.4.6/docs/index.rst +79 -0
  15. xobjects-0.4.6/docs/make.bat +35 -0
  16. xobjects-0.4.6/docs/quickstart.rst +2 -0
  17. xobjects-0.4.6/docs/reference.rst +8 -0
  18. xobjects-0.4.6/examples/api_def.py +28 -0
  19. xobjects-0.4.6/examples/api_init.py +101 -0
  20. xobjects-0.4.6/examples/capi_example.c +100 -0
  21. xobjects-0.4.6/examples/check_assembly.c +101 -0
  22. xobjects-0.4.6/examples/ex_array_init_perf.py +42 -0
  23. xobjects-0.4.6/examples/ex_cpugpu.py +46 -0
  24. xobjects-0.4.6/examples/ex_nested_ref.py +49 -0
  25. xobjects-0.4.6/examples/ex_ref_cpu.py +52 -0
  26. xobjects-0.4.6/examples/ex_struct_cpu.py +39 -0
  27. xobjects-0.4.6/examples/ex_unionref_cpu.py +49 -0
  28. xobjects-0.4.6/examples/ex_unionref_method.py +126 -0
  29. xobjects-0.4.6/examples/init_soa.py +67 -0
  30. xobjects-0.4.6/examples/issue_with_two_pyopencl_contexts.py +18 -0
  31. xobjects-0.4.6/examples/kernel_basics/kernel_cffi.py +56 -0
  32. xobjects-0.4.6/examples/kernel_basics/kernel_cupy.py +42 -0
  33. xobjects-0.4.6/examples/kernel_basics/kernel_pyopencl.py +48 -0
  34. xobjects-0.4.6/examples/opencl_offsets.py +38 -0
  35. xobjects-0.4.6/examples/simple_kernel.py +59 -0
  36. xobjects-0.4.6/examples/sixtracklib.py +81 -0
  37. xobjects-0.4.6/mktest +1 -0
  38. xobjects-0.4.6/release.sh +20 -0
  39. xobjects-0.4.6/requirements.txt +3 -0
  40. xobjects-0.4.6/tests/__init__.py +4 -0
  41. xobjects-0.4.6/tests/__pycache__/test_context.cpython-37-pytest-6.2.1.pyc +0 -0
  42. xobjects-0.4.6/tests/notest_capi.py +217 -0
  43. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_struct.py +87 -0
  44. xobjects-0.4.6/update_cprght_statement.py +49 -0
  45. xobjects-0.4.6/xobjects/_version.py +1 -0
  46. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/capi.py +1 -1
  47. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/context_cpu.py +2 -1
  48. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/test_helpers.py +20 -0
  49. {xobjects-0.4.4 → xobjects-0.4.6/xobjects.egg-info}/PKG-INFO +1 -1
  50. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects.egg-info/SOURCES.txt +42 -0
  51. xobjects-0.4.4/xobjects/_version.py +0 -1
  52. {xobjects-0.4.4 → xobjects-0.4.6}/LICENSE +0 -0
  53. {xobjects-0.4.4 → xobjects-0.4.6}/pyproject.toml +0 -0
  54. {xobjects-0.4.4 → xobjects-0.4.6}/setup.cfg +0 -0
  55. {xobjects-0.4.4 → xobjects-0.4.6}/setup.py +0 -0
  56. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_align.py +0 -0
  57. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_array.py +0 -0
  58. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_buffer.py +0 -0
  59. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_capi.py +0 -0
  60. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_chunk.py +0 -0
  61. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_context_opencl.py +0 -0
  62. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_hybrid_class.py +0 -0
  63. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_kernel.py +0 -0
  64. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_linked_array.py +0 -0
  65. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_nplike_arrays.py +0 -0
  66. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_ref.py +0 -0
  67. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_scalars.py +0 -0
  68. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_shared_memory.py +0 -0
  69. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_strides.py +0 -0
  70. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_string.py +0 -0
  71. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_to_json.py +0 -0
  72. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_typeutils.py +0 -0
  73. {xobjects-0.4.4 → xobjects-0.4.6}/tests/test_unionref.py +0 -0
  74. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/__init__.py +0 -0
  75. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/_patch_pyopencl_array.py +0 -0
  76. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/array.py +0 -0
  77. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/context.py +0 -0
  78. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/context_cupy.py +0 -0
  79. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/context_pyopencl.py +0 -0
  80. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/general.py +0 -0
  81. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/hybrid_class.py +0 -0
  82. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/linkedarray.py +0 -0
  83. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/ref.py +0 -0
  84. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/scalar.py +0 -0
  85. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/specialize_source.py +0 -0
  86. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/string.py +0 -0
  87. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/struct.py +0 -0
  88. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/typeutils.py +0 -0
  89. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects/union.py +0 -0
  90. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects.egg-info/dependency_links.txt +0 -0
  91. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects.egg-info/requires.txt +0 -0
  92. {xobjects-0.4.4 → xobjects-0.4.6}/xobjects.egg-info/top_level.txt +0 -0
@@ -0,0 +1,10 @@
1
+ name: Lint
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ lint:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - uses: psf/black@stable
@@ -0,0 +1,11 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ *.swp
5
+ *.egg-info/
6
+ docs/_build
7
+ cov_html
8
+ .vscode
9
+ .pytest_cache
10
+ .coverage
11
+ *.c
@@ -0,0 +1,12 @@
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+
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,202 @@
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xobjects
3
- Version: 0.4.4
3
+ Version: 0.4.6
4
4
  Summary: In-memory serialization and code generator for CPU and GPU
5
5
  Home-page: https://xsuite.readthedocs.io/
6
6
  Download-URL: https://pypi.python.org/pypi/xobjects
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,7 @@
1
+ The following people contributed to the development of this package:
2
+
3
+ CERN contributors:
4
+ - R. De Maria
5
+ - G. Iadarola
6
+ - P. Kiksiny
7
+ - S. Lopaciuk
@@ -0,0 +1,20 @@
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)
@@ -0,0 +1,164 @@
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
@@ -0,0 +1,179 @@
1
+ Types
2
+ =====
3
+
4
+ Introduction
5
+ -------------
6
+
7
+
8
+ Data layout and API can be defined by a composition of:
9
+ * Scalars: Int8, Int16, Int32, Int64, Float32, Float64
10
+ * Compounds: Struct, Array, Ref
11
+
12
+ Types can have a fixed size (*static types*) or a variable size (*dynamic size*).
13
+ The size of one instance cannot change after creation, but their content can.
14
+
15
+
16
+ Data Layout
17
+ -------------
18
+
19
+ Data structure is organized in 64bit slots.
20
+
21
+ Table indicates slot size and the description.
22
+
23
+ Scalar
24
+
25
+ ===== ===========
26
+ Slots Description
27
+ ===== ===========
28
+ 8 Data
29
+ ===== ===========
30
+
31
+ String of n-bytes
32
+
33
+ ============= ===============================
34
+ Slots Description
35
+ ============= ===============================
36
+ 8 Size in bytes
37
+ ceil((n+1)/8) Data in UTF-8 null terminated
38
+ ============= ===============================
39
+
40
+
41
+ Struct with static and *n* dynamical fields
42
+
43
+ ======= ===============================
44
+ Slots Description
45
+ ======= ===============================
46
+ 8 Optional: size if n>0
47
+ ... Fixed-size field data
48
+ 8*(n-1) Optional: Offsets of the 2nd to n-th last variable sized
49
+ ... Optional: Variable sized data
50
+ ======= ===============================
51
+
52
+ Array with n dimensions, whose l are dynamic of *m* items.
53
+
54
+ ======= ===============================
55
+ Slots Description
56
+ ======= ===============================
57
+ 8 Optional: size
58
+ 8*l Optional: size of l-variable dimensions
59
+ 8*n Optional: strides for n-dimensions larger than 2
60
+ m*s Data or offsets for m-items (s is the item-size or 8)
61
+ ... Optional: Items data if the item type is dynamic
62
+ ======= ===============================
63
+
64
+ Union
65
+
66
+ ======= ===============================
67
+ Slots Description
68
+ ======= ===============================
69
+ 8 Type id
70
+ ... Item data
71
+ ======= ===============================
72
+
73
+
74
+ Ref
75
+
76
+ ======= ======================================
77
+ Slots Description
78
+ ======= ======================================
79
+ 8 Offset from start of the buffer
80
+ 8 Optional: typeid
81
+ ======= ======================================
82
+
83
+
84
+ Python type interface
85
+ ----------------------
86
+
87
+ The following describe the generic interface
88
+
89
+ Class variables:
90
+
91
+ ============== ===============================
92
+ name Description
93
+ ============== ===============================
94
+ _size Size in bytes, None if not static size
95
+ ============== ===============================
96
+
97
+ Class methods:
98
+
99
+ ============= ============== ============ ============================================
100
+ name args return Description
101
+ ============= ============== ============ ============================================
102
+ _inspect_args *args, Info Return at least info.size and optionally
103
+ *kwargs other metadata to build objects in memory
104
+ from python objects. Args are propocessed
105
+ by _pre_init
106
+ _pre_init *args, args, Preprocess arguments and generate standard
107
+ *kwargs kwargs values
108
+ _to_buffer buffer None Serialize python in buffer from offset.
109
+ offset Assume sufficient size is available
110
+ value
111
+ _from_buffer buffer instance Return Python instance from buffer and
112
+ offset and offset
113
+ _to_schema string TODO String representation of the type to
114
+ deserialize objects
115
+ ============= ============== ============ ============================================
116
+
117
+
118
+ Instance variables:
119
+
120
+ ============= ========================================
121
+ name Description
122
+ ============= ========================================
123
+ _size Optional: size in bytes for dynamic-size
124
+ ============= ========================================
125
+
126
+
127
+ Class methods:
128
+
129
+ ============= ============== ============ ============================================
130
+ name args return Description
131
+ ============= ============== ============ ============================================
132
+ _post_init Run after object creation in __init__
133
+ copy buffer or None TODO Return a copy into a buffer
134
+ context Assume sufficient size is available
135
+ _update value instance Update values of an exsiting objec
136
+ _to_json json TODO json
137
+ ============= ============== ============ ============================================
138
+
139
+
140
+
141
+ **__init__**
142
+
143
+ init is used to create a new xobject by allocating memory on the buffer.
144
+ Ref and Scalars cannot be initialized alone (maybe temporarily)
145
+
146
+ Init can take by default:
147
+
148
+ * a json object:
149
+ * dict for Struct
150
+ * list for Array,
151
+ * number of Scalars
152
+ * String for String
153
+ * (Typename, {}) for Ref of multiple types
154
+ * dimensions (for string or arrays)
155
+ * an xobject of the correct type
156
+ * None for Ref
157
+
158
+ The data is dispatched to _pre_init using the following convetion:
159
+ * a dict is passed with **
160
+ * a tuple is passed with *
161
+ * any other object is passed verbatim
162
+
163
+ Init uses the following steps:
164
+
165
+ * pre_init to pre_process input
166
+ * inspect_args to calculate sizes and collect metadata
167
+ * get_a_buffer to allocate space
168
+ * _to_buffer to write to memory
169
+ * _from_buffer to build a python object
170
+ * post_init
171
+
172
+ **_from_buffer**
173
+
174
+ When accessing data inside compound object the _from_buffer method is used.
175
+ For scalar and string, python data is returned. For coumpund object,
176
+ XObjects are returned
177
+
178
+ **setters**
179
+ Setters uses to_buffer or _update to update existing data.
@@ -0,0 +1,16 @@
1
+ Architecture
2
+ ==============
3
+
4
+
5
+
6
+ The architucture is based on
7
+
8
+ * Context managers implementing buffer, compilation, running
9
+ * Type system to specify data layout and user API
10
+
11
+
12
+ .. toctree::
13
+ :maxdepth: 2
14
+
15
+ architecture/contexts
16
+ architecture/types