xobjects 0.4.6__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.6 → xobjects-0.4.7}/PKG-INFO +1 -1
- xobjects-0.4.7/xobjects/_version.py +1 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/test_helpers.py +4 -2
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects.egg-info/PKG-INFO +1 -1
- {xobjects-0.4.6 → xobjects-0.4.7}/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.4.7}/LICENSE +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/pyproject.toml +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/setup.cfg +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/setup.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_align.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_array.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_buffer.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_capi.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_chunk.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_context_opencl.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_hybrid_class.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_kernel.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_linked_array.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_nplike_arrays.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_ref.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_scalars.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_shared_memory.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_strides.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_string.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_struct.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_to_json.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_typeutils.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/tests/test_unionref.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/__init__.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/_patch_pyopencl_array.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/array.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/capi.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/context.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/context_cpu.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/context_cupy.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/context_pyopencl.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/general.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/hybrid_class.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/linkedarray.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/ref.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/scalar.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/specialize_source.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/string.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/struct.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/typeutils.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects/union.py +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects.egg-info/dependency_links.txt +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects.egg-info/requires.txt +0 -0
- {xobjects-0.4.6 → xobjects-0.4.7}/xobjects.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.4.7"
|
|
@@ -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)
|
|
@@ -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
|